@axa-fr/design-system-look-and-feel-react 1.0.5-ci.118 → 1.0.5-ci.119

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.
@@ -0,0 +1,13 @@
1
+ import { type ComponentPropsWithoutRef, type Dispatch, type ReactElement, type SetStateAction } from "react";
2
+ import "@axa-fr/design-system-look-and-feel-css/dist/Layout/Header/BurgerMenu/BurgerMenu.scss";
3
+ import "@axa-fr/design-system-look-and-feel-css/dist/Card/Card.scss";
4
+ import "@axa-fr/design-system-look-and-feel-css/dist/List/List.scss";
5
+ import "@axa-fr/design-system-look-and-feel-css/dist/List/ClickList/ClickList.scss";
6
+ type BurgerMenuProps = {
7
+ isOpen: boolean;
8
+ items: ReactElement[];
9
+ setActiveLink: Dispatch<SetStateAction<number | undefined>>;
10
+ setIsOpen: Dispatch<SetStateAction<boolean>>;
11
+ } & ComponentPropsWithoutRef<"nav">;
12
+ declare const BurgerMenu: ({ isOpen, items, setActiveLink, setIsOpen, ...props }: BurgerMenuProps) => import("react/jsx-runtime").JSX.Element | null;
13
+ export { BurgerMenu };
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import "@axa-fr/design-system-look-and-feel-css/dist/Layout/Header/BurgerMenu/BurgerMenu.scss";
3
+ import "@axa-fr/design-system-look-and-feel-css/dist/Card/Card.scss";
4
+ import "@axa-fr/design-system-look-and-feel-css/dist/List/List.scss";
5
+ import "@axa-fr/design-system-look-and-feel-css/dist/List/ClickList/ClickList.scss";
6
+ import classNames from "classnames";
7
+ import { ClickItem, createClickItemParent } from "../../../List/ClickList";
8
+ const BurgerMenu = ({ isOpen, items, setActiveLink, setIsOpen, ...props }) => {
9
+ const handleOnClick = (index) => () => {
10
+ setActiveLink(index);
11
+ setIsOpen(false);
12
+ };
13
+ if (items.length === 0)
14
+ return null;
15
+ return (_jsx("nav", { role: "navigation", "aria-label": "Menu principal mobile", "aria-hidden": !isOpen, className: classNames("af-card", "af-card--list", "af-burger-menu", {
16
+ open: isOpen,
17
+ }), ...props, children: _jsx("ul", { role: "menubar", children: items.map((item, index) => {
18
+ const { key, props: itemProps, type } = item;
19
+ const { children, ...otherProps } = itemProps;
20
+ return (_jsx("li", { className: "af-list__item", role: "none", children: _jsx(ClickItem, { classModifier: "small", onClick: handleOnClick(index), parentClickComponent: createClickItemParent(type, {
21
+ ...otherProps,
22
+ role: "menuitem",
23
+ }), children: children }) }, key ?? `list item ${index}`));
24
+ }) }) }));
25
+ };
26
+ export { BurgerMenu };
@@ -0,0 +1 @@
1
+ export { BurgerMenu } from "./BurgerMenu";
@@ -0,0 +1 @@
1
+ export { BurgerMenu } from "./BurgerMenu";
@@ -1,9 +1,9 @@
1
1
  import "@axa-fr/design-system-look-and-feel-css/dist/Layout/Header/Header.scss";
2
- import { type ComponentPropsWithoutRef, type ReactNode } from "react";
3
- type HeaderProps = {
2
+ import { ComponentProps, PropsWithChildren, ReactElement, type ReactNode } from "react";
3
+ type HeaderProps = PropsWithChildren<{
4
4
  defaultActiveLink?: number;
5
5
  previousLink?: ReactNode;
6
- rightItem?: ReactNode[];
7
- } & ComponentPropsWithoutRef<"header">;
8
- export declare const Header: ({ children, defaultActiveLink, previousLink, rightItem, }: HeaderProps) => import("react/jsx-runtime").JSX.Element;
6
+ rightItem?: ReactElement | ReactElement[];
7
+ } & ComponentProps<"header">>;
8
+ export declare const Header: ({ children, defaultActiveLink, previousLink, rightItem, ...props }: HeaderProps) => import("react/jsx-runtime").JSX.Element;
9
9
  export {};
@@ -1,11 +1,37 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import "@axa-fr/design-system-look-and-feel-css/dist/Layout/Header/Header.scss";
3
3
  import logo from "@axa-fr/design-system-look-and-feel-css/logo-axa.svg";
4
- import { useCallback, useState, } from "react";
4
+ import { Children, isValidElement, useCallback, useEffect, useMemo, useState, } from "react";
5
+ import menu from "@material-symbols/svg-400/outlined/menu.svg";
5
6
  import { NavBar } from "./NavBar";
6
7
  import { PreviousLink } from "./PreviousLink/PreviousLink";
