@axa-fr/design-system-slash-react 1.1.1-alpha.237 → 1.1.1-alpha.239

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,10 @@
1
1
  import "@axa-fr/design-system-slash-css/dist/Form/Choice/Choice.scss";
2
2
  import { type ComponentProps } from "react";
3
3
  import { Radio } from "../Radio";
4
- import type { Option } from "../core";
4
+ import { type Option } from "../core";
5
5
  type Props = Omit<ComponentProps<typeof Radio>, "options"> & {
6
6
  id: string;
7
+ name?: string;
7
8
  options?: Array<Omit<Option, "value"> & {
8
9
  value: boolean;
9
10
  }>;
@@ -1,17 +1,19 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import "@axa-fr/design-system-slash-css/dist/Form/Choice/Choice.scss";
3
- import { forwardRef } from "react";
3
+ import { forwardRef, useId } from "react";
4
4
  import { Radio } from "../Radio";
5
+ import { useOptionsWithId } from "../core";
5
6
  const defaultOptions = [
6
- { label: "Oui", value: true, id: "radioItemTrue" },
7
- { label: "Non", value: false, id: "radioItemFalse" },
7
+ { label: "Oui", value: true },
8
+ { label: "Non", value: false },
8
9
  ];
9
- const Choice = forwardRef(({ children, value, options = defaultOptions, ...otherProps }, inputRef) => {
10
- const choiceOptions = options.map((option) => ({
11
- ...option,
12
- value: `${option.value}`,
13
- }));
14
- return (_jsx(Radio, { ...otherProps, ref: inputRef, value: value?.toString(), options: choiceOptions, children: children }));
10
+ const Choice = forwardRef(({ children, value, options = defaultOptions, name, ...otherProps }, inputRef) => {
11
+ const choiceOptions = useOptionsWithId(options.map((o) => ({
12
+ ...o,
13
+ value: `${o.value}`,
14
+ })));
15
+ const generatedId = useId();
16
+ return (_jsx(Radio, { ...otherProps, ref: inputRef, name: name ?? `choice_${generatedId}`, value: value?.toString(), options: choiceOptions, children: children }));
15
17
  });
16
18
  Choice.displayName = "Choice";
17
19
  export { Choice };
@@ -4,12 +4,15 @@ import { LegacyField, useInputClassModifier, useOptionsWithId } from "../core";
4
4
  import { Choice } from "./Choice";
5
5
  import { useAriaInvalid } from "../core/useAriaInvalid";
6
6
  const defaultOptions = [
7
- { label: "Oui", value: true, id: "radioItemTrue" },
8
- { label: "Non", value: false, id: "radioItemFalse" },
7
+ { label: "Oui", value: true },
8
+ { label: "Non", value: false },
9
9
  ];
10
- const ChoiceInput = forwardRef(({ id, messageType, message, className, classModifier, isVisible, classNameContainerLabel, classNameContainerInput, label, forceDisplayMessage, options = defaultOptions, disabled, required, ...otherProps }, inputRef) => {
10
+ const ChoiceInput = forwardRef(({ id, name, messageType, message, className, classModifier, isVisible, classNameContainerLabel, classNameContainerInput, label, forceDisplayMessage, options = defaultOptions, disabled, required, ...otherProps }, inputRef) => {
11
11
  const errorUseId = useId();
12
- const newOptions = useOptionsWithId(options.map((o) => ({ ...o, value: `${o.value}` })), id);
12
+ const newOptions = useOptionsWithId(options.map((o) => ({
13
+ ...o,
14
+ value: `${o.value}`,
15
+ })));
13
16
  const { inputClassModifier, inputFieldClassModifier } = useInputClassModifier(classModifier ?? "", disabled ?? false, false, required);
14
17
  const firstId = newOptions?.[0]?.id ?? "";
15
18
  const choiceOptions = newOptions.map((o) => ({
@@ -17,7 +20,7 @@ const ChoiceInput = forwardRef(({ id, messageType, message, className, classModi
17
20
  value: o.value === "true",
18
21
  }));
19
22
  const isInvalid = useAriaInvalid(message, forceDisplayMessage, messageType);
20
- return (_jsx(LegacyField, { label: label, id: firstId, message: message, messageType: messageType, isVisible: isVisible, forceDisplayMessage: forceDisplayMessage, className: className, classModifier: inputFieldClassModifier, classNameContainerLabel: classNameContainerLabel, classNameContainerInput: classNameContainerInput, errorId: errorUseId, children: _jsx(Choice, { ...otherProps, id: id, ref: inputRef, classModifier: inputClassModifier, options: options ? choiceOptions : undefined, required: required, disabled: disabled, "aria-describedby": errorUseId, "aria-invalid": isInvalid }) }));
23
+ return (_jsx(LegacyField, { label: label, id: firstId, message: message, messageType: messageType, isVisible: isVisible, forceDisplayMessage: forceDisplayMessage, className: className, classModifier: inputFieldClassModifier, classNameContainerLabel: classNameContainerLabel, classNameContainerInput: classNameContainerInput, errorId: errorUseId, children: _jsx(Choice, { ...otherProps, id: id, name: name, ref: inputRef, classModifier: inputClassModifier, options: options ? choiceOptions : undefined, required: required, disabled: disabled, "aria-describedby": errorUseId, "aria-invalid": isInvalid }) }));
21
24
  });
22
25
  ChoiceInput.displayName = "ChoiceInput";
23
26
  export { ChoiceInput };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axa-fr/design-system-slash-react",
3
- "version": "1.1.1-alpha.237",
3
+ "version": "1.1.1-alpha.239",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -47,7 +47,7 @@
47
47
  },
48
48
  "homepage": "https://github.com/AxaFrance/design-system#readme",
49
49
  "peerDependencies": {
50
- "@axa-fr/design-system-slash-css": "1.1.1-alpha.237",
50
+ "@axa-fr/design-system-slash-css": "1.1.1-alpha.239",
51
51
  "@material-symbols/svg-400": ">= 0.19.0",
52
52
  "react": ">= 18"
53
53
  },