@axa-fr/design-system-slash-react 1.2.1-alpha.91 → 1.2.1-alpha.98
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/Divider/Divider.d.ts +7 -0
- package/dist/Divider/Divider.js +10 -0
- package/dist/Form/MultiSelect/FormatOptionLabel.d.ts +4 -0
- package/dist/Form/MultiSelect/FormatOptionLabel.js +12 -0
- package/dist/Form/MultiSelect/MultiSelect.d.ts +6 -3
- package/dist/Form/MultiSelect/MultiSelect.js +25 -5
- package/dist/Form/MultiSelect/NoOptionsMessage.d.ts +3 -0
- package/dist/Form/MultiSelect/NoOptionsMessage.js +1 -0
- package/dist/Form/MultiSelect/ValueContainer.d.ts +4 -0
- package/dist/Form/MultiSelect/ValueContainer.js +20 -0
- package/dist/Form/MultiSelect/useMultiSelectStyle.d.ts +5 -0
- package/dist/Form/MultiSelect/useMultiSelectStyle.js +81 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +4 -3
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import "@axa-fr/design-system-slash-css/dist/Divider/Divider.css";
|
|
2
|
+
type DividerProps = {
|
|
3
|
+
mode?: "horizontal" | "vertical";
|
|
4
|
+
classModifier?: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const Divider: ({ mode, classModifier, }: DividerProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import classnames from "classnames";
|
|
3
|
+
import "@axa-fr/design-system-slash-css/dist/Divider/Divider.css";
|
|
4
|
+
export const Divider = ({ mode = "horizontal", classModifier, }) => {
|
|
5
|
+
const componentClassName = classnames("af-divider", classModifier, {
|
|
6
|
+
"af-divider--horizontal": mode === "horizontal",
|
|
7
|
+
"af-divider--vertical": mode === "vertical",
|
|
8
|
+
});
|
|
9
|
+
return _jsx("hr", { className: componentClassName });
|
|
10
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type FormatOptionLabelMeta } from "react-select";
|
|
2
|
+
import { Option } from "./MultiSelect";
|
|
3
|
+
declare const formatOptionLabel: (data: Option, formatOptionLabelMeta: FormatOptionLabelMeta<Option>) => string | import("react/jsx-runtime").JSX.Element;
|
|
4
|
+
export { formatOptionLabel };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import classNames from "classnames";
|
|
3
|
+
import checkIcon from "@material-symbols/svg-700/outlined/check.svg";
|
|
4
|
+
import { Svg } from "../..";
|
|
5
|
+
const formatOptionLabel = (data, formatOptionLabelMeta) => {
|
|
6
|
+
if (formatOptionLabelMeta.context === "value") {
|
|
7
|
+
return data.label;
|
|
8
|
+
}
|
|
9
|
+
const isChecked = formatOptionLabelMeta.selectValue.some((selectValue) => data.value === selectValue.value);
|
|
10
|
+
return (_jsxs("div", { className: "react-select__multi-option-label", children: [_jsx("div", { className: "checkbox-indicator", children: _jsx("span", { className: classNames("indicator", { "checkbox-checked": isChecked }), children: isChecked ? _jsx(Svg, { src: checkIcon }) : null }) }), data.label] }));
|
|
11
|
+
};
|
|
12
|
+
export { formatOptionLabel };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { GroupBase } from "react-select";
|
|
1
|
+
import { type GroupBase } from "react-select";
|
|
2
2
|
import { AsyncProps } from "react-select/async";
|
|
3
|
+
import "@axa-fr/design-system-slash-css/dist/Form/MultiSelect/MultiSelect.scss";
|
|
3
4
|
type Option = {
|
|
4
5
|
value: string;
|
|
5
6
|
label: string;
|
|
@@ -9,6 +10,8 @@ type Props = Omit<AsyncProps<Option, true, GroupBase<Option>>, "value" | "isDisa
|
|
|
9
10
|
values?: string[] | null;
|
|
10
11
|
value?: string;
|
|
11
12
|
disabled?: boolean;
|
|
13
|
+
selectedLimit?: number;
|
|
14
|
+
selectedLimitLabel?: string;
|
|
12
15
|
};
|
|
13
16
|
type onChangeProps = {
|
|
14
17
|
id: string;
|
|
@@ -16,5 +19,5 @@ type onChangeProps = {
|
|
|
16
19
|
values?: string[];
|
|
17
20
|
value?: string;
|
|
18
21
|
};
|
|
19
|
-
declare const MultiSelect: ({ id, name, loadOptions, values, options, value, onChange, onBlur, placeholder, className, disabled, loadingMessage, ...otherProps }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
20
|
-
export { MultiSelect };
|
|
22
|
+
declare const MultiSelect: ({ id, name, loadOptions, values, options, value, onChange, onBlur, placeholder, className, disabled, loadingMessage, isMulti, selectedLimit, selectedLimitLabel, ...otherProps }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
23
|
+
export { MultiSelect, type Option };
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useId } from "react";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
3
|
+
import Select from "react-select";
|
|
4
|
+
import AsyncSelect from "react-select/async";
|
|
5
|
+
import { ValueContainer } from "./ValueContainer";
|
|
6
|
+
import "@axa-fr/design-system-slash-css/dist/Form/MultiSelect/MultiSelect.scss";
|
|
7
|
+
import { formatOptionLabel } from "./FormatOptionLabel";
|
|
8
|
+
import { useMultiSelectStyle } from "./useMultiSelectStyle";
|
|
9
|
+
import { noOptionsMessage } from "./NoOptionsMessage";
|
|
10
|
+
const MultiSelect = ({ id, name, loadOptions, values, options, value, onChange, onBlur, placeholder = "- Sélectionner -", className = "react-select", disabled, loadingMessage = () => "Chargement...", isMulti, selectedLimit, selectedLimitLabel, ...otherProps }) => {
|
|
11
|
+
const { styles } = useMultiSelectStyle();
|
|
6
12
|
const generatedId = useId();
|
|
7
13
|
const inputId = id || generatedId;
|
|
8
14
|
const handleOnChange = (newValue) => {
|
|
@@ -37,11 +43,25 @@ const MultiSelect = ({ id, name, loadOptions, values, options, value, onChange,
|
|
|
37
43
|
options,
|
|
38
44
|
valueKey: "value",
|
|
39
45
|
labelKey: "label",
|
|
46
|
+
styles,
|
|
47
|
+
isMulti,
|
|
48
|
+
noOptionsMessage,
|
|
49
|
+
isClearable: true,
|
|
50
|
+
hideSelectedOptions: false,
|
|
51
|
+
components: { ValueContainer },
|
|
52
|
+
closeMenuOnSelect: !values,
|
|
40
53
|
...otherProps,
|
|
41
54
|
};
|
|
42
55
|
if (values) {
|
|
43
56
|
const newValues = options.filter((opt) => values.includes(opt.value));
|
|
44
|
-
|
|
57
|
+
const commonValuesProps = {
|
|
58
|
+
...commonProps,
|
|
59
|
+
value: newValues,
|
|
60
|
+
formatOptionLabel,
|
|
61
|
+
selectedLimit,
|
|
62
|
+
selectedLimitLabel,
|
|
63
|
+
};
|
|
64
|
+
return loadOptions ? (_jsx(AsyncSelect, { ...commonValuesProps, loadOptions: loadOptions, loadingMessage: loadingMessage, isMulti: true })) : (_jsx(Select, { ...commonValuesProps, isMulti: true }));
|
|
45
65
|
}
|
|
46
66
|
const newValue = options.find((o) => o.value === value);
|
|
47
67
|
const commonValueProps = {
|
|
@@ -49,6 +69,6 @@ const MultiSelect = ({ id, name, loadOptions, values, options, value, onChange,
|
|
|
49
69
|
multi: false,
|
|
50
70
|
value: newValue,
|
|
51
71
|
};
|
|
52
|
-
return loadOptions ? (_jsx(
|
|
72
|
+
return loadOptions ? (_jsx(AsyncSelect, { ...commonValueProps, loadOptions: loadOptions, loadingMessage: loadingMessage })) : (_jsx(Select, { ...commonValueProps }));
|
|
53
73
|
};
|
|
54
74
|
export { MultiSelect };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const noOptionsMessage = ({ inputValue }) => `Pas de résultats pour "${inputValue}"`;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type GroupBase, type ValueContainerProps } from "react-select";
|
|
2
|
+
import { Option } from "./MultiSelect";
|
|
3
|
+
declare const ValueContainer: ({ children, ...props }: ValueContainerProps<Option, boolean, GroupBase<Option>>) => import("react/jsx-runtime").JSX.Element;
|
|
4
|
+
export { ValueContainer };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { components, } from "react-select";
|
|
4
|
+
const ValueContainer = ({ children, ...props }) => {
|
|
5
|
+
const { selectProps, getStyles, innerProps } = props;
|
|
6
|
+
const { selectedLimit, selectedLimitLabel, value: selectedOptions, isMulti, } = selectProps;
|
|
7
|
+
if (!isMulti) {
|
|
8
|
+
return (_jsx(components.ValueContainer, { ...props, children: children }));
|
|
9
|
+
}
|
|
10
|
+
const [values, input] = children;
|
|
11
|
+
const visibleOptions = React.Children.toArray(values).slice(0, selectedLimit);
|
|
12
|
+
const extraCount = Array.isArray(selectedOptions) && selectedLimit !== undefined
|
|
13
|
+
? selectedOptions.length - selectedLimit
|
|
14
|
+
: 0;
|
|
15
|
+
// On est obligé de sortir le borderRadius ici pour ne pas devoir ajouter un important dans le fichier scss
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
17
|
+
const { borderRadius, ...multiValueLabelStyles } = getStyles("multiValueLabel", props);
|
|
18
|
+
return (_jsxs(components.ValueContainer, { ...props, children: [extraCount > 0 ? (_jsxs(_Fragment, { children: [visibleOptions, _jsxs("div", { ...innerProps, style: multiValueLabelStyles, className: "multi-value-limit", children: ["+ ", extraCount, " ", selectedLimitLabel || ""] })] })) : (values), input] }));
|
|
19
|
+
};
|
|
20
|
+
export { ValueContainer };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export const useMultiSelectStyle = () => {
|
|
2
|
+
// The recommended way to provide custom styles to react-select is to use the styles prop
|
|
3
|
+
// https://react-select.com/styles#the-styles-prop
|
|
4
|
+
const styles = {
|
|
5
|
+
container: () => ({
|
|
6
|
+
width: "100%",
|
|
7
|
+
}),
|
|
8
|
+
control: (provided, state) => ({
|
|
9
|
+
...provided,
|
|
10
|
+
whiteSpace: "normal",
|
|
11
|
+
borderRadius: "0",
|
|
12
|
+
borderColor: state.isFocused ? "var(--axablue80)" : provided.borderColor,
|
|
13
|
+
boxShadow: state.isFocused ? "0" : provided.boxShadow,
|
|
14
|
+
width: "100%",
|
|
15
|
+
cursor: state.isDisabled ? "not-allowed" : "pointer",
|
|
16
|
+
":hover": {
|
|
17
|
+
borderColor: state.isFocused
|
|
18
|
+
? "var(--axablue80)"
|
|
19
|
+
: provided.borderColor,
|
|
20
|
+
},
|
|
21
|
+
}),
|
|
22
|
+
menu: (provided) => ({
|
|
23
|
+
...provided,
|
|
24
|
+
borderRadius: "0",
|
|
25
|
+
}),
|
|
26
|
+
menuList: (provided) => ({
|
|
27
|
+
...provided,
|
|
28
|
+
padding: "0",
|
|
29
|
+
}),
|
|
30
|
+
option: (provided, state) => ({
|
|
31
|
+
...provided,
|
|
32
|
+
backgroundColor: (state.isSelected && !state.isMulti) || state.isFocused
|
|
33
|
+
? "var(--axablue30)"
|
|
34
|
+
: "var(--white)",
|
|
35
|
+
color: state.isSelected || state.isFocused
|
|
36
|
+
? "var(--axablue80)"
|
|
37
|
+
: provided.color,
|
|
38
|
+
cursor: state.isDisabled ? "not-allowed" : "pointer",
|
|
39
|
+
padding: "0.406rem 0.75rem",
|
|
40
|
+
":hover": {
|
|
41
|
+
backgroundColor: "var(--axablue30)",
|
|
42
|
+
color: "var(--axablue80)",
|
|
43
|
+
},
|
|
44
|
+
}),
|
|
45
|
+
singleValue: (provided) => ({
|
|
46
|
+
...provided,
|
|
47
|
+
whiteSpace: "normal",
|
|
48
|
+
}),
|
|
49
|
+
multiValue: (provided) => ({
|
|
50
|
+
...provided,
|
|
51
|
+
whiteSpace: "normal",
|
|
52
|
+
flexDirection: "row-reverse",
|
|
53
|
+
borderRadius: "0.25rem",
|
|
54
|
+
}),
|
|
55
|
+
multiValueLabel: (provided, state) => ({
|
|
56
|
+
...provided,
|
|
57
|
+
whiteSpace: "normal",
|
|
58
|
+
backgroundColor: state.isDisabled
|
|
59
|
+
? provided.backgroundColor
|
|
60
|
+
: "var(--axablue30)",
|
|
61
|
+
color: state.isDisabled ? provided.backgroundColor : "var(--axablue80)",
|
|
62
|
+
padding: "0.125rem 0.375rem 0.125rem 0.375rem",
|
|
63
|
+
borderRadius: "0 0.25rem 0.25rem 0",
|
|
64
|
+
}),
|
|
65
|
+
multiValueRemove: (provided, state) => ({
|
|
66
|
+
...provided,
|
|
67
|
+
backgroundColor: state.isDisabled
|
|
68
|
+
? provided.backgroundColor
|
|
69
|
+
: "var(--axablue30)",
|
|
70
|
+
color: state.isDisabled ? provided.color : "var(--axablue80)",
|
|
71
|
+
// borderRadius: "0.25rem 0 0 0.25rem",
|
|
72
|
+
":hover": {
|
|
73
|
+
backgroundColor: state.isDisabled
|
|
74
|
+
? provided.backgroundColor
|
|
75
|
+
: "var(--axablue40)",
|
|
76
|
+
color: state.isDisabled ? provided.color : "var(--axablue80)",
|
|
77
|
+
},
|
|
78
|
+
}),
|
|
79
|
+
};
|
|
80
|
+
return { styles };
|
|
81
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export { Action } from "./Action/Action";
|
|
|
7
7
|
export { Badge } from "./Badge/Badge";
|
|
8
8
|
export { Button } from "./Button/Button";
|
|
9
9
|
export { Card } from "./Card/Card";
|
|
10
|
+
export { Divider } from "./Divider/Divider";
|
|
10
11
|
export { Checkbox, CheckboxInput, CheckboxItem, CheckboxModes, } from "./Form/Checkbox";
|
|
11
12
|
export { Choice, ChoiceInput } from "./Form/Choice";
|
|
12
13
|
export { LegacyField as Field, FieldError, FieldForm, FieldInput, FormClassManager, HelpMessage, InputList, MessageTypes, } from "./Form/core";
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,7 @@ export { Action } from "./Action/Action";
|
|
|
7
7
|
export { Badge } from "./Badge/Badge";
|
|
8
8
|
export { Button } from "./Button/Button";
|
|
9
9
|
export { Card } from "./Card/Card";
|
|
10
|
+
export { Divider } from "./Divider/Divider";
|
|
10
11
|
export { Checkbox, CheckboxInput, CheckboxItem, CheckboxModes, } from "./Form/Checkbox";
|
|
11
12
|
export { Choice, ChoiceInput } from "./Form/Choice";
|
|
12
13
|
export { LegacyField as Field, FieldError, FieldForm, FieldInput, FormClassManager, HelpMessage, InputList, MessageTypes, } from "./Form/core";
|
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.
|
|
3
|
+
"version": "1.2.1-alpha.98",
|
|
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.
|
|
50
|
+
"@axa-fr/design-system-slash-css": "1.2.1-alpha.98",
|
|
51
51
|
"@material-symbols/svg-400": ">= 0.19.0",
|
|
52
52
|
"react": ">= 18"
|
|
53
53
|
},
|
|
@@ -59,12 +59,13 @@
|
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"@floating-ui/react": "^0.27.8",
|
|
61
61
|
"@fontsource/source-sans-pro": "^5.2.5",
|
|
62
|
+
"@material-symbols/svg-700": ">= 0.19.0",
|
|
62
63
|
"@tanem/svg-injector": "^10.1.68",
|
|
63
64
|
"classnames": "^2.5.1",
|
|
64
65
|
"dompurify": "^3.1.5",
|
|
65
66
|
"rc-slider": "^11.1.7",
|
|
66
67
|
"react-dropzone": "^11.5.3",
|
|
67
|
-
"react-select": "^5.
|
|
68
|
+
"react-select": "^5.10.1"
|
|
68
69
|
},
|
|
69
70
|
"devDependencies": {
|
|
70
71
|
"@axa-fr/design-system-slash-css": "*",
|