diff --git a/stories/FormCheckbox/Styled.stories.mdx b/stories/FormCheckbox/Styled.stories.mdx index e5e96333..760615ee 100644 --- a/stories/FormCheckbox/Styled.stories.mdx +++ b/stories/FormCheckbox/Styled.stories.mdx @@ -8,10 +8,10 @@ import '../style.css'; In this section we're using the formCheckbox component providing the GovUk style passing the relative `className`. Feel free to use your own css and style the formInput as you prefer -### GDS styled checkboxes +### GDS styled checkbox - + {() => { const [value, setValue] = React.useState(''); const [checked, setChecked] = React.useState(false); @@ -20,56 +20,14 @@ In this section we're using the formCheckbox component providing the GovUk style setChecked(!checked); }; return ( -
-
- -

- Which types of waste do you transport? -

-
-
- Select all that apply. -
+
+
- - -### GDS styled checkboxes with hint +### GDS styled checkbox with hint - + {() => { const [value, setValue] = React.useState(''); const [checked, setChecked] = React.useState(false); @@ -102,94 +60,40 @@ In this section we're using the formCheckbox component providing the GovUk style setChecked(!checked); }; return ( -
-
- -

- What is your nationality? -

-
-
- If you have dual nationality, select all options that are relevant - to you. -
-
- - - -
-
-
+ ); }}
-### GDS styled checkboxes with conditionally revealing content +### GDS styled checkbox with conditionally revealing content {() => { const [value, setValue] = React.useState({ contact: false, - 'contact-2': false, - 'contact-3': false, }); const handleChange = (event, conditional) => { setValue({ @@ -199,129 +103,49 @@ In this section we're using the formCheckbox component providing the GovUk style console.log(conditional); }; return ( -
-
- -

- How would you like to be contacted? -

-
-
- Select all options that are relevant to you. -
-
- - {}, - name: 'contact-by-phone', - label: 'Phone number', - type: 'text', - className: 'govuk-form-group', - groupClassName: - 'govuk-checkboxes__conditional govuk-checkboxes__conditional--hidden', - id: 'conditional-contact-2', - inputClassName: 'govuk-input govuk-!-width-one-third', - inputId: 'contact-by-phone', - labelClassName: 'govuk-label', - }} - /> - {}, - name: 'contact-by-text', - label: 'Mobile phone number', - type: 'text', - className: 'govuk-form-group', - groupClassName: - 'govuk-checkboxes__conditional govuk-checkboxes__conditional--hidden', - id: 'conditional-contact-3', - inputClassName: 'govuk-input govuk-!-width-one-third', - inputId: 'contact-by-text', - labelClassName: 'govuk-label', - }} - /> -
-
-
+ ); }}
-### GDS styled checkboxes with conditionally revealing content where the conditinal is a sibling +### GDS styled checkbox with conditionally revealing content where the conditinal is a sibling {() => { const [value, setValue] = React.useState({ - contact: false, - 'contact-2': false, - 'contact-3': false, + 'contact-sibiling': false, }); const handleChange = (event, conditional) => { setValue({ @@ -331,221 +155,47 @@ In this section we're using the formCheckbox component providing the GovUk style console.log(conditional); }; return ( -
-
- -

- How would you like to be contacted? -

-
-
- Select all options that are relevant to you. -
-
- - {}, - name: 'contact-by-phone', - label: 'Phone number', - type: 'text', - className: 'govuk-form-group', - groupClassName: - 'govuk-checkboxes__conditional govuk-checkboxes__conditional--hidden', - id: 'conditional-contact-2', - inputClassName: 'govuk-input govuk-!-width-one-third', - inputId: 'contact-by-phone', - labelClassName: 'govuk-label', - position: 'sibling', - }} - /> - {}, - name: 'contact-by-text', - label: 'Mobile phone number', - type: 'text', - className: 'govuk-form-group', - groupClassName: - 'govuk-checkboxes__conditional govuk-checkboxes__conditional--hidden', - id: 'conditional-contact-3', - inputClassName: 'govuk-input govuk-!-width-one-third', - inputId: 'contact-by-text', - labelClassName: 'govuk-label', - position: 'sibling', - }} - /> -
-
-
- ); - }} -
-
- -### GDS styled small checkboxes - - - - {() => { - const [value, setValue] = React.useState(''); - const [checked, setChecked] = React.useState(false); - const handleChange = (event) => { - setValue(event.currentTarget.value); - setChecked(!checked); - }; - return ( -
-
- -

