[WIP]npm์์ pnpm์ผ๋ก ๋ฐ๊ฟจ๋๋ storybook action์ด ์๋จนํ๋ค
2025. 11. 3. 00:29ใTrouble Shooting & Issues/Linkiving
๋ฐ์ํ
npm ์์
// TextArea.stories.tsx
import { action } from '@storybook/addon-actions';
import { Meta, StoryObj } from '@storybook/react';
import React, { useState } from 'react';
import TextArea, { TextAreaProps } from './TextArea';
const meta = {
title: 'Components/TextArea',
component: TextArea,
tags: ['autodocs'],
argTypes: {
placeholder: { control: 'text' },
onSubmit: { action: 'submit' },
width: {
control: { type: 'radio' },
options: ['sm', 'md', 'lg'],
},
height: {
control: { type: 'radio' },
options: ['sm', 'md', 'lg'],
},
maxLength: {
control: 'number',
description: '์ต๋ ๊ธ์ ์ ์ง์ ',
},
radius: {
control: { type: 'inline-radio' },
options: ['none', 'sm', 'md', 'lg'],
},
variant: {
control: { type: 'inline-radio' },
options: ['default', 'surface'],
},
},
} satisfies Meta<typeof TextArea>;
export default meta;
type Story = StoryObj<typeof TextArea>;
/**
* - Enter: ์
๋ ฅ ์๋ฃ(onSubmit ํธ์ถ)
* - Shift+Enter: ์ค๋ฐ๊ฟ
*/
function InteractiveTextArea(props: TextAreaProps) {
const [text, setText] = useState('');
return (
<TextArea
{...props}
value={text}
onChange={e => setText(e.target.value)}
onSubmit={props.onSubmit ?? action('submit')}
/>
);
}
export const Default: Story = {
render: args => <InteractiveTextArea {...args} />,
args: {
placeholder: '๋ฌด์์ด๋ ๋ฌผ์ด๋ณด์ธ์',
width: 'md',
height: 'md',
maxLength: 200,
},
};
pnpm ๋ฒ์
// TextArea.stories.tsx
import { Meta, StoryObj } from '@storybook/react';
import { fn } from '@storybook/test';
import React, { useState } from 'react';
import TextArea, { TextAreaProps } from './TextArea';
const meta = {
title: 'Components/TextArea',
component: TextArea,
tags: ['autodocs'],
parameters: {
actions: { argTypesRegex: '^on.*' },
},
argTypes: {
placeholder: { control: 'text' },
width: {
control: { type: 'radio' },
options: ['sm', 'md', 'lg'],
},
height: {
control: { type: 'radio' },
options: ['sm', 'md', 'lg'],
},
maxLength: {
control: 'number',
description: '์ต๋ ๊ธ์ ์ ์ง์ ',
},
radius: {
control: { type: 'inline-radio' },
options: ['none', 'sm', 'md', 'lg'],
},
variant: {
control: { type: 'inline-radio' },
options: ['default', 'surface'],
},
},
} satisfies Meta<typeof TextArea>;
export default meta;
type Story = StoryObj<typeof TextArea>;
function InteractiveTextArea(props: TextAreaProps) {
const [text, setText] = useState('');
return (
<TextArea
{...props}
value={text}
onChange={e => setText(e.target.value)}
onSubmit={props.onSubmit ?? fn()} // fn() ์ฌ์ฉ
/>
);
}
export const Default: Story = {
render: args => <InteractiveTextArea {...args} />,
args: {
placeholder: '๋ฌด์์ด๋ ๋ฌผ์ด๋ณด์ธ์',
width: 'md',
height: 'md',
maxLength: 200,
},
};๋ฐ์ํ
GitHub