Skip to content

Commit

Permalink
feat: Added Large Checkbox menu
Browse files Browse the repository at this point in the history
  • Loading branch information
shindigira committed Jan 24, 2024
1 parent d5d03c9 commit 3cf2c8d
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 40 deletions.
43 changes: 3 additions & 40 deletions src/components/Checkbox/Checkbox.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/* eslint-disable react/jsx-handler-names */
import { useArgs } from '@storybook/client-api';
import type { Meta, StoryObj } from '@storybook/react';
import Checkbox from './Checkbox';
import { CheckboxWrapper } from './Checkbox.utils';

/**
Use checkboxes when the user can select more than one option from a list. Make clear with helper text that this is the case. Use [radio buttons](https://cfpb.github.io/design-system/components/radio-buttons) when the user can choose only one option from a list.
Source: https://cfpb.github.io/design-system/components/checkboxes
*/
const meta: Meta<typeof Checkbox> = {
title: 'Components (Verified)/Checkboxes',
title: 'Components (Verified)/Checkboxes/Default',
component: Checkbox,
argTypes: {
disabled: { control: 'boolean' },
Expand All @@ -21,22 +21,6 @@ export default meta;

type Story = StoryObj<typeof meta>;

function CheckboxWrapper({ ...arguments_ }): JSX.Element {
const [, updateArguments] = useArgs();

return (
<Checkbox
{...arguments_}
checked={arguments_.checked}
onChange={(): void => {
updateArguments({
checked: !arguments_.checked
});
}}
/>
);
}

export const Enabled: Story = {
render: _arguments => CheckboxWrapper(_arguments),
name: 'Enabled',
Expand Down Expand Up @@ -134,28 +118,7 @@ export const WithHelperText: Story = {
name: 'With helper text',
args: {
id: 'WithHelper',
label: 'With helper text',
helperText: 'This is optional helper text'
}
};

export const LargeTargetArea: Story = {
render: _arguments => CheckboxWrapper(_arguments),
name: 'Large target area',
args: {
id: 'LargeTargetArea',
label: 'Large target area',
isLarge: true
}
};

export const LargeTargetAreaWithHelperText: Story = {
render: _arguments => CheckboxWrapper(_arguments),
name: 'Large target area helper text',
args: {
id: 'LargeWithHelperText',
label: 'Large target area helper text',
isLarge: true,
label: 'Label',
helperText: 'This is optional helper text'
}
};
17 changes: 17 additions & 0 deletions src/components/Checkbox/Checkbox.utils.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useArgs } from '@storybook/client-api';
import { useState } from 'react';
import type { CheckboxProperties } from './Checkbox';
import { Checkbox } from './Checkbox';
Expand Down Expand Up @@ -29,3 +30,19 @@ export const CheckboxTestWrapper = ({
/>
);
};

export function CheckboxWrapper({ ...arguments_ }): JSX.Element {
const [, updateArguments] = useArgs();

return (
<Checkbox
{...arguments_}
checked={arguments_.checked}
onChange={(): void => {
updateArguments({
checked: !arguments_.checked
});
}}
/>
);
}
99 changes: 99 additions & 0 deletions src/components/Checkbox/CheckboxLarge.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/* eslint-disable react/jsx-handler-names */
import type { Meta, StoryObj } from '@storybook/react';
import Checkbox from './Checkbox';
import { CheckboxWrapper } from './Checkbox.utils';

/**
Use checkboxes when the user can select more than one option from a list. Make clear with helper text that this is the case. Use [radio buttons](https://cfpb.github.io/design-system/components/radio-buttons) when the user can choose only one option from a list.
Source: https://cfpb.github.io/design-system/components/checkboxes
*/
const meta: Meta<typeof Checkbox> = {
title: 'Components (Verified)/Checkboxes/Large target area',
component: Checkbox,
argTypes: {
disabled: { control: 'boolean' },
isLarge: { control: 'boolean' }
}
};

export default meta;

type Story = StoryObj<typeof meta>;

export const Enabled: Story = {
render: _arguments => CheckboxWrapper(_arguments),
name: 'Enabled',
args: {
id: 'Enabled',
label: 'Enabled',
isLarge: true
}
};

export const Hover: Story = {
render: _arguments => CheckboxWrapper(_arguments),
name: 'Hover',
args: {
id: 'hover',
label: 'Hover',
inputClassName: 'hover',
isLarge: true
}
};

export const Focus: Story = {
render: _arguments => CheckboxWrapper(_arguments),
name: 'Focus',
args: {
id: 'focus',
label: 'Focus',
inputClassName: 'focus',
isLarge: true
}
};

export const Selected: Story = {
render: _arguments => CheckboxWrapper(_arguments),
name: 'Selected',
args: {
id: 'selected',
label: 'Selected',
isLarge: true,
checked: true
}
};

export const Disabled: Story = {
render: _arguments => CheckboxWrapper(_arguments),
name: 'Disabled',
args: {
id: 'disabled',
label: 'Disabled',
isLarge: true,
disabled: true
}
};

export const DisabledSelected: Story = {
render: _arguments => CheckboxWrapper(_arguments),
name: 'Disabled/Selected',
args: {
id: 'disabled/selected',
label: 'Disabled/Selected',
isLarge: true,
disabled: true,
checked: true
}
};

export const WithHelperText: Story = {
render: _arguments => CheckboxWrapper(_arguments),
name: 'With helper text',
args: {
id: 'withHelperText',
label: 'Label',
isLarge: true,
helperText: 'This is optional helper text'
}
};

0 comments on commit 3cf2c8d

Please sign in to comment.