@axa-fr/canopee-react 2.0.0-alpha.68 → 2.0.0-alpha.69

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,10 @@
1
+ import "@axa-fr/canopee-css/distributeur/MultiActionsButton/MultiActionsButton.css";
2
+ import { type ComponentPropsWithoutRef, type ReactNode } from "react";
3
+ export type ButtonMultiActionsProps = {
4
+ label?: string;
5
+ menuLabel?: string;
6
+ align?: "auto" | "left" | "right";
7
+ } & Omit<ComponentPropsWithoutRef<"button">, "children"> & {
8
+ children: ReactNode;
9
+ };
10
+ export declare const ButtonMultiActions: ({ label, menuLabel, align, className, id, onClick, onKeyDown, onMouseDown, children, ...buttonProps }: ButtonMultiActionsProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,51 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import "@axa-fr/canopee-css/distributeur/MultiActionsButton/MultiActionsButton.css";
3
+ import chevronDown from "@material-symbols/svg-400/outlined/keyboard_arrow_down.svg";
4
+ import { useId, useRef, } from "react";
5
+ import { Button } from "../Button/Button";
6
+ import { Svg } from "../Svg";
7
+ import { getClassName } from "../utilities/helpers/getClassName";
8
+ export const ButtonMultiActions = ({ label = "Actions", menuLabel = "Actions supplémentaires", align = "auto", className, id, onClick, onKeyDown, onMouseDown, children, ...buttonProps }) => {
9
+ const generatedId = useId();
10
+ const menuId = `${id ?? `af-button-multi-actions-${generatedId}`}-menu`;
11
+ const containerRef = useRef(null);
12
+ const menuRef = useRef(null);
13
+ const triggerRef = useRef(null);
14
+ const handleMenuToggle = (event) => {
15
+ const isOpen = event.newState === "open";
16
+ triggerRef.current?.setAttribute("aria-expanded", String(isOpen));
17
+ if (!isOpen) {
18
+ triggerRef.current?.focus();
19
+ }
20
+ };
21
+ // Open the menu and focus its first item when navigating with ArrowDown
22
+ const handleTriggerKeyDown = (event) => {
23
+ onKeyDown?.(event);
24
+ if (event.defaultPrevented || menuRef.current?.matches(":popover-open"))
25
+ return;
26
+ if (event.key === "ArrowDown") {
27
+ event.preventDefault();
28
+ menuRef.current?.showPopover();
29
+ }
30
+ };
31
+ // Close the menu once an action inside it has been activated
32
+ const handleMenuClick = (event) => {
33
+ if (event.target !== event.currentTarget) {
34
+ menuRef.current?.hidePopover();
35
+ }
36
+ };
37
+ // Close the menu when the user presses Escape, returning focus to the trigger
38
+ const handleMenuKeyDown = (event) => {
39
+ if (event.key === "Escape" || event.key === "Esc") {
40
+ event.preventDefault();
41
+ menuRef.current?.hidePopover();
42
+ }
43
+ };
44
+ return (_jsxs("div", { className: "af-button-multi-actions", ref: containerRef, children: [_jsx(Button, { ref: triggerRef, variant: "ghost", className: getClassName({
45
+ baseClassName: "af-button-multi-actions__trigger",
46
+ modifiers: [align],
47
+ className,
48
+ }), "aria-haspopup": "menu", "aria-controls": menuId, "aria-expanded": "false", onClick: onClick, onKeyDown: handleTriggerKeyDown, onMouseDown: onMouseDown, ...buttonProps, popoverTarget: menuId, rightIcon: _jsx(Svg, { src: chevronDown, alt: "", "aria-hidden": "true", className: getClassName({
49
+ baseClassName: "af-button-multi-actions__icon",
50
+ }) }), children: label }), _jsx("div", { popover: "auto", id: menuId, role: "menu", "aria-label": menuLabel, tabIndex: -1, className: "af-button-multi-actions__menu", ref: menuRef, onToggle: handleMenuToggle, onKeyDown: handleMenuKeyDown, onClick: handleMenuClick, children: children })] }));
51
+ };
@@ -0,0 +1,2 @@
1
+ export { ButtonMultiActions } from "./ButtonMultiActions";
2
+ export type { ButtonMultiActionsProps } from "./ButtonMultiActions";
@@ -0,0 +1 @@
1
+ export { ButtonMultiActions } from "./ButtonMultiActions";
@@ -32,6 +32,7 @@ export { Footer } from "./distributeur/Layout/Footer";
32
32
  export { Header, HeaderTitle, Infos, MenuTitleWrapper, Name, NavBar, NavBarBase, NavBarItem, NavBarItemBase, NavBarItemLink, ToggleButton, User, type AnchorNavBarItem, } from "./distributeur/Layout/Header";
33
33
  export { MainContainer } from "./distributeur/Layout/MainContainer/MainContainer";
34
34
  export { Link, type LinkProps } from "./distributeur/Link/Link";
35
+ export { ButtonMultiActions, type ButtonMultiActionsProps, } from "./distributeur/ButtonMultiActions";
35
36
  export { MandatoryMention } from "./distributeur/MandatoryMention/MandatoryMention";
36
37
  export { BooleanModal, Modal, ModalBody, ModalFooter, ModalHeader, ModalHeaderBase, } from "./distributeur/ModalAgent";
37
38
  export { ArticleRestitution, HeaderRestitution, Restitution, RestitutionList, SectionRestitution, SectionRestitutionColumn, SectionRestitutionRow, SectionRestitutionTitle, } from "./distributeur/Restitution";
@@ -31,6 +31,7 @@ export { Footer } from "./distributeur/Layout/Footer";
31
31
  export { Header, HeaderTitle, Infos, MenuTitleWrapper, Name, NavBar, NavBarBase, NavBarItem, NavBarItemBase, NavBarItemLink, ToggleButton, User, } from "./distributeur/Layout/Header";
32
32
  export { MainContainer } from "./distributeur/Layout/MainContainer/MainContainer";
33
33
  export { Link } from "./distributeur/Link/Link";
34
+ export { ButtonMultiActions, } from "./distributeur/ButtonMultiActions";
34
35
  export { MandatoryMention } from "./distributeur/MandatoryMention/MandatoryMention";
35
36
  export { BooleanModal, Modal, ModalBody, ModalFooter, ModalHeader, ModalHeaderBase, } from "./distributeur/ModalAgent";
36
37
  export { ArticleRestitution, HeaderRestitution, Restitution, RestitutionList, SectionRestitution, SectionRestitutionColumn, SectionRestitutionRow, SectionRestitutionTitle, } from "./distributeur/Restitution";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axa-fr/canopee-react",
3
- "version": "2.0.0-alpha.68",
3
+ "version": "2.0.0-alpha.69",
4
4
  "description": "Package React - Design System Canopée",
5
5
  "exports": {
6
6
  "./distributeur": {
@@ -53,7 +53,7 @@
53
53
  },
54
54
  "homepage": "https://github.com/AxaFrance/design-system#readme",
55
55
  "peerDependencies": {
56
- "@axa-fr/canopee-css": "2.0.0-alpha.68",
56
+ "@axa-fr/canopee-css": "2.0.0-alpha.69",
57
57
  "@material-symbols/svg-400": ">= 0.19.0",
58
58
  "@material-symbols/svg-700": ">= 0.19.0",
59
59
  "react": ">= 19"