-
-
Notifications
You must be signed in to change notification settings - Fork 8
Do not merge: Draft/assetdetails #985
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
Draft
brianacnguyen
wants to merge
10
commits into
main
Choose a base branch
from
draft/assetdetails
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9ca2e55
Added keyvaluepair
brianacnguyen d906264
Added headers and titles
brianacnguyen 23b0ce1
Updated ButtonFilters according to spec
brianacnguyen 0613ef5
Added SectionBase
brianacnguyen b170523
Added SectionStandard
brianacnguyen 59aeac3
Added Attribution
brianacnguyen fd7c0c8
Added SectionInsights
brianacnguyen df7f122
Added SectionSocial component
brianacnguyen 4ab1d4e
Added ListItemBase
brianacnguyen a16f0ac
Updated Info and Token List Item
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
18 changes: 18 additions & 0 deletions
18
apps/storybook-react-native/.storybook/storybook.requires.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
110 changes: 110 additions & 0 deletions
110
packages/design-system-react-native/src/components/Attribution/Attribution.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,110 @@ | ||
| import { useTailwind } from '@metamask/design-system-twrnc-preset'; | ||
| import type { Meta, StoryObj } from '@storybook/react-native'; | ||
| import React from 'react'; | ||
| import { View } from 'react-native'; | ||
|
|
||
| import { ButtonIcon } from '../ButtonIcon'; | ||
| import { Box } from '../Box'; | ||
| import { IconName } from '../Icon'; | ||
| import { TextColor, TextVariant } from '../Text'; | ||
|
|
||
| import { Attribution } from './Attribution'; | ||
| import type { AttributionProps } from './Attribution.types'; | ||
|
|
||
| const meta: Meta<AttributionProps> = { | ||
| title: 'Components/Attribution', | ||
| component: Attribution, | ||
| args: { | ||
| children: 'Powered by MetaMask', | ||
| }, | ||
| argTypes: { | ||
| children: { control: 'text' }, | ||
| textProps: { control: 'object' }, | ||
| startAccessory: { control: false }, | ||
| endAccessory: { control: false }, | ||
| }, | ||
| }; | ||
|
|
||
| export default meta; | ||
| type Story = StoryObj<AttributionProps>; | ||
|
|
||
| export const Default: Story = { | ||
| render: (args) => { | ||
| const tw = useTailwind(); | ||
| return ( | ||
| <View style={tw`p-4`}> | ||
| <Attribution {...args} /> | ||
| </View> | ||
| ); | ||
| }, | ||
| }; | ||
|
|
||
| export const StartAccessory: Story = { | ||
| render: (args) => { | ||
| const tw = useTailwind(); | ||
| return ( | ||
| <View style={tw`p-4`}> | ||
| <Attribution | ||
| {...args} | ||
| startAccessory={ | ||
| <Box twClassName="w-6 h-6 rounded-full bg-primary-default" /> | ||
| } | ||
| > | ||
| {args.children} | ||
| </Attribution> | ||
| </View> | ||
| ); | ||
| }, | ||
| }; | ||
|
|
||
| export const EndAccessory: Story = { | ||
| render: (args) => { | ||
| const tw = useTailwind(); | ||
| return ( | ||
| <View style={tw`p-4`}> | ||
| <Attribution | ||
| {...args} | ||
| endAccessory={<ButtonIcon iconName={IconName.Info} />} | ||
| > | ||
| {args.children} | ||
| </Attribution> | ||
| </View> | ||
| ); | ||
| }, | ||
| }; | ||
|
|
||
| export const StartAndEndAccessories: Story = { | ||
| render: (args) => { | ||
| const tw = useTailwind(); | ||
| return ( | ||
| <View style={tw`p-4`}> | ||
| <Attribution | ||
| {...args} | ||
| startAccessory={<Box twClassName="w-5 h-5 rounded bg-icon-default" />} | ||
| endAccessory={<ButtonIcon iconName={IconName.Info} />} | ||
| > | ||
| {args.children} | ||
| </Attribution> | ||
| </View> | ||
| ); | ||
| }, | ||
| }; | ||
|
|
||
| export const TextPropsOverride: Story = { | ||
| render: (args) => { | ||
| const tw = useTailwind(); | ||
| return ( | ||
| <View style={tw`p-4`}> | ||
| <Attribution | ||
| {...args} | ||
| textProps={{ | ||
| variant: TextVariant.BodyMd, | ||
| color: TextColor.TextDefault, | ||
| }} | ||
| > | ||
| Custom variant and color | ||
| </Attribution> | ||
| </View> | ||
| ); | ||
| }, | ||
| }; | ||
137 changes: 137 additions & 0 deletions
137
packages/design-system-react-native/src/components/Attribution/Attribution.test.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,137 @@ | ||
| import { useTailwind } from '@metamask/design-system-twrnc-preset'; | ||
| import { renderHook } from '@testing-library/react-hooks'; | ||
| import { render } from '@testing-library/react-native'; | ||
| import React from 'react'; | ||
| import { Text } from 'react-native'; | ||
|
|
||
| import { TextColor, TextVariant } from '../Text'; | ||
|
|
||
| import { Attribution } from './Attribution'; | ||
|
|
||
| const ROOT_TEST_ID = 'attribution-root'; | ||
|
|
||
| describe('Attribution', () => { | ||
| let tw: ReturnType<typeof useTailwind>; | ||
|
|
||
| beforeAll(() => { | ||
| tw = renderHook(() => useTailwind()).result.current; | ||
| }); | ||
|
|
||
| describe('when children is a string', () => { | ||
| it('renders text content', () => { | ||
| const { getByText } = render( | ||
| <Attribution>Powered by MetaMask</Attribution>, | ||
| ); | ||
| expect(getByText('Powered by MetaMask')).toBeOnTheScreen(); | ||
| }); | ||
|
|
||
| it('applies default textProps (BodySm, TextAlternative)', () => { | ||
| const { getByText } = render(<Attribution>Label</Attribution>); | ||
| const textNode = getByText('Label'); | ||
| const styles = [textNode.props.style].flat(); | ||
| const color = styles.find( | ||
| (s: Record<string, unknown>) => s?.color !== undefined, | ||
| )?.color; | ||
| expect(color).toBe(tw.style(TextColor.TextAlternative).color); | ||
| const fontSize = styles.find( | ||
| (s: Record<string, unknown>) => s?.fontSize !== undefined, | ||
| )?.fontSize; | ||
| expect(fontSize).toBe(tw.style(`text-${TextVariant.BodySm}`).fontSize); | ||
| }); | ||
| }); | ||
|
|
||
| describe('when children is not a string', () => { | ||
| it('renders child components', () => { | ||
| const { getByText } = render( | ||
| <Attribution> | ||
| <Text>Nested content</Text> | ||
| </Attribution>, | ||
| ); | ||
| expect(getByText('Nested content')).toBeOnTheScreen(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('when textProps is provided', () => { | ||
| it('merges textProps over defaults', () => { | ||
| const { getByText } = render( | ||
| <Attribution | ||
| textProps={{ | ||
| variant: TextVariant.BodyMd, | ||
| color: TextColor.TextDefault, | ||
| }} | ||
| > | ||
| Custom | ||
| </Attribution>, | ||
| ); | ||
| const textNode = getByText('Custom'); | ||
| const styles = [textNode.props.style].flat(); | ||
| const color = styles.find( | ||
| (s: Record<string, unknown>) => s?.color !== undefined, | ||
| )?.color; | ||
| expect(color).toBe(tw.style(TextColor.TextDefault).color); | ||
| const fontSize = styles.find( | ||
| (s: Record<string, unknown>) => s?.fontSize !== undefined, | ||
| )?.fontSize; | ||
| expect(fontSize).toBe(tw.style(`text-${TextVariant.BodyMd}`).fontSize); | ||
| }); | ||
| }); | ||
|
|
||
| describe('when startAccessory is provided', () => { | ||
| it('renders startAccessory before text', () => { | ||
| const { getByTestId, getByText } = render( | ||
| <Attribution | ||
| testID={ROOT_TEST_ID} | ||
| startAccessory={<Text testID="start-icon">S</Text>} | ||
| > | ||
| Label | ||
| </Attribution>, | ||
| ); | ||
| expect(getByTestId('start-icon')).toBeOnTheScreen(); | ||
| expect(getByText('Label')).toBeOnTheScreen(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('when endAccessory is provided', () => { | ||
| it('renders endAccessory after text', () => { | ||
| const { getByTestId, getByText } = render( | ||
| <Attribution | ||
| testID={ROOT_TEST_ID} | ||
| endAccessory={<Text testID="end-badge">Badge</Text>} | ||
| > | ||
| Label | ||
| </Attribution>, | ||
| ); | ||
| expect(getByText('Label')).toBeOnTheScreen(); | ||
| expect(getByTestId('end-badge')).toBeOnTheScreen(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('root layout', () => { | ||
| it('applies default gap-2 and merges twClassName', () => { | ||
| const { getByTestId } = render( | ||
| <Attribution testID={ROOT_TEST_ID} twClassName="p-2"> | ||
| Content | ||
| </Attribution>, | ||
| ); | ||
| const root = getByTestId(ROOT_TEST_ID); | ||
| expect(root).toHaveStyle(tw`gap-2 p-2`); | ||
| }); | ||
|
|
||
| it('applies only gap-2 when twClassName is not passed', () => { | ||
| const { getByTestId } = render( | ||
| <Attribution testID={ROOT_TEST_ID}>Content</Attribution>, | ||
| ); | ||
| const root = getByTestId(ROOT_TEST_ID); | ||
| expect(root).toHaveStyle(tw`gap-2`); | ||
| }); | ||
| }); | ||
|
|
||
| describe('ViewProps extension', () => { | ||
| it('passes testID to root', () => { | ||
| const { getByTestId } = render( | ||
| <Attribution testID={ROOT_TEST_ID}>Content</Attribution>, | ||
| ); | ||
| expect(getByTestId(ROOT_TEST_ID)).toBeOnTheScreen(); | ||
| }); | ||
| }); | ||
| }); |
25 changes: 25 additions & 0 deletions
25
packages/design-system-react-native/src/components/Attribution/Attribution.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,25 @@ | ||
| import React from 'react'; | ||
|
|
||
| import { TextColor, TextVariant } from '../../types'; | ||
| import { BoxHorizontal } from '../temp-components/BoxHorizontal'; | ||
|
|
||
| import type { AttributionProps } from './Attribution.types'; | ||
|
|
||
| export const Attribution = ({ | ||
| textProps, | ||
| twClassName, | ||
| ...rest | ||
| }: AttributionProps) => ( | ||
| <BoxHorizontal | ||
| textProps={{ | ||
| ...textProps, | ||
| variant: TextVariant.BodySm, | ||
| color: TextColor.TextAlternative, | ||
| twClassName: `flex-1 ${textProps?.twClassName ?? ''}`.trim(), | ||
| }} | ||
| twClassName={`gap-2 ${twClassName ?? ''}`.trim()} | ||
| {...rest} | ||
| /> | ||
| ); | ||
|
|
||
| Attribution.displayName = 'Attribution'; | ||
3 changes: 3 additions & 0 deletions
3
packages/design-system-react-native/src/components/Attribution/Attribution.types.ts
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,3 @@ | ||
| import type { BoxHorizontalProps } from '../temp-components/BoxHorizontal/BoxHorizontal.types'; | ||
|
|
||
| export type AttributionProps = BoxHorizontalProps; |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
textProps spread order prevents user overrides
High Severity
The
textPropsobject spreads the user-providedtextPropsfirst, then hardcodesvariantandcolorafter, meaning the explicit defaults always win. Users can never overridevariantorcolorviatextProps. The defaults need to come before the spread ({ variant: BodySm, color: TextAlternative, ...textProps, twClassName: ... }) so user-supplied values take precedence. This breaks theTextPropsOverridestory and the "merges textProps over defaults" test, and contradicts the README which states overrides are supported.