7
- export const Header = ({ children, defaultActiveLink, previousLink, rightItem, }) => {
8
+ import { Button, IconBg, Svg } from "../..";
9
+ import { BurgerMenu } from "./BurgerMenu";
10
+ import { BREAKPOINT } from "../../utilities";
11
+ export const Header = ({ children, defaultActiveLink, previousLink, rightItem, ...props }) => {
8
12
  const [activeLink, setActiveLink] = useState(defaultActiveLink);
13
+ const [isOpen, setIsOpen] = useState(false);
14
+ const toggleMenu = () => setIsOpen((prev) => !prev);
9
15
  const resetActiveLink = useCallback(() => setActiveLink(defaultActiveLink), [defaultActiveLink]);
10
- return (_jsxs(_Fragment, { children: [_jsx("header", { className: "af-header", children: _jsxs("div", { className: "af-header-container", children: [_jsxs("div", { className: "af-header-left-item", children: [_jsx("img", { className: "af-logo", src: logo, alt: "" }), children && (_jsx(NavBar, { activeLink: activeLink, setActiveLink: setActiveLink, children: children }))] }), rightItem && _jsx("div", { className: "af-header-right-item", children: rightItem })] }) }), previousLink && (_jsx(PreviousLink, { handleClick: resetActiveLink, children: previousLink }))] }));
16
+ useEffect(() => {
17
+ const handleResize = () => {
18
+ if (window.innerWidth > BREAKPOINT.MD && isOpen) {
19
+ setIsOpen(false);
20
+ }
21
+ };
22
+ window.addEventListener("resize", handleResize);
23
+ return () => window.removeEventListener("resize", handleResize);
24
+ }, [isOpen]);
25
+ const burgerMenuItems = useMemo(() => {
26
+ const mapValidElements = (items) => (Children.map(items, (child) => isValidElement(child) && child) ?? []).filter(Boolean);
27
+ const validLinks = mapValidElements(children);
28
+ if (!rightItem || !isValidElement(rightItem)) {
29
+ return validLinks;
30
+ }
31
+ if (Array.isArray(rightItem)) {
32
+ return [...validLinks, ...mapValidElements(rightItem)];
33
+ }
34
+ return [...validLinks, rightItem];
35
+ }, [children, rightItem]);
36
+ return (_jsxs(_Fragment, { children: [_jsxs("header", { className: "af-header", ...props, children: [_jsxs("div", { className: "af-header-container", children: [_jsxs("div", { className: "af-header-left-item", children: [_jsx("img", { className: "af-logo", src: logo, alt: "logo AXA" }), _jsx(NavBar, { activeLink: activeLink, setActiveLink: setActiveLink, children: children })] }), rightItem && _jsx("div", { className: "af-header-right-item", children: rightItem }), burgerMenuItems && burgerMenuItems.length > 0 && (_jsx(Button, { "aria-label": isOpen ? "Fermer le menu" : "Ouvrir le menu", onClick: toggleMenu, variant: "ghost", children: _jsx(IconBg, { children: _jsx(Svg, { src: menu, "aria-hidden": "true" }) }) }))] }), _jsx(BurgerMenu, { isOpen: isOpen, items: burgerMenuItems, setActiveLink: setActiveLink, setIsOpen: setIsOpen })] }), _jsx(PreviousLink, { handleClick: resetActiveLink, children: previousLink }), burgerMenuItems && burgerMenuItems.length > 0 && (_jsx("div", { className: `af-header-overlay ${isOpen ? "open" : ""}` }))] }));
11
37
  };
@@ -4,5 +4,5 @@ type NavBarProps = {
4
4
  activeLink?: number;
5
5
  setActiveLink: Dispatch<SetStateAction<number | undefined>>;
6
6
  } & ComponentPropsWithoutRef<"nav">;
7
- declare const NavBar: ({ activeLink, children, setActiveLink, ...otherProps }: PropsWithChildren<NavBarProps>) => import("react/jsx-runtime").JSX.Element;
7
+ declare const NavBar: ({ activeLink, children, setActiveLink, ...props }: PropsWithChildren<NavBarProps>) => import("react/jsx-runtime").JSX.Element | null;
8
8
  export { NavBar };
@@ -1,10 +1,15 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { isValidElement, useMemo, Children, cloneElement, } from "react";
3
3
  import "@axa-fr/design-system-look-and-feel-css/dist/Layout/Header/NavBar/NavBar.scss";
4
- const NavBar = ({ activeLink, children, setActiveLink, ...otherProps }) => {
4
+ import classNames from "classnames";
5
+ const NavBar = ({ activeLink, children, setActiveLink, ...props }) => {
5
6
  const validChildren = useMemo(() => (Children.map(children, (child) => isValidElement(child) && child) ?? []).filter((c) => Boolean(c)), [children]);
6
- return (_jsx("nav", { role: "navigation", "aria-label": "Menu principal", ...otherProps, children: _jsx("ul", { className: "af-navbar-container", role: "menubar", children: Children.map(validChildren, (child, index) => (_jsx("li", { className: "af-navbar-item", role: "none", children: cloneElement(child, {
7
- className: `af-navbar-item__link ${index === activeLink ? "af-navbar-item__link--active" : ""}`.trim(),
7
+ if (validChildren.length === 0)
8
+ return null;
9
+ return (_jsx("nav", { role: "navigation", "aria-label": "Menu principal", ...props, children: _jsx("ul", { className: "af-navbar-container", role: "menubar", children: Children.map(validChildren, (child, index) => (_jsx("li", { className: "af-navbar-item", role: "none", children: cloneElement(child, {
10
+ className: classNames("af-navbar-item__link", {
11
+ "af-navbar-item__link--active": index === activeLink,
12
+ }),
8
13
  onClick: () => setActiveLink(index),
9
14
  onFocus: () => setActiveLink(index),
10
15
  role: "menuitem",
@@ -3,5 +3,5 @@ import { ComponentPropsWithoutRef, PropsWithChildren } from "react";
3
3
  type PreviousLinkProps = {
4
4
  handleClick: () => void;
5
5
  } & ComponentPropsWithoutRef<"div">;
6
- declare const PreviousLink: ({ handleClick, children, ...otherProps }: PropsWithChildren<PreviousLinkProps>) => import("react/jsx-runtime").JSX.Element;
6
+ declare const PreviousLink: ({ handleClick, children, ...otherProps }: PropsWithChildren<PreviousLinkProps>) => import("react/jsx-runtime").JSX.Element | null;
7
7
  export { PreviousLink };
@@ -5,8 +5,10 @@ import React, { isValidElement, useMemo, } from "react";
5
5
  import { Svg } from "../../../Svg";
6
6
  const PreviousLink = ({ handleClick, children, ...otherProps }) => {
7
7
  const validChildren = useMemo(() => (React.Children.map(children, (child) => isValidElement(child) && child) ?? []).filter((c) => Boolean(c)), [children]);
8
+ if (validChildren.length === 0)
9
+ return null;
8
10
  return (_jsx("div", { className: "af-header-previous-link-container", ...otherProps, children: React.Children.map(validChildren, (child) => React.cloneElement(child, {
9
- children: (_jsxs(_Fragment, { children: [_jsx(Svg, { src: arrowBack }), child.props.children] })),
11
+ children: (_jsxs(_Fragment, { children: [_jsx(Svg, { src: arrowBack, "aria-hidden": true }), child.props.children] })),
10
12
  className: "af-btn-client af-btn-client--ghost af-btn-client--header-previous-link",
11
13
  onClick: handleClick,
12
14
  })) }));
@@ -1 +1,4 @@
1
+ export { BurgerMenu } from "./BurgerMenu";
1
2
  export { Header } from "./Header";
3
+ export { NavBar } from "./NavBar";
4
+ export { PreviousLink } from "./PreviousLink";
@@ -1 +1,4 @@
1
+ export { BurgerMenu } from "./BurgerMenu";
1
2
  export { Header } from "./Header";
3
+ export { NavBar } from "./NavBar";
4
+ export { PreviousLink } from "./PreviousLink";
package/dist/index.d.ts CHANGED
@@ -17,9 +17,7 @@ export { TextArea } from "./Form/TextArea";
17
17
  export { DebugGrid } from "./Grid/DebugGrid";
18
18
  export { IconBg } from "./IconBg";
19
19
  export { Footer } from "./Layout/Footer/Footer";
20
- export { Header } from "./Layout/Header";
21
- export { NavBar } from "./Layout/Header/NavBar/NavBar";
22
- export { PreviousLink } from "./Layout/Header/PreviousLink";
20
+ export { BurgerMenu, Header, NavBar, PreviousLink } from "./Layout/Header";
23
21
  export { Link } from "./Link";
24
22
  export { List } from "./List";
25
23
  export { ClickItem, ClickList, createClickItemParent } from "./List/ClickList";
package/dist/index.js CHANGED
@@ -16,9 +16,7 @@ export { TextArea } from "./Form/TextArea";
16
16
  export { DebugGrid } from "./Grid/DebugGrid";
17
17
  export { IconBg } from "./IconBg";
18
18
  export { Footer } from "./Layout/Footer/Footer";
19
- export { Header } from "./Layout/Header";
20
- export { NavBar } from "./Layout/Header/NavBar/NavBar";
21
- export { PreviousLink } from "./Layout/Header/PreviousLink";
19
+ export { BurgerMenu, Header, NavBar, PreviousLink } from "./Layout/Header";
22
20
  export { Link } from "./Link";
23
21
  export { List } from "./List";
24
22
  export { ClickItem, ClickList, createClickItemParent } from "./List/ClickList";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axa-fr/design-system-look-and-feel-react",
3
- "version": "1.0.5-ci.118",
3
+ "version": "1.0.5-ci.119",
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-look-and-feel-css": "1.0.5-ci.118",
50
+ "@axa-fr/design-system-look-and-feel-css": "1.0.5-ci.119",
51
51
  "@material-symbols/svg-400": ">= 0.19.0",
52
52
  "react": ">= 18"
53
53
  },