@axa-fr/canopee-react 2.0.1-alpha.51 → 2.0.1-alpha.53

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.
package/dist/client.d.ts CHANGED
@@ -22,6 +22,7 @@ export { CardCheckboxOption } from "./prospect-client/Form/Checkbox/CardCheckbox
22
22
  export { Checkbox } from "./prospect-client/Form/Checkbox/Checkbox/CheckboxLF";
23
23
  export { CheckboxText } from "./prospect-client/Form/Checkbox/CheckboxText/CheckboxTextLF";
24
24
  export { Dropdown } from "./prospect-client/Form/Dropdown/DropdownLF";
25
+ export { DropdownMultiSelect, type DropdownMultiSelectProps, } from "./prospect-client/Form/DropdownMultiSelect/DropdownMultiSelectLF";
25
26
  export { FileUpload } from "./prospect-client/Form/FileUpload/FileUpload/FileUploadLF";
26
27
  export { InputFile } from "./prospect-client/Form/FileUpload/InputFile/InputFileLF";
27
28
  export { ItemFile } from "./prospect-client/Form/FileUpload/ItemFile/ItemFileLF";
package/dist/client.js CHANGED
@@ -22,6 +22,7 @@ export { CardCheckboxOption } from "./prospect-client/Form/Checkbox/CardCheckbox
22
22
  export { Checkbox } from "./prospect-client/Form/Checkbox/Checkbox/CheckboxLF";
23
23
  export { CheckboxText } from "./prospect-client/Form/Checkbox/CheckboxText/CheckboxTextLF";
24
24
  export { Dropdown } from "./prospect-client/Form/Dropdown/DropdownLF";
25
+ export { DropdownMultiSelect, } from "./prospect-client/Form/DropdownMultiSelect/DropdownMultiSelectLF";
25
26
  export { FileUpload } from "./prospect-client/Form/FileUpload/FileUpload/FileUploadLF";
26
27
  export { InputFile } from "./prospect-client/Form/FileUpload/InputFile/InputFileLF";
27
28
  export { ItemFile } from "./prospect-client/Form/FileUpload/ItemFile/ItemFileLF";
