Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: add small props to checbox and radio buttons #115

Merged
merged 5 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions src/shared/Fieldset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export namespace FieldsetProps {
stateRelatedMessage?: ReactNode;
/** Default: false */
disabled?: boolean;
/** default: false */
small?: boolean;
maximallain marked this conversation as resolved.
Show resolved Hide resolved
};

export type Radio = Common & {
Expand Down Expand Up @@ -70,6 +72,7 @@ export const Fieldset = memo(
disabled = false,
type,
name: name_props,
small = false,
...rest
} = props;

Expand Down Expand Up @@ -148,22 +151,22 @@ export const Fieldset = memo(
</legend>
)}
<div className={cx(fr.cx("fr-fieldset__content"), classes.content)}>
{options.map(({ label, hintText, nativeInputProps }, i) => (
<div className={fr.cx(`fr-${type}-group`)} key={i}>
<input
type={type}
id={getInputId(i)}
name={radioName}
{...nativeInputProps}
/>
<label className={fr.cx("fr-label")} htmlFor={getInputId(i)}>
{label}
{hintText !== undefined && (
<span className={fr.cx("fr-hint-text")}>{hintText}</span>
)}
</label>
</div>
))}
{options.map(({ label, hintText, nativeInputProps }, i) =>
<div className={fr.cx(`fr-${type}-group`, small && `fr-${type}-group--sm`)} key={i}>
<input
type={type}
id={getInputId(i)}
name={radioName}
{...nativeInputProps}
/>
<label className={fr.cx("fr-label")} htmlFor={getInputId(i)}>
{label}
{hintText !== undefined && (
<span className={fr.cx("fr-hint-text")}>{hintText}</span>
)}
</label>
</div>
)}
</div>
{state !== "default" && (
<p
Expand Down
31 changes: 31 additions & 0 deletions stories/Checkbox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ const { meta, getStory } = getStoryFactory({
},
"disabled": {
"control": { "type": "boolean" }
},
"small": {
"control": { "type": "boolean" }
}
},
"disabledProps": ["lang"]
Expand Down Expand Up @@ -269,6 +272,34 @@ export const SuccessState = getStory({
]
});

export const Small = getStory({
"legend": "Légende pour l’ensemble de champs",
"small": true,
"options": [
{
"label": "Label checkbox",
"nativeInputProps": {
"name": "checkboxes-1",
"value": "value1"
}
},
{
"label": "Label checkbox 2",
"nativeInputProps": {
"name": "checkboxes-1",
"value": "value2"
}
},
{
"label": "Label checkbox 3",
"nativeInputProps": {
"name": "checkboxes-1",
"value": "value3"
}
}
]
});

export const Disabled = getStory({
"legend": "Légende pour l’ensemble de champs",
"disabled": true,
Expand Down
30 changes: 29 additions & 1 deletion stories/RadioButtons.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { meta, getStory } = getStoryFactory({
sectionName,
"wrappedComponent": { RadioButtons },
"description": `
- [See DSFR documentation](https://www.systeme-de-design.gouv.fr/elements-d-interface/composants/boutons-radio)
- [See DSFR documentation](https://www.systeme-de-design.gouv.fr/elements-d-interface/composants/bouton-radio)
- [See source code](https://github.com/codegouvfr/react-dsfr/blob/main/src/RadioButtons.tsx)

## Controlled
Expand Down Expand Up @@ -138,6 +138,9 @@ function MyComponent(){
},
"disabled": {
"control": { "type": "boolean" }
},
"small": {
"control": { "type": "boolean" }
}
},
"disabledProps": ["lang"]
Expand Down Expand Up @@ -356,3 +359,28 @@ export const Disabled = getStory({
}
]
});

export const Small = getStory({
"legend": "Légende pour l’ensemble de champs",
"small": true,
"options": [
{
"label": "Label radio",
"nativeInputProps": {
"value": "value1"
}
},
{
"label": "Label radio 2",
"nativeInputProps": {
"value": "value2"
}
},
{
"label": "Label radio 3",
"nativeInputProps": {
"value": "value3"
}
}
]
});