@axa-fr/design-system-slash-react 2.0.6-alpha.1 → 2.0.6-alpha.11
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/Form/Select/SelectDefault.js +3 -3
- package/dist/Form/Select/SelectDefaultWithOptions.js +11 -4
- package/dist/Form/core/Field.js +1 -0
- package/dist/utilities/helpers/getClassName.d.ts +20 -0
- package/dist/utilities/helpers/getClassName.js +24 -0
- package/dist/utilities/helpers/getComponentClassName.d.ts +4 -0
- package/dist/utilities/helpers/getComponentClassName.js +4 -0
- package/package.json +2 -2
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef, useId, useState } from "react";
|
|
3
3
|
import { SelectBase } from "./SelectBase";
|
|
4
|
-
const SelectDefault = forwardRef(({ onChange, forceDisplayPlaceholder = false, value, placeholder = "- Select -", id, children, ...otherProps }, inputRef) => {
|
|
4
|
+
const SelectDefault = forwardRef(({ onChange, forceDisplayPlaceholder = false, value, defaultValue, required, placeholder = "- Select -", id, children, ...otherProps }, inputRef) => {
|
|
5
5
|
const [hasHandleChangeOnce, setHasHandleChangeOnce] = useState(false);
|
|
6
6
|
const generatedId = useId();
|
|
7
7
|
const inputId = id ?? generatedId;
|
|
8
|
-
const childrenWithDefault = (_jsxs(_Fragment, { children: [!(hasHandleChangeOnce ||
|
|
9
|
-
return (_jsx(SelectBase, { ...otherProps, id: inputId, value: value, onChange: (e) => {
|
|
8
|
+
const childrenWithDefault = (_jsxs(_Fragment, { children: [(!required || !(hasHandleChangeOnce || defaultValue || value)) && (_jsx("option", { value: "", children: placeholder })), children] }));
|
|
9
|
+
return (_jsx(SelectBase, { ...otherProps, id: inputId, value: value, defaultValue: defaultValue, required: required, onChange: (e) => {
|
|
10
10
|
if (onChange) {
|
|
11
11
|
onChange(e);
|
|
12
12
|
}
|
|
@@ -15,14 +15,21 @@ import { SelectBase } from "./SelectBase";
|
|
|
15
15
|
* ```
|
|
16
16
|
* It allows you to use the `optgroup` tag for example.
|
|
17
17
|
*/
|
|
18
|
-
export const SelectDefaultWithOptions = forwardRef(({ onChange, forceDisplayPlaceholder = false, value, placeholder = "- Select -", options, id, ...otherProps }, inputRef) => {
|
|
18
|
+
export const SelectDefaultWithOptions = forwardRef(({ onChange, forceDisplayPlaceholder = false, value, defaultValue, required, placeholder = "- Select -", options, id, ...otherProps }, inputRef) => {
|
|
19
19
|
const [hasHandleChangeOnce, setHasHandleChangeOnce] = useState(false);
|
|
20
20
|
const generatedId = useId();
|
|
21
21
|
const inputId = id ?? generatedId;
|
|
22
|
-
const newOptions = useMemo(() => hasHandleChangeOnce ||
|
|
22
|
+
const newOptions = useMemo(() => (hasHandleChangeOnce || defaultValue || value) && required
|
|
23
23
|
? options
|
|
24
|
-
: [{ value: "", label: placeholder }, ...options], [
|
|
25
|
-
|
|
24
|
+
: [{ value: "", label: placeholder }, ...options], [
|
|
25
|
+
hasHandleChangeOnce,
|
|
26
|
+
options,
|
|
27
|
+
defaultValue,
|
|
28
|
+
value,
|
|
29
|
+
required,
|
|
30
|
+
placeholder,
|
|
31
|
+
]);
|
|
32
|
+
return (_jsx(SelectBase, { ...otherProps, id: inputId, value: value, defaultValue: defaultValue, options: newOptions, onChange: (e) => {
|
|
26
33
|
if (onChange) {
|
|
27
34
|
onChange(e);
|
|
28
35
|
}
|
package/dist/Form/core/Field.js
CHANGED
|
@@ -36,6 +36,7 @@ export const Field = ({ classNameContainerInput = "col-md-10", classNameContaine
|
|
|
36
36
|
errorId,
|
|
37
37
|
disabled,
|
|
38
38
|
ariaInvalid: isInvalid,
|
|
39
|
+
required,
|
|
39
40
|
...otherProps,
|
|
40
41
|
}) }), forceDisplayMessage ? (_jsx(FieldError, { message: message, messageType: messageType, errorId: errorId })) : (_jsx(HelpMessage, { message: helpMessage, id: errorId })), appendChildren] })] }));
|
|
41
42
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type getClassNameParams = {
|
|
2
|
+
baseClassName: string;
|
|
3
|
+
modifiers?: Array<string | boolean | undefined>;
|
|
4
|
+
className?: string;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Generates a CSS class string from a base class name, optional modifiers, and an additional class name.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} params.baseClassName - The base class name (required).
|
|
10
|
+
* @param {Array<string|boolean|undefined>} [params.modifiers] - List of modifiers to append as `${baseClassName}--{modifier}`. Falsy values are ignored.
|
|
11
|
+
* @param {string} [params.className] - Additional class name(s) to append to the final string.
|
|
12
|
+
* @returns {string} The concatenated CSS class string, separated by spaces.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const isLarge = false;
|
|
16
|
+
* getClassName({ baseClassName: 'af-button', modifiers: ['primary', isLarge && 'large'], className: 'custom-class' })
|
|
17
|
+
* // Returns: 'af-button af-button--primary custom-class'
|
|
18
|
+
*/
|
|
19
|
+
export declare const getClassName: ({ baseClassName, modifiers, className, }: getClassNameParams) => string;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a CSS class string from a base class name, optional modifiers, and an additional class name.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} params.baseClassName - The base class name (required).
|
|
5
|
+
* @param {Array<string|boolean|undefined>} [params.modifiers] - List of modifiers to append as `${baseClassName}--{modifier}`. Falsy values are ignored.
|
|
6
|
+
* @param {string} [params.className] - Additional class name(s) to append to the final string.
|
|
7
|
+
* @returns {string} The concatenated CSS class string, separated by spaces.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const isLarge = false;
|
|
11
|
+
* getClassName({ baseClassName: 'af-button', modifiers: ['primary', isLarge && 'large'], className: 'custom-class' })
|
|
12
|
+
* // Returns: 'af-button af-button--primary custom-class'
|
|
13
|
+
*/
|
|
14
|
+
export const getClassName = ({ baseClassName, modifiers = [], className = "", }) => {
|
|
15
|
+
const parsedModifiers = modifiers
|
|
16
|
+
.filter(Boolean)
|
|
17
|
+
.map((modifier) => `${baseClassName}--${modifier}`);
|
|
18
|
+
const classList = [
|
|
19
|
+
baseClassName,
|
|
20
|
+
...parsedModifiers,
|
|
21
|
+
...className.split(" "),
|
|
22
|
+
].filter(Boolean);
|
|
23
|
+
return Array.from(new Set(classList)).join(" ");
|
|
24
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* @deprecated This function is deprecated and will be removed in a future release. Use getClassName instead.
|
|
2
3
|
* Generates a component class name string based on provided class names and modifiers.
|
|
3
4
|
*
|
|
4
5
|
* @param {string} [className] - The base class name.
|
|
@@ -12,5 +13,8 @@ type getComponentClassNameWithUserClassnameParams = {
|
|
|
12
13
|
classModifier?: string;
|
|
13
14
|
componentClassName: string;
|
|
14
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated This function is deprecated and will be removed in a future release. Use getClassName instead.
|
|
18
|
+
*/
|
|
15
19
|
export declare const getComponentClassNameWithUserClassname: ({ componentClassName, userClassName, classModifier, }: getComponentClassNameWithUserClassnameParams) => string;
|
|
16
20
|
export {};
|
|
@@ -12,6 +12,7 @@ const listClassModifier = (classModifier) => {
|
|
|
12
12
|
return classModifier.split(" ");
|
|
13
13
|
};
|
|
14
14
|
/**
|
|
15
|
+
* @deprecated This function is deprecated and will be removed in a future release. Use getClassName instead.
|
|
15
16
|
* Generates a component class name string based on provided class names and modifiers.
|
|
16
17
|
*
|
|
17
18
|
* @param {string} [className] - The base class name.
|
|
@@ -34,6 +35,9 @@ export const getComponentClassName = (className, classModifier, defaultClassName
|
|
|
34
35
|
});
|
|
35
36
|
return classNames(classNameToUse, modifiersObject);
|
|
36
37
|
};
|
|
38
|
+
/**
|
|
39
|
+
* @deprecated This function is deprecated and will be removed in a future release. Use getClassName instead.
|
|
40
|
+
*/
|
|
37
41
|
export const getComponentClassNameWithUserClassname = ({ componentClassName, userClassName, classModifier, }) => {
|
|
38
42
|
// Fail fast, when no className or componentClassName we don't want to loop on modifier
|
|
39
43
|
if (!componentClassName) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axa-fr/design-system-slash-react",
|
|
3
|
-
"version": "2.0.6-alpha.
|
|
3
|
+
"version": "2.0.6-alpha.11",
|
|
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": "2.0.6-alpha.
|
|
50
|
+
"@axa-fr/design-system-slash-css": "2.0.6-alpha.11",
|
|
51
51
|
"@material-symbols/svg-400": ">= 0.19.0",
|
|
52
52
|
"@material-symbols/svg-700": ">= 0.19.0",
|
|
53
53
|
"react": ">= 18"
|