checkbox storybook (#12757)

feature/default_network_editable
Etienne Dusseault 3 years ago committed by GitHub
parent 1523b2353d
commit 02177c4575
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      ui/components/ui/check-box/README.mdx
  2. 21
      ui/components/ui/check-box/check-box.component.js
  3. 47
      ui/components/ui/check-box/check-box.stories.js

@ -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} />

@ -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,
}; };

@ -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',
};

Loading…
Cancel
Save