File tree Expand file tree Collapse file tree 3 files changed +26
-6
lines changed
src/stories/Library/Forms/checkbox Expand file tree Collapse file tree 3 files changed +26
-6
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,12 @@ export default {
1212 type : "text" ,
1313 } ,
1414 } ,
15+ validation : {
16+ control : {
17+ type : "text" ,
18+ defaultValue : "" ,
19+ } ,
20+ } ,
1521 // We disable the isChecked control, since it is not possible to
1622 // get the states from the React component to work with Storybook controls.
1723 isChecked : {
@@ -37,6 +43,7 @@ export const Unchecked = Template.bind({});
3743Unchecked . args = {
3844 isChecked : false ,
3945 label : "Toggle this checkbox" ,
46+ validation : "Error error error" ,
4047} ;
4148
4249// Show multiple checkboxes to make it easier to test keyboard navigation.
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ export type CheckboxProps = {
44 isChecked : boolean ;
55 label ?: string ;
66 ariaLabel ?: string ;
7+ validation ?: string ;
78 callback ?: ( isChecked : boolean ) => void ;
89} ;
910
@@ -12,6 +13,7 @@ export const Checkbox: React.FC<CheckboxProps> = ({
1213 label,
1314 ariaLabel,
1415 callback,
16+ validation,
1517} ) => {
1618 const checkboxId = useRef ( `checkbox_id__${ Math . random ( ) } ` ) ;
1719 const [ checked , setChecked ] = useState ( isChecked ) ;
@@ -46,11 +48,18 @@ export const Checkbox: React.FC<CheckboxProps> = ({
4648 />
4749 </ svg >
4850 </ span >
49- { label && (
50- < span className = "checkbox__text text-small-caption color-secondary-gray" >
51- { label }
52- </ span >
53- ) }
51+ < div >
52+ { label && (
53+ < span className = "checkbox__text text-small-caption color-secondary-gray" >
54+ { label }
55+ </ span >
56+ ) }
57+ { validation && (
58+ < div className = "checkbox__text text-small-caption checkbox__text--validation" >
59+ { validation }
60+ </ div >
61+ ) }
62+ </ div >
5463 </ label >
5564 </ div >
5665 ) ;
Original file line number Diff line number Diff line change 4545 transform : translate3d (0 , 0 , 0 );
4646}
4747
48- .checkbox__label .checkbox__text :last-child {
48+ .checkbox__label .checkbox__text {
4949 padding-left : 8px ;
5050 line-height : 18px ;
51+
52+ & --validation {
53+ color : $c-signal-alert ;
54+ }
5155}
5256
5357.checkbox__label :hover .checkbox__icon :first-child {
You can’t perform that action at this time.
0 commit comments