@axa-fr/design-system-slash-react 1.2.1-alpha.62 → 1.2.1-alpha.63

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,14 +1,31 @@
1
- import { ComponentPropsWithRef } from "react";
1
+ import { ComponentPropsWithoutRef } from "react";
2
2
  import type { Option } from "../core";
3
- import { RadioItem } from "./RadioItem";
3
+ import { RadioCardGroup } from "./RadioCardGroup";
4
4
  export declare enum RadioModes {
5
5
  classic = "classic",
6
6
  default = "default",
7
- inline = "inline"
7
+ inline = "inline",
8
+ card = "card"
8
9
  }
9
- type Props = Omit<ComponentPropsWithRef<typeof RadioItem>, "id" | "label" | "className"> & {
10
+ declare const Radio: import("react").ForwardRefExoticComponent<(Omit<Omit<Omit<Omit<import("react").DetailedHTMLProps<import("react").InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "type" | "checked"> & {
11
+ classModifier?: string;
12
+ optionClassName?: string;
13
+ label?: import("react").ReactNode;
14
+ isChecked?: boolean;
15
+ }, "ref"> & import("react").RefAttributes<HTMLInputElement>, "className" | "id" | "label"> & {
10
16
  options: Option[];
11
- mode?: keyof typeof RadioModes;
12
- };
13
- declare const Radio: import("react").ForwardRefExoticComponent<Omit<Props, "ref"> & import("react").RefAttributes<HTMLInputElement>>;
17
+ } & {
18
+ mode?: "classic" | "default" | "inline";
19
+ }, "ref"> | Omit<Omit<Omit<Omit<import("react").DetailedHTMLProps<import("react").InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "type" | "checked"> & {
20
+ classModifier?: string;
21
+ optionClassName?: string;
22
+ label?: import("react").ReactNode;
23
+ isChecked?: boolean;
24
+ }, "ref"> & import("react").RefAttributes<HTMLInputElement>, "className" | "id" | "label"> & {
25
+ options: Option[];
26
+ } & {
27
+ mode: "card";
28
+ className?: string;
29
+ orientation?: ComponentPropsWithoutRef<typeof RadioCardGroup>["orientation"];
30
+ }, "ref">) & import("react").RefAttributes<HTMLInputElement>>;
14
31
  export { Radio };
@@ -1,11 +1,14 @@
1
1
  import { createElement as _createElement } from "react";
2
- import { forwardRef } from "react";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { forwardRef, } from "react";
3
4
  import { RadioItem } from "./RadioItem";
5
+ import { RadioCardGroup } from "./RadioCardGroup";
4
6
  export var RadioModes;
5
7
  (function (RadioModes) {
6
8
  RadioModes["classic"] = "classic";
7
9
  RadioModes["default"] = "default";
8
10
  RadioModes["inline"] = "inline";
11
+ RadioModes["card"] = "card";
9
12
  })(RadioModes || (RadioModes = {}));
