diff --git a/ui-kit/src/components/Switch/index.tsx b/ui-kit/src/components/Switch/index.tsx new file mode 100644 index 00000000..cd1ac28a --- /dev/null +++ b/ui-kit/src/components/Switch/index.tsx @@ -0,0 +1,33 @@ +import React, { forwardRef } from 'react'; +import { Ref } from 'react'; +import { CombineElementProps } from 'src/types/utils'; +import clxs from 'classnames'; +import { generateID } from 'src/utils/generateID'; +import { Text } from '..'; + +interface SwitchBaseProps { + label?: string; + display?: 'block' | 'inline'; +} +type SwitchProps = Omit, 'type'>; + +const Switch = ( + { label, display = 'block', style, ...props }: SwitchProps, + ref: Ref +) => { + const id = generateID('switch'); + + return ( + + ); +}; + +export default forwardRef(Switch) as typeof Switch; diff --git a/ui-kit/src/components/index.ts b/ui-kit/src/components/index.ts index 542df9ba..d314bf02 100644 --- a/ui-kit/src/components/index.ts +++ b/ui-kit/src/components/index.ts @@ -2,3 +2,4 @@ export { default as Button } from './Button'; export { default as Text } from './Text'; export { Row, Column } from './Grid'; export { default as Checkbox } from './Checkbox'; +export { default as Switch } from './Switch'; diff --git a/ui-kit/src/sass/components/_Switch.scss b/ui-kit/src/sass/components/_Switch.scss new file mode 100644 index 00000000..2a017029 --- /dev/null +++ b/ui-kit/src/sass/components/_Switch.scss @@ -0,0 +1,46 @@ +.lubycon-switch { + border-radius: 31.5px; + display: flex; + align-items: center; + position: relative; + cursor: pointer; + + &--input { + display: none; + } + + &--slider { + position: relative; + width: 40px; + height: 21px; + margin-right: 8px; + border-radius: 31.5px; + background-color: map-get($colors, 'gray40'); + transition: background-color 0.3s; + + &::before { + content: ''; + position: absolute; + width: 15px; + height: 15px; + left: 3.31px; + top: 50%; + transform: translateY(-50%); + background-color: #ffffff; + border-radius: 50%; + transition: transform 0.3s; + } + } + + &--input:checked + &--slider { + background-color: map-get($colors, 'green50'); + } + + &--input:checked + &--slider::before { + transform: translate(18.38px, -50%); + } + + &--display-inline { + display: inline-flex; + } +} diff --git a/ui-kit/src/sass/components/_index.scss b/ui-kit/src/sass/components/_index.scss index 9813a706..dda50c31 100644 --- a/ui-kit/src/sass/components/_index.scss +++ b/ui-kit/src/sass/components/_index.scss @@ -4,3 +4,4 @@ @import './Row'; @import './Column'; @import './Checkbox'; +@import './Switch'; diff --git a/ui-kit/src/stories/Switch.stories.tsx b/ui-kit/src/stories/Switch.stories.tsx new file mode 100644 index 00000000..179e12af --- /dev/null +++ b/ui-kit/src/stories/Switch.stories.tsx @@ -0,0 +1,32 @@ +import React from 'react'; +import { Meta } from '@storybook/react/types-6-0'; +import Text from 'components/Text'; +import Switch from 'components/Switch'; +import { colors } from '../constants/colors'; + +export default { + title: 'Lubycon UI Kit/Switch', +} as Meta; + +export const Default = () => { + return ( +
+ + 스위치 + +
+ + +
+
+ ); +}; + +export const Inline = () => { + return ( +
+ + +
+ ); +};