|
| 1 | +import type { Meta, StoryObj, StoryContext } from "@storybook/react"; |
| 2 | +import BottomNavigation from "@mui/material/BottomNavigation"; |
| 3 | +import BottomNavigationAction from "@mui/material/BottomNavigationAction"; |
| 4 | +import RestoreIcon from "@mui/icons-material/Restore"; |
| 5 | +import FavoriteIcon from "@mui/icons-material/Favorite"; |
| 6 | +import LocationOnIcon from "@mui/icons-material/LocationOn"; |
| 7 | +import { useArgs } from "@storybook/addons"; |
| 8 | +import { argProps, argChildren } from "./utils/formatArgs"; |
| 9 | + |
| 10 | +// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction |
| 11 | +const meta: Meta<typeof BottomNavigation> = { |
| 12 | + title: "NAVIGATION/Bottom Navigation", |
| 13 | + component: BottomNavigation, |
| 14 | + parameters: { |
| 15 | + docs: { |
| 16 | + source: { language: "tsx", format: true, type: "dynamic" }, |
| 17 | + description: { |
| 18 | + component: "Another description, overriding the comments", |
| 19 | + }, |
| 20 | + canvas: { sourceState: "shown" }, |
| 21 | + }, |
| 22 | + layout: "centered", |
| 23 | + }, |
| 24 | + tags: ["autodocs"], |
| 25 | + argTypes: { |
| 26 | + value: { |
| 27 | + control: { type: "number" }, |
| 28 | + }, |
| 29 | + showLabels: { |
| 30 | + control: { type: "boolean" }, |
| 31 | + }, |
| 32 | + }, |
| 33 | +}; |
| 34 | + |
| 35 | +export default meta; |
| 36 | +type Story = StoryObj<typeof BottomNavigation>; |
| 37 | + |
| 38 | +// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args |
| 39 | +export const Template: Story = { |
| 40 | + render: ({ onChange, value, ...args }) => { |
| 41 | + return ( |
| 42 | + <BottomNavigation value={value} onChange={onChange} {...args}> |
| 43 | + <BottomNavigationAction label="Recents" icon={<RestoreIcon />} /> |
| 44 | + <BottomNavigationAction label="Favorites" icon={<FavoriteIcon />} /> |
| 45 | + <BottomNavigationAction label="Nearby" icon={<LocationOnIcon />} /> |
| 46 | + </BottomNavigation> |
| 47 | + ); |
| 48 | + }, |
| 49 | + args: { |
| 50 | + value: 0, |
| 51 | + showLabels: true, |
| 52 | + }, |
| 53 | + decorators: [ |
| 54 | + (Story) => { |
| 55 | + const [args, updateArgs] = useArgs(); |
| 56 | + return ( |
| 57 | + <> |
| 58 | + <Story |
| 59 | + args={{ |
| 60 | + ...args, |
| 61 | + onChange: (ev, newValue) => |
| 62 | + updateArgs({ |
| 63 | + value: newValue, |
| 64 | + }), |
| 65 | + }} |
| 66 | + /> |
| 67 | + </> |
| 68 | + ); |
| 69 | + }, |
| 70 | + ], |
| 71 | + parameters: { |
| 72 | + docs: { |
| 73 | + source: { |
| 74 | + transform: (code: string, storyContext: StoryContext): string => ` |
| 75 | +import BottomNavigation from "@mui/material/BottomNavigation"; |
| 76 | +import BottomNavigationAction from "@mui/material/BottomNavigationAction"; |
| 77 | +import RestoreIcon from "@mui/icons-material/Restore"; |
| 78 | +import FavoriteIcon from "@mui/icons-material/Favorite"; |
| 79 | +import LocationOnIcon from "@mui/icons-material/LocationOn"; |
| 80 | + |
| 81 | +<BottomNavigation |
| 82 | + ${argProps(storyContext)} |
| 83 | +> |
| 84 | + <BottomNavigationAction label="Recents" icon={<RestoreIcon />} /> |
| 85 | + <BottomNavigationAction label="Favorites" icon={<FavoriteIcon />} /> |
| 86 | + <BottomNavigationAction label="Nearby" icon={<LocationOnIcon />} /> |
| 87 | +</BottomNavigation> |
| 88 | + `, |
| 89 | + }, |
| 90 | + }, |
| 91 | + }, |
| 92 | +}; |
0 commit comments