UNPKG

segmented-controls-react

Version:

A good-lookin' segmented control React component ๐Ÿ”ฅ

79 lines (58 loc) โ€ข 3.09 kB
## ์‹คํ–‰ ํ™˜๊ฒฝ ๋ถˆํ•„์š”ํ•œ ๋…ธ๋“œ๋ฅผ ์ตœ์†Œํ™” ํ•˜๊ธฐ ์œ„ํ•ด webpack์œผ๋กœ React + Typescript + Styled Components + Storybook์„ ์„ธํŒ…ํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๊ฐ„๋‹จํ•œ lint, prettier ์„ค์ •๋„ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค. label๊ณผ input์„ ์—ฐ๊ฒฐํ•ด ์›น ์ ‘๊ทผ์„ฑ์„ ๊ณ ๋ คํ•œ ๊ฐœ๋ฐœ์„ ํ•˜์˜€์Šต๋‹ˆ๋‹ค. framer-motion ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์• ๋‹ˆ๋ฉ”์ด์…˜์„ ์ ์šฉํ•˜์˜€์Šต๋‹ˆ๋‹ค. ๋ชจ๋ฐ”์ผ ํ™˜๊ฒฝ์—์„œ๋„ ๋™์ผํ•œ ์‚ฌ์šฉ๊ฐ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ๊ฐœ๋ฐœ์ž ๊ฒฝํ—˜์„ ์œ„ํ•ด tsDoc์„ ์ถ”๊ฐ€ํ•˜์˜€์Šต๋‹ˆ๋‹ค. ์„œ๋ฐ”์‚ฌ์ด๋“œ ๋ Œ๋”๋ง ์ง€์› -> ํ•ด๋‹น ๊ธฐ๋Šฅ ์ž ์‹œ ๋ณด๋ฅ˜์ž…๋‹ˆ๋‹ค. ## ์‹คํ–‰ ๋ฐฉ๋ฒ• 1. package install - npm i (or yarn) 2. run dev server - npm run dev (or yarn dev)๋ฅผ ํ†ตํ•ด ๊ตฌํ˜„๋œ ์ปดํฌ๋„ŒํŠธ๋ฅผ localhost:3000์—์„œ ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. 3. build - npm run build (or yarn build) ## ์‚ฌ์šฉ๋ฒ• ```js const App = () => { return ( <> <SegmentedControls options={[ { value: "one", disabled: true }, { value: "two" }, { value: "three" }, ]} defaultIndex={1} setValue={(val) => console.log(val)} size={"large"} name={"one"} /> <SegmentedControls options={[ { value: "one", disabled: true }, { value: "two" }, { value: "three" }, { value: "four" }, ]} defaultIndex={1} setValue={(val) => console.log(val)} size={"small"} name={"two"} /> </> ); }; ``` ## ๊ฒฐ๊ณผ๋ฌผ [Demo](https://63a6e1c767126194e2a4a9aa-cbgjyhyetq.chromatic.com/?path=/story/segmentedcontrols--three-segments) ![](https://velog.velcdn.com/images/dusdjeks/post/69213a67-6062-4c34-bacf-756526c61826/image.gif) ![](https://velog.velcdn.com/images/dusdjeks/post/7e340608-a6ea-4693-9e85-d08f76883e54/image.gif) ## ์†์„ฑ | Name | Type | Default | Description | | ------------ | ----------------------------------------- | ------- | --------------------------------------------------------------------------------------------------------- | | options | `{ value: string, disabled?: boolean }[]` | | Enter the label of segments | | setValue | `Dispatch<SetStateAction<string>>` | | callback on input change, passed the value string. Called once initially with the default value on mount. | | size | `large or small` | | Enter the size of component you want | | name | `string` | | Enter name of the radio <input>s | | defaultIndex | `number` | | You could set default value through this property |