-
-
Notifications
You must be signed in to change notification settings - Fork 11
feat: [DSRN] Added HeaderStandardAnimated #1151
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 all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7fec873
Added HeaderStandardAnimated to DSRN
brianacnguyen 85ae6f9
Merge branch 'main' of github.com:MetaMask/metamask-design-system int…
brianacnguyen 3daf77d
Updated headerstandardanimated tests
brianacnguyen 1fd7097
Updated test imports
brianacnguyen ce131eb
Updated coverage for useHeaderStandardAnimated
brianacnguyen 4d613cb
Merge branch 'main' of github.com:MetaMask/metamask-design-system int…
brianacnguyen 2fdbf4b
Addressed review comments
brianacnguyen 21613d2
Fixed lint issues
brianacnguyen 947e416
Merge branch 'main' into dsrn/headerstandardanimated
brianacnguyen af597f0
Merge branch 'main' into dsrn/headerstandardanimated
brianacnguyen 7b81f7b
Merge branch 'main' into dsrn/headerstandardanimated
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
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
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
75 changes: 24 additions & 51 deletions
75
packages/design-system-react-native/src/components/HeaderStandard/HeaderStandard.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 |
|---|---|---|
| @@ -1,58 +1,31 @@ | ||
| // Third party dependencies. | ||
| import React from 'react'; | ||
|
|
||
| // External dependencies. | ||
| import type { ButtonIconProps } from '../ButtonIcon'; | ||
| import type { HeaderBaseProps } from '../HeaderBase'; | ||
| import type { TextProps } from '../Text'; | ||
| import type { HeaderStandardCenterColumnFields } from '../temp-components/HeaderStandardCenterColumn'; | ||
|
|
||
| /** | ||
| * HeaderStandard component props. | ||
| */ | ||
| export type HeaderStandardProps = HeaderBaseProps & { | ||
| /** | ||
| * Title to display in the header. Can be a string or a React node. | ||
| * Used as children if children prop is not provided. | ||
| * When string: rendered with TextVariant.BodyMd and FontWeight.Bold by default; titleProps apply. | ||
| * When node: rendered as-is; titleProps are not applied. | ||
| */ | ||
| title?: string | React.ReactNode; | ||
| /** | ||
| * Additional props to pass to the title Text component. | ||
| * Props are spread to the Text component and can override default values. | ||
| * Only applied when title is a string. | ||
| */ | ||
| titleProps?: Partial<TextProps>; | ||
| /** | ||
| * Subtitle to display below the title. Can be a string or a React node. | ||
| * When string: rendered with TextVariant.BodySm and TextColor.TextAlternative by default; subtitleProps apply. | ||
| * When node: rendered as-is; subtitleProps are not applied (add spacing on your root if needed, e.g. twClassName). | ||
| */ | ||
| subtitle?: string | React.ReactNode; | ||
| /** | ||
| * Additional props to pass to the subtitle Text component. | ||
| * Props are spread to the Text component and can override default values. | ||
| * Only applied when subtitle is a string. | ||
| */ | ||
| subtitleProps?: Partial<TextProps>; | ||
| /** | ||
| * Callback when the back button is pressed. | ||
| * If provided, a back button will be rendered as startButtonIconProps. | ||
| */ | ||
| onBack?: () => void; | ||
| /** | ||
| * Additional props to pass to the back ButtonIcon. | ||
| * If provided, a back button will be rendered as startButtonIconProps with these props spread. | ||
| */ | ||
| backButtonProps?: Omit<ButtonIconProps, 'iconName'>; | ||
| /** | ||
| * Callback when the close button is pressed. | ||
| * If provided, a close button will be added to endButtonIconProps. | ||
| */ | ||
| onClose?: () => void; | ||
| /** | ||
| * Additional props to pass to the close ButtonIcon. | ||
| * If provided, a close button will be added to endButtonIconProps with these props spread. | ||
| */ | ||
| closeButtonProps?: Omit<ButtonIconProps, 'iconName'>; | ||
| }; | ||
| export type HeaderStandardProps = HeaderBaseProps & | ||
| HeaderStandardCenterColumnFields & { | ||
| /** | ||
| * Callback when the back button is pressed. | ||
| * If provided, a back button will be rendered as startButtonIconProps. | ||
| */ | ||
| onBack?: () => void; | ||
| /** | ||
| * Additional props to pass to the back ButtonIcon. | ||
| * If provided, a back button will be rendered as startButtonIconProps with these props spread. | ||
| */ | ||
| backButtonProps?: Omit<ButtonIconProps, 'iconName'>; | ||
| /** | ||
| * Callback when the close button is pressed. | ||
| * If provided, a close button will be added to endButtonIconProps. | ||
| */ | ||
| onClose?: () => void; | ||
| /** | ||
| * Additional props to pass to the close ButtonIcon. | ||
| * If provided, a close button will be added to endButtonIconProps with these props spread. | ||
| */ | ||
| closeButtonProps?: Omit<ButtonIconProps, 'iconName'>; | ||
| }; |
154 changes: 154 additions & 0 deletions
154
...tem-react-native/src/components/HeaderStandardAnimated/HeaderStandardAnimated.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,154 @@ | ||
| import type { Meta, StoryObj } from '@storybook/react-native'; | ||
| import type { ComponentType } from 'react'; | ||
| import React from 'react'; | ||
| import Animated from 'react-native-reanimated'; | ||
|
|
||
| import { Box } from '../Box'; | ||
| import { IconName } from '../Icon'; | ||
| import { Text, TextColor, TextVariant } from '../Text'; | ||
| import { TitleStandard } from '../TitleStandard'; | ||
|
|
||
| import { HeaderStandardAnimated } from './HeaderStandardAnimated'; | ||
| import type { HeaderStandardAnimatedProps } from './HeaderStandardAnimated.types'; | ||
| import { useHeaderStandardAnimated } from './useHeaderStandardAnimated'; | ||
|
|
||
| type ScrollStoryArgs = Omit< | ||
| HeaderStandardAnimatedProps, | ||
| 'scrollY' | 'titleSectionHeight' | 'children' | ||
| >; | ||
|
|
||
| const meta: Meta<ScrollStoryArgs> = { | ||
| title: 'Components/HeaderStandardAnimated', | ||
| component: | ||
| HeaderStandardAnimated as unknown as ComponentType<ScrollStoryArgs>, | ||
| parameters: { | ||
| docs: { | ||
| description: { | ||
| component: | ||
| 'Scroll-linked header: the center title animates with scroll position. Use `useHeaderStandardAnimated` for `scrollY`, `titleSectionHeight`, and `onScroll`, and attach `onScroll` to `Animated.ScrollView`. Use `HeaderStandard` when you do not need this behavior.', | ||
| }, | ||
| }, | ||
| }, | ||
| argTypes: { | ||
| title: { control: 'text' }, | ||
| subtitle: { control: 'text' }, | ||
| }, | ||
| decorators: [ | ||
| (Story) => ( | ||
| <Box twClassName="w-full flex-1 bg-background-default"> | ||
| <Story /> | ||
| </Box> | ||
| ), | ||
| ], | ||
| }; | ||
|
|
||
| export default meta; | ||
|
|
||
| type Story = StoryObj<ScrollStoryArgs>; | ||
|
|
||
| const SampleContent = ({ itemCount = 20 }: { itemCount?: number }) => ( | ||
| <> | ||
| {Array.from({ length: itemCount }).map((_, index) => ( | ||
| <Box key={index} twClassName="p-4 mb-2 bg-muted rounded-lg mx-4"> | ||
| <Text variant={TextVariant.BodyMd}>Item {index + 1}</Text> | ||
| <Text variant={TextVariant.BodySm}> | ||
| This is sample content to demonstrate scrolling behavior. | ||
| </Text> | ||
| </Box> | ||
| ))} | ||
| </> | ||
| ); | ||
|
|
||
| function ScrollDemo(args: ScrollStoryArgs) { | ||
| const { scrollY, onScroll, setTitleSectionHeight, titleSectionHeightSv } = | ||
| useHeaderStandardAnimated(); | ||
|
|
||
| return ( | ||
| <Box twClassName="flex-1 bg-default"> | ||
| <HeaderStandardAnimated | ||
| {...args} | ||
| scrollY={scrollY} | ||
| titleSectionHeight={titleSectionHeightSv} | ||
| /> | ||
| <Animated.ScrollView | ||
| onScroll={onScroll} | ||
| scrollEventThrottle={16} | ||
| showsVerticalScrollIndicator={false} | ||
| > | ||
| <Box | ||
| onLayout={(e) => setTitleSectionHeight(e.nativeEvent.layout.height)} | ||
| > | ||
| <TitleStandard | ||
| topAccessory={ | ||
| <Text | ||
| variant={TextVariant.BodySm} | ||
| color={TextColor.TextAlternative} | ||
| > | ||
| Perps | ||
| </Text> | ||
| } | ||
| title="ETH-PERP" | ||
| twClassName="px-4 pt-1 pb-3" | ||
| /> | ||
| </Box> | ||
| <SampleContent /> | ||
| </Animated.ScrollView> | ||
| </Box> | ||
| ); | ||
| } | ||
|
|
||
| export const Default: Story = { | ||
| args: { | ||
| title: 'Market', | ||
| }, | ||
| render: (args) => <ScrollDemo {...args} />, | ||
| }; | ||
|
|
||
| export const Subtitle: Story = { | ||
| args: { | ||
| title: 'Market', | ||
| subtitle: 'Perpetual futures', | ||
| onBack: () => undefined, | ||
| }, | ||
| render: (args) => <ScrollDemo {...args} />, | ||
| }; | ||
|
|
||
| export const OnBack: Story = { | ||
| args: { | ||
| title: 'Settings', | ||
| onBack: () => undefined, | ||
| }, | ||
| render: (args) => <ScrollDemo {...args} />, | ||
| }; | ||
|
|
||
| export const OnClose: Story = { | ||
| args: { | ||
| title: 'Modal Title', | ||
| onClose: () => undefined, | ||
| }, | ||
| render: (args) => <ScrollDemo {...args} />, | ||
| }; | ||
|
|
||
| export const BackAndClose: Story = { | ||
| args: { | ||
| title: 'Settings', | ||
| onBack: () => undefined, | ||
| onClose: () => undefined, | ||
| }, | ||
| render: (args) => <ScrollDemo {...args} />, | ||
| }; | ||
|
|
||
| export const EndButtonIconProps: Story = { | ||
| args: { | ||
| title: 'Search', | ||
| onBack: () => undefined, | ||
| onClose: () => undefined, | ||
| endButtonIconProps: [ | ||
| { | ||
| iconName: IconName.Search, | ||
| onPress: () => undefined, | ||
| }, | ||
| ], | ||
| }, | ||
| render: (args) => <ScrollDemo {...args} />, | ||
| }; | ||
|
brianacnguyen marked this conversation as resolved.
|
||
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.