@@ -0,0 +1,4 @@
1
+ import "@axa-fr/canopee-css/prospect/Form/DropdownMultiSelect/DropdownMultiSelectAll.css";
2
+ import { type DropdownMultiSelectProps } from "./DropdownMultiSelectCommon";
3
+ export type { DropdownMultiSelectProps } from "./DropdownMultiSelectCommon";
4
+ export declare const DropdownMultiSelect: (props: DropdownMultiSelectProps) => import("react").JSX.Element;
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import "@axa-fr/canopee-css/prospect/Form/DropdownMultiSelect/DropdownMultiSelectAll.css";
3
+ import { Tag } from "../../Tag/TagCommon";
4
+ import { TagList } from "../../TagList/TagListApollo";
5
+ import { MultiSelectList } from "../MultiSelectList/MultiSelectListApollo";
6
+ import { DropdownMultiSelectCommon, } from "./DropdownMultiSelectCommon";
7
+ import { ItemLabel } from "../ItemLabel/ItemLabelApollo";
8
+ import { ItemMessage } from "../ItemMessage/ItemMessage";
9
+ export const DropdownMultiSelect = (props) => (_jsx(DropdownMultiSelectCommon, { ...props, MultiSelectListComponent: MultiSelectList, TagListComponent: TagList, TagComponent: Tag, ItemLabelComponent: ItemLabel, ItemMessageComponent: ItemMessage }));
@@ -0,0 +1,47 @@
1
+ import { type ChangeEvent, type ComponentProps, type ComponentType } from "react";
2
+ import type { MultiSelectListProps } from "../MultiSelectList/MultiSelectListCommon";
3
+ import type { TagListProps } from "../../TagList/TagListCommon";
4
+ import type { TagProps } from "../../Tag/TagCommon";
5
+ import type { ItemLabelCommon, ItemLabelProps } from "../ItemLabel/ItemLabelCommon";
6
+ import type { ItemMessageProps } from "../ItemMessage/ItemMessage";
7
+ export type DropdownMultiSelectProps = Pick<ItemLabelProps, "moreButtonLabel" | "onMoreButtonClick" | "sideButtonLabel" | "onSideButtonClick"> & Pick<ItemMessageProps, "message" | "messageType"> & Pick<MultiSelectListProps, "items"> & {
8
+ id?: string;
9
+ name: string;
10
+ required?: boolean;
11
+ disabled?: boolean;
12
+ className?: string;
13
+ label?: ItemLabelProps["children"];
14
+ placeholder?: string;
15
+ description?: string;
16
+ helper?: string;
17
+ /**
18
+ * The number of items to hide before showing a "more" option.
19
+ * Defaults to `3`.
20
+ */
21
+ hideThreshold?: number;
22
+ /**
23
+ * Props to be spread onto the underlying input element.
24
+ * onChange will be override by `onChange` prop of `DropdownMultiSelect`.
25
+ */
26
+ inputProps?: Omit<ComponentProps<"input">, "type" | "onChange">;
27
+ /**
28
+ * The initially selected values. The component manages its own
29
+ * selection state afterwards (always uncontrolled): clicking an item
30
+ * always updates it, regardless of this prop. Use it only to seed the
31
+ * selection, not to drive it from a parent.
32
+ */
33
+ defaultValue?: string[];
34
+ /**
35
+ * Callback function invoked when an item is selected or deselected.
36
+ */
37
+ onChange?: (e: ChangeEvent<HTMLInputElement>) => void;
38
+ };
39
+ type DropdownMultiSelectCommonProps = DropdownMultiSelectProps & {
40
+ MultiSelectListComponent: ComponentType<MultiSelectListProps>;
41
+ TagListComponent: ComponentType<TagListProps>;
42
+ TagComponent: ComponentType<TagProps>;
43
+ ItemLabelComponent: ComponentType<Omit<ComponentProps<typeof ItemLabelCommon>, "ButtonComponent">>;
44
+ ItemMessageComponent: ComponentType<ItemMessageProps>;
45
+ };
46
+ export declare const DropdownMultiSelectCommon: ({ items, helper, name, message, messageType, description, placeholder, className, moreButtonLabel, onMoreButtonClick, sideButtonLabel, onSideButtonClick, required, id: inputId, label, disabled, hideThreshold, defaultValue, onChange, MultiSelectListComponent, TagListComponent, TagComponent, ItemLabelComponent, ItemMessageComponent, inputProps, }: DropdownMultiSelectCommonProps) => import("react").JSX.Element;
47
+ export {};
@@ -0,0 +1,39 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useId, } from "react";
3
+ import { getClassName } from "../../utilities/getClassName";
4
+ import { useDropdownMultiSelect } from "./useDropdownMultiSelect.hook";
5
+ export const DropdownMultiSelectCommon = ({ items, helper, name, message, messageType, description, placeholder, className, moreButtonLabel, onMoreButtonClick, sideButtonLabel, onSideButtonClick, required, id: inputId, label, disabled, hideThreshold, defaultValue, onChange, MultiSelectListComponent, TagListComponent, TagComponent, ItemLabelComponent, ItemMessageComponent, inputProps, }) => {
6
+ const { selectedItems, selectedValues, summary, accessibleCount, handleOnItemSelect, } = useDropdownMultiSelect({
7
+ items,
8
+ defaultValue,
9
+ placeholder,
10
+ });
11
+ const inputItems = items.map((item) => ({
12
+ ...inputProps,
13
+ name,
14
+ onChange: (e) => {
15
+ onChange?.(e);
16
+ handleOnItemSelect(item.id, e.target.checked);
17
+ },
18
+ ...item,
19
+ checked: selectedValues.includes(item.id),
20
+ value: item.id,
21
+ }));
22
+ const generatedId = useId();
23
+ const idMessage = useId();
24
+ const fieldId = inputId ?? generatedId;
25
+ const triggerId = `${fieldId}-trigger`;
26
+ const panelId = `${fieldId}-panel`;
27
+ const countId = `${fieldId}-count`;
28
+ const componentClassName = getClassName({
29
+ baseClassName: "af-form__dropdown-multi-select",
30
+ modifiers: [disabled && "disabled"],
31
+ className,
32
+ });
33
+ const componentInputClassName = getClassName({
34
+ baseClassName: "af-form__dropdown-input",
35
+ modifiers: [Boolean(message) && messageType],
36
+ className: "dropdown-multi-select__trigger",
37
+ });
38
+ return (_jsxs("div", { className: componentClassName, id: fieldId, children: [_jsx(ItemLabelComponent, { description: description, moreButtonLabel: moreButtonLabel, onMoreButtonClick: onMoreButtonClick, sideButtonLabel: sideButtonLabel, onSideButtonClick: onSideButtonClick, required: required, id: `${fieldId}-label`, htmlFor: triggerId, children: label }), _jsxs("div", { className: "dropdown-multi-select__surface", children: [_jsxs("button", { type: "button", id: triggerId, className: componentInputClassName, "aria-controls": panelId, "aria-haspopup": "listbox", "aria-label": summary, disabled: disabled, "data-empty": selectedItems.length === 0, popoverTarget: panelId, popoverTargetAction: "toggle", children: [_jsx("span", { className: "dropdown-multi-select__summary", children: summary }), _jsx("span", { id: countId, className: "sr-only", children: accessibleCount })] }), items.length > 0 ? (_jsx("div", { id: panelId, popover: "auto", className: "dropdown-multi-select__list", role: "group", "aria-labelledby": triggerId, children: _jsx(MultiSelectListComponent, { items: inputItems }) })) : null] }), selectedItems.length > 0 ? (_jsx(TagListComponent, { className: "dropdown-multi-select__tags", hideThreshold: hideThreshold, OverflowTagComponent: TagComponent, "aria-hidden": "true", children: selectedItems.map((item) => (_jsx(TagComponent, { children: item.label }, item.id))) })) : null, helper ? _jsx("span", { className: "af-form__input-helper", children: helper }) : null, _jsx(ItemMessageComponent, { id: idMessage, message: message, messageType: messageType })] }));
39
+ };
@@ -0,0 +1,4 @@
1
+ import "@axa-fr/canopee-css/client/Form/DropdownMultiSelect/DropdownMultiSelectAll.css";
2
+ import { type DropdownMultiSelectProps } from "./DropdownMultiSelectCommon";
3
+ export type { DropdownMultiSelectProps } from "./DropdownMultiSelectCommon";
4
+ export declare const DropdownMultiSelect: (props: DropdownMultiSelectProps) => import("react").JSX.Element;
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import "@axa-fr/canopee-css/client/Form/DropdownMultiSelect/DropdownMultiSelectAll.css";
3
+ import { Tag } from "../../Tag/TagCommon";
4
+ import { TagList } from "../../TagList/TagListLF";
5
+ import { MultiSelectList } from "../MultiSelectList/MultiSelectListLF";
6
+ import { DropdownMultiSelectCommon, } from "./DropdownMultiSelectCommon";
7
+ import { ItemLabel } from "../ItemLabel/ItemLabelLF";
8
+ import { ItemMessage } from "../ItemMessage/ItemMessage";
9
+ export const DropdownMultiSelect = (props) => (_jsx(DropdownMultiSelectCommon, { ...props, MultiSelectListComponent: MultiSelectList, TagListComponent: TagList, TagComponent: Tag, ItemLabelComponent: ItemLabel, ItemMessageComponent: ItemMessage }));
@@ -0,0 +1,14 @@
1
+ import type { ItemMultiSelectCommonProps } from "../ItemMultiSelect/ItemMultiSelectCommon";
2
+ type UseDropdownMultiSelect = {
3
+ items: Omit<ItemMultiSelectCommonProps, "Checkbox">[];
4
+ defaultValue?: string[];
5
+ placeholder?: string;
6
+ };
7
+ export declare const useDropdownMultiSelect: ({ items, defaultValue, placeholder, }: UseDropdownMultiSelect) => {
8
+ selectedValues: string[];
9
+ selectedItems: Omit<ItemMultiSelectCommonProps, "Checkbox">[];
10
+ summary: string;
11
+ accessibleCount: string;
12
+ handleOnItemSelect: (id: string, checked: boolean) => void;
13
+ };
14
+ export {};
@@ -0,0 +1,31 @@
1
+ import { useState, useMemo } from "react";
2
+ export const useDropdownMultiSelect = ({ items, defaultValue, placeholder, }) => {
3
+ const [internalValues, setInternalValues] = useState(() => defaultValue ??
4
+ items.filter((item) => item.checked).map((item) => item.id));
5
+ const valuesLength = internalValues.length;
6
+ const selectedItems = useMemo(() => internalValues.length > 0
7
+ ? items.filter((item) => internalValues.includes(item.id))
8
+ : [], [items, internalValues]);
9
+ const summary = useMemo(() => {
10
+ if (valuesLength === 0) {
11
+ return placeholder ?? "Sélectionner";
12
+ }
13
+ return valuesLength === 1
14
+ ? "1 élément sélectionné"
15
+ : `${valuesLength} éléments sélectionnés`;
16
+ }, [valuesLength, placeholder]);
17
+ const accessibleCount = useMemo(() => {
18
+ const base = valuesLength === 0 ? "0 élément sélectionné" : summary;
19
+ return `${base} sur ${items.length}`;
20
+ }, [summary, valuesLength, items.length]);
21
+ const handleOnItemSelect = (id, checked) => {
22
+ setInternalValues((current) => checked ? [...current, id] : current.filter((itemId) => itemId !== id));
23
+ };
24
+ return {
25
+ selectedValues: internalValues,
26
+ selectedItems,
27
+ summary,
28
+ accessibleCount,
29
+ handleOnItemSelect,
30
+ };
31
+ };
@@ -1,6 +1,7 @@
1
1
  import { type ComponentProps, type ComponentType, type FC, type ReactNode } from "react";
