-
-
Notifications
You must be signed in to change notification settings - Fork 11
feat: [DSRN ]Added TitleStandard #1051
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
22350b8
Added TitleStandard to DSRN
brianacnguyen ec63d5b
Fixed lint errors
brianacnguyen ad74ecb
Merge branch 'main' of github.com:MetaMask/metamask-design-system int…
brianacnguyen 14e03a2
Added end Accessory to both title and bottomLabel
brianacnguyen 5b517ef
Updated readmes
brianacnguyen 4b21f9f
Merge branch 'main' of github.com:MetaMask/metamask-design-system int…
brianacnguyen f78d77e
Merge branch 'main' of github.com:MetaMask/metamask-design-system int…
brianacnguyen 831043d
Merge branch 'main' of github.com:MetaMask/metamask-design-system int…
brianacnguyen c00bdae
Simplied TitleStandard
brianacnguyen 6a2cedc
Updated TitleStandard based on new rules
brianacnguyen a806803
Merge branch 'main' into dsrn/titlestandard
brianacnguyen f01b203
Updated TitleStandard based on feedback
brianacnguyen 54dcb42
Merge branch 'main' of github.com:MetaMask/metamask-design-system int…
brianacnguyen 15d427d
Merge branch 'dsrn/titlestandard' of github.com:MetaMask/metamask-des…
brianacnguyen 3de41fc
Removed extra types
brianacnguyen 28cfdb2
Merge branch 'main' of github.com:MetaMask/metamask-design-system int…
brianacnguyen b7af38d
Updated based on suggestions
brianacnguyen 771b99e
Merge branch 'main' into dsrn/titlestandard
brianacnguyen 8b4c60b
Merge branch 'main' of github.com:MetaMask/metamask-design-system int…
brianacnguyen 7bad20a
Updated TitleStandard based on feedback
brianacnguyen c7bcdcc
Merge branch 'dsrn/titlestandard' of github.com:MetaMask/metamask-des…
brianacnguyen aed148c
Merge branch 'main' of github.com:MetaMask/metamask-design-system int…
brianacnguyen d28279b
Merge branch 'main' of github.com:MetaMask/metamask-design-system int…
brianacnguyen e906687
Removed storybook requires from merge
brianacnguyen 6a9454d
Merge branch 'main' of github.com:MetaMask/metamask-design-system int…
brianacnguyen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
241 changes: 241 additions & 0 deletions
241
packages/design-system-react-native/src/components/TitleStandard/README.md
This file contains hidden or 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,241 @@ | ||
| # TitleStandard | ||
|
|
||
| TitleStandard is used to display a required primary title with optional rows above and below the title, optional inline accessories next to the title and bottom label, and optional bottom label or custom bottom content. | ||
|
|
||
| ```tsx | ||
| import { TitleStandard } from '@metamask/design-system-react-native'; | ||
|
|
||
| <TitleStandard title="$4.42" />; | ||
| ``` | ||
|
|
||
| Cross-platform layout props are defined as `TitleStandardPropsShared` in `@metamask/design-system-shared`. This package adds `twClassName`, React Native `View` props, and `titleProps` / `bottomLabelProps` for the platform `Text` component. | ||
|
|
||
| ## Props | ||
|
|
||
| ### `title` | ||
|
|
||
| The primary title. The title row always renders. When `title` is a string, it is wrapped with heading typography (`TextVariant.HeadingLg` and `titleProps`); other `ReactNode` values render as provided. | ||
|
|
||
| | TYPE | REQUIRED | DEFAULT | | ||
| | ----------- | -------- | ------- | | ||
| | `ReactNode` | Yes | — | | ||
|
|
||
| ```tsx | ||
| <TitleStandard title="$1,234.56" /> | ||
| ``` | ||
|
|
||
| ### `titleEndAccessory` | ||
|
|
||
| Optional node rendered to the right of the title (for example an info icon). | ||
|
|
||
| | TYPE | REQUIRED | DEFAULT | | ||
| | ----------- | -------- | ----------- | | ||
| | `ReactNode` | No | `undefined` | | ||
|
|
||
| ```tsx | ||
| import { | ||
| TitleStandard, | ||
| Box, | ||
| Icon, | ||
| IconName, | ||
| IconSize, | ||
| } from '@metamask/design-system-react-native'; | ||
|
|
||
| <TitleStandard | ||
| title="$4.42" | ||
| titleEndAccessory={ | ||
| <Box twClassName="ml-2"> | ||
| <Icon name={IconName.Info} size={IconSize.Md} /> | ||
| </Box> | ||
| } | ||
| />; | ||
| ``` | ||
|
|
||
| ### `topAccessory` | ||
|
|
||
| Optional row above the title (for example secondary label text or a row with icons). | ||
|
|
||
| | TYPE | REQUIRED | DEFAULT | | ||
| | ----------- | -------- | ----------- | | ||
| | `ReactNode` | No | `undefined` | | ||
|
|
||
| ```tsx | ||
| import { | ||
| TitleStandard, | ||
| Text, | ||
| TextVariant, | ||
| TextColor, | ||
| FontWeight, | ||
| } from '@metamask/design-system-react-native'; | ||
|
|
||
| <TitleStandard | ||
| topAccessory={ | ||
| <Text | ||
| variant={TextVariant.BodySm} | ||
| fontWeight={FontWeight.Medium} | ||
| color={TextColor.TextAlternative} | ||
| > | ||
| Send | ||
| </Text> | ||
| } | ||
| title="$4.42" | ||
| bottomLabel="0.002 ETH" | ||
| />; | ||
| ``` | ||
|
|
||
| ### `bottomLabel` | ||
|
|
||
| Optional bottom row with secondary label typography when the value is a string (`BodySm`, medium, `TextColor.TextAlternative`). If `bottomLabel` is renderable, `bottomAccessory` is not shown. | ||
|
|
||
| | TYPE | REQUIRED | DEFAULT | | ||
| | ----------- | -------- | ----------- | | ||
| | `ReactNode` | No | `undefined` | | ||
|
|
||
| ```tsx | ||
| <TitleStandard title="$4.42" bottomLabel="0.002 ETH" /> | ||
| ``` | ||
|
|
||
| ### `bottomLabelEndAccessory` | ||
|
|
||
| Optional node rendered to the right of the bottom label. Only used when `bottomLabel` is renderable (same row as the default bottom label typography). | ||
|
|
||
| | TYPE | REQUIRED | DEFAULT | | ||
| | ----------- | -------- | ----------- | | ||
| | `ReactNode` | No | `undefined` | | ||
|
|
||
| ```tsx | ||
| import { | ||
| TitleStandard, | ||
| Box, | ||
| Icon, | ||
| IconName, | ||
| IconSize, | ||
| IconColor, | ||
| } from '@metamask/design-system-react-native'; | ||
|
|
||
| <TitleStandard | ||
| title="$4.42" | ||
| bottomLabel="0.002 ETH" | ||
| bottomLabelEndAccessory={ | ||
| <Box twClassName="ml-2"> | ||
| <Icon | ||
| name={IconName.Info} | ||
| size={IconSize.Sm} | ||
| color={IconColor.IconAlternative} | ||
| /> | ||
| </Box> | ||
|
brianacnguyen marked this conversation as resolved.
Outdated
|
||
| } | ||
| />; | ||
| ``` | ||
|
|
||
| ### `bottomAccessory` | ||
|
|
||
| Optional custom bottom row when `bottomLabel` is not renderable. Renders without default label typography; compose layout inside the node. | ||
|
|
||
| | TYPE | REQUIRED | DEFAULT | | ||
| | ----------- | -------- | ----------- | | ||
| | `ReactNode` | No | `undefined` | | ||
|
|
||
| ```tsx | ||
| import { | ||
| TitleStandard, | ||
| Box, | ||
| BoxFlexDirection, | ||
| BoxAlignItems, | ||
| Icon, | ||
| IconName, | ||
| IconSize, | ||
| Text, | ||
| TextVariant, | ||
| } from '@metamask/design-system-react-native'; | ||
|
|
||
| <TitleStandard | ||
| title="$4.42" | ||
| bottomAccessory={ | ||
| <Box | ||
| flexDirection={BoxFlexDirection.Row} | ||
| alignItems={BoxAlignItems.Center} | ||
| gap={1} | ||
| > | ||
| <Icon name={IconName.Gas} size={IconSize.Xs} /> | ||
| <Text variant={TextVariant.BodySm}>~$0.50 fee</Text> | ||
| </Box> | ||
| } | ||
| />; | ||
| ``` | ||
|
|
||
| ### `titleProps` | ||
|
|
||
| Optional props merged into the heading `Text` when `title` is a string. Use for `testID` or typography overrides. | ||
|
|
||
| | TYPE | REQUIRED | DEFAULT | | ||
| | -------------------- | -------- | ----------- | | ||
| | `Partial<TextProps>` | No | `undefined` | | ||
|
|
||
| ```tsx | ||
| <TitleStandard title="$4.42" titleProps={{ testID: 'title-standard-title' }} /> | ||
| ``` | ||
|
|
||
| ### `bottomLabelProps` | ||
|
|
||
| Optional props merged into the bottom label `Text` when `bottomLabel` is a string. | ||
|
|
||
| | TYPE | REQUIRED | DEFAULT | | ||
| | -------------------- | -------- | ----------- | | ||
| | `Partial<TextProps>` | No | `undefined` | | ||
|
|
||
| ```tsx | ||
| <TitleStandard | ||
| title="$4.42" | ||
| bottomLabel="0.002 ETH" | ||
| bottomLabelProps={{ testID: 'title-standard-bottom' }} | ||
| /> | ||
| ``` | ||
|
|
||
| ### `twClassName` | ||
|
|
||
| Use the `twClassName` prop to add Tailwind CSS classes to the component. These classes will be merged with the component's default classes using `tw.style()`, allowing you to: | ||
|
|
||
| - Add new styles that don't exist in the default component | ||
| - Override the component's default styles when needed | ||
|
|
||
| | TYPE | REQUIRED | DEFAULT | | ||
| | -------- | -------- | ----------- | | ||
| | `string` | No | `undefined` | | ||
|
|
||
| ```tsx | ||
| // Add additional styles | ||
| <TitleStandard twClassName="mt-4" title="$4.42" /> | ||
|
|
||
| // Override default styles | ||
| <TitleStandard twClassName="px-6" title="$4.42" /> | ||
| ``` | ||
|
|
||
| ### `style` | ||
|
|
||
| Use the `style` prop to customize the component's appearance with React Native styles. For consistent styling, prefer using `twClassName` with Tailwind classes when possible. Use `style` with `tw.style()` for conditionals or dynamic values. Other `View` props (for example `testID` and accessibility fields) are also accepted on the root container. | ||
|
|
||
| | TYPE | REQUIRED | DEFAULT | | ||
| | ---------------------- | -------- | ----------- | | ||
| | `StyleProp<ViewStyle>` | No | `undefined` | | ||
|
|
||
| ```tsx | ||
| import { useTailwind } from '@metamask/design-system-twrnc-preset'; | ||
|
|
||
| import { TitleStandard } from '@metamask/design-system-react-native'; | ||
|
|
||
| export const ConditionalExample = ({ isActive }: { isActive: boolean }) => { | ||
| const tw = useTailwind(); | ||
|
|
||
| return ( | ||
| <TitleStandard | ||
| title="$4.42" | ||
| style={tw.style('opacity-90', isActive && 'opacity-100')} | ||
| /> | ||
| ); | ||
| }; | ||
| ``` | ||
|
|
||
| ## References | ||
|
|
||
| [MetaMask Design System Guides](https://www.notion.so/MetaMask-Design-System-Guides-Design-f86ecc914d6b4eb6873a122b83c12940) | ||
139 changes: 139 additions & 0 deletions
139
packages/design-system-react-native/src/components/TitleStandard/TitleStandard.stories.tsx
This file contains hidden or 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,139 @@ | ||
| import type { Meta, StoryObj } from '@storybook/react-native'; | ||
| import React from 'react'; | ||
| import { View } from 'react-native'; | ||
|
|
||
| import { Box, BoxFlexDirection, BoxAlignItems } from '../Box'; | ||
| import { Icon, IconName, IconSize, IconColor } from '../Icon'; | ||
| import { Text, TextVariant, TextColor, FontWeight } from '../Text'; | ||
|
|
||
| import { TitleStandard } from './TitleStandard'; | ||
| import type { TitleStandardProps } from './TitleStandard.types'; | ||
|
|
||
| const meta: Meta<TitleStandardProps> = { | ||
| title: 'Components/TitleStandard', | ||
| component: TitleStandard, | ||
| argTypes: { | ||
| title: { | ||
| control: 'text', | ||
| }, | ||
| bottomLabel: { | ||
| control: 'text', | ||
| }, | ||
| }, | ||
| decorators: [ | ||
| (Story) => ( | ||
| <Box twClassName="w-full bg-background-default p-4"> | ||
| <Story /> | ||
| </Box> | ||
|
brianacnguyen marked this conversation as resolved.
|
||
| ), | ||
| ], | ||
| }; | ||
|
|
||
| export default meta; | ||
|
|
||
| type Story = StoryObj<TitleStandardProps>; | ||
|
|
||
| export const Default: Story = { | ||
| args: { | ||
|
brianacnguyen marked this conversation as resolved.
|
||
| title: 'Import a wallet', | ||
| bottomLabel: 'Enter your Secret Recovery Phrase', | ||
| }, | ||
| }; | ||
|
|
||
| export const Title: Story = { | ||
| render: () => <TitleStandard title="Import a wallet" />, | ||
| }; | ||
|
|
||
| export const TitleEndAccessory: Story = { | ||
| render: () => ( | ||
| <TitleStandard | ||
| title="Import a wallet" | ||
| titleEndAccessory={ | ||
| <Box twClassName="ml-2"> | ||
| <Icon | ||
| name={IconName.Info} | ||
| size={IconSize.Sm} | ||
| color={IconColor.IconAlternative} | ||
| /> | ||
| </Box> | ||
| } | ||
| /> | ||
| ), | ||
| }; | ||
|
|
||
| export const TopAccessory: Story = { | ||
| render: () => ( | ||
| <View style={{ gap: 16 }}> | ||
|
brianacnguyen marked this conversation as resolved.
Outdated
|
||
| <TitleStandard | ||
| topAccessory={ | ||
| <Text | ||
| variant={TextVariant.BodySm} | ||
| fontWeight={FontWeight.Medium} | ||
| color={TextColor.TextAlternative} | ||
| > | ||
| Step 2 of 3 | ||
| </Text> | ||
| } | ||
| title="Create your wallet password" | ||
| /> | ||
| <TitleStandard | ||
| topAccessory={ | ||
| <Box | ||
| flexDirection={BoxFlexDirection.Row} | ||
| alignItems={BoxAlignItems.Center} | ||
| gap={1} | ||
| > | ||
| <Icon name={IconName.Mobile} size={IconSize.Sm} /> | ||
| <Text variant={TextVariant.BodySm}>Import from mobile</Text> | ||
|
brianacnguyen marked this conversation as resolved.
|
||
| </Box> | ||
| } | ||
| title="Enter your Secret Recovery Phrase" | ||
| /> | ||
| </View> | ||
| ), | ||
| }; | ||
|
|
||
| export const BottomLabel: Story = { | ||
| args: { | ||
| title: 'Import a wallet', | ||
| bottomLabel: 'Enter your Secret Recovery Phrase', | ||
| }, | ||
| }; | ||
|
|
||
| export const BottomLabelEndAccessory: Story = { | ||
| render: () => ( | ||
| <TitleStandard | ||
| title="Import a wallet" | ||
| bottomLabel="Enter your Secret Recovery Phrase" | ||
| bottomLabelEndAccessory={ | ||
| <Box twClassName="ml-2"> | ||
| <Icon | ||
| name={IconName.Info} | ||
| size={IconSize.Sm} | ||
| color={IconColor.IconAlternative} | ||
| /> | ||
| </Box> | ||
| } | ||
| /> | ||
| ), | ||
| }; | ||
|
|
||
| export const BottomAccessory: Story = { | ||
| render: () => ( | ||
| <TitleStandard | ||
| title="Secure your wallet" | ||
| bottomAccessory={ | ||
| <Box | ||
| flexDirection={BoxFlexDirection.Row} | ||
| alignItems={BoxAlignItems.Center} | ||
| gap={1} | ||
| > | ||
| <Icon name={IconName.SecurityAlert} size={IconSize.Xs} /> | ||
| <Text variant={TextVariant.BodySm}> | ||
| MetaMask support will never ask for your phrase. | ||
| </Text> | ||
| </Box> | ||
| } | ||
| /> | ||
| ), | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.