-
-
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.
chore(suite): refactor transaction details modal
- Loading branch information
Showing
42 changed files
with
1,206 additions
and
1,550 deletions.
There are no files selected for viewing
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
105 changes: 105 additions & 0 deletions
105
packages/components/src/components/InfoItem/InfoItem.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,105 @@ | ||
import { ReactNode } from 'react'; | ||
|
||
import styled from 'styled-components'; | ||
|
||
import { spacings, TypographyStyle } from '@trezor/theme'; | ||
|
||
import { | ||
FrameProps, | ||
FramePropsKeys, | ||
pickAndPrepareFrameProps, | ||
withFrameProps, | ||
} from '../../utils/frameProps'; | ||
import { TextPropsKeys, TextProps } from '../typography/utils'; | ||
import { TransientProps } from '../../utils/transientProps'; | ||
import { FlexDirection, Flex, Row, FlexAlignItems } from '../Flex/Flex'; | ||
import { IconName, Icon } from '../Icon/Icon'; | ||
import { Text } from '../typography/Text/Text'; | ||
import { UIVerticalAlignment } from '../../config/types'; | ||
|
||
export const allowedInfoItemTextProps = ['typographyStyle'] as const satisfies TextPropsKeys[]; | ||
type AllowedTextProps = Pick<TextProps, (typeof allowedInfoItemTextProps)[number]>; | ||
|
||
export const allowedInfoItemFrameProps = ['margin'] as const satisfies FramePropsKeys[]; | ||
type AllowedFrameProps = Pick<FrameProps, (typeof allowedInfoItemFrameProps)[number]>; | ||
|
||
export const verticalAlignments = ['top', 'center', 'bottom'] as const; | ||
type VerticalAlignment = Extract<UIVerticalAlignment, (typeof verticalAlignments)[number]>; | ||
|
||
const mapVerticalAlignmentToAlignItems = (verticalAlignment: VerticalAlignment): FlexAlignItems => { | ||
const alignItemsMap: Record<VerticalAlignment, FlexAlignItems> = { | ||
top: 'baseline', | ||
center: 'center', | ||
bottom: 'flex-end', | ||
}; | ||
|
||
return alignItemsMap[verticalAlignment]; | ||
}; | ||
|
||
type ContainerProps = TransientProps<AllowedFrameProps & AllowedTextProps>; | ||
|
||
const Container = styled.div<ContainerProps>` | ||
width: 100%; | ||
${withFrameProps} | ||
`; | ||
|
||
export type InfoItemProps = AllowedFrameProps & | ||
AllowedTextProps & { | ||
children?: ReactNode; | ||
direction?: FlexDirection; | ||
iconName?: IconName; | ||
label: ReactNode; | ||
labelTypographyStyle?: TypographyStyle; | ||
labelWidth?: string | number; | ||
verticalAlignment?: VerticalAlignment; | ||
}; | ||
|
||
export const InfoItem = ({ | ||
children, | ||
label, | ||
direction = 'column', | ||
iconName, | ||
typographyStyle = 'body', | ||
labelTypographyStyle = 'hint', | ||
labelWidth, | ||
verticalAlignment = 'center', | ||
...rest | ||
}: InfoItemProps) => { | ||
const frameProps = pickAndPrepareFrameProps(rest, allowedInfoItemFrameProps); | ||
const isRow = direction === 'row'; | ||
|
||
return ( | ||
<Container {...frameProps}> | ||
<Flex | ||
direction={direction} | ||
alignItems={isRow ? mapVerticalAlignmentToAlignItems(verticalAlignment) : 'normal'} | ||
gap={isRow ? spacings.md : spacings.xxxs} | ||
> | ||
<Row | ||
gap={spacings.xxs} | ||
width={labelWidth} | ||
flex={labelWidth ? '0 0 auto' : '1 0 auto'} | ||
> | ||
{iconName && <Icon name={iconName} size="medium" variant="tertiary" />} | ||
<Text | ||
variant="tertiary" | ||
typographyStyle={labelTypographyStyle} | ||
as="div" | ||
ellipsisLineCount={1} | ||
> | ||
{label} | ||
</Text> | ||
</Row> | ||
<Text | ||
as="div" | ||
typographyStyle={typographyStyle} | ||
align={isRow && !labelWidth ? 'right' : 'left'} | ||
ellipsisLineCount={isRow ? 1 : undefined} | ||
> | ||
{children} | ||
</Text> | ||
</Flex> | ||
</Container> | ||
); | ||
}; |
36 changes: 36 additions & 0 deletions
36
packages/components/src/components/InfoPair/InfoPair.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,36 @@ | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { | ||
InfoPair as InfoPairComponent, | ||
allowedInfoPairFrameProps, | ||
allowedInfoPairTextProps, | ||
InfoPairProps, | ||
} from './InfoPair'; | ||
import { getFramePropsStory } from '../../utils/frameProps'; | ||
import { getTextPropsStory } from '../typography/utils'; | ||
import { textVariants } from '../typography/Text/Text'; | ||
|
||
const meta: Meta = { | ||
title: 'InfoPair', | ||
component: InfoPairComponent, | ||
} as Meta; | ||
export default meta; | ||
|
||
export const InfoPair: StoryObj<InfoPairProps> = { | ||
args: { | ||
leftContent: 'Left', | ||
rightContent: 'Right', | ||
...getFramePropsStory(allowedInfoPairFrameProps).args, | ||
...getTextPropsStory(allowedInfoPairTextProps).args, | ||
}, | ||
argTypes: { | ||
variant: { | ||
control: { | ||
type: 'select', | ||
}, | ||
options: textVariants, | ||
}, | ||
...getFramePropsStory(allowedInfoPairFrameProps).argTypes, | ||
...getTextPropsStory(allowedInfoPairTextProps).argTypes, | ||
}, | ||
}; |
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,40 @@ | ||
import { ReactNode } 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 allowedInfoPairTextProps = ['typographyStyle'] as const satisfies TextPropsKeys[]; | ||
type AllowedTextProps = Pick<TextProps, (typeof allowedInfoPairTextProps)[number]>; | ||
|
||
export const allowedInfoPairFrameProps = ['margin'] as const satisfies FramePropsKeys[]; | ||
type AllowedFrameProps = Pick<FrameProps, (typeof allowedInfoPairFrameProps)[number]>; | ||
|
||
export type InfoPairProps = AllowedFrameProps & | ||
AllowedTextProps & { | ||
variant?: TextVariant; | ||
} & ( | ||
| { leftContent: ReactNode; rightContent?: ReactNode } | ||
| { leftContent?: ReactNode; rightContent: ReactNode } | ||
); | ||
|
||
export const InfoPair = ({ | ||
leftContent, | ||
rightContent, | ||
typographyStyle, | ||
variant, | ||
margin, | ||
}: InfoPairProps) => { | ||
return ( | ||
<Text as="div" typographyStyle={typographyStyle} margin={margin} variant={variant}> | ||
<Row gap={spacings.xxs}> | ||
{leftContent} | ||
{leftContent && rightContent && <span>•</span>} | ||
{rightContent} | ||
</Row> | ||
</Text> | ||
); | ||
}; |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.