Organisation

-
-
- - - - -
-
-
+ ); }}
-### GDS styled checkboxes with error validation +### GDS styled small checkbox - + {() => { const [value, setValue] = React.useState(''); const [checked, setChecked] = React.useState(false); @@ -554,84 +204,23 @@ In this section we're using the formCheckbox component providing the GovUk style setChecked(!checked); }; return ( -
-
- -

- What is your nationality? -

-
-
- If you have dual nationality, select all options that are relevant - to you. -
- - Error: Select if - you are British, Irish or a citizen of a different country - -
- - - -
-
-
+ ); }}
diff --git a/stories/FormCheckbox/UnStyled.stories.mdx b/stories/FormCheckbox/UnStyled.stories.mdx index d464b857..07216c65 100644 --- a/stories/FormCheckbox/UnStyled.stories.mdx +++ b/stories/FormCheckbox/UnStyled.stories.mdx @@ -7,7 +7,7 @@ import '../style.css'; ### Example of basic checkbox - + {() => { const [value, setValue] = React.useState(''); const [checked, setChecked] = React.useState(false); @@ -36,7 +36,7 @@ import '../style.css'; By default, the hint will display underneath the checkbox - + {() => { const [value, setValue] = React.useState(''); const [checked, setChecked] = React.useState(false); @@ -67,7 +67,7 @@ By default, the hint will display underneath the checkbox ### Example of basic checkbox with hint positioned above - + {() => { const [value, setValue] = React.useState(''); const [checked, setChecked] = React.useState(false); @@ -98,7 +98,7 @@ By default, the hint will display underneath the checkbox ### Example of disabled checkbox - + {() => { const [value, setValue] = React.useState(''); const [checked, setChecked] = React.useState(false); @@ -126,7 +126,7 @@ By default, the hint will display underneath the checkbox ### Example of preselected checkbox - + {() => { const [value, setValue] = React.useState(''); const [checked, setChecked] = React.useState(true); @@ -153,7 +153,7 @@ By default, the hint will display underneath the checkbox ### Example of checkbox with conditional input field - + {() => { const [value, setValue] = React.useState(''); const [checked, setChecked] = React.useState(true); @@ -181,10 +181,7 @@ By default, the hint will display underneath the checkbox name: 'conditional-6', label: 'condition label', type: 'text', - className: 'classes', - groupClassName: 'group-classes', id: 'checkbox-6', - inputClassName: 'input-classes', inputId: 'input-6', }} /> @@ -194,76 +191,44 @@ By default, the hint will display underneath the checkbox -### Example of nested checkbox - - - - {() => { - const [value, setValue] = React.useState(''); - const [checked, setChecked] = React.useState(false); - const handleChange = (event) => { - setValue(event.currentTarget.value); - setChecked(!checked); - }; - return ( - - ); - }} - - - ### Example of a checkbox with a sibling conditional The property conditionalPosition can be set to 'sibling' if you want the conditional element to be a sibling of the main input elment for styling purposes - + {() => { - const [value, setValue] = React.useState(''); - const [checked, setChecked] = React.useState(true); + const [value, setValue] = React.useState({ + 'contact-sibiling': false, + 'contact-sibiling-2': false, + 'contact-sibiling-3': false, + }); const handleChange = (event, conditional) => { - if (conditional) { - console.log(conditional); - return; - } - setValue(event.currentTarget.value); - setChecked(event.currentTarget.checked); + setValue({ + ...value, + [event.target.id]: event.target.checked, + }); + console.log(conditional); }; return ( - <> - ); }}