From 8c408d3d34cfdb36ba59445b892b95111a78b33a Mon Sep 17 00:00:00 2001 From: Anamika T S Date: Mon, 29 Apr 2024 12:28:19 +0530 Subject: [PATCH 1/3] refactor(NonLineraReading): add typescript types --- .../{NonLinearReading.js => NonLinearReading.tsx} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename packages/ibm-products/src/components/NonLinearReading/{NonLinearReading.js => NonLinearReading.tsx} (100%) diff --git a/packages/ibm-products/src/components/NonLinearReading/NonLinearReading.js b/packages/ibm-products/src/components/NonLinearReading/NonLinearReading.tsx similarity index 100% rename from packages/ibm-products/src/components/NonLinearReading/NonLinearReading.js rename to packages/ibm-products/src/components/NonLinearReading/NonLinearReading.tsx From 5e027dacd9c466ecd3d8b518b9443fc9c3164a80 Mon Sep 17 00:00:00 2001 From: Anamika T S Date: Mon, 29 Apr 2024 12:29:35 +0530 Subject: [PATCH 2/3] refactor(NonLineraReading): add typescript types --- .../NonLinearReading/NonLinearReading.tsx | 41 +++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/packages/ibm-products/src/components/NonLinearReading/NonLinearReading.tsx b/packages/ibm-products/src/components/NonLinearReading/NonLinearReading.tsx index 46543b38d3..904fb4ed9a 100644 --- a/packages/ibm-products/src/components/NonLinearReading/NonLinearReading.tsx +++ b/packages/ibm-products/src/components/NonLinearReading/NonLinearReading.tsx @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import React, { useRef, useState } from 'react'; +import React, { PropsWithChildren, ReactNode, useRef, useState } from 'react'; import PropTypes from 'prop-types'; import cx from 'classnames'; @@ -19,19 +19,45 @@ import { pkg } from '../../settings'; const blockClass = `${pkg.prefix}--non-linear-reading`; const componentName = 'NonLinearReading'; -// Default values for props -const defaults = { - theme: 'light', -}; +type Theme = 'light' | 'dark'; +interface NonLinearReadingProps extends PropsWithChildren { + /** + * The keyword of the component appears as a pill. + */ + children: ReactNode; + + /** + * Provide an optional class to be applied to the containing node. + */ + className?: string; + /** + * The content that appears when the keyword is toggled open. + */ + definition: ReactNode; + + /** + * Determines the theme of the component. + */ + theme?: Theme; +} /** * Use non-linear reading when space is limited to share a * brief, at-a-glance, summary of a concept that may require * more explanation for some users. */ -export let NonLinearReading = React.forwardRef( +export let NonLinearReading = React.forwardRef< + HTMLSpanElement, + NonLinearReadingProps +>( ( - { children, className, definition, theme = defaults.theme, ...rest }, + { + children, + className, + definition, + theme = 'light', + ...rest + }: NonLinearReadingProps, ref ) => { const [isOpen, setOpen] = useState(false); @@ -79,6 +105,7 @@ NonLinearReading.propTypes = { /** * The keyword of the component appears as a pill. */ + children: PropTypes.node.isRequired, /** From 2970db05b826a9ff1cce6aa960fcc1f92c0892cb Mon Sep 17 00:00:00 2001 From: Anamika T S Date: Mon, 29 Apr 2024 20:18:25 +0530 Subject: [PATCH 3/3] refactor(NonLineraReading): review changes --- .../src/components/NonLinearReading/NonLinearReading.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ibm-products/src/components/NonLinearReading/NonLinearReading.tsx b/packages/ibm-products/src/components/NonLinearReading/NonLinearReading.tsx index 904fb4ed9a..98c4d41051 100644 --- a/packages/ibm-products/src/components/NonLinearReading/NonLinearReading.tsx +++ b/packages/ibm-products/src/components/NonLinearReading/NonLinearReading.tsx @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import React, { PropsWithChildren, ReactNode, useRef, useState } from 'react'; +import React, { ReactNode, useRef, useState } from 'react'; import PropTypes from 'prop-types'; import cx from 'classnames'; @@ -20,7 +20,7 @@ const blockClass = `${pkg.prefix}--non-linear-reading`; const componentName = 'NonLinearReading'; type Theme = 'light' | 'dark'; -interface NonLinearReadingProps extends PropsWithChildren { +interface NonLinearReadingProps { /** * The keyword of the component appears as a pill. */