Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/switch #29

Merged
merged 9 commits into from
Dec 22, 2020
33 changes: 33 additions & 0 deletions ui-kit/src/components/Switch/index.tsx
Original file line number Diff line number Diff line change
@@ -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<CombineElementProps<'input', SwitchBaseProps>, 'type'>;

const Switch = (
{ label, display = 'block', style, ...props }: SwitchProps,
ref: Ref<HTMLInputElement>
) => {
const id = generateID('switch');

return (
<label
role="switch"
className={clxs('lubycon-switch', `lubycon-switch--display-${display}`)}
style={style}
>
<input className="lubycon-switch--input" ref={ref} type="checkbox" {...props} id={id} />
<span className="lubycon-switch--slider" />
{label ? <Text as="span">{label}</Text> : null}
</label>
);
};

export default forwardRef(Switch) as typeof Switch;
1 change: 1 addition & 0 deletions ui-kit/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
46 changes: 46 additions & 0 deletions ui-kit/src/sass/components/_Switch.scss
Original file line number Diff line number Diff line change
@@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 애니메이션 디테일 👍👍👍


&::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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 나중에 스위치도 사이즈 요소가 추가될 수 있을 것 같은데, X측도 %로 하면 어떨까유?

transform: translate(18.38px, -50%);
}

&--display-inline {
display: inline-flex;
}
}
1 change: 1 addition & 0 deletions ui-kit/src/sass/components/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
@import './Row';
@import './Column';
@import './Checkbox';
@import './Switch';
32 changes: 32 additions & 0 deletions ui-kit/src/stories/Switch.stories.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<div>
<Text as="h2" typography="h2" style={{ color: colors.gray100 }}>
스위치
</Text>
<div style={{ padding: 0 }}>
<Switch label={'Off'} style={{ marginBottom: '23.17px' }} />
<Switch defaultChecked={true} label={'On'} />
</div>
</div>
);
};

export const Inline = () => {
return (
<div>
<Switch display="inline" label="Off" style={{ marginRight: '20px' }} />
<Switch defaultChecked={true} display="inline" label="On" />
</div>
);
};