Skip to content

Commit

Permalink
Merge pull request #67 from sopt-makers/feat/storybook
Browse files Browse the repository at this point in the history
[DOCS] input storybook 작성
  • Loading branch information
sohee-K authored Apr 16, 2024
2 parents a750e9c + c1cb3e4 commit 3fa4b3b
Show file tree
Hide file tree
Showing 6 changed files with 343 additions and 38 deletions.
2 changes: 1 addition & 1 deletion apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"chromatic": "npx chromatic --project-token=chpt_98c750b6bad066a"
},
"dependencies": {
"@sopt-makers/ui": "^1.0.2"
"@sopt-makers/ui": "1.1.1"
},
"devDependencies": {
"@storybook/addon-essentials": "^7.6.3",
Expand Down
49 changes: 49 additions & 0 deletions apps/docs/src/stories/SearchField.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { ChangeEvent, useState, type InputHTMLAttributes } from 'react';
import { StoryObj } from '@storybook/react';
import { SearchField } from '@sopt-makers/ui';
import { fn } from '@storybook/test';

interface SearchFieldProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'value'> {
value: string;
onSubmit: () => void;
onReset: () => void;
}

const useSearchField = (props: SearchFieldProps) => {
const [search, setSearch] = useState(props.value);

const handleSearchChange = (e: ChangeEvent<HTMLInputElement>) => {
setSearch(e.target.value);
}

const handleSearchReset = () => {
setSearch('');
}

return <SearchField {...props} value={search} onChange={handleSearchChange} onReset={handleSearchReset} />
}

export default {
title: 'Components/Input/SearchField',
component: useSearchField,
tags: ['autodocs'],
args: {
value: '',
style: { width: '335px' },
onSubmit: fn(),
},
argTypes: {
value: { control: false },
style: { control: false },
onSubmit: { action: 'onSubmit' }
}
}

export const SearchFieldStory: StoryObj<SearchFieldProps> = {
args: {
placeholder: 'Placeholder...',
readOnly: false,
disabled: false,
style: { width: '335px' },
},
};
37 changes: 0 additions & 37 deletions apps/docs/src/stories/Test.stories.ts

This file was deleted.

157 changes: 157 additions & 0 deletions apps/docs/src/stories/TextArea.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import { ChangeEvent, useState, type TextareaHTMLAttributes } from 'react';
import { StoryObj } from '@storybook/react';
import { TextArea } from '@sopt-makers/ui';
import { fn } from '@storybook/test';

interface TextAreaProps extends Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, 'value'> {
labelText?: string;
descriptionText?: string;
errorMessage?: string;
value: string;
maxLength: number;
height?: string;
isError?: boolean;
onSubmit: () => void;
}

const useTextArea = (props: TextAreaProps) => {
const [text, setText] = useState(props.value);

const handleTextChange = (e: ChangeEvent<HTMLTextAreaElement>) => {
setText(e.target.value);
}

return <TextArea {...props} value={text} onChange={handleTextChange} />
}

export default {
title: 'Components/Input/TextArea',
component: useTextArea,
tags: ['autodocs'],
args: {
value: '',
style: { width: '335px', height: '48px' },
onSubmit: fn(),
},
argTypes: {
value: { control: false },
style: { control: false },
onSubmit: { action: 'onSubmit' }
}
}

export const Default: StoryObj<TextAreaProps> = {
args: {
labelText: 'Label',
descriptionText: 'Description',
placeholder: 'Placeholder...',
maxLength: 300,
isError: false,
errorMessage: 'error message',
required: true,
readOnly: false,
disabled: false,
}
};

export const DoubleLine: StoryObj<TextAreaProps> = {
args: {
labelText: 'Label',
descriptionText: 'Description',
placeholder: 'Placeholder...',
value: 'text\ntext',
maxLength: 300,
isError: false,
errorMessage: 'error message',
required: true,
readOnly: false,
disabled: false,
style: { width: '335px', height: '76px' },
}
};

export const NoLabel: StoryObj<TextAreaProps> = {
args: {
labelText: '',
descriptionText: 'Description',
placeholder: 'Placeholder...',
maxLength: 300,
isError: false,
errorMessage: 'error message',
required: true,
readOnly: false,
disabled: false,
}
};

export const NoDescription: StoryObj<TextAreaProps> = {
args: {
labelText: 'Label',
descriptionText: '',
placeholder: 'Placeholder...',
maxLength: 300,
isError: false,
errorMessage: 'error message',
required: true,
readOnly: false,
disabled: false,
}
};

export const NoRequired: StoryObj<TextAreaProps> = {
args: {
labelText: 'Label',
descriptionText: 'Description',
placeholder: 'Placeholder...',
maxLength: 300,
isError: false,
errorMessage: 'error message',
required: false,
readOnly: false,
disabled: false,
}
};

export const OnlyText: StoryObj<TextAreaProps> = {
args: {
labelText: '',
descriptionText: '',
placeholder: 'Placeholder...',
maxLength: 300,
isError: false,
errorMessage: 'error message',
required: false,
readOnly: false,
disabled: false,
}
};

export const Readonly: StoryObj<TextAreaProps> = {
args: {
labelText: 'Label',
descriptionText: 'Description',
placeholder: 'Placeholder...',
value: 'text',
maxLength: 300,
isError: false,
errorMessage: 'error message',
required: true,
readOnly: true,
disabled: false,
}
};

export const Disabled: StoryObj<TextAreaProps> = {
args: {
labelText: 'Label',
descriptionText: 'Description',
placeholder: 'Placeholder...',
value: 'text',
maxLength: 300,
isError: false,
errorMessage: 'error message',
required: true,
readOnly: false,
disabled: true,
}
};
126 changes: 126 additions & 0 deletions apps/docs/src/stories/TextField.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import { ChangeEvent, useState, type InputHTMLAttributes } from 'react';
import { StoryObj } from '@storybook/react';
import { TextField } from '@sopt-makers/ui';

interface TextFieldProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'value'> {
labelText?: string;
descriptionText?: string;
value: string;
errorMessage?: string;
isError?: boolean;
}

const useTextField = (props: TextFieldProps) => {
const [text, setText] = useState(props.value);

const handleTextChange = (e: ChangeEvent<HTMLInputElement>) => {
setText(e.target.value);
}

return <TextField<string> {...props} value={text} onChange={handleTextChange} />
}

export default {
title: 'Components/Input/TextField',
component: useTextField,
tags: ['autodocs'],
args: {
style: { width: '335px' }
},
argTypes: {
style: { control: false }
}
}

export const Default: StoryObj<TextFieldProps> = {
args: {
labelText: 'Label',
descriptionText: 'Description',
placeholder: 'Placeholder...',
isError: false,
errorMessage: 'error message',
required: true,
readOnly: false,
disabled: false,
},
};

export const NoLabel: StoryObj<TextFieldProps> = {
args: {
labelText: '',
descriptionText: 'Description',
placeholder: 'Placeholder...',
isError: false,
errorMessage: 'error message',
required: true,
readOnly: false,
disabled: false,
},
};

export const NoDescription: StoryObj<TextFieldProps> = {
args: {
labelText: 'Label',
descriptionText: '',
placeholder: 'Placeholder...',
isError: false,
errorMessage: 'error message',
required: true,
readOnly: false,
disabled: false,
},
};

export const NoRequired: StoryObj<TextFieldProps> = {
args: {
labelText: 'Label',
descriptionText: 'Description',
placeholder: 'Placeholder...',
isError: false,
errorMessage: 'error message',
required: false,
readOnly: false,
disabled: false,
},
};

export const OnlyText: StoryObj<TextFieldProps> = {
args: {
labelText: '',
descriptionText: '',
placeholder: 'Placeholder...',
isError: false,
errorMessage: 'error message',
required: false,
readOnly: false,
disabled: false,
},
};

export const Readonly: StoryObj<TextFieldProps> = {
args: {
labelText: 'Label',
descriptionText: 'Description',
placeholder: 'Placeholder...',
value: 'text',
isError: false,
errorMessage: 'error message',
required: true,
readOnly: true,
disabled: false,
},
};

export const Disabled: StoryObj<TextFieldProps> = {
args: {
labelText: 'Label',
descriptionText: 'Description',
placeholder: 'Placeholder...',
value: 'text',
isError: false,
errorMessage: 'error message',
required: true,
readOnly: false,
disabled: true,
},
};
Loading

0 comments on commit 3fa4b3b

Please sign in to comment.