@axa-fr/design-system-look-and-feel-react 1.0.5-ci.24 → 1.0.5-ci.25

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,7 +1,11 @@
1
1
  import "@axa-fr/design-system-look-and-feel-css/dist/Form/Checkbox/Checkbox.scss";
2
2
  import React, { ReactNode } from "react";
3
3
  declare const Checkbox: React.ForwardRefExoticComponent<{
4
- label: string | ReactNode;
4
+ label: ReactNode;
5
+ subtitle?: ReactNode;
6
+ description?: ReactNode;
7
+ icon?: ReactNode;
5
8
  errorMessage?: string;
9
+ showErrorMessage?: boolean;
6
10
  } & Omit<React.InputHTMLAttributes<HTMLInputElement>, "label"> & React.RefAttributes<HTMLInputElement>>;
7
11
  export { Checkbox };
@@ -2,15 +2,15 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import "@axa-fr/design-system-look-and-feel-css/dist/Form/Checkbox/Checkbox.scss";
3
3
  import checkBoxIcon from "@material-symbols/svg-400/outlined/check_box-fill.svg";
4
4
  import checkBoxOutlineBlankIcon from "@material-symbols/svg-400/outlined/check_box_outline_blank.svg";
5
- import errorOutline from "@material-symbols/svg-400/outlined/error.svg";
6
5
  import { forwardRef, useId } from "react";
7
6
  import classNames from "classnames";
8
7
  import { Svg } from "../../Svg";