10
13
  const getClassNameMode = (mode) => {
11
14
  switch (mode) {
@@ -13,13 +16,21 @@ const getClassNameMode = (mode) => {
13
16
  return "af-form__radio";
14
17
  case RadioModes.inline:
15
18
  return "af-form__radio-inline";
19
+ case RadioModes.card:
20
+ return "af-form__radio-card";
16
21
  default:
17
22
  return "af-form__radio-custom";
18
23
  }
19
24
  };
20
- const Radio = forwardRef(({ classModifier, options, value = "", mode = RadioModes.default, children, disabled, ...otherProps }, inputRef) => {
21
- const classNameMode = getClassNameMode(mode);
22
- return options.map((option) => (_createElement(RadioItem, { ...otherProps, key: option.value, isChecked: option.value === value, disabled: option.disabled || disabled, className: classNameMode, classModifier: classModifier, ref: inputRef, ...option }, children)));
25
+ const Radio = forwardRef(({ classModifier, options, value = "", children, disabled, ...otherProps }, inputRef) => {
26
+ const classNameMode = getClassNameMode(otherProps.mode ?? "default");
27
+ // ICI - le if qui permet de rendre un autre composant
28
+ if (otherProps.mode === "card") {
29
+ return (_jsx(RadioCardGroup, { className: otherProps.className, options: options, error: classModifier === "error", disabled: disabled, orientation: otherProps.orientation, children: children }));
30
+ }
31
+ const onlyNecessaryProps = { ...otherProps };
32
+ delete onlyNecessaryProps.mode;
33
+ return options.map((option) => (_createElement(RadioItem, { ...onlyNecessaryProps, key: option.value, isChecked: option.value === value, disabled: option.disabled || disabled, className: classNameMode, classModifier: classModifier, ref: inputRef, ...option }, children)));
23
34
  });
24
35
  Radio.displayName = "EnhancedInputRadio";
25
36
  export { Radio };
@@ -0,0 +1,12 @@
1
+ import "@axa-fr/design-system-slash-css/dist/Form/Radio/RadioCardGroup.css";
2
+ import { PropsWithChildren } from "react";
3
+ import type { Option } from "../core";
4
+ type Props = PropsWithChildren & {
5
+ options: Option[];
6
+ orientation?: "horizontal" | "vertical";
7
+ error?: boolean;
8
+ disabled?: boolean;
9
+ className?: string;
10
+ };
11
+ export declare const RadioCardGroup: ({ children, options, className, orientation, disabled, error, }: Props) => import("react/jsx-runtime").JSX.Element;
12
+ export {};
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import "@axa-fr/design-system-slash-css/dist/Form/Radio/RadioCardGroup.css";
3
+ import { useId, useRef } from "react";
4
+ import classNames from "classnames";
5
+ import { Svg } from "../../Svg";
6
+ const DEFAULT_CLASSNAME = "af-card";
7
+ const DEFAULT_CONTAINER_CLASSNAME = "af-form__radio-card-group";
8
+ export const RadioCardGroup = ({ children, options, className, orientation = "vertical", disabled = false, error = false, }) => {
9
+ const idGenerated = useId();
10
+ const radioGroupRef = useRef(null);
11
+ return (_jsxs("div", { ref: radioGroupRef, role: "radiogroup", className: classNames([
12
+ DEFAULT_CONTAINER_CLASSNAME,
13
+ className,
14
+ orientation === "horizontal" &&
15
+ `${DEFAULT_CONTAINER_CLASSNAME}--horizontal`,
16
+ ]), children: [options.map(({ name, icon, label, disabled: optionDisabled, checked, ...otherOptionProps }) => {
17
+ const newName = name ?? idGenerated;
18
+ const allClassNames = classNames([
19
+ DEFAULT_CLASSNAME,
20
+ orientation === "horizontal" && `${DEFAULT_CLASSNAME}--horizontal`,
21
+ error && `${DEFAULT_CLASSNAME}--error`,
22
+ ]);
23
+ const isDisabled = disabled || optionDisabled;
24
+ return (_jsxs("label", { className: allClassNames, children: [_jsx("input", { type: "radio", name: newName, disabled: isDisabled, checked: isDisabled ? false : checked, ...otherOptionProps }), typeof icon === "string" ? _jsx(Svg, { src: icon }) : icon, label] }, otherOptionProps.value));
25
+ }), children] }));
26
+ };
@@ -1,12 +1,6 @@
1
+ import { ComponentPropsWithoutRef } from "react";
1
2
  import { type ConsumerFieldProps } from "../core";
2
- import { RadioModes } from "./Radio";
3
- declare const RadioInput: import("react").ForwardRefExoticComponent<ConsumerFieldProps & Omit<Omit<Omit<Omit<Omit<import("react").DetailedHTMLProps<import("react").InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "type" | "checked"> & {
4
- classModifier?: string;
5
- optionClassName?: string;
6
- label?: import("react").ReactNode;
7
- isChecked?: boolean;
8
- }, "ref"> & import("react").RefAttributes<HTMLInputElement>, "className" | "id" | "label"> & {
9
- options: import("../core").Option[];
10
- mode?: keyof typeof RadioModes;
11
- }, "ref"> & import("react").RefAttributes<HTMLInputElement>, "ref"> & import("react").RefAttributes<HTMLInputElement>>;
3
+ import { Radio } from "./Radio";
4
+ type RadioInputProps = ConsumerFieldProps & ComponentPropsWithoutRef<typeof Radio>;
5
+ declare const RadioInput: import("react").ForwardRefExoticComponent<RadioInputProps & import("react").RefAttributes<HTMLInputElement>>;
12
6
  export { RadioInput };
@@ -17,9 +17,11 @@ export type Option = {
17
17
  id?: string;
18
18
  icon?: ReactNode;
19
19
  label: ReactNode;
20
+ /**
21
+ * @deprecated Ne semble pas utilisé
22
+ */
20
23
  description?: ReactNode;
21
24
  value: string;
22
- disabled?: boolean;
23
25
  } & React.InputHTMLAttributes<HTMLInputElement>;
24
26
  type BaseFormEvent = {
25
27
  id: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axa-fr/design-system-slash-react",
3
- "version": "1.2.1-alpha.62",
3
+ "version": "1.2.1-alpha.63",
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.2.1-alpha.62",
50
+ "@axa-fr/design-system-slash-css": "1.2.1-alpha.63",
51
51
  "@material-symbols/svg-400": ">= 0.19.0",
52
52
  "react": ">= 18"
53
53
  },