From edbc728014c7eca3a0327e8ae979d461d6f3f336 Mon Sep 17 00:00:00 2001 From: Dhruv <79097544+dhruvv173@users.noreply.github.com> Date: Tue, 25 Jul 2023 02:12:10 +0530 Subject: [PATCH] Migrate component to TS: Tag (#20086) * migrating Tag to TS --------- Co-authored-by: Garrett Bear --- .../tag/__snapshots__/tag.test.js.snap | 16 ------ .../tag/__snapshots__/tag.test.tsx.snap | 16 ++++++ ui/components/component-library/tag/index.js | 1 - ui/components/component-library/tag/index.ts | 2 + ui/components/component-library/tag/tag.js | 55 ------------------- .../tag/{tag.stories.js => tag.stories.tsx} | 10 ++-- .../tag/{tag.test.js => tag.test.tsx} | 0 ui/components/component-library/tag/tag.tsx | 44 +++++++++++++++ .../component-library/tag/tag.types.ts | 27 +++++++++ .../snap-account-detail-page.test.tsx.snap | 6 +- .../snap-account-detail-page/header.tsx | 6 +- 11 files changed, 99 insertions(+), 84 deletions(-) delete mode 100644 ui/components/component-library/tag/__snapshots__/tag.test.js.snap create mode 100644 ui/components/component-library/tag/__snapshots__/tag.test.tsx.snap delete mode 100644 ui/components/component-library/tag/index.js create mode 100644 ui/components/component-library/tag/index.ts delete mode 100644 ui/components/component-library/tag/tag.js rename ui/components/component-library/tag/{tag.stories.js => tag.stories.tsx} (65%) rename ui/components/component-library/tag/{tag.test.js => tag.test.tsx} (100%) create mode 100644 ui/components/component-library/tag/tag.tsx create mode 100644 ui/components/component-library/tag/tag.types.ts diff --git a/ui/components/component-library/tag/__snapshots__/tag.test.js.snap b/ui/components/component-library/tag/__snapshots__/tag.test.js.snap deleted file mode 100644 index e0d709483..000000000 --- a/ui/components/component-library/tag/__snapshots__/tag.test.js.snap +++ /dev/null @@ -1,16 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Tag should render the label inside the tag and match snapshot 1`] = ` -
-
-

- Imported -

-
-
-`; diff --git a/ui/components/component-library/tag/__snapshots__/tag.test.tsx.snap b/ui/components/component-library/tag/__snapshots__/tag.test.tsx.snap new file mode 100644 index 000000000..543be6c92 --- /dev/null +++ b/ui/components/component-library/tag/__snapshots__/tag.test.tsx.snap @@ -0,0 +1,16 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Tag should render the label inside the tag and match snapshot 1`] = ` +
+
+

+ Imported +

+
+
+`; diff --git a/ui/components/component-library/tag/index.js b/ui/components/component-library/tag/index.js deleted file mode 100644 index e533e2003..000000000 --- a/ui/components/component-library/tag/index.js +++ /dev/null @@ -1 +0,0 @@ -export { Tag } from './tag'; diff --git a/ui/components/component-library/tag/index.ts b/ui/components/component-library/tag/index.ts new file mode 100644 index 000000000..262ac21d4 --- /dev/null +++ b/ui/components/component-library/tag/index.ts @@ -0,0 +1,2 @@ +export { Tag } from './tag'; +export type { TagProps } from './tag.types'; diff --git a/ui/components/component-library/tag/tag.js b/ui/components/component-library/tag/tag.js deleted file mode 100644 index da927ba02..000000000 --- a/ui/components/component-library/tag/tag.js +++ /dev/null @@ -1,55 +0,0 @@ -import React from 'react'; -import PropTypes from 'prop-types'; -import classnames from 'classnames'; -import { - AlignItems, - BackgroundColor, - BorderColor, - BorderRadius, - DISPLAY, - JustifyContent, - TextVariant, -} from '../../../helpers/constants/design-system'; -import Box from '../../ui/box/box'; -import { Text } from '..'; - -export const Tag = ({ label, className, labelProps, ...props }) => { - return ( - - - {label} - - - ); -}; - -Tag.propTypes = { - /** - * The text content of the Tag component - */ - label: PropTypes.string, - /** - * The label props of the component. Most Text component props can be used - */ - labelProps: PropTypes.object, - /** - * Additional classNames to be added to the Tag component - */ - className: PropTypes.string, - /** - * Tag also accepts all props from Box - */ - ...Box.propTypes, -}; diff --git a/ui/components/component-library/tag/tag.stories.js b/ui/components/component-library/tag/tag.stories.tsx similarity index 65% rename from ui/components/component-library/tag/tag.stories.js rename to ui/components/component-library/tag/tag.stories.tsx index 51c3604ef..7dae10a33 100644 --- a/ui/components/component-library/tag/tag.stories.js +++ b/ui/components/component-library/tag/tag.stories.tsx @@ -1,10 +1,10 @@ import React from 'react'; -import README from './README.mdx'; +import { StoryFn, Meta } from '@storybook/react'; import { Tag } from './tag'; +import README from './README.mdx'; export default { title: 'Components/ComponentLibrary/Tag', - component: Tag, parameters: { docs: { @@ -19,13 +19,13 @@ export default { args: { label: 'Imported', }, -}; +} as Meta; -export const DefaultStory = (args) => ; +export const DefaultStory: StoryFn = (args) => ; DefaultStory.storyName = 'Default'; -export const Label = (args) => Anchor Element; +export const Label: StoryFn = (args) => ; Label.args = { label: 'Label Story', diff --git a/ui/components/component-library/tag/tag.test.js b/ui/components/component-library/tag/tag.test.tsx similarity index 100% rename from ui/components/component-library/tag/tag.test.js rename to ui/components/component-library/tag/tag.test.tsx diff --git a/ui/components/component-library/tag/tag.tsx b/ui/components/component-library/tag/tag.tsx new file mode 100644 index 000000000..4077889b7 --- /dev/null +++ b/ui/components/component-library/tag/tag.tsx @@ -0,0 +1,44 @@ +import React from 'react'; +import classnames from 'classnames'; +import { Text, Box } from '..'; +import type { PolymorphicRef, BoxProps } from '../box'; + +import { + AlignItems, + BackgroundColor, + BorderColor, + BorderRadius, + Display, + JustifyContent, + TextVariant, +} from '../../../helpers/constants/design-system'; + +import { TagComponent, TagProps } from './tag.types'; + +export const Tag: TagComponent = React.forwardRef( + ( + { label, className = '', labelProps, ...props }: TagProps, + ref: PolymorphicRef, + ) => { + return ( + )} + > + + {label} + + + ); + }, +); diff --git a/ui/components/component-library/tag/tag.types.ts b/ui/components/component-library/tag/tag.types.ts new file mode 100644 index 000000000..ca2d748b4 --- /dev/null +++ b/ui/components/component-library/tag/tag.types.ts @@ -0,0 +1,27 @@ +import { TextProps, ValidTagType } from '../text/text.types'; +import type { + StyleUtilityProps, + PolymorphicComponentPropWithRef, +} from '../box'; + +export interface TagStyleUtilityProps extends StyleUtilityProps { + /** + * The text content of the Tag component, can either be a string or ReactNode + */ + label?: string | React.ReactNode; + /** + * The label props of the component. Most Text component props can be used + */ + labelProps?: TextProps; + /** + * Additional classNames to be added to the Tag component + */ + className?: string; +} + +export type TagProps = + PolymorphicComponentPropWithRef; + +export type TagComponent = ( + props: TagProps, +) => React.ReactElement | null; diff --git a/ui/pages/keyring-snaps/snap-account-detail-page/__snapshots__/snap-account-detail-page.test.tsx.snap b/ui/pages/keyring-snaps/snap-account-detail-page/__snapshots__/snap-account-detail-page.test.tsx.snap index 2cf92a640..3aa813a67 100644 --- a/ui/pages/keyring-snaps/snap-account-detail-page/__snapshots__/snap-account-detail-page.test.tsx.snap +++ b/ui/pages/keyring-snaps/snap-account-detail-page/__snapshots__/snap-account-detail-page.test.tsx.snap @@ -61,7 +61,7 @@ exports[`SnapAccountDetails should take a snapshot 1`] = ` />

)} @@ -152,7 +150,7 @@ export const SnapDetailHeader = ({