9
- const Checkbox = forwardRef(({ label, errorMessage, className, ...inputProps }, ref) => {
8
+ import { InputError } from "../InputError";
9
+ const Checkbox = forwardRef(({ label, icon, description, subtitle, errorMessage, className, showErrorMessage = true, ...inputProps }, ref) => {
10
10
  const idError = useId();
11
11
  let inputId = useId();
12
12
  inputId = inputProps.id || inputId;
13
- return (_jsxs("div", { children: [_jsx("div", { className: classNames("af-checkbox", className), children: _jsxs("label", { htmlFor: inputId, children: [_jsx("input", { ref: ref, ...inputProps, type: "checkbox", id: inputId, "aria-errormessage": idError, "aria-invalid": !!errorMessage }), _jsxs("div", { className: "af-checkbox__icons", children: [_jsx(Svg, { src: checkBoxOutlineBlankIcon, className: "af-checkbox__unchecked" }), _jsx(Svg, { src: checkBoxIcon, className: "af-checkbox__checked" })] }), label] }, inputProps.name) }), errorMessage && (_jsxs("div", { className: "af-checkbox__error", "aria-live": "assertive", id: idError, children: [_jsx(Svg, { src: errorOutline }), errorMessage] }))] }));
13
+ return (_jsxs("div", { children: [_jsx("div", { className: classNames("af-checkbox", className), children: _jsxs("label", { htmlFor: inputId, children: [_jsx("input", { ref: ref, ...inputProps, type: "checkbox", id: inputId, "aria-errormessage": idError, "aria-invalid": Boolean(errorMessage) && !inputProps.disabled }), _jsxs("div", { className: "af-checkbox__icons", children: [_jsx(Svg, { src: checkBoxOutlineBlankIcon, className: "af-checkbox__unchecked" }), _jsx(Svg, { src: checkBoxIcon, className: "af-checkbox__checked" })] }), _jsxs("div", { className: "af-checkbox__content", children: [icon, _jsxs("div", { className: "af-checkbox__content-description", children: [_jsx("span", { children: label }), description && _jsx("span", { children: description }), subtitle && _jsx("span", { children: subtitle })] })] })] }, inputProps.name) }), errorMessage && showErrorMessage && (_jsx(InputError, { id: idError, message: errorMessage }))] }));
14
14
  });
15
15
  Checkbox.displayName = "Checkbox";
16
16
  export { Checkbox };
@@ -1,7 +1,8 @@
1
1
  import "@axa-fr/design-system-look-and-feel-css/dist/Form/Checkbox/Checkbox.scss";
2
- import React, { ComponentPropsWithRef, type ReactNode } from "react";
3
- type CheckboxProps = ComponentPropsWithRef<"input"> & {
2
+ import React, { ComponentPropsWithRef, ReactNode } from "react";
3
+ type Props = ComponentPropsWithRef<"input"> & {
4
4
  type: "vertical" | "horizontal";
5
+ border?: boolean;
5
6
  labelGroup?: string;
6
7
  descriptionGroup?: string;
7
8
  isRequired?: boolean;
@@ -12,7 +13,8 @@ type CheckboxProps = ComponentPropsWithRef<"input"> & {
12
13
  icon?: ReactNode;
13
14
  } & React.InputHTMLAttributes<HTMLInputElement>)[];
14
15
  errorMessage?: string;
15
- onChange?: React.ChangeEventHandler;
16
+ onChange?: (...event: unknown[]) => void;
17
+ value?: unknown[];
16
18
  };
17
- export declare const CheckboxSelect: ({ className, labelGroup, descriptionGroup, isRequired, options, errorMessage, onChange, type, }: CheckboxProps) => import("react/jsx-runtime").JSX.Element;
18
- export {};
19
+ declare const CheckboxSelect: React.ForwardRefExoticComponent<Omit<Props, "ref"> & React.RefAttributes<HTMLInputElement>>;
20
+ export { CheckboxSelect };
@@ -1,14 +1,34 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import "@axa-fr/design-system-look-and-feel-css/dist/Form/Checkbox/Checkbox.scss";
3
- import checkBoxIcon from "@material-symbols/svg-400/outlined/check_box-fill.svg";
4
- import checkBoxOutlineBlankIcon from "@material-symbols/svg-400/outlined/check_box_outline_blank.svg";
5
- import errorOutline from "@material-symbols/svg-400/outlined/error.svg";
6
- import { useId } from "react";
7
- import { Svg } from "../../Svg";
8
- import { getComponentClassName } from "../../utilities/helpers/getComponentClassName";
9
- export const CheckboxSelect = ({ className, labelGroup, descriptionGroup, isRequired, options, errorMessage, onChange, type = "vertical", }) => {
10
- const componentClassName = getComponentClassName("af-checkbox__container", className);
11
- const checkboxGroupClassName = getComponentClassName(`af-checkbox af-checkbox-select af-checkbox-select--${type}`, className);
3
+ import { forwardRef, useEffect, useId, useState, } from "react";
4
+ import { Checkbox } from "./Checkbox";
5
+ import { getComponentClassName } from "../core";
6
+ import { InputError } from "../InputError";
7
+ const CheckboxSelect = forwardRef(({ options, errorMessage, onChange, value, type = "vertical", className, labelGroup, descriptionGroup, isRequired, border = true, }, ref) => {
8
+ const [checkedState, setCheckedState] = useState(options.map((x) => Boolean(value?.includes(x.value))));
12
9
  const optionId = useId();
13
- return (_jsxs("div", { className: componentClassName, children: [_jsxs("div", { className: "af-checkbox__label-container", children: [labelGroup && (_jsxs("span", { className: "af-checkbox__label", id: optionId, children: [labelGroup, isRequired && _jsx("span", { "aria-hidden": "true", children: "\u00A0*" })] })), descriptionGroup && (_jsx("span", { className: "af-checkbox__description", children: descriptionGroup }))] }), _jsx("div", { role: "group", className: checkboxGroupClassName, children: options.map(({ label, description, subtitle, icon, ...inputProps }) => (_jsxs("label", { htmlFor: `id-${inputProps.name}`, children: [_jsx("input", { type: "checkbox", ...inputProps, id: `id-${inputProps.name}`, onChange: onChange, "aria-invalid": Boolean(errorMessage) && !inputProps.disabled }), _jsxs("div", { className: "af-checkbox__icons", children: [_jsx(Svg, { src: checkBoxOutlineBlankIcon, className: "af-checkbox__unchecked" }), _jsx(Svg, { src: checkBoxIcon, className: "af-checkbox__checked" })] }), _jsxs("div", { className: "af-checkbox__content", children: [icon, _jsxs("div", { className: "af-checkbox__content-description", children: [_jsx("span", { children: label }), description && _jsx("span", { children: description }), subtitle && _jsx("span", { children: subtitle })] })] })] }, inputProps.name))) }), errorMessage && (_jsxs("div", { className: "af-checkbox__error", "aria-live": "assertive", children: [_jsx(Svg, { src: errorOutline }), errorMessage] }))] }));
14
- };
10
+ const idError = useId();
11
+ const handleOnChange = (position) => {
12
+ const updatedCheckedState = checkedState.map((item, index) => index === position ? !item : item);
13
+ setCheckedState(updatedCheckedState);
14
+ if (onChange) {
15
+ const arr = [];
16
+ updatedCheckedState.forEach((x, idx) => {
17
+ if (x === true) {
18
+ arr.push(options[idx].value);
19
+ }
20
+ });
21
+ onChange(arr);
22
+ }
23
+ };
24
+ useEffect(() => {
25
+ setCheckedState(options.map((x) => Boolean(value?.includes(x.value))));
26
+ }, [setCheckedState, options, value]);
27
+ const componentClassName = getComponentClassName("af-checkbox__container", className);
28
+ const checkboxGroupClassName = getComponentClassName(`af-checkbox${border ? " af-checkbox-select" : ""} af-checkbox-select--${type}`, className);
29
+ return (_jsxs("div", { className: componentClassName, children: [_jsxs("div", { className: "af-checkbox__label-container", children: [labelGroup && (_jsxs("span", { className: "af-checkbox__label", id: optionId, children: [labelGroup, isRequired && _jsx("span", { "aria-hidden": "true", children: "\u00A0*" })] })), descriptionGroup && (_jsx("span", { className: "af-checkbox__description", children: descriptionGroup }))] }), _jsx("div", { role: "group", className: checkboxGroupClassName, children: _jsx("ul", { children: options.map(({ label, value: valueOption, ...inputProps }, idx) => (_jsx("li", { children: _jsx(Checkbox, { ...inputProps, showErrorMessage: false, ref: idx === 0 ? ref : null, value: valueOption, checked: checkedState[idx], onChange: () => handleOnChange(idx), id: `id-${inputProps.name}`, label: label, errorMessage: errorMessage, "aria-errormessage": Boolean(errorMessage) && !inputProps.disabled
30
+ ? idError
31
+ : undefined }) }, `key-${inputProps.name}`))) }) }), errorMessage && _jsx(InputError, { id: idError, message: errorMessage })] }));
32
+ });
33
+ CheckboxSelect.displayName = "CheckboxSelect";
34
+ export { CheckboxSelect };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axa-fr/design-system-look-and-feel-react",
3
- "version": "1.0.5-ci.24",
3
+ "version": "1.0.5-ci.25",
4
4
  "description": "",
5
5
  "exports": {
6
6
  ".": {
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "homepage": "https://github.com/AxaFrance/design-system#readme",
47
47
  "peerDependencies": {
48
- "@axa-fr/design-system-look-and-feel-css": "1.0.5-ci.24",
48
+ "@axa-fr/design-system-look-and-feel-css": "1.0.5-ci.25",
49
49
  "@material-symbols/svg-400": ">= 0.19.0",
50
50
  "react": ">= 18"
51
51
  },