2
2
  export type ItemMultiSelectVariant = "primary" | "secondary";
3
- export type ItemMultiSelectCommonProps = Omit<ComponentProps<"input">, "type"> & {
3
+ export type ItemMultiSelectCommonProps = Omit<ComponentProps<"input">, "type" | "id"> & {
4
+ id: string;
4
5
  label: ReactNode;
5
6
  variant?: ItemMultiSelectVariant;
6
7
  Checkbox: ComponentType<ComponentProps<"input">>;
@@ -2,4 +2,4 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { Tag } from "../Tag/TagCommon";
3
3
  import { TagListCommon, } from "./TagListCommon";
4
4
  import "@axa-fr/canopee-css/prospect/TagList/TagListAll.css";
5
- export const TagList = (props) => (_jsx(TagListCommon, { ...props, OverflowTag: Tag }));
5
+ export const TagList = (props) => (_jsx(TagListCommon, { ...props, OverflowTagComponent: Tag }));
@@ -1,10 +1,8 @@
1
- import { type ComponentType, type ReactNode } from "react";
2
- export type TagListProps = {
1
+ import { type ComponentProps, type ComponentType, type ReactNode } from "react";
2
+ import type { TagProps } from "../Tag/TagCommon";
3
+ export type TagListProps = ComponentProps<"ul"> & {
3
4
  children: ReactNode;
4
5
  hideThreshold?: number;
5
- className?: string;
6
- OverflowTag: ComponentType<{
7
- children: ReactNode;
8
- }>;
6
+ OverflowTagComponent: ComponentType<TagProps>;
9
7
  };
10
- export declare const TagListCommon: ({ children, hideThreshold, className, OverflowTag, }: TagListProps) => import("react").JSX.Element;
8
+ export declare const TagListCommon: ({ children, hideThreshold, className, OverflowTagComponent: OverflowTag, ...divProps }: TagListProps) => import("react").JSX.Element;
@@ -1,7 +1,8 @@
1
- import { jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Children, isValidElement, } from "react";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Children, isValidElement, useId, } from "react";
3
3
  import { getClassName } from "../utilities/getClassName";
4
- export const TagListCommon = ({ children, hideThreshold = 2, className = "", OverflowTag, }) => {
4
+ export const TagListCommon = ({ children, hideThreshold = 2, className = "", OverflowTagComponent: OverflowTag, ...divProps }) => {
5
+ const id = useId();
5
6
  const childArray = Children.toArray(children).filter(isValidElement);
6
7
  const total = childArray.length;
7
8
  const isOverflowing = total > hideThreshold;
@@ -9,8 +10,8 @@ export const TagListCommon = ({ children, hideThreshold = 2, className = "", Ove
9
10
  ? childArray.slice(0, hideThreshold)
10
11
  : childArray;
11
12
  const hiddenCount = total - hideThreshold;
12
- return (_jsxs("div", { className: getClassName({
13
+ return (_jsxs("ul", { className: getClassName({
13
14
  baseClassName: "af-tag-list",
14
15
  className,
15
- }), children: [visibleChildren, isOverflowing ? _jsxs(OverflowTag, { children: ["+", hiddenCount] }) : null] }));
16
+ }), ...divProps, children: [visibleChildren.map((child, index) => (_jsx("li", { children: child }, child.props.id ?? `${id}-${index}`))), isOverflowing ? (_jsx("li", { children: _jsxs(OverflowTag, { children: ["+", hiddenCount] }) })) : null] }));
16
17
  };
@@ -2,4 +2,4 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { Tag } from "../Tag/TagCommon";
3
3
  import { TagListCommon, } from "./TagListCommon";
4
4
  import "@axa-fr/canopee-css/client/TagList/TagListAll.css";
5
- export const TagList = (props) => (_jsx(TagListCommon, { ...props, OverflowTag: Tag }));
5
+ export const TagList = (props) => (_jsx(TagListCommon, { ...props, OverflowTagComponent: Tag }));
@@ -22,6 +22,7 @@ export { CardCheckboxOption } from "./prospect-client/Form/Checkbox/CardCheckbox
22
22
  export { Checkbox } from "./prospect-client/Form/Checkbox/Checkbox/CheckboxApollo";
23
23
  export { CheckboxText } from "./prospect-client/Form/Checkbox/CheckboxText/CheckboxTextApollo";
24
24
  export { Dropdown } from "./prospect-client/Form/Dropdown/DropdownApollo";
25
+ export { DropdownMultiSelect, type DropdownMultiSelectProps, } from "./prospect-client/Form/DropdownMultiSelect/DropdownMultiSelectApollo";
25
26
  export { FileUpload } from "./prospect-client/Form/FileUpload/FileUpload/FileUploadApollo";
26
27
  export { InputFile } from "./prospect-client/Form/FileUpload/InputFile/InputFileApollo";
27
28
  export { ItemFile } from "./prospect-client/Form/FileUpload/ItemFile/ItemFileApollo";
package/dist/prospect.js CHANGED
@@ -22,6 +22,7 @@ export { CardCheckboxOption } from "./prospect-client/Form/Checkbox/CardCheckbox
22
22
  export { Checkbox } from "./prospect-client/Form/Checkbox/Checkbox/CheckboxApollo";
23
23
  export { CheckboxText } from "./prospect-client/Form/Checkbox/CheckboxText/CheckboxTextApollo";
24
24
  export { Dropdown } from "./prospect-client/Form/Dropdown/DropdownApollo";
25
+ export { DropdownMultiSelect, } from "./prospect-client/Form/DropdownMultiSelect/DropdownMultiSelectApollo";
25
26
  export { FileUpload } from "./prospect-client/Form/FileUpload/FileUpload/FileUploadApollo";
26
27
  export { InputFile } from "./prospect-client/Form/FileUpload/InputFile/InputFileApollo";
27
28
  export { ItemFile } from "./prospect-client/Form/FileUpload/ItemFile/ItemFileApollo";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axa-fr/canopee-react",
3
- "version": "2.0.1-alpha.51",
3
+ "version": "2.0.1-alpha.53",
4
4
  "description": "Package React - Design System Canopée",
5
5
  "type": "module",
6
6
  "exports": {
@@ -54,7 +54,7 @@
54
54
  },
55
55
  "homepage": "https://github.com/AxaFrance/design-system#readme",
56
56
  "peerDependencies": {
57
- "@axa-fr/canopee-css": "2.0.1-alpha.51",
57
+ "@axa-fr/canopee-css": "2.0.1-alpha.53",
58
58
  "@material-symbols/svg-400": ">= 0.19.0",
59
59
  "@material-symbols/svg-700": ">= 0.19.0",
60
60
  "react": ">= 19"