diff --git a/src/Checkbox.tsx b/src/Checkbox.tsx index c865599cd..dfa9daec8 100644 --- a/src/Checkbox.tsx +++ b/src/Checkbox.tsx @@ -2,12 +2,12 @@ import React, { memo, forwardRef } from "react"; import { symToStr } from "tsafe/symToStr"; import { Fieldset, type FieldsetProps } from "./shared/Fieldset"; -export type CheckboxProps = FieldsetProps.Common; +export type CheckboxProps = Omit; /** @see */ export const Checkbox = memo( forwardRef((props, ref) => ( -
+
)) ); diff --git a/src/RadioButtons.tsx b/src/RadioButtons.tsx index a692e0764..ce36f581a 100644 --- a/src/RadioButtons.tsx +++ b/src/RadioButtons.tsx @@ -2,12 +2,12 @@ import React, { memo, forwardRef } from "react"; import { symToStr } from "tsafe/symToStr"; import { Fieldset, type FieldsetProps } from "./shared/Fieldset"; -export type RadioButtonsProps = FieldsetProps.Common & { name?: string }; +export type RadioButtonsProps = Omit; /** @see */ export const RadioButtons = memo( forwardRef((props, ref) => ( -
+
)) ); diff --git a/src/shared/Fieldset.tsx b/src/shared/Fieldset.tsx index 101730528..3396747f5 100644 --- a/src/shared/Fieldset.tsx +++ b/src/shared/Fieldset.tsx @@ -4,8 +4,7 @@ import React, { forwardRef, type ReactNode, type CSSProperties, - type InputHTMLAttributes, - type DetailedHTMLProps + type ComponentProps } from "react"; import { symToStr } from "tsafe/symToStr"; import { assert } from "tsafe/assert"; @@ -27,11 +26,9 @@ export namespace FieldsetProps { options: { label: ReactNode; hintText?: ReactNode; - nativeInputProps: DetailedHTMLProps< - InputHTMLAttributes, - HTMLInputElement - >; + nativeInputProps: ComponentProps<"input">; }[]; + /** Default: "vertical" */ orientation?: "vertical" | "horizontal"; /** Default: "default" */ @@ -47,9 +44,12 @@ export namespace FieldsetProps { small?: boolean; }; - export type Radio = Common & { + export type Radio = Omit & { type: "radio"; name?: string; + options: (Common["options"][number] & { + illustration?: ReactNode; + })[]; }; export type Checkbox = Common & { @@ -79,6 +79,10 @@ export const Fieldset = memo( ...rest } = props; + const isRichRadio = + type === "radio" && + options.find(options => options.illustration !== undefined) !== undefined; + assert>(); const id = useAnalyticsId({ @@ -145,9 +149,13 @@ export const Fieldset = memo( )}
- {options.map(({ label, hintText, nativeInputProps }, i) => ( + {options.map(({ label, hintText, nativeInputProps, ...rest }, i) => (
{hintText} )} + {"illustration" in rest && ( +
+ {rest.illustration} +
+ )}
))}
diff --git a/stories/RadioButtons.stories.tsx b/stories/RadioButtons.stories.tsx index 45635da32..a131f4bab 100644 --- a/stories/RadioButtons.stories.tsx +++ b/stories/RadioButtons.stories.tsx @@ -1,3 +1,4 @@ +import React from "react"; import { RadioButtons, type RadioButtonsProps } from "../dist/RadioButtons"; import { sectionName } from "./sectionName"; import { getStoryFactory } from "./getStory"; @@ -384,3 +385,33 @@ export const Small = getStory({ } ] }); + +export const Rich = getStory({ + "legend": "Légende pour l’ensemble de champs", + "name": "radio", + "options": [ + { + "label": "Label radio", + "nativeInputProps": { + "value": "value1" + }, + "illustration": illustration + }, + { + "label": "Label radio 2", + "nativeInputProps": { + "value": "value2" + }, + "illustration": illustration + }, + { + "label": "Label radio 3", + "nativeInputProps": { + "value": "value3" + }, + "illustration": illustration + } + ], + "state": "default", + "stateRelatedMessage": "State description" +}); diff --git a/test/types/Checkbox.tsx b/test/types/Checkbox.tsx new file mode 100644 index 000000000..3e3cc56b3 --- /dev/null +++ b/test/types/Checkbox.tsx @@ -0,0 +1,48 @@ +import React from "react"; +import { Checkbox } from "../../src/Checkbox"; + +{ + ; +} +{ + + } + ]} + />; +} diff --git a/test/types/RadioButtons.tsx b/test/types/RadioButtons.tsx new file mode 100644 index 000000000..ed033c385 --- /dev/null +++ b/test/types/RadioButtons.tsx @@ -0,0 +1,101 @@ +import React from "react"; +import { RadioButtons } from "../../src/RadioButtons"; +import { RadioRichButtons } from "../../src/RadioRichButtons"; + +{ + ; +} + +{ + + }, + { + "label": "Label 2", + "hintText": "Hint text", + "nativeInputProps": { + "value": 2 + }, + "illustration": illustration + } + ]} + />; +} + +{ + + }, + { + "label": "Label 2", + "hintText": "Hint text", + "nativeInputProps": { + "value": 2 + } + } + ]} + />; +} + +{ + + }, + // @ts-expect-error + { + "label": "Label 2", + "hintText": "Hint text", + "nativeInputProps": { + "value": 2 + } + } + ]} + />; +}