@axa-fr/canopee-react 1.4.2-alpha.3 → 1.4.2-alpha.5
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/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/prospect-client/Stepper/StepperCommon.d.ts +1 -1
- package/package.json +2 -2
- package/dist/distributeur/Tabs/components/Title.d.ts +0 -15
- package/dist/distributeur/Tabs/components/Title.js +0 -14
|
@@ -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 };
|
|
@@ -6,7 +6,7 @@ export type StepperProps = {
|
|
|
6
6
|
currentStep: number;
|
|
7
7
|
currentSubtitle?: string;
|
|
8
8
|
currentTitle?: string;
|
|
9
|
-
nbSteps?: 3 | 4 | 5 | 6 | 7 | 8;
|
|
9
|
+
nbSteps?: 2 | 3 | 4 | 5 | 6 | 7 | 8;
|
|
10
10
|
helper?: string;
|
|
11
11
|
message?: string;
|
|
12
12
|
messageType?: ItemMessageProps["messageType"];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axa-fr/canopee-react",
|
|
3
|
-
"version": "1.4.2-alpha.
|
|
3
|
+
"version": "1.4.2-alpha.5",
|
|
4
4
|
"description": "Package React - Design System Canopée",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./distributeur": {
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
},
|
|
50
50
|
"homepage": "https://github.com/AxaFrance/design-system#readme",
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"@axa-fr/canopee-css": "1.4.2-alpha.
|
|
52
|
+
"@axa-fr/canopee-css": "1.4.2-alpha.5",
|
|
53
53
|
"@material-symbols/svg-400": ">= 0.19.0",
|
|
54
54
|
"@material-symbols/svg-700": ">= 0.19.0",
|
|
55
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 };
|