|
1 | | -import type { Meta, StoryObj } from "@storybook/react"; |
2 | | -import React, { useState } from "react"; |
3 | | -import { FeaturedTag } from "./featured-tag"; |
4 | | -import { Panel } from "../panel"; |
5 | | -import { FormField } from "../form-field"; |
| 1 | +import type { Meta, StoryObj } from '@storybook/react-vite' |
| 2 | +import { useState } from 'react' |
| 3 | +import { FeaturedTag } from './featured-tag' |
| 4 | +import { Panel } from '../panel' |
| 5 | +import { FormField } from '../form-field' |
6 | 6 |
|
7 | 7 | const meta: Meta<typeof FeaturedTag> = { |
8 | | - title: "Input/FeaturedTag", |
9 | | - component: FeaturedTag, |
10 | | -}; |
11 | | - |
12 | | -export default meta; |
13 | | - |
14 | | -type Story = StoryObj<typeof FeaturedTag>; |
15 | | - |
16 | | -const RadioBoxWithRecommendationTag = () => { |
17 | | - const [value, setValue] = useState("value_1"); |
18 | | - |
19 | | - return ( |
20 | | - <div className="w-96"> |
21 | | - <FormField> |
22 | | - <FormField.RadioBox |
23 | | - value={value} |
24 | | - onChange={(newValue) => { |
25 | | - setValue(newValue); |
26 | | - }} |
27 | | - id="value" |
28 | | - > |
29 | | - <FormField.RadioBox.Option value="option_1"> |
30 | | - Option 1<FeaturedTag>Recommended!</FeaturedTag> |
31 | | - </FormField.RadioBox.Option> |
32 | | - |
33 | | - <FormField.RadioBox.Option value="option_2">Option 2</FormField.RadioBox.Option> |
34 | | - |
35 | | - <FormField.RadioBox.Option value="option_3">Option 3</FormField.RadioBox.Option> |
36 | | - </FormField.RadioBox> |
37 | | - </FormField> |
38 | | - </div> |
39 | | - ); |
40 | | -}; |
| 8 | + title: 'Input/FeaturedTag', |
| 9 | + component: FeaturedTag, |
| 10 | + args: { |
| 11 | + tagLabel: 'Recommended!', |
| 12 | + panelText: 'This example uses a Panel component', |
| 13 | + }, |
| 14 | + argTypes: { |
| 15 | + tagLabel: { control: 'text' }, |
| 16 | + panelText: { control: 'text' }, |
| 17 | + }, |
| 18 | +} |
| 19 | + |
| 20 | +export default meta |
| 21 | + |
| 22 | +type Story = StoryObj<typeof FeaturedTag> |
| 23 | + |
| 24 | +const RadioBoxWithRecommendationTag = ({ tagLabel }: { tagLabel: string }) => { |
| 25 | + const [value, setValue] = useState('value_1') |
| 26 | + |
| 27 | + return ( |
| 28 | + <div className='w-96'> |
| 29 | + <FormField> |
| 30 | + <FormField.RadioBox |
| 31 | + value={value} |
| 32 | + onChange={(newValue) => { |
| 33 | + setValue(newValue) |
| 34 | + }} |
| 35 | + id='value' |
| 36 | + > |
| 37 | + <FormField.RadioBox.Option value='option_1'> |
| 38 | + Option 1<FeaturedTag>{tagLabel}</FeaturedTag> |
| 39 | + </FormField.RadioBox.Option> |
| 40 | + |
| 41 | + <FormField.RadioBox.Option value='option_2'> |
| 42 | + Option 2 |
| 43 | + </FormField.RadioBox.Option> |
| 44 | + |
| 45 | + <FormField.RadioBox.Option value='option_3'> |
| 46 | + Option 3 |
| 47 | + </FormField.RadioBox.Option> |
| 48 | + </FormField.RadioBox> |
| 49 | + </FormField> |
| 50 | + </div> |
| 51 | + ) |
| 52 | +} |
41 | 53 |
|
42 | 54 | export const Default: Story = { |
43 | | - render: () => { |
44 | | - return <RadioBoxWithRecommendationTag />; |
45 | | - }, |
46 | | -}; |
| 55 | + render: ({ tagLabel }) => ( |
| 56 | + <RadioBoxWithRecommendationTag tagLabel={tagLabel} /> |
| 57 | + ), |
| 58 | +} |
47 | 59 |
|
48 | 60 | export const PanelExample: Story = { |
49 | | - render: () => ( |
50 | | - <div className="w-96"> |
51 | | - <Panel className="relative"> |
52 | | - <p>This example uses a Panel component</p> |
53 | | - <FeaturedTag>Recommended!</FeaturedTag> |
54 | | - </Panel> |
55 | | - </div> |
56 | | - ), |
57 | | -}; |
| 61 | + render: ({ tagLabel, panelText }) => ( |
| 62 | + <div className='w-96'> |
| 63 | + <Panel className='relative'> |
| 64 | + <p>{panelText}</p> |
| 65 | + <FeaturedTag>{tagLabel}</FeaturedTag> |
| 66 | + </Panel> |
| 67 | + </div> |
| 68 | + ), |
| 69 | +} |
0 commit comments