1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

checkbox storybook (#12757)

This commit is contained in:
Etienne Dusseault 2021-11-25 05:20:39 +07:00 committed by GitHub
parent 1523b2353d
commit 02177c4575
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 69 additions and 14 deletions

View File

@ -0,0 +1,15 @@
import { Story, Canvas, ArgsTable } from '@storybook/addon-docs';
import CheckBox from '.';
# Checkbox
A small interactive box that can be toggled by the user to indicate an affirmative or negative choice.
<Canvas>
<Story id="ui-components-ui-check-box-check-box-stories-js--default-story" />
</Canvas>
## Component API
<ArgsTable of={CheckBox} />

View File

@ -58,13 +58,34 @@ const CheckBox = ({
}; };
CheckBox.propTypes = { CheckBox.propTypes = {
/**
* Add custom classname css
*/
className: PropTypes.string, className: PropTypes.string,
/**
* Check if checkbox disabled or not
*/
disabled: PropTypes.bool, disabled: PropTypes.bool,
/**
* Checkbox ID
*/
id: PropTypes.string, id: PropTypes.string,
/**
* Click handler
*/
onClick: PropTypes.func, onClick: PropTypes.func,
/**
* Check if the checkbox are checked or not
*/
checked: PropTypes.oneOf([...Object.keys(CHECKBOX_STATE), true, false]) checked: PropTypes.oneOf([...Object.keys(CHECKBOX_STATE), true, false])
.isRequired, .isRequired,
/**
* Show title
*/
title: PropTypes.string, title: PropTypes.string,
/**
* Data test ID for checkbox Component
*/
dataTestId: PropTypes.string, dataTestId: PropTypes.string,
}; };

View File

@ -1,17 +1,11 @@
import React from 'react'; import React from 'react';
import { action } from '@storybook/addon-actions'; import README from './README.mdx';
import { boolean, select, text } from '@storybook/addon-knobs';
import CheckBox, { import CheckBox, {
CHECKED, CHECKED,
INDETERMINATE, INDETERMINATE,
UNCHECKED, UNCHECKED,
} from './check-box.component'; } from './check-box.component';
export default {
title: 'Check Box',
id: __filename,
};
const checkboxOptions = { const checkboxOptions = {
[CHECKED]: CHECKED, [CHECKED]: CHECKED,
[INDETERMINATE]: INDETERMINATE, [INDETERMINATE]: INDETERMINATE,
@ -20,11 +14,36 @@ const checkboxOptions = {
False: false, False: false,
}; };
export const primaryType = () => ( export default {
<CheckBox title: 'Components/UI/Check Box',
checked={select('checked state', checkboxOptions, UNCHECKED)} id: __filename,
disabled={boolean('Disabled', false)} component: CheckBox,
id={text('ID', 'checkboxId')} parameters: {
onClick={action('checkbox clicked')} docs: {
/> page: README,
},
},
argTypes: {
className: { control: 'text' },
disabled: { control: 'boolean' },
id: { control: 'text' },
onClick: { action: 'clicked' },
checked: {
options: ['CHECKED', 'INDETERMINATE', 'UNCHECKED', 'True', 'False'],
control: 'select',
},
title: { control: 'text' },
dataTestId: { control: 'text' },
},
};
export const DefaultStory = (args) => (
<CheckBox {...args} checked={checkboxOptions[args.checked]} />
); );
DefaultStory.storyName = 'Default';
DefaultStory.args = {
checked: UNCHECKED,
disabled: false,
id: 'checkboxID',
};