Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(NonLinearReading): add typescript types #4993

Merged
merged 4 commits into from
Apr 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import React, { useRef, useState } from 'react';
import React, { ReactNode, useRef, useState } from 'react';

import PropTypes from 'prop-types';
import cx from 'classnames';
Expand All @@ -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 {
/**
* The keyword of the component appears as a pill.
*/
children: ReactNode;
anamikaanu96 marked this conversation as resolved.
Show resolved Hide resolved

/**
* 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);
Expand Down Expand Up @@ -79,6 +105,7 @@ NonLinearReading.propTypes = {
/**
* The keyword of the component appears as a pill.
*/

children: PropTypes.node.isRequired,

/**
Expand Down
Loading