Skip to content

Commit

Permalink
add Storybook example
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras committed Apr 6, 2023
1 parent afeebf3 commit cbf295d
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const animationExitDelay = 0;
// as some of them would overlap with HTML props (e.g. `onAnimationStart`, ...)
type Props = Omit<
WordPressComponentProps< NavigatorScreenProps, 'div', false >,
keyof MotionProps
Exclude< keyof MotionProps, 'style' >
>;

function UnconnectedNavigatorScreen(
Expand Down
68 changes: 68 additions & 0 deletions packages/components/src/navigator/stories/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,71 @@ export const NestedNavigator: ComponentStory< typeof NavigatorProvider > =
NestedNavigator.args = {
initialPath: '/child2/grandchild',
};

const NavigatorButtonWithSkipFocus = ( {
path,
onClick,
...props
}: React.ComponentProps< typeof NavigatorButton > ) => {
const { goTo } = useNavigator();

return (
<Button
{ ...props }
onClick={ ( e: React.MouseEvent< HTMLButtonElement > ) => {
goTo( path, { skipFocus: true } );
onClick?.( e );
} }
/>
);
};

export const SkipFocus: ComponentStory< typeof NavigatorProvider > = (
args
) => {
return <NavigatorProvider { ...args } />;
};
SkipFocus.args = {
initialPath: '/',
children: (
<>
<div
style={ {
height: 250,
border: '1px solid black',
} }
>
<NavigatorScreen
path="/"
style={ {
height: '100%',
} }
>
<h1>Home screen</h1>
<NavigatorButton variant="secondary" path="/child">
Go to child screen.
</NavigatorButton>
</NavigatorScreen>
<NavigatorScreen
path="/child"
style={ {
height: '100%',
} }
>
<h2>Child screen</h2>
<NavigatorToParentButton variant="secondary">
Go to parent screen.
</NavigatorToParentButton>
</NavigatorScreen>
</div>

<NavigatorButtonWithSkipFocus
variant="secondary"
path="/child"
style={ { margin: '1rem 2rem' } }
>
Go to child screen, but keep focus on this button
</NavigatorButtonWithSkipFocus>
</>
),
};

0 comments on commit cbf295d

Please sign in to comment.