@axa-fr/design-system-look-and-feel-react 0.2.0-beta.308 → 0.2.0-beta.314
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/Alert/Alert.d.ts
CHANGED
@@ -1,12 +1,22 @@
|
|
1
1
|
import { ComponentPropsWithoutRef, PropsWithChildren, ReactElement } from "react";
|
2
2
|
import "@axa-fr/design-system-look-and-feel-css/dist/Alert/Alert.scss";
|
3
3
|
import { Link } from "../Link/Link";
|
4
|
-
|
4
|
+
import { ButtonClient } from "../Button/Button";
|
5
|
+
type Headings = "h2" | "h3" | "h4" | "h5" | "h6";
|
6
|
+
export declare const alertTypes: {
|
7
|
+
readonly validation: "validation";
|
8
|
+
readonly error: "error";
|
9
|
+
readonly warning: "warning";
|
10
|
+
readonly information: "information";
|
11
|
+
readonly neutral: "neutral";
|
12
|
+
};
|
13
|
+
export type AlertType = keyof typeof alertTypes;
|
5
14
|
type AlertProps = {
|
6
15
|
type: AlertType;
|
7
16
|
title?: string;
|
8
|
-
|
17
|
+
action?: ReactElement<typeof Link | typeof ButtonClient>;
|
9
18
|
iconSize?: number;
|
19
|
+
heading?: Headings;
|
10
20
|
} & ComponentPropsWithoutRef<"div">;
|
11
|
-
export declare const Alert: ({ type, title, children,
|
21
|
+
export declare const Alert: ({ type, title, children, action, iconSize, heading: Heading, }: PropsWithChildren<AlertProps>) => import("react/jsx-runtime").JSX.Element;
|
12
22
|
export {};
|
package/dist/Alert/Alert.js
CHANGED
@@ -6,21 +6,21 @@ import errorOutline from "@material-symbols/svg-400/outlined/error.svg";
|
|
6
6
|
import checkCircleOutline from "@material-symbols/svg-400/outlined/check_circle.svg";
|
7
7
|
import "@axa-fr/design-system-look-and-feel-css/dist/Alert/Alert.scss";
|
8
8
|
import { Svg } from "../Svg";
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
}
|
23
|
-
export const Alert = ({ type =
|
9
|
+
export const alertTypes = {
|
10
|
+
validation: "validation",
|
11
|
+
error: "error",
|
12
|
+
warning: "warning",
|
13
|
+
information: "information",
|
14
|
+
neutral: "neutral",
|
15
|
+
};
|
16
|
+
const getIconFromType = (type) => ({
|
17
|
+
[alertTypes.validation]: checkCircleOutline,
|
18
|
+
[alertTypes.error]: errorIcon,
|
19
|
+
[alertTypes.neutral]: errorOutline,
|
20
|
+
[alertTypes.warning]: errorOutline,
|
21
|
+
[alertTypes.information]: wbIncandescentOutlined,
|
22
|
+
})[type] || wbIncandescentOutlined;
|
23
|
+
export const Alert = ({ type = alertTypes.information, title, children, action, iconSize = 24, heading: Heading = "h4", }) => {
|
24
24
|
const icon = useMemo(() => getIconFromType(type), [type]);
|
25
|
-
return (_jsxs("div", { className: `af-alert af-alert--${type}`, children: [_jsx(Svg, { src: icon, width: iconSize, height: iconSize, className: "af-alert__icon" }), _jsxs("div", { className: "af-alert-client__content", children: [title && _jsx(
|
25
|
+
return (_jsxs("div", { className: `af-alert af-alert--${type}`, role: "alert", children: [_jsx(Svg, { src: icon, width: iconSize, height: iconSize, className: "af-alert__icon", "aria-hidden": true }), _jsxs("div", { className: "af-alert-client__content", children: [title && _jsx(Heading, { className: "af-alert__title", children: title }), children, action && _jsx("p", { className: "af-alert__action", children: action })] })] }));
|
26
26
|
};
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
2
2
|
import { Alert } from "./Alert";
|
3
3
|
import { Link } from "../Link/Link";
|
4
|
+
import { ButtonClient, Variants } from "../Button/Button";
|
4
5
|
const MODIFIERS = ["information", "neutral", "error", "validation", "warning"];
|
5
6
|
const meta = {
|
6
7
|
title: "Components/Alert",
|
@@ -13,7 +14,7 @@ export const Default = {
|
|
13
14
|
title: "My Alert title",
|
14
15
|
type: "information",
|
15
16
|
children: "Vestibulum nunc neque, sodales non luctus in, dictum vitae nisl. Curabitur vitae massa non nisl lacinia tempus. Pellentesque id nulla tortor.",
|
16
|
-
|
17
|
+
action: (_jsx(Link, { openInNewTab: true, href: "https://fakelink.com", children: "Plus de d\u00E9tails" })),
|
17
18
|
iconSize: 24,
|
18
19
|
},
|
19
20
|
argTypes: {
|
@@ -24,3 +25,13 @@ export const Default = {
|
|
24
25
|
},
|
25
26
|
},
|
26
27
|
};
|
28
|
+
export const WithButtonAction = {
|
29
|
+
name: "Alert with Button action",
|
30
|
+
args: {
|
31
|
+
title: "My Alert title",
|
32
|
+
type: "information",
|
33
|
+
children: "Vestibulum nunc neque, sodales non luctus in, dictum vitae nisl. Curabitur vitae massa non nisl lacinia tempus. Pellentesque id nulla tortor.",
|
34
|
+
action: _jsx(ButtonClient, { variant: Variants.ghost, children: "Actualiser" }),
|
35
|
+
iconSize: 24,
|
36
|
+
},
|
37
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
+
import { render, screen } from "@testing-library/react";
|
3
|
+
import { Alert, alertTypes } from "../Alert";
|
4
|
+
import { Link } from "../../Link/Link";
|
5
|
+
import { ButtonClient, Variants } from "../../Button/Button";
|
6
|
+
const MoreDetails = () => (_jsx(Link, { openInNewTab: true, href: "https://fakelink.com", children: "Plus de d\u00E9tails" }));
|
7
|
+
describe("Alert", () => {
|
8
|
+
it.each `
|
9
|
+
type | title | children | action | icon | iconSize | expectLink | expectButton
|
10
|
+
${undefined} | ${undefined} | ${undefined} | ${undefined} | ${"wb_incandescent.svg"} | ${undefined} | ${false} | ${false}
|
11
|
+
${alertTypes.information} | ${"my title"} | ${"some text"} | ${(_jsx(MoreDetails, {}))} | ${"wb_incandescent.svg"} | ${undefined} | ${true} | ${false}
|
12
|
+
${alertTypes.error} | ${"my title"} | ${"some text"} | ${(_jsx(MoreDetails, {}))} | ${"emergency_home.svg"} | ${undefined} | ${true} | ${false}
|
13
|
+
${alertTypes.neutral} | ${"my title"} | ${"some text"} | ${(_jsx(MoreDetails, {}))} | ${"error.svg"} | ${undefined} | ${true} | ${false}
|
14
|
+
${alertTypes.validation} | ${"my title"} | ${"some text"} | ${(_jsx(MoreDetails, {}))} | ${"check_circle.svg"} | ${undefined} | ${true} | ${false}
|
15
|
+
${alertTypes.warning} | ${"my title"} | ${"some text"} | ${(_jsx(ButtonClient, { variant: Variants.ghost, children: "Actualiser" }))} | ${"error.svg"} | ${undefined} | ${false} | ${true}
|
16
|
+
`("Should render correctly with type: $type, title: $title, children: $children, icon: $icon, action: $action, iconSize: $iconSize", ({ type, title, children, action, icon, iconSize, expectLink, expectButton, }) => {
|
17
|
+
const { container } = render(_jsx(Alert, { type, title, action, iconSize, children: children }));
|
18
|
+
if (title) {
|
19
|
+
expect(screen.getByText(RegExp(title))).toBeDefined();
|
20
|
+
}
|
21
|
+
if (children) {
|
22
|
+
expect(screen.getByText(RegExp(children))).toBeDefined();
|
23
|
+
}
|
24
|
+
expect(screen.getByRole("alert")).toHaveClass(`af-alert--${type || alertTypes.information}`);
|
25
|
+
if (expectLink && action) {
|
26
|
+
expect(screen.getByRole("link")).toHaveAttribute("href", "https://fakelink.com");
|
27
|
+
}
|
28
|
+
if (expectButton && action) {
|
29
|
+
expect(screen.getByRole("button", { name: /Actualiser/ })).toBeInTheDocument();
|
30
|
+
}
|
31
|
+
expect(container.querySelector(`[data-src$="${icon}"]`)).toBeDefined();
|
32
|
+
});
|
33
|
+
});
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@axa-fr/design-system-look-and-feel-react",
|
3
|
-
"version": "0.2.0-beta.
|
3
|
+
"version": "0.2.0-beta.314",
|
4
4
|
"description": "",
|
5
5
|
"exports": {
|
6
6
|
".": {
|
@@ -41,7 +41,7 @@
|
|
41
41
|
},
|
42
42
|
"homepage": "https://github.com/AxaFrance/design-system#readme",
|
43
43
|
"peerDependencies": {
|
44
|
-
"@axa-fr/design-system-look-and-feel-css": "0.2.0-beta.
|
44
|
+
"@axa-fr/design-system-look-and-feel-css": "0.2.0-beta.314",
|
45
45
|
"@material-symbols/svg-400": ">= 0.19.0",
|
46
46
|
"react": ">= 18"
|
47
47
|
},
|
@@ -93,7 +93,7 @@
|
|
93
93
|
"eslint-plugin-import": "^2.29.1",
|
94
94
|
"eslint-plugin-jsx-a11y": "^6.8.0",
|
95
95
|
"eslint-plugin-prettier": "^5.1.3",
|
96
|
-
"eslint-plugin-react": "^7.
|
96
|
+
"eslint-plugin-react": "^7.36.1",
|
97
97
|
"eslint-plugin-react-hooks": "^4.6.0",
|
98
98
|
"jest-axe": "^8.0.0",
|
99
99
|
"jsdom": "^24.0.0",
|