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 all 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 classnames from 'classnames';
import { generateID } from 'utils/index';
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={classnames('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.2 L4.51852 8 L11 1" />
</svg>
</span>
</span>
{label ? <Text>{label}</Text> : null}
</label>
);
};

export default forwardRef(Checkbox) as typeof Checkbox;
2 changes: 2 additions & 0 deletions ui-kit/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export { default as Button } from './Button';
export { default as Text } from './Text';
export { Row, Column } from './Grid';
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';

> input, > span {
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 @@ -3,3 +3,4 @@
@import './Radio';
@import './Row';
@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>
);
};
1 change: 1 addition & 0 deletions ui-kit/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { generateID } from './generateID';
1 change: 1 addition & 0 deletions ui-kit/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"components/*": ["./src/components/*"],
"types/*": ["./src/types/*"],
"constants/*": ["./src/constants/*"],
"utils/*": ["./src/utils/*"],
}
}
}