@axa-fr/canopee-react 1.4.2-alpha.2 → 1.4.2-alpha.4
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/distributeur/Form/Experimental/Input.d.ts +3 -0
- package/dist/distributeur/Form/Experimental/Input.js +13 -0
- package/dist/distributeur/Form/Experimental/InputContainer.d.ts +8 -0
- package/dist/distributeur/Form/Experimental/InputContainer.js +7 -0
- package/dist/distributeur/Form/Experimental/InputUnit.d.ts +3 -0
- package/dist/distributeur/Form/Experimental/InputUnit.js +3 -0
- package/dist/distributeur/Form/Experimental/ItemMessage.d.ts +28 -0
- package/dist/distributeur/Form/Experimental/ItemMessage.js +19 -0
- package/dist/distributeur/Form/Experimental/Label.d.ts +13 -0
- package/dist/distributeur/Form/Experimental/Label.js +3 -0
- package/dist/distributeur/Form/Experimental/TextInput.d.ts +11 -0
- package/dist/distributeur/Form/Experimental/TextInput.js +26 -0
- package/dist/distributeur/Form/Experimental/index.d.ts +9 -1
- package/dist/distributeur/Form/Experimental/index.js +7 -1
- package/dist/distributeur/Form/Experimental/types.d.ts +55 -0
- package/dist/distributeur/Form/Experimental/types.js +1 -0
- package/dist/distributeur/Form/Experimental/useInput.hook.d.ts +21 -0
- package/dist/distributeur/Form/Experimental/useInput.hook.js +30 -0
- package/dist/distributeur/Tabs/components/Tab.d.ts +4 -1
- package/dist/distributeur/Tabs/components/Tab.js +1 -2
- package/dist/distributeur/Tabs/components/TabsCore.d.ts +3 -4
- package/dist/distributeur/Tabs/components/TabsCore.js +15 -12
- package/dist/distributeur/Tabs/components/TabsStateless.d.ts +12 -8
- package/dist/distributeur/Tabs/components/TabsStateless.js +48 -6
- package/dist/distributeur-experimental.d.ts +1 -0
- package/dist/distributeur-experimental.js +1 -0
- package/package.json +6 -2
- package/dist/distributeur/Tabs/components/Title.d.ts +0 -15
- package/dist/distributeur/Tabs/components/Title.js +0 -14
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import "@axa-fr/canopee-css/distributeur/Form/Experimental/Input.css";
|
|
2
|
+
declare const Input: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "ref"> & import("react").RefAttributes<HTMLInputElement>>;
|
|
3
|
+
export { Input };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import "@axa-fr/canopee-css/distributeur/Form/Experimental/Input.css";
|
|
3
|
+
import { forwardRef } from "react";
|
|
4
|
+
import { getClassName } from "../../utilities/helpers/getClassName";
|
|
5
|
+
const Input = forwardRef(({ className, ...otherProps }, inputRef) => {
|
|
6
|
+
const componentClassName = getClassName({
|
|
7
|
+
baseClassName: "af-input__input",
|
|
8
|
+
className,
|
|
9
|
+
});
|
|
10
|
+
return (_jsx("input", { className: componentClassName, ref: inputRef, ...otherProps }));
|
|
11
|
+
});
|
|
12
|
+
Input.displayName = "Input";
|
|
13
|
+
export { Input };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import "@axa-fr/canopee-css/distributeur/Form/Experimental/InputContainer.css";
|
|
2
|
+
import type { PropsWithChildren } from "react";
|
|
3
|
+
type InputContainerProps = PropsWithChildren<{
|
|
4
|
+
vertical?: boolean;
|
|
5
|
+
className?: string;
|
|
6
|
+
}>;
|
|
7
|
+
export declare const InputContainer: ({ children, vertical, className, }: InputContainerProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import "@axa-fr/canopee-css/distributeur/Form/Experimental/InputContainer.css";
|
|
3
|
+
import classNames from "classnames";
|
|
4
|
+
export const InputContainer = ({ children, vertical, className, }) => {
|
|
5
|
+
const containerClass = classNames("af-input__container", { "af-input__container--vertical": vertical }, className);
|
|
6
|
+
return _jsx("div", { className: containerClass, children: children });
|
|
7
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import "@axa-fr/canopee-css/distributeur/Form/Experimental/ItemMessage.css";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
type Props = {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
/**
|
|
6
|
+
* The variant of the message.
|
|
7
|
+
* - "error": displays an error message with an error icon.
|
|
8
|
+
* - "success": displays a success message with a success icon.
|
|
9
|
+
* - undefined: displays an help message without any icon.
|
|
10
|
+
*
|
|
11
|
+
* @default undefined
|
|
12
|
+
*/
|
|
13
|
+
variant?: "error" | "success";
|
|
14
|
+
/**
|
|
15
|
+
* Additional class name(s) to apply to the component.
|
|
16
|
+
*/
|
|
17
|
+
className?: string;
|
|
18
|
+
/**
|
|
19
|
+
* The id attribute for the component.
|
|
20
|
+
*
|
|
21
|
+
* Useful for linking the message to other elements for accessibility.
|
|
22
|
+
* @default undefined
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
id?: string;
|
|
26
|
+
};
|
|
27
|
+
export declare const ItemMessage: ({ variant, children, className, id }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import "@axa-fr/canopee-css/distributeur/Form/Experimental/ItemMessage.css";
|
|
3
|
+
import success from "@material-symbols/svg-400/outlined/check_circle-fill.svg";
|
|
4
|
+
import error from "@material-symbols/svg-400/outlined/error-fill.svg";
|
|
5
|
+
import { Svg } from "../../Svg";
|
|
6
|
+
import { getClassName } from "../../utilities/helpers/getClassName";
|
|
7
|
+
const iconByVariant = {
|
|
8
|
+
success,
|
|
9
|
+
error,
|
|
10
|
+
};
|
|
11
|
+
export const ItemMessage = ({ variant, children, className, id }) => {
|
|
12
|
+
const componentClassName = getClassName({
|
|
13
|
+
baseClassName: "af-item-message",
|
|
14
|
+
className,
|
|
15
|
+
modifiers: [variant],
|
|
16
|
+
});
|
|
17
|
+
const icon = variant ? iconByVariant[variant] : null;
|
|
18
|
+
return (_jsxs("div", { className: componentClassName, id: id, children: [icon ? _jsx(Svg, { src: icon, className: "af-item-message__icon" }) : null, children] }));
|
|
19
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import "@axa-fr/canopee-css/distributeur/Form/Experimental/Label.css";
|
|
2
|
+
import type { ComponentProps } from "react";
|
|
3
|
+
type LabelProps = ComponentProps<"label"> & {
|
|
4
|
+
/**
|
|
5
|
+
* Whether the label is required or not.
|
|
6
|
+
* This will add a `*` after the label text.
|
|
7
|
+
* This is purely presentational and does not enforce any validation logic.
|
|
8
|
+
* @default false
|
|
9
|
+
*/
|
|
10
|
+
required?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare const Label: ({ children, required, ...props }: LabelProps) => import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import "@axa-fr/canopee-css/distributeur/Form/Experimental/Label.css";
|
|
3
|
+
export const Label = ({ children, required = false, ...props }) => (_jsxs("label", { className: "af-label", ...props, children: [children, required ? (_jsx("span", { className: "af-label__required", "aria-hidden": true, children: "*" })) : null] }));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ComponentProps } from "react";
|
|
2
|
+
import { Input } from "./Input";
|
|
3
|
+
import type { InputBaseProps } from "./types";
|
|
4
|
+
export type TextInputProps = Omit<ComponentProps<typeof Input>, "children"> & InputBaseProps;
|
|
5
|
+
/**
|
|
6
|
+
* This component renders a label, a text input field and optionnally help and error messages.
|
|
7
|
+
* It can be customized to render the label on top, or on the left of the input.
|
|
8
|
+
* It also supports adding a unit on the right of the input.
|
|
9
|
+
*/
|
|
10
|
+
declare const TextInput: import("react").ForwardRefExoticComponent<Omit<TextInputProps, "ref"> & import("react").RefAttributes<HTMLInputElement>>;
|
|
11
|
+
export { TextInput };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from "react";
|
|
3
|
+
import { Input } from "./Input";
|
|
4
|
+
import { InputContainer } from "./InputContainer";
|
|
5
|
+
import { InputUnit } from "./InputUnit";
|
|
6
|
+
import { ItemMessage } from "./ItemMessage";
|
|
7
|
+
import { Label } from "./Label";
|
|
8
|
+
import { useInput } from "./useInput.hook";
|
|
9
|
+
/**
|
|
10
|
+
* This component renders a label, a text input field and optionnally help and error messages.
|
|
11
|
+
* It can be customized to render the label on top, or on the left of the input.
|
|
12
|
+
* It also supports adding a unit on the right of the input.
|
|
13
|
+
*/
|
|
14
|
+
const TextInput = forwardRef(({ contentRight, id, labelPosition, inputClassName: inputClassNameProp, labelClassName: labelClassNameProp, helpMessage, containerClassName, required, label, errorMessage, ...props }, inputRef) => {
|
|
15
|
+
const { describedBy, errorId, helperId, inputClassName, inputId, isContainerVertical, isInvalid, labelClassName, } = useInput({
|
|
16
|
+
id,
|
|
17
|
+
labelPosition,
|
|
18
|
+
inputClassName: inputClassNameProp,
|
|
19
|
+
labelClassName: labelClassNameProp,
|
|
20
|
+
errorMessage,
|
|
21
|
+
helpMessage,
|
|
22
|
+
});
|
|
23
|
+
return (_jsxs(InputContainer, { vertical: isContainerVertical, className: containerClassName, children: [_jsx(Label, { htmlFor: inputId, required: required, className: labelClassName, children: label }), _jsx(Input, { ...props, className: inputClassName, id: inputId, ref: inputRef, "aria-describedby": describedBy, "aria-invalid": isInvalid }), contentRight ? _jsx(InputUnit, { children: contentRight }) : null, helpMessage ? (_jsx(ItemMessage, { id: helperId, children: helpMessage })) : null, errorMessage ? (_jsx(ItemMessage, { variant: "error", id: errorId, children: errorMessage })) : null] }));
|
|
24
|
+
});
|
|
25
|
+
TextInput.displayName = "TextInput";
|
|
26
|
+
export { TextInput };
|
|
@@ -1 +1,9 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export { Input } from "./Input";
|
|
2
|
+
export { InputContainer } from "./InputContainer";
|
|
3
|
+
export { InputUnit } from "./InputUnit";
|
|
4
|
+
export { ItemMessage } from "./ItemMessage";
|
|
5
|
+
export { Label } from "./Label";
|
|
6
|
+
export { TextInput } from "./TextInput";
|
|
7
|
+
export type { TextInputProps } from "./TextInput";
|
|
8
|
+
export type { InputBaseProps, LabelPosition, SingleLineLabelPosition, } from "./types";
|
|
9
|
+
export { useInput } from "./useInput.hook";
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export { Input } from "./Input";
|
|
2
|
+
export { InputContainer } from "./InputContainer";
|
|
3
|
+
export { InputUnit } from "./InputUnit";
|
|
4
|
+
export { ItemMessage } from "./ItemMessage";
|
|
5
|
+
export { Label } from "./Label";
|
|
6
|
+
export { TextInput } from "./TextInput";
|
|
7
|
+
export { useInput } from "./useInput.hook";
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export type InputBaseProps = {
|
|
3
|
+
/**
|
|
4
|
+
* The id of the input element.
|
|
5
|
+
* This is used to link the label to the input, and its descriptions (helper and error messages).
|
|
6
|
+
* If not provided, a unique id will be generated.
|
|
7
|
+
*/
|
|
8
|
+
id?: string;
|
|
9
|
+
/**
|
|
10
|
+
* The label text for the input.
|
|
11
|
+
*/
|
|
12
|
+
label: ReactNode;
|
|
13
|
+
/**
|
|
14
|
+
* Whether the input is required or not.
|
|
15
|
+
* This will add a `*` after the label text.
|
|
16
|
+
* This is purely presentational and does not enforce any validation logic.
|
|
17
|
+
* @default false
|
|
18
|
+
*/
|
|
19
|
+
required?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* className for the container. Use this to apply styles to the input container.
|
|
22
|
+
*/
|
|
23
|
+
containerClassName?: string;
|
|
24
|
+
/**
|
|
25
|
+
* className for the label. Use this to apply styles to the label.
|
|
26
|
+
*/
|
|
27
|
+
labelClassName?: string;
|
|
28
|
+
/**
|
|
29
|
+
* className for the input. Use this to apply styles to the input.
|
|
30
|
+
*/
|
|
31
|
+
inputClassName?: string;
|
|
32
|
+
/**
|
|
33
|
+
* The position of the label relative to the input.
|
|
34
|
+
* - `centerLeft` will place the label on the left of the input, centered vertically. This is the default position for most inputs.
|
|
35
|
+
* - `leftAbove` will place the label above the input, aligned to the left. This is used to have the label above the input.
|
|
36
|
+
* @default "centerLeft"
|
|
37
|
+
*/
|
|
38
|
+
labelPosition?: SingleLineLabelPosition;
|
|
39
|
+
/**
|
|
40
|
+
* The help message to display below the input.
|
|
41
|
+
*/
|
|
42
|
+
helpMessage?: string;
|
|
43
|
+
/**
|
|
44
|
+
* The error message to display below the input.
|
|
45
|
+
* This will also set the `aria-invalid` attribute on the input, and apply the error styles to the input.
|
|
46
|
+
*/
|
|
47
|
+
errorMessage?: string;
|
|
48
|
+
/**
|
|
49
|
+
* The right element to display next to the input.
|
|
50
|
+
* This should be used to display a unit, but **if you really need to** an icon, or any other element that should be displayed next to the input.
|
|
51
|
+
*/
|
|
52
|
+
contentRight?: ReactNode;
|
|
53
|
+
};
|
|
54
|
+
export type LabelPosition = "topLeft" | SingleLineLabelPosition;
|
|
55
|
+
export type SingleLineLabelPosition = "centerLeft" | "above";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {} from "react";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type LabelPosition } from "./types";
|
|
3
|
+
type useInputProps = {
|
|
4
|
+
id?: string;
|
|
5
|
+
labelPosition?: LabelPosition;
|
|
6
|
+
inputClassName?: string;
|
|
7
|
+
labelClassName?: string;
|
|
8
|
+
errorMessage?: ReactNode;
|
|
9
|
+
helpMessage?: ReactNode;
|
|
10
|
+
};
|
|
11
|
+
export declare const useInput: (props: useInputProps) => {
|
|
12
|
+
isInvalid: boolean;
|
|
13
|
+
isContainerVertical: boolean;
|
|
14
|
+
inputClassName: string;
|
|
15
|
+
labelClassName: string;
|
|
16
|
+
describedBy: string;
|
|
17
|
+
errorId: string | undefined;
|
|
18
|
+
helperId: string | undefined;
|
|
19
|
+
inputId: string;
|
|
20
|
+
};
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useId } from "react";
|
|
2
|
+
import { getClassName } from "../../utilities/helpers/getClassName";
|
|
3
|
+
import {} from "./types";
|
|
4
|
+
export const useInput = (props) => {
|
|
5
|
+
const inputUseId = useId();
|
|
6
|
+
const inputId = props.id ?? inputUseId;
|
|
7
|
+
const isInvalid = Boolean(props.errorMessage);
|
|
8
|
+
const inputClassName = getClassName({
|
|
9
|
+
baseClassName: "af-input__input",
|
|
10
|
+
className: props.inputClassName,
|
|
11
|
+
});
|
|
12
|
+
const labelClassName = getClassName({
|
|
13
|
+
baseClassName: "af-label",
|
|
14
|
+
modifiers: [props.labelPosition === "above" && "top"],
|
|
15
|
+
className: props.labelClassName,
|
|
16
|
+
});
|
|
17
|
+
const errorId = isInvalid ? `${inputId}-description` : undefined;
|
|
18
|
+
const helperId = props.helpMessage ? `${inputId}-helper` : undefined;
|
|
19
|
+
const describedBy = [errorId, helperId].filter(Boolean).join(" ").trim();
|
|
20
|
+
return {
|
|
21
|
+
isInvalid,
|
|
22
|
+
isContainerVertical: props.labelPosition === "above",
|
|
23
|
+
inputClassName,
|
|
24
|
+
labelClassName,
|
|
25
|
+
describedBy,
|
|
26
|
+
errorId,
|
|
27
|
+
helperId,
|
|
28
|
+
inputId,
|
|
29
|
+
};
|
|
30
|
+
};
|
|
@@ -4,7 +4,10 @@ export type TabProps = {
|
|
|
4
4
|
title: ReactNode;
|
|
5
5
|
children?: ReactNode;
|
|
6
6
|
className?: string;
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use className instead
|
|
9
|
+
*/
|
|
7
10
|
classModifier?: string;
|
|
8
11
|
};
|
|
9
|
-
declare const Tab: () =>
|
|
12
|
+
declare const Tab: () => null;
|
|
10
13
|
export { Tab };
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type FormEvent } from "react";
|
|
2
2
|
import { type TabsStatelessProps } from "./TabsStateless";
|
|
3
3
|
type Tabs = {
|
|
4
|
-
onChange?: (event:
|
|
4
|
+
onChange?: (event: FormEvent<HTMLButtonElement>) => void;
|
|
5
5
|
activeIndex?: string;
|
|
6
6
|
};
|
|
7
7
|
export type TabsCoreProps = Tabs & Omit<TabsStatelessProps, "activeIndex">;
|
|
8
|
-
|
|
9
|
-
declare const TabsCore: React.FunctionComponent<TabsCoreProps>;
|
|
8
|
+
declare const TabsCore: ({ activeIndex: activeIndexProp, onChange, ...otherProps }: TabsCoreProps) => import("react/jsx-runtime").JSX.Element;
|
|
10
9
|
export { TabsCore };
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
3
|
import { TabsStateless } from "./TabsStateless";
|
|
4
4
|
const DEFAULT_ACTIVE_INDEX = "0";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
const TabsCore = ({ activeIndex: activeIndexProp = DEFAULT_ACTIVE_INDEX, onChange, ...otherProps }) => {
|
|
6
|
+
const [activeIndex, setActiveIndex] = useState(Number(activeIndexProp));
|
|
7
|
+
// Allow to update activeIndex from props
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
setActiveIndex(Number(activeIndexProp));
|
|
10
|
+
}, [activeIndexProp]);
|
|
11
|
+
return (_jsx(TabsStateless, { activeIndex: activeIndex, ...otherProps, onChange: (e, index) => {
|
|
12
|
+
if (onChange) {
|
|
13
|
+
onChange(e);
|
|
14
|
+
}
|
|
15
|
+
if (index >= 0) {
|
|
16
|
+
setActiveIndex(index);
|
|
17
|
+
}
|
|
18
|
+
} }));
|
|
16
19
|
};
|
|
17
20
|
export { TabsCore };
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { type FormEvent, type ReactElement } from "react";
|
|
2
|
+
import type { TabProps } from "./Tab";
|
|
3
|
+
export type TabsStatelessProps = {
|
|
4
|
+
children: ReactElement<TabProps> | ReactElement<TabProps>[];
|
|
5
|
+
activeIndex: number;
|
|
5
6
|
className?: string;
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use `className` instead
|
|
9
|
+
*/
|
|
6
10
|
classModifier?: string;
|
|
7
|
-
}
|
|
8
|
-
export
|
|
9
|
-
onChange: (event:
|
|
10
|
-
}
|
|
11
|
+
};
|
|
12
|
+
export type TabsStatelessHandlers = {
|
|
13
|
+
onChange: (event: FormEvent<HTMLButtonElement>, index: number) => void;
|
|
14
|
+
};
|
|
11
15
|
type Props = TabsStatelessProps & TabsStatelessHandlers;
|
|
12
16
|
declare const TabsStateless: ({ activeIndex, className, classModifier, children, onChange, }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
13
17
|
export { TabsStateless };
|
|
@@ -1,11 +1,53 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
/* eslint-disable react/no-array-index-key */
|
|
3
|
-
import { Children, isValidElement, } from "react";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import { Children, isValidElement, useId, useRef, } from "react";
|
|
4
|
+
import { getClassName } from "../../utilities/helpers/getClassName";
|
|
5
|
+
function handleKeyDown(event, moveToTab, index, totalNumberOfTabs) {
|
|
6
|
+
let targetIndex = null;
|
|
7
|
+
if (event.key === "ArrowLeft") {
|
|
8
|
+
targetIndex = index - 1;
|
|
9
|
+
}
|
|
10
|
+
else if (event.key === "ArrowRight") {
|
|
11
|
+
targetIndex = index + 1;
|
|
12
|
+
}
|
|
13
|
+
else if (event.key === "Home") {
|
|
14
|
+
targetIndex = 0;
|
|
15
|
+
}
|
|
16
|
+
else if (event.key === "End") {
|
|
17
|
+
targetIndex = totalNumberOfTabs - 1;
|
|
18
|
+
}
|
|
19
|
+
if (targetIndex !== null) {
|
|
20
|
+
moveToTab(event, targetIndex);
|
|
21
|
+
event.preventDefault();
|
|
22
|
+
event.stopPropagation();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
7
25
|
const TabsStateless = ({ activeIndex, className = "af-tabs", classModifier, children, onChange, }) => {
|
|
8
|
-
const componentClassName =
|
|
9
|
-
|
|
26
|
+
const componentClassName = getClassName({
|
|
27
|
+
baseClassName: "af-tabs",
|
|
28
|
+
className,
|
|
29
|
+
modifiers: classModifier?.split(" "),
|
|
30
|
+
});
|
|
31
|
+
const tabRefs = useRef([]);
|
|
32
|
+
const moveToTab = (event, index) => {
|
|
33
|
+
if (index < 0 || index >= Children.count(children)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
tabRefs.current[index]?.focus();
|
|
37
|
+
onChange(event, index);
|
|
38
|
+
};
|
|
39
|
+
const id = useId();
|
|
40
|
+
return (_jsxs("div", { className: componentClassName, role: "tablist", children: [_jsx("ul", { className: "af-tabs__control", children: Children.map(children, (child, index) => isValidElement(child) && (_jsx("li", { className: getClassName({
|
|
41
|
+
className,
|
|
42
|
+
modifiers: [activeIndex === index && "active"],
|
|
43
|
+
baseClassName: "af-tabs__item",
|
|
44
|
+
}), children: _jsx("button", { type: "button", id: `${id}-tab-${index}`, ref: (el) => {
|
|
45
|
+
tabRefs.current[index] = el;
|
|
46
|
+
}, "aria-controls": `${id}-pane-${index}`, onChange: (event) => onChange(event, index), onKeyDown: (event) => {
|
|
47
|
+
handleKeyDown(event, moveToTab, index, Children.count(children));
|
|
48
|
+
}, className: "af-tabs__link", onClick: (event) => onChange(event, index), tabIndex: activeIndex === index ? 0 : -1, children: child.props.title }) }))) }), _jsx("div", { className: "af-tabs__content", children: Children.map(children, (child, index) => isValidElement(child) && (_jsx("div", { id: `${id}-pane-${index}`, "aria-labelledby": `${id}-tab-${index}`, className: getClassName({
|
|
49
|
+
baseClassName: "af-tabs__pane",
|
|
50
|
+
modifiers: [activeIndex === index && "active"],
|
|
51
|
+
}), role: "tabpanel", tabIndex: 0, children: child.props.children }, `pane-${index}`))) })] }));
|
|
10
52
|
};
|
|
11
53
|
export { TabsStateless };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./distributeur/Form/Experimental";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./distributeur/Form/Experimental";
|
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axa-fr/canopee-react",
|
|
3
|
-
"version": "1.4.2-alpha.
|
|
3
|
+
"version": "1.4.2-alpha.4",
|
|
4
4
|
"description": "Package React - Design System Canopée",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./distributeur": {
|
|
7
7
|
"import": "./dist/distributeur.js",
|
|
8
8
|
"types": "./dist/distributeur.d.ts"
|
|
9
9
|
},
|
|
10
|
+
"./distributeur/experimental": {
|
|
11
|
+
"import": "./dist/distributeur-experimental.js",
|
|
12
|
+
"types": "./dist/distributeur-experimental.d.ts"
|
|
13
|
+
},
|
|
10
14
|
"./client": {
|
|
11
15
|
"import": "./dist/client.js",
|
|
12
16
|
"types": "./dist/client.d.ts"
|
|
@@ -45,7 +49,7 @@
|
|
|
45
49
|
},
|
|
46
50
|
"homepage": "https://github.com/AxaFrance/design-system#readme",
|
|
47
51
|
"peerDependencies": {
|
|
48
|
-
"@axa-fr/canopee-css": "1.4.2-alpha.
|
|
52
|
+
"@axa-fr/canopee-css": "1.4.2-alpha.4",
|
|
49
53
|
"@material-symbols/svg-400": ">= 0.19.0",
|
|
50
54
|
"@material-symbols/svg-700": ">= 0.19.0",
|
|
51
55
|
"react": ">= 18"
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
export type TitleComponentProps = {
|
|
3
|
-
enable?: boolean | null;
|
|
4
|
-
active: boolean;
|
|
5
|
-
className?: string;
|
|
6
|
-
classModifier?: string;
|
|
7
|
-
id: string;
|
|
8
|
-
children?: React.ReactNode;
|
|
9
|
-
onChange: (event: React.MouseEvent<HTMLButtonElement>, index: string) => void;
|
|
10
|
-
};
|
|
11
|
-
declare const Title: {
|
|
12
|
-
({ active, onChange, children, classModifier, className, enable, id, }: TitleComponentProps): import("react/jsx-runtime").JSX.Element;
|
|
13
|
-
displayName: string;
|
|
14
|
-
};
|
|
15
|
-
export { Title };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import classNames from "classnames";
|
|
3
|
-
import React from "react";
|
|
4
|
-
import { getComponentClassName } from "../../utilities";
|
|
5
|
-
const Title = ({ active, onChange, children, classModifier, className, enable, id, }) => {
|
|
6
|
-
const newClassModifier = classNames(classModifier, {
|
|
7
|
-
disabled: enable === false,
|
|
8
|
-
active,
|
|
9
|
-
});
|
|
10
|
-
const componentClassName = getComponentClassName(className, newClassModifier, "af-tabs__item");
|
|
11
|
-
return (_jsx("li", { className: componentClassName, children: _jsx("button", { type: "button", id: id, className: "af-tabs__link", onClick: (event) => onChange(event, id), children: children }) }));
|
|
12
|
-
};
|
|
13
|
-
Title.displayName = "Title";
|
|
14
|
-
export { Title };
|