-
-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(suite): Refactor InfoPair to InfoSegments (#15627)
- Loading branch information
Showing
8 changed files
with
103 additions
and
121 deletions.
There are no files selected for viewing
36 changes: 0 additions & 36 deletions
36
packages/components/src/components/InfoPair/InfoPair.stories.tsx
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
packages/components/src/components/InfoSegments/InfoSegments.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { | ||
InfoSegments as InfoSegmentsComponent, | ||
allowedInfoSegmentsFrameProps, | ||
allowedInfoSegmentsTextProps, | ||
InfoSegmentsProps, | ||
} from './InfoSegments'; | ||
import { getFramePropsStory } from '../../utils/frameProps'; | ||
import { getTextPropsStory } from '../typography/utils'; | ||
import { textVariants } from '../typography/Text/Text'; | ||
|
||
const meta: Meta = { | ||
title: 'InfoSegments', | ||
component: InfoSegmentsComponent, | ||
} as Meta; | ||
export default meta; | ||
|
||
export const InfoSegments: StoryObj<InfoSegmentsProps> = { | ||
args: { | ||
children: ['Left', 'Right'], | ||
...getFramePropsStory(allowedInfoSegmentsFrameProps).args, | ||
...getTextPropsStory(allowedInfoSegmentsTextProps).args, | ||
}, | ||
argTypes: { | ||
variant: { | ||
control: { | ||
type: 'select', | ||
}, | ||
options: textVariants, | ||
}, | ||
...getFramePropsStory(allowedInfoSegmentsFrameProps).argTypes, | ||
...getTextPropsStory(allowedInfoSegmentsTextProps).argTypes, | ||
}, | ||
}; |
36 changes: 36 additions & 0 deletions
36
packages/components/src/components/InfoSegments/InfoSegments.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { ReactNode, Children } from 'react'; | ||
|
||
import { spacings } from '@trezor/theme'; | ||
|
||
import { FrameProps, FramePropsKeys } from '../../utils/frameProps'; | ||
import { TextPropsKeys, TextProps } from '../typography/utils'; | ||
import { Text, TextVariant } from '../typography/Text/Text'; | ||
import { Row } from '../Flex/Flex'; | ||
|
||
export const allowedInfoSegmentsTextProps = ['typographyStyle'] as const satisfies TextPropsKeys[]; | ||
type AllowedTextProps = Pick<TextProps, (typeof allowedInfoSegmentsTextProps)[number]>; | ||
|
||
export const allowedInfoSegmentsFrameProps = ['margin'] as const satisfies FramePropsKeys[]; | ||
type AllowedFrameProps = Pick<FrameProps, (typeof allowedInfoSegmentsFrameProps)[number]>; | ||
|
||
export type InfoSegmentsProps = AllowedFrameProps & | ||
AllowedTextProps & { | ||
variant?: TextVariant; | ||
} & { children: Array<ReactNode> }; | ||
|
||
export const InfoSegments = ({ children, typographyStyle, variant, margin }: InfoSegmentsProps) => { | ||
const validChildren = Children.toArray(children).filter(child => Boolean(child)); | ||
|
||
return ( | ||
<Text as="div" typographyStyle={typographyStyle} margin={margin} variant={variant}> | ||
<Row gap={spacings.xxs}> | ||
{validChildren.map((child, index) => ( | ||
<> | ||
{child} | ||
{index < validChildren.length - 1 && <span>•</span>} | ||
</> | ||
))} | ||
</Row> | ||
</Text> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
packages/suite/src/components/suite/FormattedDateWithBullet.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { InfoPair } from '@trezor/components'; | ||
import { InfoSegments } from '@trezor/components'; | ||
|
||
import { FormattedDate, FormattedDateProps } from './FormattedDate'; | ||
|
||
export const FormattedDateWithBullet = ({ ...props }: FormattedDateProps) => ( | ||
<InfoPair | ||
leftContent={<FormattedDate date {...props} />} | ||
rightContent={<FormattedDate time {...props} />} | ||
/> | ||
<InfoSegments> | ||
<FormattedDate date {...props} /> | ||
<FormattedDate time {...props} /> | ||
</InfoSegments> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters