@frontify/fondue 12.0.9 → 12.0.10

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.
@@ -1 +1 @@
1
- {"version":3,"file":"ActionMenu.es.js","sources":["../../../../src/components/ActionMenu/ActionMenu/ActionMenu.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { useMenu } from '@react-aria/menu';\nimport { useTreeState } from '@react-stately/tree';\nimport { type FocusStrategy } from '@react-types/shared';\nimport { type ReactElement, useRef } from 'react';\n\nimport { AriaList } from '@components/ActionMenu/Aria/AriaList';\nimport { AriaMenuItem } from '@components/ActionMenu/Aria/AriaMenuItem';\nimport { AriaSection } from '@components/ActionMenu/Aria/AriaSection';\nimport { getDisabledItemIds, getKeyItemRecord, getMenuItems, mapToAriaProps } from '@components/ActionMenu/Aria/helper';\nimport { type MenuItemType } from '@components/Dropdown/SelectMenu/SelectMenu';\n\nexport type ActionMenuItemType = MenuItemType & { onClick: () => void };\nexport type ActionMenuSwitchItemType = MenuItemType & {\n onClick: (switchValue: boolean) => void;\n type: 'switch';\n initialValue: boolean;\n};\n\nexport type ActionMenuBlock = {\n id: string;\n menuItems: (ActionMenuItemType | ActionMenuSwitchItemType)[];\n ariaLabel?: string;\n};\n\nexport type ActionMenuProps = {\n ariaLabel?: string;\n menuBlocks: ActionMenuBlock[];\n focus?: FocusStrategy;\n border?: boolean;\n scrollable?: boolean;\n onClick?: () => void;\n};\n\nexport const ActionMenu = ({\n menuBlocks,\n ariaLabel = 'Action Menu',\n focus,\n border = true,\n scrollable = false,\n onClick,\n}: ActionMenuProps): ReactElement<ActionMenuProps> => {\n const items = getMenuItems(menuBlocks);\n const keyItemRecord = getKeyItemRecord(items);\n const props = mapToAriaProps(ariaLabel, menuBlocks);\n const state = useTreeState({\n ...props,\n selectionMode: 'none',\n disabledKeys: getDisabledItemIds(items),\n });\n const menuRef = useRef<HTMLUListElement | null>(null);\n const { menuProps } = useMenu({ ...props, autoFocus: focus }, state, menuRef);\n\n return (\n <AriaList ariaProps={{ ...menuProps }} ref={menuRef} border={border} scrollable={scrollable}>\n {[...state.collection].map((section) => {\n const { key: sectionKey, 'aria-label': sectionAriaLabel } = section;\n\n return (\n <AriaSection key={sectionKey} ariaLabel={sectionAriaLabel}>\n {[...section.childNodes].map((item) => (\n <AriaMenuItem\n key={item.key}\n menuItem={keyItemRecord[item.key as string]}\n state={state}\n node={item}\n onClick={onClick}\n />\n ))}\n </AriaSection>\n );\n })}\n </AriaList>\n );\n};\nActionMenu.displayName = 'FondueActionMenu';\n"],"names":["ActionMenu","menuBlocks","ariaLabel","focus","border","scrollable","onClick","items","getMenuItems","keyItemRecord","getKeyItemRecord","props","mapToAriaProps","state","useTreeState","getDisabledItemIds","menuRef","useRef","menuProps","useMenu","AriaList","section","sectionKey","sectionAriaLabel","jsx","AriaSection","item","AriaMenuItem"],"mappings":";;;;;;;;AAmCO,MAAMA,IAAa,CAAC;AAAA,EACvB,YAAAC;AAAA,EACA,WAAAC,IAAY;AAAA,EACZ,OAAAC;AAAA,EACA,QAAAC,IAAS;AAAA,EACT,YAAAC,IAAa;AAAA,EACb,SAAAC;AACJ,MAAsD;AAC5C,QAAAC,IAAQC,EAAaP,CAAU,GAC/BQ,IAAgBC,EAAiBH,CAAK,GACtCI,IAAQC,EAAeV,GAAWD,CAAU,GAC5CY,IAAQC,EAAa;AAAA,IACvB,GAAGH;AAAA,IACH,eAAe;AAAA,IACf,cAAcI,EAAmBR,CAAK;AAAA,EAAA,CACzC,GACKS,IAAUC,EAAgC,IAAI,GAC9C,EAAE,WAAAC,EAAU,IAAIC,EAAQ,EAAE,GAAGR,GAAO,WAAWR,EAAS,GAAAU,GAAOG,CAAO;AAE5E,2BACKI,GAAS,EAAA,WAAW,EAAE,GAAGF,EAAA,GAAa,KAAKF,GAAS,QAAAZ,GAAgB,YAAAC,GAChE,WAAC,GAAGQ,EAAM,UAAU,EAAE,IAAI,CAACQ,MAAY;AACpC,UAAM,EAAE,KAAKC,GAAY,cAAcC,MAAqBF;AAGxD,WAAA,gBAAAG,EAACC,GAA6B,EAAA,WAAWF,GACpC,UAAA,CAAC,GAAGF,EAAQ,UAAU,EAAE,IAAI,CAACK,MAC1B,gBAAAF;AAAA,MAACG;AAAA,MAAA;AAAA,QAEG,UAAUlB,EAAciB,EAAK,GAAa;AAAA,QAC1C,OAAAb;AAAA,QACA,MAAMa;AAAA,QACN,SAAApB;AAAA,MAAA;AAAA,MAJKoB,EAAK;AAAA,IAAA,CAMjB,KATaJ,CAUlB;AAAA,EAEP,CAAA,EACL,CAAA;AAER;AACAtB,EAAW,cAAc;"}
1
+ {"version":3,"file":"ActionMenu.es.js","sources":["../../../../src/components/ActionMenu/ActionMenu/ActionMenu.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { useMenu } from '@react-aria/menu';\nimport { useTreeState } from '@react-stately/tree';\nimport { type FocusStrategy } from '@react-types/shared';\nimport { type ReactElement, useRef } from 'react';\n\nimport { AriaList } from '@components/ActionMenu/Aria/AriaList';\nimport { AriaMenuItem } from '@components/ActionMenu/Aria/AriaMenuItem';\nimport { AriaSection } from '@components/ActionMenu/Aria/AriaSection';\nimport { getDisabledItemIds, getKeyItemRecord, getMenuItems, mapToAriaProps } from '@components/ActionMenu/Aria/helper';\nimport { type MenuItemType } from '@components/Dropdown/SelectMenu/SelectMenu';\n\nexport type ActionMenuItemType = MenuItemType & { onClick: () => void };\nexport type ActionMenuSwitchItemType = MenuItemType & {\n onClick: (switchValue: boolean) => void;\n type: 'switch';\n initialValue: boolean;\n};\n\nexport type ActionMenuBlock = {\n id: string;\n menuItems: (ActionMenuItemType | ActionMenuSwitchItemType)[];\n ariaLabel?: string;\n};\n\nexport type ActionMenuProps = {\n ariaLabel?: string;\n menuBlocks: ActionMenuBlock[];\n focus?: FocusStrategy;\n border?: boolean;\n scrollable?: boolean;\n /**\n * @deprecated Use the onClick method available on each `menuItem` in the `menuBlocks` instead.\n * @example\n * <ActionMenu\n menuBlocks={[\n {\n id: 'menu-block-1',\n menuItems: [\n {\n id: 'menu-item-1',\n label: 'Item 1',\n onClick: () => console.log('Item 1 clicked');\n },\n ],\n },\n ]}\n />\n * */\n onClick?: () => void;\n};\n\nexport const ActionMenu = ({\n menuBlocks,\n ariaLabel = 'Action Menu',\n focus,\n border = true,\n scrollable = false,\n onClick,\n}: ActionMenuProps): ReactElement<ActionMenuProps> => {\n const items = getMenuItems(menuBlocks);\n const keyItemRecord = getKeyItemRecord(items);\n const props = mapToAriaProps(ariaLabel, menuBlocks);\n const state = useTreeState({\n ...props,\n selectionMode: 'none',\n disabledKeys: getDisabledItemIds(items),\n });\n const menuRef = useRef<HTMLUListElement | null>(null);\n const { menuProps } = useMenu({ ...props, autoFocus: focus }, state, menuRef);\n\n return (\n <AriaList ariaProps={{ ...menuProps }} ref={menuRef} border={border} scrollable={scrollable}>\n {[...state.collection].map((section) => {\n const { key: sectionKey, 'aria-label': sectionAriaLabel } = section;\n\n return (\n <AriaSection key={sectionKey} ariaLabel={sectionAriaLabel}>\n {[...section.childNodes].map((item) => (\n <AriaMenuItem\n key={item.key}\n menuItem={keyItemRecord[item.key as string]}\n state={state}\n node={item}\n onClick={onClick}\n />\n ))}\n </AriaSection>\n );\n })}\n </AriaList>\n );\n};\nActionMenu.displayName = 'FondueActionMenu';\n"],"names":["ActionMenu","menuBlocks","ariaLabel","focus","border","scrollable","onClick","items","getMenuItems","keyItemRecord","getKeyItemRecord","props","mapToAriaProps","state","useTreeState","getDisabledItemIds","menuRef","useRef","menuProps","useMenu","AriaList","section","sectionKey","sectionAriaLabel","jsx","AriaSection","item","AriaMenuItem"],"mappings":";;;;;;;;AAqDO,MAAMA,IAAa,CAAC;AAAA,EACvB,YAAAC;AAAA,EACA,WAAAC,IAAY;AAAA,EACZ,OAAAC;AAAA,EACA,QAAAC,IAAS;AAAA,EACT,YAAAC,IAAa;AAAA,EACb,SAAAC;AACJ,MAAsD;AAC5C,QAAAC,IAAQC,EAAaP,CAAU,GAC/BQ,IAAgBC,EAAiBH,CAAK,GACtCI,IAAQC,EAAeV,GAAWD,CAAU,GAC5CY,IAAQC,EAAa;AAAA,IACvB,GAAGH;AAAA,IACH,eAAe;AAAA,IACf,cAAcI,EAAmBR,CAAK;AAAA,EAAA,CACzC,GACKS,IAAUC,EAAgC,IAAI,GAC9C,EAAE,WAAAC,EAAU,IAAIC,EAAQ,EAAE,GAAGR,GAAO,WAAWR,EAAS,GAAAU,GAAOG,CAAO;AAE5E,2BACKI,GAAS,EAAA,WAAW,EAAE,GAAGF,EAAA,GAAa,KAAKF,GAAS,QAAAZ,GAAgB,YAAAC,GAChE,WAAC,GAAGQ,EAAM,UAAU,EAAE,IAAI,CAACQ,MAAY;AACpC,UAAM,EAAE,KAAKC,GAAY,cAAcC,MAAqBF;AAGxD,WAAA,gBAAAG,EAACC,GAA6B,EAAA,WAAWF,GACpC,UAAA,CAAC,GAAGF,EAAQ,UAAU,EAAE,IAAI,CAACK,MAC1B,gBAAAF;AAAA,MAACG;AAAA,MAAA;AAAA,QAEG,UAAUlB,EAAciB,EAAK,GAAa;AAAA,QAC1C,OAAAb;AAAA,QACA,MAAMa;AAAA,QACN,SAAApB;AAAA,MAAA;AAAA,MAJKoB,EAAK;AAAA,IAAA,CAMjB,KATaJ,CAUlB;AAAA,EAEP,CAAA,EACL,CAAA;AAER;AACAtB,EAAW,cAAc;"}
@@ -1,69 +1,66 @@
1
1
  import { jsx as r } from "react/jsx-runtime";
2
- import { useFocusRing as A } from "@react-aria/focus";
3
- import { useMenuItem as k } from "@react-aria/menu";
2
+ import { useFocusRing as C } from "@react-aria/focus";
3
+ import { useMenuItem as A } from "@react-aria/menu";
4
4
  import { mergeProps as x } from "@react-aria/utils";
5
- import { useRef as F, useState as d, useEffect as P } from "react";
6
- import { MenuItem as j } from "../../MenuItem/MenuItem.es.js";
7
- import { FOCUS_STYLE_INSET as E } from "../../../utilities/focusStyle.es.js";
8
- import { merge as N } from "../../../utilities/merge.es.js";
9
- import { Switch as O } from "../../Switch/Switch.es.js";
10
- const z = (o) => typeof o.onClick < "u" && typeof o.type > "u", c = (o) => typeof o.onClick < "u" && o.type === "switch", R = (o, e) => {
11
- const [t, l] = d(e ?? !1), [i, s] = d({
5
+ import { useRef as F, useState as d, useEffect as j } from "react";
6
+ import { MenuItem as E } from "../../MenuItem/MenuItem.es.js";
7
+ import { FOCUS_STYLE_INSET as N } from "../../../utilities/focusStyle.es.js";
8
+ import { merge as O } from "../../../utilities/merge.es.js";
9
+ import { Switch as P } from "../../Switch/Switch.es.js";
10
+ const z = (t) => typeof t.onClick < "u" && typeof t.type > "u", n = (t) => typeof t.onClick < "u" && t.type === "switch", R = (t, e) => {
11
+ const [o, l] = d(e ?? !1), [i, s] = d({
12
12
  switchComponent: void 0,
13
13
  switchValue: null,
14
14
  toggleSwitch: null
15
15
  });
16
- return P(() => {
17
- o && s({
18
- switchComponent: /* @__PURE__ */ r(O, { size: "small", mode: t ? "on" : "off" }),
19
- switchValue: t,
20
- toggleSwitch: () => l(!t)
16
+ return j(() => {
17
+ t && s({
18
+ switchComponent: /* @__PURE__ */ r(P, { size: "small", mode: o ? "on" : "off" }),
19
+ switchValue: o,
20
+ toggleSwitch: () => l(!o)
21
21
  });
22
- }, [o, t]), i;
23
- }, T = ({ menuItem: o, node: e, state: t, isSelected: l, onClick: i }) => {
24
- const s = F(null), a = c(o) ? o.initialValue : !1, {
22
+ }, [t, o]), i;
23
+ }, T = ({ menuItem: t, node: e, state: o, isSelected: l, onClick: i }) => {
24
+ const s = F(null), a = n(t) ? t.initialValue : !1, {
25
25
  switchComponent: f = void 0,
26
26
  switchValue: w = null,
27
- toggleSwitch: n = null
28
- } = R(c(o), a), { menuItemProps: h } = k(
27
+ toggleSwitch: c = null
28
+ } = R(n(t), a), { menuItemProps: h } = A(
29
29
  {
30
30
  ...e,
31
31
  onAction: () => {
32
- z(o) && o.onClick(), c(o) && (n == null || n(), o.onClick(!w));
32
+ z(t) && t.onClick(), n(t) && (c == null || c(), t.onClick(!w));
33
33
  },
34
- isDisabled: (o == null ? void 0 : o.disabled) || !1,
35
- "aria-label": typeof (o == null ? void 0 : o.title) == "string" ? o == null ? void 0 : o.title : "Menu item"
34
+ isDisabled: (t == null ? void 0 : t.disabled) || !1,
35
+ "aria-label": typeof (t == null ? void 0 : t.title) == "string" ? t == null ? void 0 : t.title : "Menu item"
36
36
  },
37
- t,
37
+ o,
38
38
  s
39
- ), { title: u, decorator: b, subtitle: g, size: S, style: C, disabled: p, selectionIndicator: y } = o, { isFocusVisible: v, focusProps: M } = A();
39
+ ), { title: u, decorator: b, subtitle: S, size: g, style: y, disabled: p, selectionIndicator: v } = t, { isFocusVisible: M, focusProps: V } = C();
40
40
  return (
41
41
  // eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-noninteractive-element-interactions
42
42
  /* @__PURE__ */ r(
43
43
  "li",
44
44
  {
45
- ...x(h, M),
45
+ ...x(h, V, { onClick: () => i == null ? void 0 : i() }),
46
46
  "data-test-id": "menu-item",
47
- className: N([
47
+ className: O([
48
48
  "tw-relative hover:tw-bg-box-neutral-hover tw-list-none tw-outline-none",
49
49
  p && "tw-pointer-events-none tw-top-px",
50
- v && E
50
+ M && N
51
51
  ]),
52
52
  ref: s,
53
- onClick: (V) => {
54
- V.stopPropagation(), i && i();
55
- },
56
53
  children: /* @__PURE__ */ r(
57
- j,
54
+ E,
58
55
  {
59
56
  title: u,
60
57
  decorator: b,
61
- subtitle: g,
62
- size: S,
63
- style: C,
58
+ subtitle: S,
59
+ size: g,
60
+ style: y,
64
61
  disabled: p,
65
62
  active: l,
66
- selectionIndicator: y,
63
+ selectionIndicator: v,
67
64
  switchComponent: f
68
65
  }
69
66
  )
@@ -1 +1 @@
1
- {"version":3,"file":"AriaMenuItem.es.js","sources":["../../../../src/components/ActionMenu/Aria/AriaMenuItem.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { useFocusRing } from '@react-aria/focus';\nimport { useMenuItem } from '@react-aria/menu';\nimport { mergeProps } from '@react-aria/utils';\nimport { type TreeState } from '@react-stately/tree';\nimport { type Node } from '@react-types/shared';\nimport { type ReactElement, useEffect, useRef, useState } from 'react';\n\nimport { type ActionMenuItemType, type ActionMenuSwitchItemType } from '@components/ActionMenu';\nimport { type MenuItemType } from '@components/Dropdown';\nimport { MenuItem } from '@components/MenuItem/MenuItem';\nimport { Switch } from '@components/Switch';\nimport { FOCUS_STYLE_INSET } from '@utilities/focusStyle';\nimport { merge } from '@utilities/merge';\n\nexport type AriaOptionProps = {\n menuItem: MenuItemType | ActionMenuItemType | ActionMenuSwitchItemType;\n node: Node<object>;\n isSelected?: boolean;\n state: TreeState<object>;\n onClick?: () => void;\n};\n\ninterface SwitchObject {\n switchComponent: ReactElement | undefined;\n switchValue: boolean | null;\n toggleSwitch: VoidFunction | null;\n}\n\nconst isActionMenuItem = (\n menuItem: MenuItemType | ActionMenuItemType | ActionMenuSwitchItemType,\n): menuItem is ActionMenuItemType =>\n typeof (menuItem as ActionMenuItemType).onClick !== 'undefined' && typeof menuItem.type === 'undefined';\nconst isActionMenuSwitchItem = (\n menuItem: MenuItemType | ActionMenuItemType | ActionMenuSwitchItemType,\n): menuItem is ActionMenuSwitchItemType =>\n typeof (menuItem as ActionMenuSwitchItemType).onClick !== 'undefined' && menuItem.type === 'switch';\n\nconst useSwitch = (isSwitch: boolean, initialValue: boolean) => {\n const [switchValue, setSwitchValue] = useState<boolean>(initialValue ?? false);\n const [switchObject, setSwitchObject] = useState<SwitchObject>({\n switchComponent: undefined,\n switchValue: null,\n toggleSwitch: null,\n });\n\n useEffect(() => {\n if (isSwitch) {\n const toggleSwitch = () => setSwitchValue(!switchValue);\n const switchComponent = <Switch size=\"small\" mode={switchValue ? 'on' : 'off'} />;\n\n setSwitchObject({\n switchComponent,\n switchValue,\n toggleSwitch,\n });\n }\n }, [isSwitch, switchValue]);\n\n return switchObject;\n};\n\nexport const AriaMenuItem = ({ menuItem, node, state, isSelected, onClick }: AriaOptionProps): ReactElement => {\n const ref = useRef<HTMLLIElement | null>(null);\n const initialValue = isActionMenuSwitchItem(menuItem) ? menuItem.initialValue : false;\n const {\n switchComponent = undefined,\n switchValue = null,\n toggleSwitch = null,\n } = useSwitch(isActionMenuSwitchItem(menuItem), initialValue);\n\n const { menuItemProps } = useMenuItem(\n {\n ...node,\n onAction: () => {\n if (isActionMenuItem(menuItem)) {\n menuItem.onClick();\n }\n if (isActionMenuSwitchItem(menuItem)) {\n toggleSwitch?.();\n menuItem.onClick(Boolean(!switchValue));\n }\n },\n isDisabled: menuItem?.disabled || false,\n 'aria-label': typeof menuItem?.title === 'string' ? menuItem?.title : 'Menu item',\n },\n state,\n ref,\n );\n const { title, decorator, subtitle, size, style, disabled, selectionIndicator } = menuItem;\n const { isFocusVisible, focusProps } = useFocusRing();\n\n return (\n // eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-noninteractive-element-interactions\n <li\n {...mergeProps(menuItemProps, focusProps)}\n data-test-id=\"menu-item\"\n className={merge([\n 'tw-relative hover:tw-bg-box-neutral-hover tw-list-none tw-outline-none',\n disabled && 'tw-pointer-events-none tw-top-px',\n isFocusVisible && FOCUS_STYLE_INSET,\n ])}\n ref={ref}\n onClick={(event) => {\n event.stopPropagation();\n if (onClick) {\n onClick();\n }\n }}\n >\n <MenuItem\n title={title}\n decorator={decorator}\n subtitle={subtitle}\n size={size}\n style={style}\n disabled={disabled}\n active={isSelected}\n selectionIndicator={selectionIndicator}\n switchComponent={switchComponent}\n />\n </li>\n );\n};\nAriaMenuItem.displayName = 'FondueAriaMenuItem';\n"],"names":["isActionMenuItem","menuItem","isActionMenuSwitchItem","useSwitch","isSwitch","initialValue","switchValue","setSwitchValue","useState","switchObject","setSwitchObject","useEffect","Switch","AriaMenuItem","node","state","isSelected","onClick","ref","useRef","switchComponent","toggleSwitch","menuItemProps","useMenuItem","title","decorator","subtitle","size","style","disabled","selectionIndicator","isFocusVisible","focusProps","useFocusRing","jsx","mergeProps","merge","FOCUS_STYLE_INSET","event","MenuItem"],"mappings":";;;;;;;;;AA8BA,MAAMA,IAAmB,CACrBC,MAEA,OAAQA,EAAgC,UAAY,OAAe,OAAOA,EAAS,OAAS,KAC1FC,IAAyB,CAC3BD,MAEA,OAAQA,EAAsC,UAAY,OAAeA,EAAS,SAAS,UAEzFE,IAAY,CAACC,GAAmBC,MAA0B;AAC5D,QAAM,CAACC,GAAaC,CAAc,IAAIC,EAAkBH,KAAgB,EAAK,GACvE,CAACI,GAAcC,CAAe,IAAIF,EAAuB;AAAA,IAC3D,iBAAiB;AAAA,IACjB,aAAa;AAAA,IACb,cAAc;AAAA,EAAA,CACjB;AAED,SAAAG,EAAU,MAAM;AACZ,IAAIP,KAIgBM,EAAA;AAAA,MACZ,mCAHqBE,GAAO,EAAA,MAAK,SAAQ,MAAMN,IAAc,OAAO,MAAO,CAAA;AAAA,MAI3E,aAAAA;AAAA,MACA,cANiB,MAAMC,EAAe,CAACD,CAAW;AAAA,IAMlD,CACH;AAAA,EACL,GACD,CAACF,GAAUE,CAAW,CAAC,GAEnBG;AACX,GAEaI,IAAe,CAAC,EAAE,UAAAZ,GAAU,MAAAa,GAAM,OAAAC,GAAO,YAAAC,GAAY,SAAAC,QAA6C;AACrG,QAAAC,IAAMC,EAA6B,IAAI,GACvCd,IAAeH,EAAuBD,CAAQ,IAAIA,EAAS,eAAe,IAC1E;AAAA,IACF,iBAAAmB,IAAkB;AAAA,IAClB,aAAAd,IAAc;AAAA,IACd,cAAAe,IAAe;AAAA,EACf,IAAAlB,EAAUD,EAAuBD,CAAQ,GAAGI,CAAY,GAEtD,EAAE,eAAAiB,MAAkBC;AAAA,IACtB;AAAA,MACI,GAAGT;AAAA,MACH,UAAU,MAAM;AACR,QAAAd,EAAiBC,CAAQ,KACzBA,EAAS,QAAQ,GAEjBC,EAAuBD,CAAQ,MAChBoB,KAAA,QAAAA,KACfpB,EAAS,QAAgB,CAACK,CAAY;AAAA,MAE9C;AAAA,MACA,aAAYL,KAAA,gBAAAA,EAAU,aAAY;AAAA,MAClC,cAAc,QAAOA,KAAA,gBAAAA,EAAU,UAAU,WAAWA,KAAA,gBAAAA,EAAU,QAAQ;AAAA,IAC1E;AAAA,IACAc;AAAA,IACAG;AAAA,EAAA,GAEE,EAAE,OAAAM,GAAO,WAAAC,GAAW,UAAAC,GAAU,MAAAC,GAAM,OAAAC,GAAO,UAAAC,GAAU,oBAAAC,EAAuB,IAAA7B,GAC5E,EAAE,gBAAA8B,GAAgB,YAAAC,EAAW,IAAIC,EAAa;AAEpD;AAAA;AAAA,IAEI,gBAAAC;AAAA,MAAC;AAAA,MAAA;AAAA,QACI,GAAGC,EAAWb,GAAeU,CAAU;AAAA,QACxC,gBAAa;AAAA,QACb,WAAWI,EAAM;AAAA,UACb;AAAA,UACAP,KAAY;AAAA,UACZE,KAAkBM;AAAA,QAAA,CACrB;AAAA,QACD,KAAAnB;AAAA,QACA,SAAS,CAACoB,MAAU;AAChB,UAAAA,EAAM,gBAAgB,GAClBrB,KACQA;QAEhB;AAAA,QAEA,UAAA,gBAAAiB;AAAA,UAACK;AAAA,UAAA;AAAA,YACG,OAAAf;AAAA,YACA,WAAAC;AAAA,YACA,UAAAC;AAAA,YACA,MAAAC;AAAA,YACA,OAAAC;AAAA,YACA,UAAAC;AAAA,YACA,QAAQb;AAAA,YACR,oBAAAc;AAAA,YACA,iBAAAV;AAAA,UAAA;AAAA,QACJ;AAAA,MAAA;AAAA,IACJ;AAAA;AAER;AACAP,EAAa,cAAc;"}
1
+ {"version":3,"file":"AriaMenuItem.es.js","sources":["../../../../src/components/ActionMenu/Aria/AriaMenuItem.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { useFocusRing } from '@react-aria/focus';\nimport { useMenuItem } from '@react-aria/menu';\nimport { mergeProps } from '@react-aria/utils';\nimport { type TreeState } from '@react-stately/tree';\nimport { type Node } from '@react-types/shared';\nimport { type ReactElement, useEffect, useRef, useState } from 'react';\n\nimport { type ActionMenuItemType, type ActionMenuSwitchItemType } from '@components/ActionMenu';\nimport { type MenuItemType } from '@components/Dropdown';\nimport { MenuItem } from '@components/MenuItem/MenuItem';\nimport { Switch } from '@components/Switch';\nimport { FOCUS_STYLE_INSET } from '@utilities/focusStyle';\nimport { merge } from '@utilities/merge';\n\nexport type AriaOptionProps = {\n menuItem: MenuItemType | ActionMenuItemType | ActionMenuSwitchItemType;\n node: Node<object>;\n isSelected?: boolean;\n state: TreeState<object>;\n /**\n * @deprecated Use `menuItem.onClick` instead\n * */\n onClick?: () => void;\n};\n\ninterface SwitchObject {\n switchComponent: ReactElement | undefined;\n switchValue: boolean | null;\n toggleSwitch: VoidFunction | null;\n}\n\nconst isActionMenuItem = (\n menuItem: MenuItemType | ActionMenuItemType | ActionMenuSwitchItemType,\n): menuItem is ActionMenuItemType =>\n typeof (menuItem as ActionMenuItemType).onClick !== 'undefined' && typeof menuItem.type === 'undefined';\nconst isActionMenuSwitchItem = (\n menuItem: MenuItemType | ActionMenuItemType | ActionMenuSwitchItemType,\n): menuItem is ActionMenuSwitchItemType =>\n typeof (menuItem as ActionMenuSwitchItemType).onClick !== 'undefined' && menuItem.type === 'switch';\n\nconst useSwitch = (isSwitch: boolean, initialValue: boolean) => {\n const [switchValue, setSwitchValue] = useState<boolean>(initialValue ?? false);\n const [switchObject, setSwitchObject] = useState<SwitchObject>({\n switchComponent: undefined,\n switchValue: null,\n toggleSwitch: null,\n });\n\n useEffect(() => {\n if (isSwitch) {\n const toggleSwitch = () => setSwitchValue(!switchValue);\n const switchComponent = <Switch size=\"small\" mode={switchValue ? 'on' : 'off'} />;\n\n setSwitchObject({\n switchComponent,\n switchValue,\n toggleSwitch,\n });\n }\n }, [isSwitch, switchValue]);\n\n return switchObject;\n};\n\nexport const AriaMenuItem = ({ menuItem, node, state, isSelected, onClick }: AriaOptionProps): ReactElement => {\n const ref = useRef<HTMLLIElement | null>(null);\n const initialValue = isActionMenuSwitchItem(menuItem) ? menuItem.initialValue : false;\n const {\n switchComponent = undefined,\n switchValue = null,\n toggleSwitch = null,\n } = useSwitch(isActionMenuSwitchItem(menuItem), initialValue);\n\n const { menuItemProps } = useMenuItem(\n {\n ...node,\n onAction: () => {\n if (isActionMenuItem(menuItem)) {\n menuItem.onClick();\n }\n if (isActionMenuSwitchItem(menuItem)) {\n toggleSwitch?.();\n menuItem.onClick(Boolean(!switchValue));\n }\n },\n isDisabled: menuItem?.disabled || false,\n 'aria-label': typeof menuItem?.title === 'string' ? menuItem?.title : 'Menu item',\n },\n state,\n ref,\n );\n const { title, decorator, subtitle, size, style, disabled, selectionIndicator } = menuItem;\n const { isFocusVisible, focusProps } = useFocusRing();\n\n return (\n // eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-noninteractive-element-interactions\n <li\n {...mergeProps(menuItemProps, focusProps, { onClick: () => onClick?.() })}\n data-test-id=\"menu-item\"\n className={merge([\n 'tw-relative hover:tw-bg-box-neutral-hover tw-list-none tw-outline-none',\n disabled && 'tw-pointer-events-none tw-top-px',\n isFocusVisible && FOCUS_STYLE_INSET,\n ])}\n ref={ref}\n >\n <MenuItem\n title={title}\n decorator={decorator}\n subtitle={subtitle}\n size={size}\n style={style}\n disabled={disabled}\n active={isSelected}\n selectionIndicator={selectionIndicator}\n switchComponent={switchComponent}\n />\n </li>\n );\n};\nAriaMenuItem.displayName = 'FondueAriaMenuItem';\n"],"names":["isActionMenuItem","menuItem","isActionMenuSwitchItem","useSwitch","isSwitch","initialValue","switchValue","setSwitchValue","useState","switchObject","setSwitchObject","useEffect","Switch","AriaMenuItem","node","state","isSelected","onClick","ref","useRef","switchComponent","toggleSwitch","menuItemProps","useMenuItem","title","decorator","subtitle","size","style","disabled","selectionIndicator","isFocusVisible","focusProps","useFocusRing","jsx","mergeProps","merge","FOCUS_STYLE_INSET","MenuItem"],"mappings":";;;;;;;;;AAiCA,MAAMA,IAAmB,CACr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