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/checkbox #28

Merged
merged 6 commits into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions ui-kit/src/components/Checkbox/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React, { forwardRef } from 'react';
import { Ref } from 'react';
import { CombineElementProps } from 'src/types/utils';
import clxs from 'classnames';
evan-moon marked this conversation as resolved.
Show resolved Hide resolved
import { generateID } from 'src/utils/generateID';
Copy link
Member

Choose a reason for hiding this comment

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

마이너) 요런거 tsconfig.jsonpath에 alias 등록해둬도 좋을 것 같아요!

import { Text } from '..';

interface CheckboxBaseProps {
label?: string;
display?: 'block' | 'inline';
}
type CheckboxProps = Omit<CombineElementProps<'input', CheckboxBaseProps>, 'type'>;

const Checkbox = (
{ label, display = 'block', style, disabled, ...props }: CheckboxProps,
ref: Ref<HTMLInputElement>
) => {
const id = generateID('checkbox');

return (
<label
role="checkbox"
className={clxs('lubycon-checkbox', `lubycon-checkbox--display-${display}`, {
'lubycon-checkbox--disabled': disabled,
})}
style={style}
>
<span className="lubycon-checkbox--input">
<input id={id} name="checkbox" ref={ref} type="checkbox" {...props} disabled={disabled} />
<span className="lubycon-checkbox--control">
<svg
xmlns="http://www.w3.org/2000/svg"
width="12"
height="10"
viewBox="0 0 12 10"
fill="none"
aria-hidden="true"
focusable="false"
>
<path fill="none" stroke="#ffffff" strokeWidth="2" d="M1 4.2L4.51852 8L11 1" />
evan-moon marked this conversation as resolved.
Show resolved Hide resolved
</svg>
</span>
</span>
{label ? <Text as="span">{label}</Text> : null}
evan-moon marked this conversation as resolved.
Show resolved Hide resolved
</label>
);
};

export default forwardRef(Checkbox) as typeof Checkbox;
1 change: 1 addition & 0 deletions ui-kit/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { default as Button } from './Button';
export { default as Text } from './Text';
export { default as Column } from './Column';
export { default as Checkbox } from './Checkbox';
73 changes: 73 additions & 0 deletions ui-kit/src/sass/components/_Checkbox.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
$box-size: 16px;

.lubycon-checkbox {
display: flex;
align-items: center;
cursor: pointer;

&:hover:not(&--disabled) {
.lubycon-checkbox--control {
border-color: map-get($colors, 'green50');
}
}

&--input {
display: grid;
grid-template-areas: 'checkbox';

> * {
evan-moon marked this conversation as resolved.
Show resolved Hide resolved
grid-area: checkbox;
}
> input {
opacity: 0;
width: $box-size;
height: $box-size;
padding: 0;
margin: 0;
cursor: pointer;
}
}

&--control {
display: flex;
align-items: center;
justify-content: center;
width: $box-size;
height: $box-size;
border-radius: 2px;
box-sizing: border-box;
border: 1px solid map-get($colors, 'gray40');
margin-right: 8px;

> svg {
transition: transform 0.1s;
transform: scale(0);
}
}

&--input input:checked + &--control svg {
transform: scale(1);
}
&--input input:checked + &--control {
background-color: map-get($colors, 'green50');
border-color: map-get($colors, 'green50');
}

&--display-inline {
display: inline-flex;
}

&--disabled {
cursor: not-allowed;
color: map-get($colors, 'gray50');

input {
cursor: not-allowed;
}

.lubycon-checkbox--input > input:checked + .lubycon-checkbox--control {
border-color: map-get($colors, 'gray40');
background-color: map-get($colors, 'gray40');
}
}
}
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 @@ -2,3 +2,4 @@
@import './Text';
@import './Radio';
@import './Column';
@import './Checkbox';
36 changes: 36 additions & 0 deletions ui-kit/src/stories/Checkbox.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react';
import { Meta } from '@storybook/react/types-6-0';
import Checkbox from 'components/Checkbox';

export default {
title: 'Lubycon UI Kit/Checkbox',
} as Meta;

export const Default = () => {
return (
<div>
<Checkbox label={'체크박스1'} />
<Checkbox label={'체크박스2'} />
</div>
);
};

export const Disabled = () => {
return (
<div>
<Checkbox label={'체크박스'} />
<Checkbox label={'체크박스2'} />
<Checkbox label={'체크박스3'} disabled />
<Checkbox label={'체크박스4'} disabled defaultChecked={true} />
</div>
);
};

export const inline = () => {
return (
<div>
<Checkbox label={'체크박스'} display="inline" style={{ marginRight: '20px' }} />
<Checkbox label={'체크박스2'} display="inline" />
</div>
);
};