|
| 1 | +import { Stack, Typography } from '@mui/material' |
| 2 | +import type { Meta, StoryObj } from '@storybook/react-vite' |
| 3 | +import { FormTabs } from '../FormTabs/FormTabs' |
| 4 | + |
| 5 | +type DemoParams = { |
| 6 | + availableBalance: number |
| 7 | + canWithdraw: boolean |
| 8 | + showAdvanced: boolean |
| 9 | + userAddress: string |
| 10 | +} |
| 11 | + |
| 12 | +const Panel = ({ title, body }: { title: string; body: string }) => ( |
| 13 | + <Stack gap={1} sx={{ padding: 3, borderRadius: 2, border: (t) => `1px solid ${t.palette.divider}` }}> |
| 14 | + <Typography variant="headingSBold">{title}</Typography> |
| 15 | + <Typography variant="bodyMRegular">{body}</Typography> |
| 16 | + </Stack> |
| 17 | +) |
| 18 | + |
| 19 | +const OverviewTab = ({ availableBalance, userAddress }: DemoParams) => ( |
| 20 | + <Panel |
| 21 | + title="Overview" |
| 22 | + body={`Connected as ${userAddress}. Available balance: ${availableBalance.toLocaleString()} crvUSD.`} |
| 23 | + /> |
| 24 | +) |
| 25 | + |
| 26 | +const DepositTab = ({ availableBalance }: DemoParams) => ( |
| 27 | + <Panel |
| 28 | + title="Deposit" |
| 29 | + body={`Use this tab for simple flows. Balance shown in labels comes from props (${availableBalance.toLocaleString()} crvUSD).`} |
| 30 | + /> |
| 31 | +) |
| 32 | + |
| 33 | +const WithdrawTab = ({ canWithdraw }: DemoParams) => ( |
| 34 | + <Panel |
| 35 | + title="Withdraw" |
| 36 | + body={ |
| 37 | + canWithdraw |
| 38 | + ? 'Withdraw actions are available and the sub-tab is enabled.' |
| 39 | + : 'This sub-tab shows the disabled state when withdrawals are locked.' |
| 40 | + } |
| 41 | + /> |
| 42 | +) |
| 43 | + |
| 44 | +const AdvancedTab = () => <Panel title="Advanced" body="Conditional tab that appears when enabled." /> |
| 45 | + |
| 46 | +type StoryArgs = DemoParams & { defaultTab: string; shouldWrap: boolean } |
| 47 | + |
| 48 | +const FormTabsStory = ({ shouldWrap, defaultTab, ...params }: StoryArgs) => ( |
| 49 | + <FormTabs<DemoParams> |
| 50 | + params={params} |
| 51 | + shouldWrap={shouldWrap} |
| 52 | + defaultTab={defaultTab} |
| 53 | + menu={[ |
| 54 | + { |
| 55 | + value: 'overview', |
| 56 | + label: 'Overview', |
| 57 | + visible: () => true, |
| 58 | + component: OverviewTab, |
| 59 | + }, |
| 60 | + { |
| 61 | + value: 'manage', |
| 62 | + label: ({ availableBalance }) => `Manage (${availableBalance.toLocaleString()} crvUSD)`, |
| 63 | + visible: () => true, |
| 64 | + subTabs: [ |
| 65 | + { value: 'deposit', label: 'Deposit', visible: () => true, component: DepositTab }, |
| 66 | + { |
| 67 | + value: 'withdraw', |
| 68 | + label: ({ canWithdraw }) => (canWithdraw ? 'Withdraw' : 'Withdraw (locked)'), |
| 69 | + visible: () => true, |
| 70 | + disabled: ({ canWithdraw }) => !canWithdraw, |
| 71 | + component: WithdrawTab, |
| 72 | + }, |
| 73 | + ], |
| 74 | + }, |
| 75 | + { |
| 76 | + value: 'advanced', |
| 77 | + label: 'Advanced', |
| 78 | + visible: ({ showAdvanced }) => showAdvanced, |
| 79 | + component: AdvancedTab, |
| 80 | + }, |
| 81 | + ]} |
| 82 | + /> |
| 83 | + ) |
| 84 | + |
| 85 | +const meta: Meta<typeof FormTabsStory> = { |
| 86 | + title: 'UI Kit/Widgets/FormTabs', |
| 87 | + component: FormTabsStory, |
| 88 | + args: { |
| 89 | + availableBalance: 1250, |
| 90 | + canWithdraw: true, |
| 91 | + showAdvanced: false, |
| 92 | + userAddress: '0x1234...cafe', |
| 93 | + defaultTab: 'overview', |
| 94 | + shouldWrap: false, |
| 95 | + }, |
| 96 | + argTypes: { |
| 97 | + availableBalance: { |
| 98 | + control: { type: 'number', min: 0 }, |
| 99 | + description: 'Value forwarded to labels and tab content.', |
| 100 | + }, |
| 101 | + canWithdraw: { |
| 102 | + control: 'boolean', |
| 103 | + description: 'Toggles the disabled state of the Withdraw sub-tab.', |
| 104 | + }, |
| 105 | + showAdvanced: { |
| 106 | + control: 'boolean', |
| 107 | + description: 'Controls visibility of the Advanced tab.', |
| 108 | + }, |
| 109 | + userAddress: { |
| 110 | + control: 'text', |
| 111 | + description: 'Sample address injected into tab content.', |
| 112 | + }, |
| 113 | + defaultTab: { |
| 114 | + control: 'select', |
| 115 | + options: ['overview', 'manage', 'advanced'], |
| 116 | + description: 'Initial tab selection.', |
| 117 | + }, |
| 118 | + shouldWrap: { |
| 119 | + control: 'boolean', |
| 120 | + description: 'Renders content with the legacy AppForm wrapper background.', |
| 121 | + }, |
| 122 | + }, |
| 123 | + parameters: { |
| 124 | + docs: { |
| 125 | + description: { |
| 126 | + component: |
| 127 | + 'FormTabs renders primary and nested tabs with optional visibility and disabled states. This story showcases the possible states with sample content.', |
| 128 | + }, |
| 129 | + }, |
| 130 | + }, |
| 131 | +} |
| 132 | + |
| 133 | +type Story = StoryObj<typeof FormTabsStory> |
| 134 | + |
| 135 | +export const BasicTabs: Story = { |
| 136 | + parameters: { |
| 137 | + docs: { |
| 138 | + description: { |
| 139 | + story: 'Default layout with nested Manage sub-tabs and dynamic labels.', |
| 140 | + }, |
| 141 | + }, |
| 142 | + }, |
| 143 | +} |
| 144 | + |
| 145 | +export const StartOnManage: Story = { |
| 146 | + args: { defaultTab: 'manage' }, |
| 147 | + parameters: { |
| 148 | + docs: { |
| 149 | + description: { |
| 150 | + story: 'Shows nested sub-tabs immediately by starting on the Manage tab.', |
| 151 | + }, |
| 152 | + }, |
| 153 | + }, |
| 154 | +} |
| 155 | + |
| 156 | +export const WithConditionalTab: Story = { |
| 157 | + args: { showAdvanced: true, defaultTab: 'advanced' }, |
| 158 | + parameters: { |
| 159 | + docs: { |
| 160 | + description: { |
| 161 | + story: 'Advanced tab appears when visibility is enabled.', |
| 162 | + }, |
| 163 | + }, |
| 164 | + }, |
| 165 | +} |
| 166 | + |
| 167 | +export const WithDisabledSubTab: Story = { |
| 168 | + args: { canWithdraw: false, defaultTab: 'manage' }, |
| 169 | + parameters: { |
| 170 | + docs: { |
| 171 | + description: { |
| 172 | + story: 'Withdraw sub-tab rendered disabled to highlight the disabled state handling.', |
| 173 | + }, |
| 174 | + }, |
| 175 | + }, |
| 176 | +} |
| 177 | + |
| 178 | +export const LegacyWrapped: Story = { |
| 179 | + args: { shouldWrap: true }, |
| 180 | + parameters: { |
| 181 | + docs: { |
| 182 | + description: { |
| 183 | + story: 'Illustrates the legacy AppForm background applied via shouldWrap.', |
| 184 | + }, |
| 185 | + }, |
| 186 | + }, |
| 187 | +} |
| 188 | + |
| 189 | +export default meta |
0 commit comments