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

Migrate component to TS: Tag #20086

Merged
merged 18 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Tag should render the label inside the tag and match snapshot 1`] = `
<div>
<div
class="mm-box mm-tag mm-box--padding-right-1 mm-box--padding-left-1 mm-box--display-inline-block mm-box--justify-content-center mm-box--align-items-center mm-box--background-color-background-default mm-box--rounded-pill mm-box--border-color-border-default mm-box--border-width-1 box--border-style-solid"
data-testid="tag"
>
<p
class="mm-box mm-text mm-text--body-sm mm-box--color-text-default"
>
Imported
</p>
</div>
</div>
`;
1 change: 0 additions & 1 deletion ui/components/component-library/tag/index.js

This file was deleted.

2 changes: 2 additions & 0 deletions ui/components/component-library/tag/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { Tag } from './tag';
export type { TagProps } from './tag.types';
55 changes: 0 additions & 55 deletions ui/components/component-library/tag/tag.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -19,13 +19,13 @@ export default {
args: {
label: 'Imported',
},
};
} as Meta<typeof Tag>;

export const DefaultStory = (args) => <Tag {...args} />;
export const DefaultStory: StoryFn<typeof Tag> = (args) => <Tag {...args} />;

DefaultStory.storyName = 'Default';

export const Label = (args) => <Tag {...args}>Anchor Element</Tag>;
export const Label: StoryFn<typeof Tag> = (args) => <Tag {...args} />;

Label.args = {
label: 'Label Story',
Expand Down
44 changes: 44 additions & 0 deletions ui/components/component-library/tag/tag.tsx
Original file line number Diff line number Diff line change
@@ -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(
<C extends React.ElementType = 'div'>(
{ label, className = '', labelProps, ...props }: TagProps<C>,
ref: PolymorphicRef<C>,
) => {
return (
<Box
ref={ref}
className={classnames('mm-tag', className)}
backgroundColor={BackgroundColor.backgroundDefault}
borderColor={BorderColor.borderDefault}
borderWidth={1}
justifyContent={JustifyContent.center}
alignItems={AlignItems.center}
paddingLeft={1}
paddingRight={1}
borderRadius={BorderRadius.pill}
display={Display.InlineBlock}
{...(props as BoxProps<C>)}
>
<Text variant={TextVariant.bodySm} {...labelProps}>
{label}
</Text>
</Box>
);
},
);
27 changes: 27 additions & 0 deletions ui/components/component-library/tag/tag.types.ts
Original file line number Diff line number Diff line change
@@ -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;
dhruvv173 marked this conversation as resolved.
Show resolved Hide resolved
/**
* The label props of the component. Most Text component props can be used
*/
labelProps?: TextProps<ValidTagType>;
/**
* Additional classNames to be added to the Tag component
*/
className?: string;
}

export type TagProps<C extends React.ElementType> =
PolymorphicComponentPropWithRef<C, TagStyleUtilityProps>;

export type TagComponent = <C extends React.ElementType = 'div'>(
dhruvv173 marked this conversation as resolved.
Show resolved Hide resolved
props: TagProps<C>,
) => React.ReactElement | null;
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ exports[`SnapAccountDetails should take a snapshot 1`] = `
/>
</div>
<div
class="box mm-tag box--margin-right-1 box--padding-right-1 box--padding-left-1 box--display-inline-block box--flex-direction-row box--justify-content-center box--align-items-center box--color-info-default box--background-color-info-muted box--rounded-pill box--border-color-info-muted box--border-width-1 box--border-style-solid"
class="mm-box mm-tag mm-box--margin-right-1 mm-box--padding-right-1 mm-box--padding-left-1 mm-box--display-inline-block mm-box--justify-content-center mm-box--align-items-center mm-box--color-info-default mm-box--background-color-info-muted mm-box--rounded-pill mm-box--border-color-info-muted mm-box--border-width-1 box--border-style-solid"
>
<p
class="mm-box mm-text mm-text--body-sm mm-box--color-info-default"
Expand All @@ -83,7 +83,7 @@ exports[`SnapAccountDetails should take a snapshot 1`] = `
</p>
</div>
<div
class="box mm-tag box--padding-right-1 box--padding-left-1 box--display-inline-block box--flex-direction-row box--justify-content-center box--align-items-center box--color-info-default box--background-color-info-muted box--rounded-pill box--border-color-info-muted box--border-width-1 box--border-style-solid"
class="mm-box mm-tag mm-box--padding-right-1 mm-box--padding-left-1 mm-box--display-inline-block mm-box--justify-content-center mm-box--align-items-center mm-box--color-info-default mm-box--background-color-info-muted mm-box--rounded-pill mm-box--border-color-info-muted mm-box--border-width-1 box--border-style-solid"
>
<p
class="mm-box mm-text mm-text--body-sm mm-box--color-info-default"
Expand Down Expand Up @@ -135,7 +135,7 @@ exports[`SnapAccountDetails should take a snapshot 1`] = `
Tags
</p>
<div
class="box mm-tag box--margin-right-1 box--padding-right-1 box--padding-left-1 box--display-inline-block box--flex-direction-row box--justify-content-center box--align-items-center box--background-color-background-default box--rounded-pill box--border-color-border-default box--border-width-1 box--border-style-solid"
class="mm-box mm-tag mm-box--margin-right-1 mm-box--padding-right-1 mm-box--padding-left-1 mm-box--display-inline-block mm-box--justify-content-center mm-box--align-items-center mm-box--background-color-background-default mm-box--rounded-pill mm-box--border-color-border-default mm-box--border-width-1 box--border-style-solid"
>
<p
class="mm-box mm-text mm-text--body-sm mm-box--color-text-alternative"
Expand Down
6 changes: 2 additions & 4 deletions ui/pages/keyring-snaps/snap-account-detail-page/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ export const SnapDetailHeader = ({
labelProps={{
color: TextColor.textAlternative,
}}
className=""
height={2}
/>
)}
</Box>
Expand Down Expand Up @@ -152,7 +150,7 @@ export const SnapDetailHeader = ({
<Tag
color={TextColor.infoDefault}
backgroundColor={BackgroundColor.infoMuted}
borderColor={BackgroundColor.infoMuted}
borderColor={BorderColor.infoMuted}
label={
<Box
display={Display.Flex}
Expand Down Expand Up @@ -180,7 +178,7 @@ export const SnapDetailHeader = ({
className=""
color={TextColor.infoDefault}
backgroundColor={BackgroundColor.infoMuted}
borderColor={BackgroundColor.infoMuted}
borderColor={BorderColor.infoMuted}
label={
<Box
display={Display.Flex}
Expand Down