Skip to content

Commit

Permalink
feat(checkbox): size m
Browse files Browse the repository at this point in the history
  • Loading branch information
SiebenSieben committed Dec 8, 2020
1 parent 51d6188 commit 9fdbf2b
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 21 deletions.
28 changes: 14 additions & 14 deletions packages/checkbox-group/src/__snapshots__/Component.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Object {
class="checkboxList"
>
<label
class="component my-checkbox checkbox"
class="component s my-checkbox checkbox"
>
<span
class="box"
Expand All @@ -37,7 +37,7 @@ Object {
</span>
</label>
<label
class="component checkbox"
class="component s checkbox"
>
<span
class="box"
Expand All @@ -57,7 +57,7 @@ Object {
</span>
</label>
<label
class="component checkbox"
class="component s checkbox"
>
<span
class="box"
Expand Down Expand Up @@ -93,7 +93,7 @@ Object {
class="checkboxList"
>
<label
class="component my-checkbox checkbox"
class="component s my-checkbox checkbox"
>
<span
class="box"
Expand All @@ -113,7 +113,7 @@ Object {
</span>
</label>
<label
class="component checkbox"
class="component s checkbox"
>
<span
class="box"
Expand All @@ -133,7 +133,7 @@ Object {
</span>
</label>
<label
class="component checkbox"
class="component s checkbox"
>
<span
class="box"
Expand Down Expand Up @@ -226,7 +226,7 @@ Object {
class="checkboxList"
>
<label
class="component my-checkbox checkbox"
class="component s my-checkbox checkbox"
>
<span
class="box"
Expand All @@ -246,7 +246,7 @@ Object {
</span>
</label>
<label
class="component checkbox"
class="component s checkbox"
>
<span
class="box"
Expand All @@ -266,7 +266,7 @@ Object {
</span>
</label>
<label
class="component checkbox"
class="component s checkbox"
>
<span
class="box"
Expand Down Expand Up @@ -307,7 +307,7 @@ Object {
class="checkboxList"
>
<label
class="component my-checkbox checkbox"
class="component s my-checkbox checkbox"
>
<span
class="box"
Expand All @@ -327,7 +327,7 @@ Object {
</span>
</label>
<label
class="component checkbox"
class="component s checkbox"
>
<span
class="box"
Expand All @@ -347,7 +347,7 @@ Object {
</span>
</label>
<label
class="component checkbox"
class="component s checkbox"
>
<span
class="box"
Expand Down Expand Up @@ -445,7 +445,7 @@ Object {
class="checkboxList"
>
<label
class="component my-checkbox checkbox"
class="component s my-checkbox checkbox"
>
<span
class="box"
Expand Down Expand Up @@ -481,7 +481,7 @@ Object {
class="checkboxList"
>
<label
class="component my-checkbox checkbox"
class="component s my-checkbox checkbox"
>
<span
class="box"
Expand Down
4 changes: 3 additions & 1 deletion packages/checkbox/src/Component.stories.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Meta, Story, Props, Preview } from '@storybook/addon-docs/blocks';
import { text, boolean } from '@storybook/addon-knobs';
import { text, boolean, select } from '@storybook/addon-knobs';
import { ComponentHeader } from 'storybook/blocks/component-header';

import { Checkbox } from './Component';
Expand All @@ -19,13 +19,15 @@ import { name, version } from '../package.json';
{React.createElement(() => {
const [checked, setChecked] = React.useState(false);
const handleChange = () => setChecked(!checked);
const size = select('size', ['s', 'm'], 's');
const disabled = boolean('disabled', false);
const label = text('label', 'Согласен с условиями');
const indeterminate = boolean('indeterminate', false);
const hint = text('hint', 'Дополнительная информация');
return (
<Checkbox
disabled={disabled}
size={size}
onChange={handleChange}
checked={checked}
label={label}
Expand Down
12 changes: 12 additions & 0 deletions packages/checkbox/src/Component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ describe('Checkbox', () => {

expect(container.firstElementChild).toHaveClass('indeterminate');
});

it('should set size `s` as default size', () => {
const { container } = render(<Checkbox />);

expect(container.firstElementChild).toHaveClass('s');
});

it('should set size', () => {
const { container } = render(<Checkbox size='m' />);

expect(container.firstElementChild).toHaveClass('m');
});
});

describe('Attributes tests', () => {
Expand Down
10 changes: 8 additions & 2 deletions packages/checkbox/src/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import styles from './index.module.css';

type NativeProps = InputHTMLAttributes<HTMLInputElement>;

export type CheckboxProps = Omit<NativeProps, 'onChange'> & {
export type CheckboxProps = Omit<NativeProps, 'size' | 'onChange'> & {
/**
* Управление состоянием вкл/выкл чекбокса (native prop)
*/
Expand All @@ -37,6 +37,11 @@ export type CheckboxProps = Omit<NativeProps, 'onChange'> & {
*/
hint?: ReactNode;

/**
* Размер компонента
*/
size?: 's' | 'm';

/**
* Идентификатор для систем автоматизированного тестирования
*/
Expand All @@ -54,6 +59,7 @@ export const Checkbox = forwardRef<HTMLLabelElement, CheckboxProps>(
checked,
label,
hint,
size = 's',
onChange,
className,
name,
Expand All @@ -77,7 +83,7 @@ export const Checkbox = forwardRef<HTMLLabelElement, CheckboxProps>(
return (
// eslint-disable-next-line jsx-a11y/label-has-associated-control
<label
className={cn(styles.component, className, {
className={cn(styles.component, styles[size], className, {
[styles.disabled]: disabled,
[styles.checked]: checked,
[styles.indeterminate]: indeterminate,
Expand Down
8 changes: 4 additions & 4 deletions packages/checkbox/src/__snapshots__/Component.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Object {
"baseElement": <body>
<div>
<label
class="component"
class="component s"
>
<span
class="box"
Expand Down Expand Up @@ -34,7 +34,7 @@ Object {
</body>,
"container": <div>
<label
class="component"
class="component s"
>
<span
class="box"
Expand Down Expand Up @@ -119,7 +119,7 @@ Object {
"baseElement": <body>
<div>
<label
class="component indeterminate"
class="component s indeterminate"
>
<span
class="box"
Expand Down Expand Up @@ -157,7 +157,7 @@ Object {
</body>,
"container": <div>
<label
class="component indeterminate"
class="component s indeterminate"
>
<span
class="box"
Expand Down
7 changes: 7 additions & 0 deletions packages/checkbox/src/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@
overflow: hidden;
}

.m .box {
width: 20px;
height: 20px;
margin-right: var(--gap-m);
margin-top: 2px;
}

.component:hover:not(.disabled) .box {
background-color: var(--checkbox-hover-bg-color);
border-color: var(--checkbox-hover-border-color);
Expand Down

0 comments on commit 9fdbf2b

Please sign in to comment.