From f26186c4f84c640c27d5490b30d17758665a8f1a Mon Sep 17 00:00:00 2001 From: Igor Vidic Date: Tue, 22 Jan 2019 19:13:48 +1100 Subject: [PATCH] feat: add control option to Checkbox (#102) --- docs/components/Checkbox.mdx | 45 ++++++++++++++++++++++++++++-- packages/shared/core/Checkbox.js | 48 +++++++++++++++++++++++++++++++- 2 files changed, 89 insertions(+), 4 deletions(-) diff --git a/docs/components/Checkbox.mdx b/docs/components/Checkbox.mdx index 52f544eba..a6ff0afb3 100644 --- a/docs/components/Checkbox.mdx +++ b/docs/components/Checkbox.mdx @@ -18,20 +18,20 @@ Set sizes using `size` prop like `"sm"`, `"md"` or `"lg"`. Small - + Medium Large @@ -54,6 +54,43 @@ Disable using `disabled` prop. +## Control & Validation + +* Set `display` to "block" and `width` to "100%" using `control` prop. +* Set validation using `valid` or `valid={false}` + + + + + Control + + + + Valid Control + + + + Invalid Control + + + ## API ### Checkbox @@ -61,9 +98,11 @@ Disable using `disabled` prop. { + switch (p.valid) { + case true: + return validStyle + case false: + return invalidStyle + default: + return null + } + }}; +` + const containerSystem = compose( basics, dimensions, @@ -75,6 +117,7 @@ const system = compose( const Checkbox = createComponent(() => ({ name: 'checkbox', + omitProps: ['control', 'valid'], system, applySystem: null, render: ({ Component, ref, className, size, ...props }) => ( @@ -134,7 +177,7 @@ const Checkbox = createComponent(() => ({ } } - input:focused + .sui-checkbox-content { + input:focus + .sui-checkbox-content { ${mixin('controlFocus')}; } @@ -143,6 +186,7 @@ const Checkbox = createComponent(() => ({ } ${p => sizeStyle[p.size]}; + ${p => p.control && controlStyle}; ${containerSystem.props}; @@ -152,9 +196,11 @@ const Checkbox = createComponent(() => ({ `, propTypes: { checked: PropTypes.bool, + control: PropTypes.bool, disabled: PropTypes.bool, onChange: PropTypes.func, size: PropTypes.oneOf(['sm', 'md', 'lg']), + valid: PropTypes.bool, value: PropTypes.string, }, defaultProps: {