From fccdf4de8df31b9e8469d3142e24a330de975b31 Mon Sep 17 00:00:00 2001 From: Igor Vidic Date: Mon, 21 Jan 2019 21:28:29 +1100 Subject: [PATCH 1/2] feat: add control option to Checkbox --- docs/components/Checkbox.mdx | 39 ++++++++++++++++++++++++++ packages/shared/core/Checkbox.js | 48 +++++++++++++++++++++++++++++++- 2 files changed, 86 insertions(+), 1 deletion(-) diff --git a/docs/components/Checkbox.mdx b/docs/components/Checkbox.mdx index 52f544eba..f87c409c9 100644 --- a/docs/components/Checkbox.mdx +++ b/docs/components/Checkbox.mdx @@ -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: { From cbfa206386a980db7c263245be992e0d05abd700 Mon Sep 17 00:00:00 2001 From: Igor Vidic Date: Tue, 22 Jan 2019 06:27:21 +1100 Subject: [PATCH 2/2] fix: Checkbox docs names and ids --- docs/components/Checkbox.mdx | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/components/Checkbox.mdx b/docs/components/Checkbox.mdx index f87c409c9..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 @@ -62,32 +62,32 @@ Disable using `disabled` prop. - Control + Control - Valid Control + Valid Control - Invalid Control + Invalid Control