segmented-controls-react
Version:
A good-lookin' segmented control React component ๐ฅ
79 lines (58 loc) โข 3.09 kB
Markdown
๋ถํ์ํ ๋
ธ๋๋ฅผ ์ต์ํ ํ๊ธฐ ์ํด 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"}
/>
</>
);
};
```
[](https://63a6e1c767126194e2a4a9aa-cbgjyhyetq.chromatic.com/?path=/story/segmentedcontrols--three-segments)


| 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 |