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

Checkbox Sidemenu Updated, Checkbox States (Error/Warning/Success) #287

Merged
merged 28 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3578915
feat: Checkbox Sidemenu Updated, placeholder for statuses
shindigira Jan 23, 2024
9c01165
fix: changed to proper variable name
shindigira Jan 23, 2024
e3946ae
Package Update: CFPB Design System - 0.35.0
shindigira Jan 23, 2024
787b899
Merge branch 'Update-DS-0.35.0' into checkbox-radiobuttons-sidemenu-u…
shindigira Jan 23, 2024
1a80e81
fix: updated all CFPB subpackages to 0.35.0
shindigira Jan 23, 2024
f76c066
Merge branch 'Update-DS-0.35.0' into checkbox-radiobuttons-sidemenu-u…
shindigira Jan 23, 2024
865ec82
Merge branch 'main' of github.com:cfpb/design-system-react into check…
shindigira Jan 24, 2024
9e6a237
chore: renamed Default to Enabled
shindigira Jan 24, 2024
d5d03c9
chore: removed comment
shindigira Jan 24, 2024
3cf2c8d
feat: Added Large Checkbox menu
shindigira Jan 24, 2024
bba1246
chore: sidemenu changed from default to Checkbox
shindigira Jan 24, 2024
dfd369d
feat: Added autodocs by tag
shindigira Jan 25, 2024
6bbbf77
feat: Checkbox sidemenu's new tree format
shindigira Jan 25, 2024
2e4a373
fix: resolved TextInput merge conflict
shindigira Jan 25, 2024
13aba26
feat: added Checkbox Overview mdx
shindigira Jan 26, 2024
2320fe1
feat: links on Checkbox Overview
shindigira Jan 26, 2024
f1a774e
chore: removed unused line
shindigira Jan 26, 2024
1b76e62
chore: remove no longer needed workaround
shindigira Jan 26, 2024
722ad14
style: Updated styles on Checkbox Overview
shindigira Jan 26, 2024
7125d9c
feat: prettier should ignore MDX files
shindigira Jan 26, 2024
463550d
revert: revert List workaround
shindigira Jan 29, 2024
7ca0ddd
style: updates with workaround so that storybook doesn't overwrite CF…
shindigira Jan 29, 2024
e92b125
chore: updated shortcircuit
shindigira Jan 29, 2024
b3667ef
chore: reverted style workaround till next PR to address CFPB style o…
shindigira Jan 29, 2024
de7aa3d
style: readded cfpb styling
shindigira Jan 29, 2024
487dae0
chore: removed descriptins in Checkbox and Large target area
shindigira Jan 30, 2024
e522706
chore: removed dead code
shindigira Jan 30, 2024
4a3845c
Merge branch 'main' of github.com:cfpb/design-system-react into check…
shindigira Jan 30, 2024
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
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/*.mdx
2 changes: 1 addition & 1 deletion .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
'display-element-css'
],
docs: {
autodocs: true,
autodocs: 'tag',
defaultName: 'Overview'
},
framework: {
Expand Down
1 change: 0 additions & 1 deletion .storybook/manager-head.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@
.sidebar-item svg {
color: black;
}

</style>
1 change: 1 addition & 0 deletions src/components/Alert/Alert.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { StatusType } from '../TextInput/TextInput';
const meta: Meta<typeof Alert> = {
title: 'Components (Draft)/Alerts',
component: Alert,
tags: ['autodocs'],
argTypes: {
message: { control: 'text' }
}
Expand Down
1 change: 1 addition & 0 deletions src/components/Banner/Banner.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AllLanguageCodes, LanguageLink } from './BannerLanguageLink';

const meta: Meta<typeof Banner> = {
title: 'Components (Verified)/Banner (US gov)',
tags: ['autodocs'],
component: Banner,
argTypes: {}
};
Expand Down
1 change: 1 addition & 0 deletions src/components/Buttons/Buttons.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ButtonGroup } from './ButtonGroup';
const meta: Meta<typeof Button> = {
title: 'Components (Verified)/Buttons',
component: Button,
tags: ['autodocs'],
argTypes: {
appearance: { control: 'select' },
size: { control: 'select' },
Expand Down
121 changes: 88 additions & 33 deletions src/components/Checkbox/Checkbox.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/* eslint-disable react/jsx-handler-names */
import type { Meta, StoryObj } from '@storybook/react';
import { Checkbox } from './Checkbox';
import { CheckboxTestWrapper } from './Checkbox.utils';
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/Checkbox',
tags: ['autodocs'],
component: Checkbox,
argTypes: {
disabled: { control: 'boolean' },
Expand All @@ -21,50 +22,104 @@ export default meta;

type Story = StoryObj<typeof meta>;

export const StandardCheckbox: Story = {
render: _arguments => CheckboxTestWrapper(_arguments),
name: 'Standard checkbox',
export const Enabled: Story = {
render: _arguments => CheckboxWrapper(_arguments),
name: 'Enabled',
args: {
id: 'standard',
name: 'standard',
label: 'Standard checkbox',
id: 'enabled',
label: 'Enabled',
checked: false
}
};

export const StandardCheckboxWithHelperText: Story = {
render: _arguments => CheckboxTestWrapper(_arguments),
name: 'Standard checkbox with helper text',
export const Hover: Story = {
render: _arguments => CheckboxWrapper(_arguments),
name: 'Hover',
args: {
...StandardCheckbox.args,
id: 'StandardCheckboxWithHelper',
name: 'StandardCheckboxWithHelper',
label: 'Standard checkbox with helper text',
helperText: 'This is optional helper text'
id: 'hover',
inputClassName: 'hover',
label: 'Hover'
}
};

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

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

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

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

export const Success: Story = {
render: _arguments => CheckboxWrapper(_arguments),
name: 'Success',
args: {
id: 'success',
label: 'Success',
status: 'success'
}
};

export const Warning: Story = {
render: _arguments => CheckboxWrapper(_arguments),
name: 'Warning',
args: {
id: 'warning',
label: 'Warning',
status: 'warning'
}
};

export const LargeTargetAreaCheckbox: Story = {
render: _arguments => CheckboxTestWrapper(_arguments),
name: 'Large target area checkbox',
export const Error: Story = {
render: _arguments => CheckboxWrapper(_arguments),
name: 'Error',
args: {
...StandardCheckbox.args,
id: 'LargeTargetAreaCheckbox',
name: 'LargeTargetAreaCheckbox',
label: 'Large target area checkbox',
isLarge: true
id: 'error',
label: 'Error',
status: 'error'
}
};

export const LargeTargetAreaCheckboxWithHelperText: Story = {
render: _arguments => CheckboxTestWrapper(_arguments),
name: 'Large target area checkbox helper text',
export const WithHelperText: Story = {
render: _arguments => CheckboxWrapper(_arguments),
name: 'With helper text',
args: {
...StandardCheckbox.args,
id: 'LargeCheckboxWithHelperText',
name: 'LargeCheckboxWithHelperText',
label: 'Large target area checkbox helper text',
isLarge: true,
id: 'WithHelper',
label: 'Label',
helperText: 'This is optional helper text'
}
};
10 changes: 10 additions & 0 deletions src/components/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,18 @@ export interface CheckboxProperties {
disabled?: boolean;
/** An event handler function that will be called when the checkbox's value is changed */
onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
/** Border status */
status: 'success' | 'warning' | 'error';
}

const containerBaseStyles = ['m-form-field m-form-field__checkbox'];

const borderStatus = {
success: 'm-form-field__checkbox__success',
warning: 'm-form-field__checkbox__warning',
error: 'm-form-field__checkbox__error'
};

export const Checkbox = ({
id,
label,
Expand All @@ -55,6 +63,7 @@ export const Checkbox = ({
labelInline = true, // 'true' REMOVES the a.label__heading class
name,
onChange,
status,
...properties
}: CheckboxProperties): ReactElement => {
const onChangeHandler = useCallback(
Expand All @@ -67,6 +76,7 @@ export const Checkbox = ({
const containerClasses = [
...containerBaseStyles,
isLarge ? 'm-form-field__lg-target' : '',
borderStatus[status] ? borderStatus[status] : '',
className
];

Expand Down
28 changes: 26 additions & 2 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 All @@ -8,9 +9,10 @@ import { Checkbox } from './Checkbox';
*/
export const CheckboxTestWrapper = ({
onChange,
checked,
...others
}: CheckboxProperties): JSX.Element => {
const [checked, setChecked] = useState(false);
const [inputChecked, setChecked] = useState(false);

const onWrapperChange = (
event: React.ChangeEvent<HTMLInputElement>
Expand All @@ -20,5 +22,27 @@ export const CheckboxTestWrapper = ({
setChecked(event.target.checked);
};

return <Checkbox {...others} checked={checked} onChange={onWrapperChange} />;
return (
<Checkbox
checked={checked || inputChecked}
{...others}
onChange={onWrapperChange}
/>
);
};

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

return (
<Checkbox
{...arguments_}
checked={arguments_.checked}
onChange={(): void => {
updateArguments({
checked: !arguments_.checked
});
}}
/>
);
}
100 changes: 100 additions & 0 deletions src/components/Checkbox/CheckboxLarge.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/* 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',
tags: ['autodocs'],
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'
}
};
Loading
Loading