@stackone/malachite 2.82.0 → 2.83.1
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/COMPONENTS.md +2 -2
- package/dist/components/ActionMenu.js +193 -172
- package/dist/components/ActionMenu.js.map +1 -1
- package/dist/components/ConfirmationDialog.js +93 -94
- package/dist/components/ConfirmationDialog.js.map +1 -1
- package/dist/components/actionMenuGroups.js +19 -0
- package/dist/components/actionMenuGroups.js.map +1 -0
- package/dist/components/actionMenuStyles.js +34 -31
- package/dist/components/actionMenuStyles.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActionMenu.js","sources":["../../src/components/ActionMenu.tsx"],"sourcesContent":["import React, { useEffect, useId, useMemo, useRef, useState } from 'react';\nimport { createPortal } from 'react-dom';\nimport Button from './Button';\nimport type { ButtonVariant } from './Button';\nimport CheckmarkIcon from './CustomIcons/CheckmarkIcon';\nimport MoreHorizontalIcon from './CustomIcons/MoreHorizontalIcon';\nimport EllipsisText from './Typography/EllipsisText';\nimport {\n type MenuEdge,\n edgeForTriggerKey,\n enabledItems,\n focusEdge,\n focusOpeningItem,\n itemForMenuKey,\n scrollCheckedIntoView,\n scrollFocusedIntoView,\n} from './actionMenuKeyboard';\nimport {\n type ActionMenuTone,\n CHECK_SLOT_STYLE,\n DESCRIPTION_CLASS,\n EMPTY_ITEM_STYLE,\n ITEM_CLASS,\n ITEM_ICON_CLASS,\n ITEM_ICON_LAYOUT,\n ITEM_ICON_STYLE,\n ITEM_TEXT_STYLE,\n LABEL_STYLE,\n TEXT_ITEM_LABEL_STYLE,\n TEXT_ITEM_STYLE,\n TRIGGER_SIZES,\n VISUALLY_HIDDEN_STYLE,\n descriptionStyle,\n itemStyle,\n menuStyle,\n} from './actionMenuStyles';\nimport type { ActionMenuItem, ActionMenuPlacement } from './actionMenuTypes';\nimport { getDeepActiveElement } from './activeElement';\nimport { chainHandler, composeRefs, elementRef } from './composeRefs';\nimport { pushEscapeLayer } from './escapeLayers';\nimport type { FloatingOffset } from './floatingMenuGeometry';\nimport { isPlainClick } from './linkClick';\nimport { resolveRel } from './linkRel';\nimport { usePopupLayer } from './overlayLayers';\nimport { isRenderableNode } from './renderableNode';\nimport { safeHref } from './safeHref';\nimport { useActionMenuPosition } from './useActionMenuPosition';\n\nexport type { ActionMenuItem, ActionMenuPlacement, ActionMenuTone };\n\nexport interface ActionMenuProps {\n items: ActionMenuItem[];\n label?: string;\n triggerIcon?: React.ReactNode;\n minWidth?: number;\n size?: 'small' | 'xsmall';\n /**\n * Shows `label` beside the icon instead of leaving it to the accessible name. For a menu\n * that is the point of its corner rather than an overflow for a row that already reads —\n * a kebab nobody can name is only safe when the row it belongs to says what it acts on.\n */\n showLabel?: boolean;\n /** Trigger's Button variant. Defaults to `outline`, the overflow-kebab look. */\n variant?: ButtonVariant;\n trigger?: React.ReactElement;\n placement?: ActionMenuPlacement;\n offset?: FloatingOffset;\n /** `muted` reads items in the secondary text colour, as in a sidebar's menus. */\n tone?: ActionMenuTone;\n}\n\ntype TriggerHandlers = {\n onClick?: (event: React.MouseEvent) => void;\n onMouseDown?: (event: React.MouseEvent) => void;\n onKeyDown?: (event: React.KeyboardEvent) => void;\n};\n\n// Loaded only when an item has a tag: its shadow host pulls in the Tailwind sheet, which a menu\n// without tags should not pay for.\nconst ActionMenuTagHost = React.lazy(() => import('./ActionMenuTagHost'));\n\nconst stopPropagation = (event: React.SyntheticEvent) => event.stopPropagation();\n\nconst MenuItemRow: React.FC<{\n item: ActionMenuItem;\n tone: ActionMenuTone;\n onSelect: (item: ActionMenuItem) => void;\n onFollow: () => void;\n}> = ({ item, tone, onSelect, onFollow }) => {\n const descriptionId = useId();\n if (item.type === 'divider') {\n return <div role=\"separator\" style={itemStyle(item)} />;\n }\n if (item.type === 'text') {\n return (\n <div role=\"menuitem\" aria-disabled=\"true\" style={TEXT_ITEM_STYLE}>\n {typeof item.label === 'string' ? (\n <EllipsisText\n tooltip={item.label}\n tooltipWhenTruncated\n inline\n style={TEXT_ITEM_LABEL_STYLE}\n >\n {item.label}\n </EllipsisText>\n ) : (\n item.label\n )}\n </div>\n );\n }\n const isChoice = item.checked !== undefined;\n const described = isRenderableNode(item.description);\n const tagged = isRenderableNode(item.tag);\n const shared = {\n role: isChoice ? 'menuitemradio' : 'menuitem',\n 'aria-checked': isChoice ? item.checked : undefined,\n 'aria-describedby': described\n ? `${descriptionId}${item.tooltip ? ` ${descriptionId}-tooltip` : ''}`\n : undefined,\n title: item.tooltip,\n 'aria-current': item.current ? ('page' as const) : undefined,\n className: ITEM_CLASS,\n 'data-danger': item.danger === 'hover' ? 'hover' : undefined,\n 'data-tone': tone,\n style: itemStyle(item, tone),\n };\n const href = item.disabled ? undefined : safeHref(item.href);\n const opensNewTab = href !== undefined && item.target?.toLowerCase() === '_blank';\n const label = (\n <span style={LABEL_STYLE}>\n {item.label}\n {opensNewTab && <span style={VISUALLY_HIDDEN_STYLE}> (opens in a new tab)</span>}\n </span>\n );\n const content = (\n <>\n {isRenderableNode(item.icon) && (\n <span\n className={ITEM_ICON_CLASS}\n style={item.danger === 'hover' ? ITEM_ICON_LAYOUT : ITEM_ICON_STYLE}\n >\n {item.icon}\n </span>\n )}\n {described ? (\n <span style={ITEM_TEXT_STYLE}>\n {label}\n <span\n id={descriptionId}\n aria-hidden=\"true\"\n className={DESCRIPTION_CLASS}\n style={descriptionStyle(item)}\n >\n {item.description}\n </span>\n {item.tooltip ? (\n <span\n id={`${descriptionId}-tooltip`}\n aria-hidden=\"true\"\n style={VISUALLY_HIDDEN_STYLE}\n >\n {item.tooltip}\n </span>\n ) : null}\n </span>\n ) : (\n label\n )}\n {tagged ? (\n <React.Suspense fallback={null}>\n <ActionMenuTagHost>{item.tag}</ActionMenuTagHost>\n </React.Suspense>\n ) : null}\n {isChoice ? (\n <span aria-hidden=\"true\" style={CHECK_SLOT_STYLE}>\n {item.checked ? <CheckmarkIcon size={14} /> : null}\n </span>\n ) : null}\n </>\n );\n if (href !== undefined) {\n return (\n <a\n {...shared}\n href={href}\n target={item.target}\n rel={resolveRel(undefined, item.target)}\n onClick={(event) => {\n if (isPlainClick(event) && item.onClick) {\n event.preventDefault();\n onSelect(item);\n return;\n }\n onFollow();\n }}\n onAuxClick={(event) => {\n if (event.button === 1) {\n onFollow();\n }\n }}\n >\n {content}\n </a>\n );\n }\n return (\n <button {...shared} type=\"button\" disabled={item.disabled} onClick={() => onSelect(item)}>\n {content}\n </button>\n );\n};\n\n/**\n * ActionMenu is an overflow action menu. The trigger is a three-dot `Button` by default, or\n * your own control via `trigger`. The menu is portaled to document.body, so it escapes any\n * Shadow DOM or overflow:hidden ancestor, which is also why it is styled inline.\n */\nconst ActionMenu: React.FC<ActionMenuProps> = ({\n items,\n label = 'More actions',\n triggerIcon,\n minWidth,\n size = 'small',\n showLabel = false,\n variant = 'outline',\n trigger: customTrigger,\n placement = 'bottom-end',\n offset,\n tone = 'default',\n}) => {\n const triggerSize = TRIGGER_SIZES[size];\n const [open, setOpen] = useState(false);\n const triggerRef = useRef<HTMLElement | null>(null);\n const menuRef = useRef<HTMLDivElement>(null);\n const focusOnOpen = useRef<MenuEdge | null>(null);\n const focusInMenu = useRef(false);\n const popupIdentity = usePopupLayer('actionmenu', open, menuRef);\n\n const position = useActionMenuPosition(open, triggerRef, menuRef, {\n minWidth,\n placement,\n offset,\n });\n\n // A hidden item cannot take focus, so wait until the menu is positioned and shown.\n const positioned = position !== null;\n useEffect(() => {\n if (!open || !positioned) {\n return;\n }\n scrollCheckedIntoView(menuRef.current);\n if (focusOnOpen.current) {\n focusOpeningItem(menuRef.current, focusOnOpen.current);\n focusOnOpen.current = null;\n scrollFocusedIntoView(menuRef.current);\n }\n }, [open, positioned]);\n\n useEffect(() => {\n if (!open) {\n return;\n }\n const closeOnOutsidePress = (event: MouseEvent) => {\n const path = event.composedPath();\n const inside = [triggerRef.current, menuRef.current].some(\n (node) => node && path.includes(node),\n );\n if (!inside) {\n focusInMenu.current = false;\n setOpen(false);\n }\n };\n document.addEventListener('mousedown', closeOnOutsidePress, true);\n const popEscapeLayer = pushEscapeLayer(() => setOpen(false));\n return () => {\n document.removeEventListener('mousedown', closeOnOutsidePress, true);\n popEscapeLayer();\n const active = getDeepActiveElement();\n if (focusInMenu.current && (!active || active === document.body)) {\n triggerRef.current?.focus({ preventScroll: true });\n }\n focusInMenu.current = false;\n };\n }, [open]);\n\n const toggleFromTrigger = (event: React.MouseEvent) => {\n event.stopPropagation();\n const openedFromKeyboard = !open && event.detail === 0;\n focusOnOpen.current = openedFromKeyboard ? 'first' : null;\n setOpen((v) => !v);\n };\n\n const handleTriggerKeyDown = (event: React.KeyboardEvent) => {\n if (event.key === 'Tab' && open) {\n setOpen(false);\n return;\n }\n const edge = edgeForTriggerKey(event.key, placement);\n if (!edge) {\n return;\n }\n event.preventDefault();\n if (open) {\n focusEdge(menuRef.current, edge);\n return;\n }\n focusOnOpen.current = edge;\n setOpen(true);\n };\n\n const handleMenuKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (event.key === 'Tab') {\n focusInMenu.current = false;\n triggerRef.current?.focus({ preventScroll: true });\n setOpen(false);\n return;\n }\n if (event.key === ' ' && event.target instanceof HTMLAnchorElement) {\n event.preventDefault();\n event.target.click();\n return;\n }\n const target = itemForMenuKey(enabledItems(menuRef.current), event.target, event.key);\n if (target) {\n event.preventDefault();\n target.focus();\n }\n };\n\n const selectItem = (item: ActionMenuItem) => {\n if (item.type === 'divider' || item.type === 'text' || item.disabled) {\n return;\n }\n item.onClick?.();\n setOpen(false);\n };\n\n const ownTriggerRef = customTrigger ? elementRef<HTMLElement>(customTrigger) : undefined;\n const composedTriggerRef = useMemo(\n () => composeRefs(ownTriggerRef, triggerRef),\n [ownTriggerRef],\n );\n const customHandlers = customTrigger?.props as TriggerHandlers | undefined;\n\n const triggerElement = customTrigger ? (\n React.cloneElement(customTrigger, {\n ref: composedTriggerRef,\n 'aria-haspopup': 'menu',\n 'aria-expanded': open,\n onClick: chainHandler(customHandlers?.onClick, toggleFromTrigger),\n onMouseDown: chainHandler(customHandlers?.onMouseDown, stopPropagation),\n onKeyDown: chainHandler(customHandlers?.onKeyDown, handleTriggerKeyDown),\n } as Record<string, unknown>)\n ) : (\n <Button\n ref={triggerRef as React.RefObject<HTMLButtonElement>}\n type=\"button\"\n variant={variant}\n size={size}\n iconOnly={!showLabel}\n aria-label={showLabel ? undefined : label}\n aria-haspopup=\"menu\"\n aria-expanded={open}\n className={`shrink-0${showLabel ? ' gap-2' : ''}`}\n onClick={toggleFromTrigger}\n onMouseDown={stopPropagation}\n onKeyDown={handleTriggerKeyDown}\n >\n <span className={`inline-flex items-center justify-center ${triggerSize.iconBox}`}>\n {triggerIcon ?? <MoreHorizontalIcon size={triggerSize.icon} />}\n </span>\n {showLabel && <span>{label}</span>}\n </Button>\n );\n\n return (\n <>\n {triggerElement}\n {open &&\n createPortal(\n <div\n ref={menuRef}\n role=\"menu\"\n tabIndex={-1}\n aria-label={label}\n {...popupIdentity}\n style={menuStyle(position)}\n onMouseDown={stopPropagation}\n onClick={stopPropagation}\n onKeyDown={handleMenuKeyDown}\n onFocus={() => {\n focusInMenu.current = true;\n }}\n onBlur={(e) => {\n if (!menuRef.current?.contains(e.relatedTarget as Node | null)) {\n focusInMenu.current = false;\n }\n }}\n >\n {items.length === 0 && (\n <div role=\"menuitem\" aria-disabled=\"true\" style={EMPTY_ITEM_STYLE}>\n No actions available\n </div>\n )}\n {items.map((item) => (\n <MenuItemRow\n key={item.key}\n item={item}\n tone={tone}\n onSelect={selectItem}\n onFollow={() => setOpen(false)}\n />\n ))}\n </div>,\n document.body,\n )}\n </>\n );\n};\n\nexport default ActionMenu;\n"],"names":["ActionMenuTagHost","React","stopPropagation","event","MenuItemRow","item","tone","onSelect","onFollow","descriptionId","useId","itemStyle","jsx","TEXT_ITEM_STYLE","EllipsisText","TEXT_ITEM_LABEL_STYLE","isChoice","described","isRenderableNode","tagged","shared","ITEM_CLASS","href","safeHref","opensNewTab","_a","label","jsxs","LABEL_STYLE","VISUALLY_HIDDEN_STYLE","content","Fragment","ITEM_ICON_CLASS","ITEM_ICON_LAYOUT","ITEM_ICON_STYLE","ITEM_TEXT_STYLE","DESCRIPTION_CLASS","descriptionStyle","CHECK_SLOT_STYLE","CheckmarkIcon","resolveRel","isPlainClick","ActionMenu","items","triggerIcon","minWidth","size","showLabel","variant","customTrigger","placement","offset","triggerSize","TRIGGER_SIZES","open","setOpen","useState","triggerRef","useRef","menuRef","focusOnOpen","focusInMenu","popupIdentity","usePopupLayer","position","useActionMenuPosition","positioned","useEffect","scrollCheckedIntoView","focusOpeningItem","scrollFocusedIntoView","closeOnOutsidePress","path","node","popEscapeLayer","pushEscapeLayer","active","getDeepActiveElement","toggleFromTrigger","openedFromKeyboard","v","handleTriggerKeyDown","edge","edgeForTriggerKey","focusEdge","handleMenuKeyDown","target","itemForMenuKey","enabledItems","selectItem","ownTriggerRef","elementRef","composedTriggerRef","useMemo","composeRefs","customHandlers","triggerElement","chainHandler","Button","MoreHorizontalIcon","createPortal","menuStyle","e","EMPTY_ITEM_STYLE"],"mappings":";;;;;;;;;;;;;;;;;;AA+EA,MAAMA,KAAoBC,EAAM,KAAK,MAAM,OAAO,wBAAqB,CAAC,GAElEC,IAAkB,CAACC,MAAgCA,EAAM,gBAAA,GAEzDC,KAKD,CAAC,EAAE,MAAAC,GAAM,MAAAC,GAAM,UAAAC,GAAU,UAAAC,QAAe;;AACzC,QAAMC,IAAgBC,EAAA;AACtB,MAAIL,EAAK,SAAS;AACd,6BAAQ,OAAA,EAAI,MAAK,aAAY,OAAOM,EAAUN,CAAI,GAAG;AAEzD,MAAIA,EAAK,SAAS;AACd,WACI,gBAAAO,EAAC,OAAA,EAAI,MAAK,YAAW,iBAAc,QAAO,OAAOC,IAC5C,UAAA,OAAOR,EAAK,SAAU,WACnB,gBAAAO;AAAA,MAACE;AAAA,MAAA;AAAA,QACG,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AAe,gBAAAhC,EAACuF,GAAA,EAAmB,MAAM/C,EAAY,KAAA,CAAM,GAChE;AAAA,QACCL,KAAa,gBAAAnC,EAAC,QAAA,EAAM,UAAAc,EAAA,CAAM;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAInC,SACI,gBAAAC,EAAAI,GAAA,EACK,UAAA;AAAA,IAAAiE;AAAA,IACA1C,KACG8C;AAAA,MACI,gBAAAzE;AAAA,QAAC;AAAA,QAAA;AAAA,UACG,KAAKgC;AAAA,UACL,MAAK;AAAA,UACL,UAAU;AAAA,UACV,cAAYjC;AAAA,UACX,GAAGoC;AAAA,UACJ,OAAOuC,GAAUrC,CAAQ;AAAA,UACzB,aAAa9D;AAAA,UACb,SAASA;AAAA,UACT,WAAWmF;AAAA,UACX,SAAS,MAAM;AACX,YAAAxB,EAAY,UAAU;AAAA,UAC1B;AAAA,UACA,QAAQ,CAACyC,MAAM;;AACX,aAAK7E,IAAAkC,EAAQ,YAAR,QAAAlC,EAAiB,SAAS6E,EAAE,mBAC7BzC,EAAY,UAAU;AAAA,UAE9B;AAAA,UAEC,UAAA;AAAA,YAAAlB,EAAM,WAAW,KACd,gBAAA/B,EAAC,OAAA,EAAI,MAAK,YAAW,iBAAc,QAAO,OAAO2F,IAAkB,UAAA,uBAAA,CAEnE;AAAA,YAEH5D,EAAM,IAAI,CAACtC,MACR,gBAAAO;AAAA,cAACR;AAAA,cAAA;AAAA,gBAEG,MAAAC;AAAA,gBACA,MAAAC;AAAA,gBACA,UAAUmF;AAAA,gBACV,UAAU,MAAMlC,EAAQ,EAAK;AAAA,cAAA;AAAA,cAJxBlD,EAAK;AAAA,YAAA,CAMjB;AAAA,UAAA;AAAA,QAAA;AAAA,MAAA;AAAA,MAEL,SAAS;AAAA,IAAA;AAAA,EACb,GACR;AAER;"}
|
|
1
|
+
{"version":3,"file":"ActionMenu.js","sources":["../../src/components/ActionMenu.tsx"],"sourcesContent":["import React, { useEffect, useId, useMemo, useRef, useState } from 'react';\nimport { createPortal } from 'react-dom';\nimport Button from './Button';\nimport type { ButtonVariant } from './Button';\nimport CheckmarkIcon from './CustomIcons/CheckmarkIcon';\nimport MoreHorizontalIcon from './CustomIcons/MoreHorizontalIcon';\nimport EllipsisText from './Typography/EllipsisText';\nimport { groupChoices, isChoiceItem } from './actionMenuGroups';\nimport {\n type MenuEdge,\n edgeForTriggerKey,\n enabledItems,\n focusEdge,\n focusOpeningItem,\n itemForMenuKey,\n scrollCheckedIntoView,\n scrollFocusedIntoView,\n} from './actionMenuKeyboard';\nimport {\n type ActionMenuTone,\n CHECK_SLOT_STYLE,\n DESCRIPTION_CLASS,\n EMPTY_ITEM_STYLE,\n ITEM_CLASS,\n ITEM_ICON_CLASS,\n ITEM_ICON_LAYOUT,\n ITEM_ICON_STYLE,\n ITEM_TEXT_STYLE,\n LABEL_STYLE,\n MENU_COLUMN_STYLE,\n TEXT_ITEM_LABEL_STYLE,\n TEXT_ITEM_STYLE,\n TRIGGER_SIZES,\n VISUALLY_HIDDEN_STYLE,\n descriptionStyle,\n itemStyle,\n menuStyle,\n} from './actionMenuStyles';\nimport type { ActionMenuItem, ActionMenuPlacement } from './actionMenuTypes';\nimport { getDeepActiveElement } from './activeElement';\nimport { chainHandler, composeRefs, elementRef } from './composeRefs';\nimport { pushEscapeLayer } from './escapeLayers';\nimport type { FloatingOffset } from './floatingMenuGeometry';\nimport { isPlainClick } from './linkClick';\nimport { resolveRel } from './linkRel';\nimport { usePopupLayer } from './overlayLayers';\nimport { isRenderableNode } from './renderableNode';\nimport { safeHref } from './safeHref';\nimport { useActionMenuPosition } from './useActionMenuPosition';\n\nexport type { ActionMenuItem, ActionMenuPlacement, ActionMenuTone };\n\nexport interface ActionMenuProps {\n items: ActionMenuItem[];\n label?: string;\n triggerIcon?: React.ReactNode;\n minWidth?: number;\n size?: 'small' | 'xsmall';\n /**\n * Shows `label` beside the icon instead of leaving it to the accessible name. For a menu\n * that is the point of its corner rather than an overflow for a row that already reads —\n * a kebab nobody can name is only safe when the row it belongs to says what it acts on.\n */\n showLabel?: boolean;\n /** Trigger's Button variant. Defaults to `outline`, the overflow-kebab look. */\n variant?: ButtonVariant;\n trigger?: React.ReactElement;\n placement?: ActionMenuPlacement;\n offset?: FloatingOffset;\n /** `muted` reads items in the secondary text colour, as in a sidebar's menus. */\n tone?: ActionMenuTone;\n}\n\ntype TriggerHandlers = {\n onClick?: (event: React.MouseEvent) => void;\n onMouseDown?: (event: React.MouseEvent) => void;\n onKeyDown?: (event: React.KeyboardEvent) => void;\n};\n\n// Loaded only when an item has a tag: its shadow host pulls in the Tailwind sheet, which a menu\n// without tags should not pay for.\nconst ActionMenuTagHost = React.lazy(() => import('./ActionMenuTagHost'));\n\nconst stopPropagation = (event: React.SyntheticEvent) => event.stopPropagation();\n\nconst MenuItemRow: React.FC<{\n item: ActionMenuItem;\n tone: ActionMenuTone;\n onSelect: (item: ActionMenuItem) => void;\n onFollow: () => void;\n labelId?: string;\n}> = ({ item, tone, onSelect, onFollow, labelId }) => {\n const descriptionId = useId();\n if (item.type === 'divider') {\n return <div role=\"separator\" style={itemStyle(item)} />;\n }\n if (item.type === 'text') {\n return (\n <div id={labelId} role=\"menuitem\" aria-disabled=\"true\" style={TEXT_ITEM_STYLE}>\n {typeof item.label === 'string' ? (\n <EllipsisText\n tooltip={item.label}\n tooltipWhenTruncated\n inline\n style={TEXT_ITEM_LABEL_STYLE}\n >\n {item.label}\n </EllipsisText>\n ) : (\n item.label\n )}\n </div>\n );\n }\n const isChoice = isChoiceItem(item);\n const described = isRenderableNode(item.description);\n const tagged = isRenderableNode(item.tag);\n const shared = {\n role: isChoice ? 'menuitemradio' : 'menuitem',\n 'aria-checked': isChoice ? item.checked : undefined,\n 'aria-describedby': described\n ? `${descriptionId}${item.tooltip ? ` ${descriptionId}-tooltip` : ''}`\n : undefined,\n title: item.tooltip,\n 'aria-current': item.current ? ('page' as const) : undefined,\n className: ITEM_CLASS,\n 'data-danger': item.danger === 'hover' ? 'hover' : undefined,\n 'data-tone': tone,\n style: itemStyle(item, tone),\n };\n const href = item.disabled ? undefined : safeHref(item.href);\n const opensNewTab = href !== undefined && item.target?.toLowerCase() === '_blank';\n const label = (\n <span style={LABEL_STYLE}>\n {item.label}\n {opensNewTab && <span style={VISUALLY_HIDDEN_STYLE}> (opens in a new tab)</span>}\n </span>\n );\n const content = (\n <>\n {isRenderableNode(item.icon) && (\n <span\n className={ITEM_ICON_CLASS}\n style={item.danger === 'hover' ? ITEM_ICON_LAYOUT : ITEM_ICON_STYLE}\n >\n {item.icon}\n </span>\n )}\n {described ? (\n <span style={ITEM_TEXT_STYLE}>\n {label}\n <span\n id={descriptionId}\n aria-hidden=\"true\"\n className={DESCRIPTION_CLASS}\n style={descriptionStyle(item)}\n >\n {item.description}\n </span>\n {item.tooltip ? (\n <span\n id={`${descriptionId}-tooltip`}\n aria-hidden=\"true\"\n style={VISUALLY_HIDDEN_STYLE}\n >\n {item.tooltip}\n </span>\n ) : null}\n </span>\n ) : (\n label\n )}\n {tagged ? (\n <React.Suspense fallback={null}>\n <ActionMenuTagHost>{item.tag}</ActionMenuTagHost>\n </React.Suspense>\n ) : null}\n {isChoice ? (\n <span aria-hidden=\"true\" style={CHECK_SLOT_STYLE}>\n {item.checked ? <CheckmarkIcon size={14} /> : null}\n </span>\n ) : null}\n </>\n );\n if (href !== undefined) {\n return (\n <a\n {...shared}\n href={href}\n target={item.target}\n rel={resolveRel(undefined, item.target)}\n onClick={(event) => {\n if (isPlainClick(event) && item.onClick) {\n event.preventDefault();\n onSelect(item);\n return;\n }\n onFollow();\n }}\n onAuxClick={(event) => {\n if (event.button === 1) {\n onFollow();\n }\n }}\n >\n {content}\n </a>\n );\n }\n return (\n <button {...shared} type=\"button\" disabled={item.disabled} onClick={() => onSelect(item)}>\n {content}\n </button>\n );\n};\n\n/**\n * ActionMenu is an overflow action menu. The trigger is a three-dot `Button` by default, or\n * your own control via `trigger`. The menu is portaled to document.body, so it escapes any\n * Shadow DOM or overflow:hidden ancestor, which is also why it is styled inline.\n */\nconst ActionMenu: React.FC<ActionMenuProps> = ({\n items,\n label = 'More actions',\n triggerIcon,\n minWidth,\n size = 'small',\n showLabel = false,\n variant = 'outline',\n trigger: customTrigger,\n placement = 'bottom-end',\n offset,\n tone = 'default',\n}) => {\n const triggerSize = TRIGGER_SIZES[size];\n const [open, setOpen] = useState(false);\n const headingBase = useId();\n const triggerRef = useRef<HTMLElement | null>(null);\n const menuRef = useRef<HTMLDivElement>(null);\n const focusOnOpen = useRef<MenuEdge | null>(null);\n const focusInMenu = useRef(false);\n const popupIdentity = usePopupLayer('actionmenu', open, menuRef);\n\n const position = useActionMenuPosition(open, triggerRef, menuRef, {\n minWidth,\n placement,\n offset,\n });\n\n // A hidden item cannot take focus, so wait until the menu is positioned and shown.\n const positioned = position !== null;\n useEffect(() => {\n if (!open || !positioned) {\n return;\n }\n scrollCheckedIntoView(menuRef.current);\n if (focusOnOpen.current) {\n focusOpeningItem(menuRef.current, focusOnOpen.current);\n focusOnOpen.current = null;\n scrollFocusedIntoView(menuRef.current);\n }\n }, [open, positioned]);\n\n useEffect(() => {\n if (!open) {\n return;\n }\n const closeOnOutsidePress = (event: MouseEvent) => {\n const path = event.composedPath();\n const inside = [triggerRef.current, menuRef.current].some(\n (node) => node && path.includes(node),\n );\n if (!inside) {\n focusInMenu.current = false;\n setOpen(false);\n }\n };\n document.addEventListener('mousedown', closeOnOutsidePress, true);\n const popEscapeLayer = pushEscapeLayer(() => setOpen(false));\n return () => {\n document.removeEventListener('mousedown', closeOnOutsidePress, true);\n popEscapeLayer();\n const active = getDeepActiveElement();\n if (focusInMenu.current && (!active || active === document.body)) {\n triggerRef.current?.focus({ preventScroll: true });\n }\n focusInMenu.current = false;\n };\n }, [open]);\n\n const toggleFromTrigger = (event: React.MouseEvent) => {\n event.stopPropagation();\n const openedFromKeyboard = !open && event.detail === 0;\n focusOnOpen.current = openedFromKeyboard ? 'first' : null;\n setOpen((v) => !v);\n };\n\n const handleTriggerKeyDown = (event: React.KeyboardEvent) => {\n if (event.key === 'Tab' && open) {\n setOpen(false);\n return;\n }\n const edge = edgeForTriggerKey(event.key, placement);\n if (!edge) {\n return;\n }\n event.preventDefault();\n if (open) {\n focusEdge(menuRef.current, edge);\n return;\n }\n focusOnOpen.current = edge;\n setOpen(true);\n };\n\n const handleMenuKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (event.key === 'Tab') {\n focusInMenu.current = false;\n triggerRef.current?.focus({ preventScroll: true });\n setOpen(false);\n return;\n }\n if (event.key === ' ' && event.target instanceof HTMLAnchorElement) {\n event.preventDefault();\n event.target.click();\n return;\n }\n const target = itemForMenuKey(enabledItems(menuRef.current), event.target, event.key);\n if (target) {\n event.preventDefault();\n target.focus();\n }\n };\n\n const selectItem = (item: ActionMenuItem) => {\n if (item.type === 'divider' || item.type === 'text' || item.disabled) {\n return;\n }\n item.onClick?.();\n setOpen(false);\n };\n\n const ownTriggerRef = customTrigger ? elementRef<HTMLElement>(customTrigger) : undefined;\n const composedTriggerRef = useMemo(\n () => composeRefs(ownTriggerRef, triggerRef),\n [ownTriggerRef],\n );\n const customHandlers = customTrigger?.props as TriggerHandlers | undefined;\n\n const triggerElement = customTrigger ? (\n React.cloneElement(customTrigger, {\n ref: composedTriggerRef,\n 'aria-haspopup': 'menu',\n 'aria-expanded': open,\n onClick: chainHandler(customHandlers?.onClick, toggleFromTrigger),\n onMouseDown: chainHandler(customHandlers?.onMouseDown, stopPropagation),\n onKeyDown: chainHandler(customHandlers?.onKeyDown, handleTriggerKeyDown),\n } as Record<string, unknown>)\n ) : (\n <Button\n ref={triggerRef as React.RefObject<HTMLButtonElement>}\n type=\"button\"\n variant={variant}\n size={size}\n iconOnly={!showLabel}\n aria-label={showLabel ? undefined : label}\n aria-haspopup=\"menu\"\n aria-expanded={open}\n className={`shrink-0${showLabel ? ' gap-2' : ''}`}\n onClick={toggleFromTrigger}\n onMouseDown={stopPropagation}\n onKeyDown={handleTriggerKeyDown}\n >\n <span className={`inline-flex items-center justify-center ${triggerSize.iconBox}`}>\n {triggerIcon ?? <MoreHorizontalIcon size={triggerSize.icon} />}\n </span>\n {showLabel && <span>{label}</span>}\n </Button>\n );\n\n const entries = useMemo(() => groupChoices(items), [items]);\n const closeMenu = () => setOpen(false);\n const headingIdOf = (index: number) => `${headingBase}-${index}`;\n const renderRow = (item: ActionMenuItem, labelId?: string, key = item.key) => (\n <MenuItemRow\n key={key}\n item={item}\n tone={tone}\n onSelect={selectItem}\n onFollow={closeMenu}\n labelId={labelId}\n />\n );\n\n return (\n <>\n {triggerElement}\n {open &&\n createPortal(\n <div\n ref={menuRef}\n role=\"menu\"\n tabIndex={-1}\n aria-label={label}\n {...popupIdentity}\n style={menuStyle(position)}\n onMouseDown={stopPropagation}\n onClick={stopPropagation}\n onKeyDown={handleMenuKeyDown}\n onFocus={() => {\n focusInMenu.current = true;\n }}\n onBlur={(e) => {\n if (!menuRef.current?.contains(e.relatedTarget as Node | null)) {\n focusInMenu.current = false;\n }\n }}\n >\n {items.length === 0 && (\n <div role=\"menuitem\" aria-disabled=\"true\" style={EMPTY_ITEM_STYLE}>\n No actions available\n </div>\n )}\n {entries.map((entry, index) =>\n entry.kind === 'item' ? (\n renderRow(\n entry.item,\n entry.labelsNext ? headingIdOf(index) : undefined,\n `item:${entry.item.key}`,\n )\n ) : (\n <div\n key={`group:${entry.items[0]?.key}`}\n role=\"group\"\n aria-labelledby={\n entry.labelledByPrevious\n ? headingIdOf(index - 1)\n : undefined\n }\n aria-label={entry.labelledByPrevious ? undefined : entry.name}\n style={MENU_COLUMN_STYLE}\n >\n {entry.items.map((item) => renderRow(item))}\n </div>\n ),\n )}\n </div>,\n document.body,\n )}\n </>\n );\n};\n\nexport default ActionMenu;\n"],"names":["ActionMenuTagHost","React","stopPropagation","event","MenuItemRow","item","tone","onSelect","onFollow","labelId","descriptionId","useId","itemStyle","jsx","TEXT_ITEM_STYLE","EllipsisText","TEXT_ITEM_LABEL_STYLE","isChoice","isChoiceItem","described","isRenderableNode","tagged","shared","ITEM_CLASS","href","safeHref","opensNewTab","_a","label","jsxs","LABEL_STYLE","VISUALLY_HIDDEN_STYLE","content","Fragment","ITEM_ICON_CLASS","ITEM_ICON_LAYOUT","ITEM_ICON_STYLE","ITEM_TEXT_STYLE","DESCRIPTION_CLASS","descriptionStyle","CHECK_SLOT_STYLE","CheckmarkIcon","resolveRel","isPlainClick","ActionMenu","items","triggerIcon","minWidth","size","showLabel","variant","customTrigger","placement","offset","triggerSize","TRIGGER_SIZES","open","setOpen","useState","headingBase","triggerRef","useRef","menuRef","focusOnOpen","focusInMenu","popupIdentity","usePopupLayer","position","useActionMenuPosition","positioned","useEffect","scrollCheckedIntoView","focusOpeningItem","scrollFocusedIntoView","closeOnOutsidePress","path","node","popEscapeLayer","pushEscapeLayer","active","getDeepActiveElement","toggleFromTrigger","openedFromKeyboard","v","handleTriggerKeyDown","edge","edgeForTriggerKey","focusEdge","handleMenuKeyDown","target","itemForMenuKey","enabledItems","selectItem","ownTriggerRef","elementRef","composedTriggerRef","useMemo","composeRefs","customHandlers","triggerElement","chainHandler","Button","MoreHorizontalIcon","entries","groupChoices","closeMenu","headingIdOf","index","renderRow","key","createPortal","menuStyle","EMPTY_ITEM_STYLE","entry","MENU_COLUMN_STYLE"],"mappings":";;;;;;;;;;;;;;;;;;;AAiFA,MAAMA,KAAoBC,EAAM,KAAK,MAAM,OAAO,wBAAqB,CAAC,GAElEC,IAAkB,CAACC,MAAgCA,EAAM,gBAAA,GAEzDC,KAMD,CAAC,EAAE,MAAAC,GAAM,MAAAC,GAAM,UAAAC,GAAU,UAAAC,GAAU,SAAAC,QAAc;;AAClD,QAAMC,IAAgBC,EAAA;AACtB,MAAIN,EAAK,SAAS;AACd,6BAAQ,OAAA,EAAI,MAAK,aAAY,OAAOO,EAAUP,CAAI,GAAG;AAEzD,MAAIA,EAAK,SAAS;AACd,WACI,gBAAAQ,EAAC,OAAA,EAAI,IAAIJ,GAAS,MAAK,YAAW,iBA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BAAAhC,EAAC,OAAA,EAAI,MAAK,YAAW,iBAAc,QAAO,OAAOmG,IAAkB,UAAA,uBAAA,CAEnE;AAAA,YAEHT,EAAQ;AAAA,cAAI,CAACU,GAAON,MAAA;;AACjB,uBAAAM,EAAM,SAAS,SACXL;AAAA,kBACIK,EAAM;AAAA,kBACNA,EAAM,aAAaP,EAAYC,CAAK,IAAI;AAAA,kBACxC,QAAQM,EAAM,KAAK,GAAG;AAAA,gBAAA,IAG1B,gBAAApG;AAAA,kBAAC;AAAA,kBAAA;AAAA,oBAEG,MAAK;AAAA,oBACL,mBACIoG,EAAM,qBACAP,EAAYC,IAAQ,CAAC,IACrB;AAAA,oBAEV,cAAYM,EAAM,qBAAqB,SAAYA,EAAM;AAAA,oBACzD,OAAOC;AAAA,oBAEN,YAAM,MAAM,IAAI,CAAC7G,MAASuG,EAAUvG,CAAI,CAAC;AAAA,kBAAA;AAAA,kBAVrC,UAASsB,IAAAsF,EAAM,MAAM,CAAC,MAAb,gBAAAtF,EAAgB,GAAG;AAAA,gBAAA;AAAA;AAAA,YAWrC;AAAA,UAER;AAAA,QAAA;AAAA,MAAA;AAAA,MAEJ,SAAS;AAAA,IAAA;AAAA,EACb,GACR;AAER;"}
|
|
@@ -1,70 +1,69 @@
|
|
|
1
1
|
import { jsxs as p, jsx as o } from "react/jsx-runtime";
|
|
2
|
-
import { useState as
|
|
3
|
-
import { Button as
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import { FieldMessage as
|
|
12
|
-
import { IconBadge as
|
|
13
|
-
import { Modal as
|
|
14
|
-
import { Typography as
|
|
15
|
-
import { useClipboardCopy as
|
|
16
|
-
import { CONFIRMATION_DIALOG_VARIANTS as
|
|
17
|
-
import
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const { outcome: m, canCopy: f, copy: a } = ne(`${i}|${e}`), s = async () => {
|
|
2
|
+
import { useState as M, useId as d, Children as P } from "react";
|
|
3
|
+
import { Button as T } from "./Button.js";
|
|
4
|
+
import ee from "./CalloutStrip.js";
|
|
5
|
+
import oe from "./CustomIcons/CheckCircleFilled.js";
|
|
6
|
+
import ie from "./CustomIcons/CheckmarkIcon.js";
|
|
7
|
+
import te from "./CustomIcons/CopyIcon.js";
|
|
8
|
+
import le from "./CustomIcons/ErrorCircleFilled.js";
|
|
9
|
+
import re from "./CustomIcons/InfoCircleFilled.js";
|
|
10
|
+
import se from "./CustomIcons/WarningCircleFilled.js";
|
|
11
|
+
import { FieldMessage as ae } from "./FieldMessage.js";
|
|
12
|
+
import { IconBadge as ne } from "./IconBadge.js";
|
|
13
|
+
import { Modal as ce } from "./Modal.js";
|
|
14
|
+
import { Typography as $ } from "./Typography/index.js";
|
|
15
|
+
import { useClipboardCopy as de } from "./useClipboardCopy.js";
|
|
16
|
+
import { CONFIRMATION_DIALOG_VARIANTS as pe } from "./confirmationDialogVariants.js";
|
|
17
|
+
import me from "./Input/Input.js";
|
|
18
|
+
const v = 12, h = (e) => e.replace(/\s+/g, " "), fe = (e, i) => {
|
|
19
|
+
if (!(i === "" || e === "" || e === i) && h(e).toLowerCase() === h(i).toLowerCase())
|
|
20
|
+
return h(e) === h(i) ? "The spacing has to match exactly." : "This is case-sensitive.";
|
|
21
|
+
}, ue = "Could not copy. Enter the phrase manually.", ye = (e, i) => {
|
|
22
|
+
const l = typeof e == "object" && e !== null ? e : void 0;
|
|
23
|
+
return l ? { parts: l, text: [l.prefix, i, l.suffix].filter(Boolean).join(" ") } : { text: typeof e == "string" ? e : `Type ${i} to confirm` };
|
|
24
|
+
}, xe = (e, i) => e === "copied" ? `${i} copied to clipboard` : "", Ce = (e, i, l, c) => {
|
|
25
|
+
const { outcome: m, canCopy: f, copy: a } = de(`${i}|${e}`), s = async () => {
|
|
27
26
|
e && await a(e) && queueMicrotask(() => c == null ? void 0 : c(e));
|
|
28
27
|
};
|
|
29
|
-
return { outcome: m, canCopy: f && !
|
|
30
|
-
},
|
|
28
|
+
return { outcome: m, canCopy: f && !l, copy: () => void s() };
|
|
29
|
+
}, N = ({ children: e }) => /* @__PURE__ */ o($.Text, { size: "small", color: "primary", children: e }), be = ({
|
|
31
30
|
phrase: e,
|
|
32
31
|
parts: i,
|
|
33
|
-
plainLabel:
|
|
32
|
+
plainLabel: l,
|
|
34
33
|
placeholder: c,
|
|
35
34
|
value: m,
|
|
36
35
|
onChange: f,
|
|
37
36
|
disabled: a,
|
|
38
37
|
copyLabel: s,
|
|
39
38
|
copyOutcome: n,
|
|
40
|
-
canCopy:
|
|
39
|
+
canCopy: t,
|
|
41
40
|
onCopy: I,
|
|
42
41
|
nearMissMessage: y
|
|
43
42
|
}) => {
|
|
44
|
-
const u = d(), x = d(), C = d(), b = d(), r = [y, n === "failed" ?
|
|
43
|
+
const u = d(), x = d(), C = d(), b = d(), r = [y, n === "failed" ? ue : void 0].filter(Boolean).join(" ") || void 0, g = i ? [u, i.suffix ? x : void 0].filter(Boolean).join(" ") : void 0;
|
|
45
44
|
return /* @__PURE__ */ p("div", { className: "flex flex-col gap-[6px]", children: [
|
|
46
45
|
i ? /* @__PURE__ */ p("div", { className: "flex flex-wrap items-center gap-[6px] px-2 text-[13px]", children: [
|
|
47
46
|
/* @__PURE__ */ p("span", { id: u, children: [
|
|
48
|
-
/* @__PURE__ */ o(
|
|
47
|
+
/* @__PURE__ */ o(N, { children: i.prefix }),
|
|
49
48
|
" ",
|
|
50
|
-
/* @__PURE__ */ o(
|
|
49
|
+
/* @__PURE__ */ o($.CodeText, { variant: "inline", children: e })
|
|
51
50
|
] }),
|
|
52
51
|
/* @__PURE__ */ o(
|
|
53
|
-
|
|
52
|
+
T,
|
|
54
53
|
{
|
|
55
54
|
variant: "ghost",
|
|
56
55
|
size: "small",
|
|
57
56
|
iconOnly: !0,
|
|
58
57
|
"aria-label": `${s} ${e}`,
|
|
59
|
-
icon: n === "copied" ? /* @__PURE__ */ o(
|
|
58
|
+
icon: n === "copied" ? /* @__PURE__ */ o(ie, { size: 13 }) : /* @__PURE__ */ o(te, { size: 13 }),
|
|
60
59
|
onClick: I,
|
|
61
|
-
disabled: !
|
|
60
|
+
disabled: !t
|
|
62
61
|
}
|
|
63
62
|
),
|
|
64
|
-
i.suffix ? /* @__PURE__ */ o("span", { id: x, children: /* @__PURE__ */ o(
|
|
65
|
-
] }) : /* @__PURE__ */ o("label", { id: u, htmlFor: b, className: "px-2 text-[13px]", children: /* @__PURE__ */ o(
|
|
63
|
+
i.suffix ? /* @__PURE__ */ o("span", { id: x, children: /* @__PURE__ */ o(N, { children: i.suffix }) }) : null
|
|
64
|
+
] }) : /* @__PURE__ */ o("label", { id: u, htmlFor: b, className: "px-2 text-[13px]", children: /* @__PURE__ */ o(N, { children: l }) }),
|
|
66
65
|
/* @__PURE__ */ o(
|
|
67
|
-
|
|
66
|
+
me,
|
|
68
67
|
{
|
|
69
68
|
id: b,
|
|
70
69
|
name: "confirmation-phrase",
|
|
@@ -79,25 +78,25 @@ const h = 12, v = (e) => e.replace(/\s+/g, " "), pe = (e, i) => {
|
|
|
79
78
|
disabled: a
|
|
80
79
|
}
|
|
81
80
|
),
|
|
82
|
-
/* @__PURE__ */ o(
|
|
83
|
-
i ? /* @__PURE__ */ o("span", { role: "status", className: "sr-only", children:
|
|
81
|
+
/* @__PURE__ */ o(ae, { id: C, message: r }),
|
|
82
|
+
i ? /* @__PURE__ */ o("span", { role: "status", className: "sr-only", children: xe(n, e) }) : null
|
|
84
83
|
] });
|
|
85
|
-
},
|
|
86
|
-
default: /* @__PURE__ */ o(
|
|
87
|
-
warning: /* @__PURE__ */ o(
|
|
88
|
-
destructive: /* @__PURE__ */ o(
|
|
89
|
-
success: /* @__PURE__ */ o(
|
|
90
|
-
},
|
|
84
|
+
}, ve = {
|
|
85
|
+
default: /* @__PURE__ */ o(re, { size: v }),
|
|
86
|
+
warning: /* @__PURE__ */ o(se, { size: v }),
|
|
87
|
+
destructive: /* @__PURE__ */ o(le, { size: v }),
|
|
88
|
+
success: /* @__PURE__ */ o(oe, { size: v })
|
|
89
|
+
}, De = ({
|
|
91
90
|
open: e,
|
|
92
91
|
onClose: i,
|
|
93
|
-
onConfirm:
|
|
92
|
+
onConfirm: l,
|
|
94
93
|
title: c,
|
|
95
94
|
titleAdornment: m,
|
|
96
95
|
badgeIcon: f,
|
|
97
96
|
description: a,
|
|
98
97
|
variant: s = "default",
|
|
99
98
|
callout: n,
|
|
100
|
-
confirmPhrase:
|
|
99
|
+
confirmPhrase: t,
|
|
101
100
|
confirmPhraseLabel: I,
|
|
102
101
|
confirmPhraseCopyLabel: y = "Copy",
|
|
103
102
|
onPhraseCopied: u,
|
|
@@ -106,97 +105,97 @@ const h = 12, v = (e) => e.replace(/\s+/g, " "), pe = (e, i) => {
|
|
|
106
105
|
cancelLabel: b = "Cancel",
|
|
107
106
|
loading: r = !1,
|
|
108
107
|
tip: g,
|
|
109
|
-
size:
|
|
110
|
-
"aria-label":
|
|
111
|
-
"aria-labelledby":
|
|
112
|
-
children:
|
|
108
|
+
size: G = "medium",
|
|
109
|
+
"aria-label": R,
|
|
110
|
+
"aria-labelledby": V,
|
|
111
|
+
children: z
|
|
113
112
|
}) => {
|
|
114
|
-
const [A,
|
|
115
|
-
(
|
|
116
|
-
const { parts:
|
|
113
|
+
const [A, L] = M(""), w = d(), S = d(), B = pe[s], [j, q] = M({ open: e, confirmPhrase: t });
|
|
114
|
+
(j.open !== e || j.confirmPhrase !== t) && (q({ open: e, confirmPhrase: t }), e && L(""));
|
|
115
|
+
const { parts: Y, text: k } = ye(
|
|
117
116
|
I,
|
|
118
|
-
|
|
117
|
+
t
|
|
119
118
|
), {
|
|
120
|
-
outcome:
|
|
121
|
-
canCopy:
|
|
122
|
-
copy:
|
|
123
|
-
} =
|
|
124
|
-
(
|
|
125
|
-
),
|
|
126
|
-
/* @__PURE__ */ o(
|
|
119
|
+
outcome: H,
|
|
120
|
+
canCopy: W,
|
|
121
|
+
copy: Z
|
|
122
|
+
} = Ce(t, e, r, u), E = A.trim(), F = (t == null ? void 0 : t.trim()) ?? "", O = !t || (F === "" ? A === t : E === F), J = fe(E, F), K = r || !O, Q = P.toArray(z).some(
|
|
123
|
+
(D) => typeof D != "string" || D.trim() !== ""
|
|
124
|
+
), _ = !!a || Q || !!t, U = [n ? S : null, a ? w : null].filter(Boolean).join(" ") || void 0, X = /* @__PURE__ */ p("div", { className: "flex w-full flex-wrap items-center justify-end gap-[8px]", children: [
|
|
125
|
+
/* @__PURE__ */ o(T, { variant: "outline", size: "small", onClick: i, disabled: r, children: b }),
|
|
127
126
|
/* @__PURE__ */ o(
|
|
128
|
-
|
|
127
|
+
T,
|
|
129
128
|
{
|
|
130
129
|
variant: B.confirmVariant,
|
|
131
130
|
size: "small",
|
|
132
|
-
onClick:
|
|
133
|
-
disabled:
|
|
131
|
+
onClick: l,
|
|
132
|
+
disabled: K,
|
|
134
133
|
loading: r,
|
|
135
|
-
tooltip: !r && !
|
|
134
|
+
tooltip: !r && !O ? k : void 0,
|
|
136
135
|
children: C
|
|
137
136
|
}
|
|
138
137
|
)
|
|
139
138
|
] });
|
|
140
139
|
return /* @__PURE__ */ p(
|
|
141
|
-
|
|
140
|
+
ce,
|
|
142
141
|
{
|
|
143
142
|
open: e,
|
|
144
143
|
onClose: i,
|
|
145
144
|
title: c,
|
|
146
|
-
size:
|
|
147
|
-
footer:
|
|
145
|
+
size: G,
|
|
146
|
+
footer: X,
|
|
148
147
|
busy: r,
|
|
149
148
|
role: s === "destructive" ? "alertdialog" : "dialog",
|
|
150
|
-
"aria-label":
|
|
151
|
-
"aria-labelledby":
|
|
152
|
-
"aria-describedby":
|
|
153
|
-
closeOnOverlayClick: s !== "destructive" && !
|
|
149
|
+
"aria-label": R,
|
|
150
|
+
"aria-labelledby": V,
|
|
151
|
+
"aria-describedby": U,
|
|
152
|
+
closeOnOverlayClick: s !== "destructive" && !t,
|
|
154
153
|
headerDivider: !0,
|
|
155
154
|
titleAdornment: m,
|
|
156
155
|
bodyPadding: !1,
|
|
157
156
|
tray: { tone: B.tray, caption: g },
|
|
158
157
|
icon: /* @__PURE__ */ o(
|
|
159
|
-
|
|
158
|
+
ne,
|
|
160
159
|
{
|
|
161
160
|
variant: s,
|
|
162
|
-
icon: f ??
|
|
161
|
+
icon: f ?? ve[s]
|
|
163
162
|
}
|
|
164
163
|
),
|
|
165
164
|
children: [
|
|
166
165
|
n ? /* @__PURE__ */ o(
|
|
167
|
-
|
|
166
|
+
ee,
|
|
168
167
|
{
|
|
169
|
-
id:
|
|
168
|
+
id: S,
|
|
170
169
|
type: n.type ?? B.calloutType,
|
|
171
170
|
message: n.message,
|
|
172
|
-
divider:
|
|
171
|
+
divider: _
|
|
173
172
|
}
|
|
174
173
|
) : null,
|
|
175
|
-
|
|
174
|
+
_ ? /* @__PURE__ */ p("div", { className: "flex flex-col gap-[12px] p-[28px]", children: [
|
|
176
175
|
a ? /* @__PURE__ */ o(
|
|
177
176
|
"div",
|
|
178
177
|
{
|
|
179
|
-
id:
|
|
178
|
+
id: w,
|
|
180
179
|
className: "text-[13px] leading-[1.6] text-[var(--malachite-text-secondary)]",
|
|
181
180
|
children: a
|
|
182
181
|
}
|
|
183
182
|
) : null,
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
183
|
+
z,
|
|
184
|
+
t ? /* @__PURE__ */ o(
|
|
185
|
+
be,
|
|
187
186
|
{
|
|
188
|
-
phrase:
|
|
189
|
-
parts:
|
|
190
|
-
plainLabel:
|
|
187
|
+
phrase: t,
|
|
188
|
+
parts: Y,
|
|
189
|
+
plainLabel: k,
|
|
191
190
|
placeholder: x,
|
|
192
191
|
value: A,
|
|
193
|
-
onChange:
|
|
192
|
+
onChange: L,
|
|
194
193
|
disabled: r,
|
|
195
194
|
copyLabel: y,
|
|
196
|
-
copyOutcome:
|
|
197
|
-
canCopy:
|
|
198
|
-
onCopy:
|
|
199
|
-
nearMissMessage:
|
|
195
|
+
copyOutcome: H,
|
|
196
|
+
canCopy: W,
|
|
197
|
+
onCopy: Z,
|
|
198
|
+
nearMissMessage: J
|
|
200
199
|
}
|
|
201
200
|
) : null
|
|
202
201
|
] }) : null
|
|
@@ -205,7 +204,7 @@ const h = 12, v = (e) => e.replace(/\s+/g, " "), pe = (e, i) => {
|
|
|
205
204
|
);
|
|
206
205
|
};
|
|
207
206
|
export {
|
|
208
|
-
|
|
209
|
-
|
|
207
|
+
De as ConfirmationDialog,
|
|
208
|
+
De as default
|
|
210
209
|
};
|
|
211
210
|
//# sourceMappingURL=ConfirmationDialog.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfirmationDialog.js","sources":["../../src/components/ConfirmationDialog.tsx"],"sourcesContent":["import type React from 'react';\nimport { Children, useId, useState } from 'react';\nimport type { AlertType } from './Alert';\nimport Button from './Button';\nimport CalloutStrip from './CalloutStrip';\nimport CheckCircleFilled from './CustomIcons/CheckCircleFilled';\nimport CheckmarkIcon from './CustomIcons/CheckmarkIcon';\nimport CopyIcon from './CustomIcons/CopyIcon';\nimport ErrorCircleFilled from './CustomIcons/ErrorCircleFilled';\nimport InfoCircleFilled from './CustomIcons/InfoCircleFilled';\nimport WarningCircleFilled from './CustomIcons/WarningCircleFilled';\nimport FieldMessage from './FieldMessage';\nimport IconBadge from './IconBadge';\nimport { Input } from './Input';\nimport Modal, { type ModalSize } from './Modal';\nimport Typography from './Typography';\nimport { type CopyOutcome, useClipboardCopy } from './useClipboardCopy';\nimport {\n CONFIRMATION_DIALOG_VARIANTS,\n type ConfirmationDialogVariant,\n} from './confirmationDialogVariants';\n\n/** Kept beside the component: an icon is a node, not a value the variant table can hold. */\nconst BADGE_GLYPH_SIZE = 12;\n\nconst collapseSpaces = (value: string) => value.replace(/\\s+/g, ' ');\n\nconst nearMissAgainst = (typedPhrase: string, confirmPhrase?: string): string | undefined => {\n const typed = typedPhrase.trim();\n if (!confirmPhrase || typed === '' || typed === confirmPhrase) {\n return undefined;\n }\n if (collapseSpaces(typed).toLowerCase() !== collapseSpaces(confirmPhrase).toLowerCase()) {\n return undefined;\n }\n return collapseSpaces(typed) === collapseSpaces(confirmPhrase)\n ? 'The spacing has to match exactly.'\n : 'This is case-sensitive.';\n};\n\ntype PhraseLabel = string | { prefix: string; suffix?: string };\n\nconst COPY_FAILED_MESSAGE = 'Could not copy. Enter the phrase manually.';\n\nconst resolvePhraseLabel = (\n label: PhraseLabel | undefined,\n phrase?: string,\n): { parts?: { prefix: string; suffix?: string }; text: string } => {\n const parts = typeof label === 'object' && label !== null ? label : undefined;\n if (parts) {\n return { parts, text: [parts.prefix, phrase, parts.suffix].filter(Boolean).join(' ') };\n }\n return { text: typeof label === 'string' ? label : `Type ${phrase} to confirm` };\n};\n\nconst copyStatusFor = (outcome: CopyOutcome, phrase: string): string =>\n outcome === 'copied' ? `${phrase} copied to clipboard` : '';\n\nconst usePhraseCopy = (\n phrase: string | undefined,\n open: boolean,\n disabled: boolean,\n onCopied?: (phrase: string) => void,\n): { outcome: CopyOutcome; canCopy: boolean; copy: () => void } => {\n const { outcome, canCopy, copy } = useClipboardCopy(`${open}|${phrase}`);\n\n const run = async () => {\n if (phrase && (await copy(phrase))) {\n queueMicrotask(() => onCopied?.(phrase));\n }\n };\n\n return { outcome, canCopy: canCopy && !disabled, copy: () => void run() };\n};\n\nconst LabelText: React.FC<{ children: React.ReactNode }> = ({ children }) => (\n <Typography.Text size=\"small\" color=\"primary\">\n {children}\n </Typography.Text>\n);\n\ninterface PhraseFieldProps {\n phrase: string;\n parts?: { prefix: string; suffix?: string };\n plainLabel: string;\n placeholder?: string;\n value: string;\n onChange: (value: string) => void;\n disabled: boolean;\n copyLabel: string;\n copyOutcome: CopyOutcome;\n canCopy: boolean;\n onCopy: () => void;\n nearMissMessage?: string;\n}\n\nconst PhraseField: React.FC<PhraseFieldProps> = ({\n phrase,\n parts,\n plainLabel,\n placeholder,\n value,\n onChange,\n disabled,\n copyLabel,\n copyOutcome,\n canCopy,\n onCopy,\n nearMissMessage,\n}) => {\n const beforeId = useId();\n const afterId = useId();\n const messageId = useId();\n const inputId = useId();\n const message =\n [nearMissMessage, copyOutcome === 'failed' ? COPY_FAILED_MESSAGE : undefined]\n .filter(Boolean)\n .join(' ') || undefined;\n const labelledBy = parts\n ? [beforeId, parts.suffix ? afterId : undefined].filter(Boolean).join(' ')\n : undefined;\n\n return (\n <div className=\"flex flex-col gap-[6px]\">\n {parts ? (\n <div className=\"flex flex-wrap items-center gap-[6px] px-2 text-[13px]\">\n <span id={beforeId}>\n <LabelText>{parts.prefix}</LabelText>{' '}\n <Typography.CodeText variant=\"inline\">\n {phrase}\n </Typography.CodeText>\n </span>\n <Button\n variant=\"ghost\"\n size=\"small\"\n iconOnly\n aria-label={`${copyLabel} ${phrase}`}\n icon={\n copyOutcome === 'copied' ? (\n <CheckmarkIcon size={13} />\n ) : (\n <CopyIcon size={13} />\n )\n }\n onClick={onCopy}\n disabled={!canCopy}\n />\n {parts.suffix ? (\n <span id={afterId}>\n <LabelText>{parts.suffix}</LabelText>\n </span>\n ) : null}\n </div>\n ) : (\n <label id={beforeId} htmlFor={inputId} className=\"px-2 text-[13px]\">\n <LabelText>{plainLabel}</LabelText>\n </label>\n )}\n <Input\n id={inputId}\n name=\"confirmation-phrase\"\n size=\"medium\"\n value={value}\n onChange={onChange}\n aria-labelledby={labelledBy}\n placeholder={placeholder}\n requiredIndicator=\"none\"\n error={!!nearMissMessage}\n aria-describedby={message ? messageId : undefined}\n disabled={disabled}\n />\n <FieldMessage id={messageId} message={message} />\n {parts ? (\n <span role=\"status\" className=\"sr-only\">\n {copyStatusFor(copyOutcome, phrase)}\n </span>\n ) : null}\n </div>\n );\n};\n\nconst VARIANT_ICON: Record<ConfirmationDialogVariant, React.ReactNode> = {\n default: <InfoCircleFilled size={BADGE_GLYPH_SIZE} />,\n warning: <WarningCircleFilled size={BADGE_GLYPH_SIZE} />,\n destructive: <ErrorCircleFilled size={BADGE_GLYPH_SIZE} />,\n success: <CheckCircleFilled size={BADGE_GLYPH_SIZE} />,\n};\n\nexport interface ConfirmationDialogProps {\n open: boolean;\n /** Dismiss handler — cancel, close button, ESC or scrim. `loading` suppresses every\n * route except ESC, which always reaches this so a keyboard user is never stranded. */\n onClose: () => void;\n /** Runs when the confirm action is taken. Closing is left to the consumer. */\n onConfirm: () => void;\n title: React.ReactNode;\n titleAdornment?: React.ReactNode;\n badgeIcon?: React.ReactNode;\n /** The sentence saying what is about to happen. */\n description?: React.ReactNode;\n variant?: ConfirmationDialogVariant;\n /** Coloured callout below the body. Defaults to the variant's own type. */\n callout?: { type?: AlertType; message: string };\n /**\n * Requires this exact phrase to be typed before the confirm action enables — for a\n * consequence severe enough that a single click should not be able to cause it.\n */\n confirmPhrase?: string;\n /** Label above the type-to-confirm field. `{ prefix, suffix }` makes the phrase copyable. */\n confirmPhraseLabel?: PhraseLabel;\n /** Names the copy control, e.g. `Copy profile name`. Default: `Copy`. */\n confirmPhraseCopyLabel?: string;\n /** Runs after the phrase reaches the clipboard, with what was copied. */\n onPhraseCopied?: (phrase: string) => void;\n confirmPhrasePlaceholder?: string;\n confirmLabel?: string;\n cancelLabel?: string;\n /**\n * Disables the actions, spins the confirm button and suppresses the pointer dismissal\n * routes — but never ESC, which always reaches `onClose`.\n */\n loading?: boolean;\n tip?: { label?: string; message: string };\n size?: ModalSize;\n /** Accessible dialog name; required when `title` isn't a plain string. */\n 'aria-label'?: string;\n /** ID of a visible element naming the dialog (alternative to `aria-label`). */\n 'aria-labelledby'?: string;\n /** Extra body content between the description and the callout, e.g. an entity chip. */\n children?: React.ReactNode;\n}\n\nconst ConfirmationDialog: React.FC<ConfirmationDialogProps> = ({\n open,\n onClose,\n onConfirm,\n title,\n titleAdornment,\n badgeIcon,\n description,\n variant = 'default',\n callout,\n confirmPhrase,\n confirmPhraseLabel,\n confirmPhraseCopyLabel = 'Copy',\n onPhraseCopied,\n confirmPhrasePlaceholder,\n confirmLabel = 'Confirm',\n cancelLabel = 'Cancel',\n loading = false,\n tip,\n size = 'medium',\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n children,\n}) => {\n const [typedPhrase, setTypedPhrase] = useState('');\n const descriptionId = useId();\n const calloutId = useId();\n const base = CONFIRMATION_DIALOG_VARIANTS[variant];\n\n // On open, not close: the dialog outlives `open` by its exit transition, so resetting on\n // close empties the field in front of the user. Adjusted during render rather than from an\n // effect, or a reopen paints the previous answer once with confirm already enabled.\n const [answeredFor, setAnsweredFor] = useState({ open, confirmPhrase });\n if (answeredFor.open !== open || answeredFor.confirmPhrase !== confirmPhrase) {\n setAnsweredFor({ open, confirmPhrase });\n if (open) {\n setTypedPhrase('');\n }\n }\n\n const { parts: phraseParts, text: phraseLabel } = resolvePhraseLabel(\n confirmPhraseLabel,\n confirmPhrase,\n );\n const {\n outcome: copyOutcome,\n canCopy: canCopyPhrase,\n copy: handleCopyPhrase,\n } = usePhraseCopy(confirmPhrase, open, loading, onPhraseCopied);\n // Trimmed because copying an entity name commonly picks up a trailing space; the gate is\n // still exact, and deliberately case-sensitive.\n const phraseSatisfied = !confirmPhrase || typedPhrase.trim() === confirmPhrase;\n const nearMissMessage = nearMissAgainst(typedPhrase, confirmPhrase);\n const confirmDisabled = loading || !phraseSatisfied;\n const hasChildren = Children.toArray(children).some(\n (child) => typeof child !== 'string' || child.trim() !== '',\n );\n const hasBody = Boolean(description) || hasChildren || Boolean(confirmPhrase);\n // The callout is often the whole consequence, so it is announced along with the description.\n const describedBy =\n [callout ? calloutId : null, description ? descriptionId : null]\n .filter(Boolean)\n .join(' ') || undefined;\n\n const footer = (\n <div className=\"flex w-full flex-wrap items-center justify-end gap-[8px]\">\n <Button variant=\"outline\" size=\"small\" onClick={onClose} disabled={loading}>\n {cancelLabel}\n </Button>\n <Button\n variant={base.confirmVariant}\n size=\"small\"\n onClick={onConfirm}\n disabled={confirmDisabled}\n loading={loading}\n // A disabled control emits no hover, so the tooltip explains the gate from the\n // wrapper Button renders for exactly this case.\n tooltip={!loading && !phraseSatisfied ? phraseLabel : undefined}\n >\n {confirmLabel}\n </Button>\n </div>\n );\n\n return (\n <Modal\n open={open}\n onClose={onClose}\n title={title}\n size={size}\n footer={footer}\n busy={loading}\n // A consequential choice is an alertdialog: it asks assistive tech to announce the\n // body, which is where the consequence is written.\n role={variant === 'destructive' ? 'alertdialog' : 'dialog'}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n aria-describedby={describedBy}\n // A choice this deliberate should not be undone by a stray click, and a scrim\n // click must not discard a phrase the customer has already typed.\n closeOnOverlayClick={variant !== 'destructive' && !confirmPhrase}\n headerDivider\n titleAdornment={titleAdornment}\n bodyPadding={false}\n tray={{ tone: base.tray, caption: tip }}\n icon={\n <IconBadge\n variant={variant}\n icon={badgeIcon ?? VARIANT_ICON[variant]}\n />\n }\n >\n {callout ? (\n <CalloutStrip\n id={calloutId}\n type={callout.type ?? base.calloutType}\n message={callout.message}\n divider={hasBody}\n />\n ) : null}\n {hasBody ? (\n <div className=\"flex flex-col gap-[12px] p-[28px]\">\n {description ? (\n <div\n id={descriptionId}\n className=\"text-[13px] leading-[1.6] text-[var(--malachite-text-secondary)]\"\n >\n {description}\n </div>\n ) : null}\n {children}\n {confirmPhrase ? (\n <PhraseField\n phrase={confirmPhrase}\n parts={phraseParts}\n plainLabel={phraseLabel}\n placeholder={confirmPhrasePlaceholder}\n value={typedPhrase}\n onChange={setTypedPhrase}\n disabled={loading}\n copyLabel={confirmPhraseCopyLabel}\n copyOutcome={copyOutcome}\n canCopy={canCopyPhrase}\n onCopy={handleCopyPhrase}\n nearMissMessage={nearMissMessage}\n />\n ) : null}\n </div>\n ) : null}\n </Modal>\n );\n};\n\nexport default ConfirmationDialog;\nexport { ConfirmationDialog };\nexport type { ConfirmationDialogVariant };\n"],"names":["BADGE_GLYPH_SIZE","collapseSpaces","value","nearMissAgainst","typedPhrase","confirmPhrase","typed","COPY_FAILED_MESSAGE","resolvePhraseLabel","label","phrase","parts","copyStatusFor","outcome","usePhraseCopy","open","disabled","onCopied","canCopy","copy","useClipboardCopy","run","LabelText","children","jsx","Typography","PhraseField","plainLabel","placeholder","onChange","copyLabel","copyOutcome","onCopy","nearMissMessage","beforeId","useId","afterId","messageId","inputId","message","labelledBy","jsxs","Button","CheckmarkIcon","CopyIcon","Input","FieldMessage","VARIANT_ICON","InfoCircleFilled","WarningCircleFilled","ErrorCircleFilled","CheckCircleFilled","ConfirmationDialog","onClose","onConfirm","title","titleAdornment","badgeIcon","description","variant","callout","confirmPhraseLabel","confirmPhraseCopyLabel","onPhraseCopied","confirmPhrasePlaceholder","confirmLabel","cancelLabel","loading","tip","size","ariaLabel","ariaLabelledBy","setTypedPhrase","useState","descriptionId","calloutId","base","CONFIRMATION_DIALOG_VARIANTS","answeredFor","setAnsweredFor","phraseParts","phraseLabel","canCopyPhrase","handleCopyPhrase","phraseSatisfied","confirmDisabled","hasChildren","Children","child","hasBody","describedBy","footer","Modal","IconBadge","CalloutStrip"],"mappings":";;;;;;;;;;;;;;;;;AAuBA,MAAMA,IAAmB,IAEnBC,IAAiB,CAACC,MAAkBA,EAAM,QAAQ,QAAQ,GAAG,GAE7DC,KAAkB,CAACC,GAAqBC,MAA+C;AACzF,QAAMC,IAAQF,EAAY,KAAA;AAC1B,MAAI,GAACC,KAAiBC,MAAU,MAAMA,MAAUD,MAG5CJ,EAAeK,CAAK,EAAE,YAAA,MAAkBL,EAAeI,CAAa,EAAE;AAG1E,WAAOJ,EAAeK,CAAK,MAAML,EAAeI,CAAa,IACvD,sCACA;AACV,GAIME,KAAsB,8CAEtBC,KAAqB,CACvBC,GACAC,MACgE;AAChE,QAAMC,IAAQ,OAAOF,KAAU,YAAYA,MAAU,OAAOA,IAAQ;AACpE,SAAIE,IACO,EAAE,OAAAA,GAAO,MAAM,CAACA,EAAM,QAAQD,GAAQC,EAAM,MAAM,EAAE,OAAO,OAAO,EAAE,KAA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AA;AAGhB;"}
|
|
1
|
+
{"version":3,"file":"ConfirmationDialog.js","sources":["../../src/components/ConfirmationDialog.tsx"],"sourcesContent":["import type React from 'react';\nimport { Children, useId, useState } from 'react';\nimport type { AlertType } from './Alert';\nimport Button from './Button';\nimport CalloutStrip from './CalloutStrip';\nimport CheckCircleFilled from './CustomIcons/CheckCircleFilled';\nimport CheckmarkIcon from './CustomIcons/CheckmarkIcon';\nimport CopyIcon from './CustomIcons/CopyIcon';\nimport ErrorCircleFilled from './CustomIcons/ErrorCircleFilled';\nimport InfoCircleFilled from './CustomIcons/InfoCircleFilled';\nimport WarningCircleFilled from './CustomIcons/WarningCircleFilled';\nimport FieldMessage from './FieldMessage';\nimport IconBadge from './IconBadge';\nimport { Input } from './Input';\nimport Modal, { type ModalSize } from './Modal';\nimport Typography from './Typography';\nimport { type CopyOutcome, useClipboardCopy } from './useClipboardCopy';\nimport {\n CONFIRMATION_DIALOG_VARIANTS,\n type ConfirmationDialogVariant,\n} from './confirmationDialogVariants';\n\n/** Kept beside the component: an icon is a node, not a value the variant table can hold. */\nconst BADGE_GLYPH_SIZE = 12;\n\nconst collapseSpaces = (value: string) => value.replace(/\\s+/g, ' ');\n\nconst nearMissAgainst = (typed: string, phrase: string): string | undefined => {\n if (phrase === '' || typed === '' || typed === phrase) {\n return undefined;\n }\n if (collapseSpaces(typed).toLowerCase() !== collapseSpaces(phrase).toLowerCase()) {\n return undefined;\n }\n return collapseSpaces(typed) === collapseSpaces(phrase)\n ? 'The spacing has to match exactly.'\n : 'This is case-sensitive.';\n};\n\ntype PhraseLabel = string | { prefix: string; suffix?: string };\n\nconst COPY_FAILED_MESSAGE = 'Could not copy. Enter the phrase manually.';\n\nconst resolvePhraseLabel = (\n label: PhraseLabel | undefined,\n phrase?: string,\n): { parts?: { prefix: string; suffix?: string }; text: string } => {\n const parts = typeof label === 'object' && label !== null ? label : undefined;\n if (parts) {\n return { parts, text: [parts.prefix, phrase, parts.suffix].filter(Boolean).join(' ') };\n }\n return { text: typeof label === 'string' ? label : `Type ${phrase} to confirm` };\n};\n\nconst copyStatusFor = (outcome: CopyOutcome, phrase: string): string =>\n outcome === 'copied' ? `${phrase} copied to clipboard` : '';\n\nconst usePhraseCopy = (\n phrase: string | undefined,\n open: boolean,\n disabled: boolean,\n onCopied?: (phrase: string) => void,\n): { outcome: CopyOutcome; canCopy: boolean; copy: () => void } => {\n const { outcome, canCopy, copy } = useClipboardCopy(`${open}|${phrase}`);\n\n const run = async () => {\n if (phrase && (await copy(phrase))) {\n queueMicrotask(() => onCopied?.(phrase));\n }\n };\n\n return { outcome, canCopy: canCopy && !disabled, copy: () => void run() };\n};\n\nconst LabelText: React.FC<{ children: React.ReactNode }> = ({ children }) => (\n <Typography.Text size=\"small\" color=\"primary\">\n {children}\n </Typography.Text>\n);\n\ninterface PhraseFieldProps {\n phrase: string;\n parts?: { prefix: string; suffix?: string };\n plainLabel: string;\n placeholder?: string;\n value: string;\n onChange: (value: string) => void;\n disabled: boolean;\n copyLabel: string;\n copyOutcome: CopyOutcome;\n canCopy: boolean;\n onCopy: () => void;\n nearMissMessage?: string;\n}\n\nconst PhraseField: React.FC<PhraseFieldProps> = ({\n phrase,\n parts,\n plainLabel,\n placeholder,\n value,\n onChange,\n disabled,\n copyLabel,\n copyOutcome,\n canCopy,\n onCopy,\n nearMissMessage,\n}) => {\n const beforeId = useId();\n const afterId = useId();\n const messageId = useId();\n const inputId = useId();\n const message =\n [nearMissMessage, copyOutcome === 'failed' ? COPY_FAILED_MESSAGE : undefined]\n .filter(Boolean)\n .join(' ') || undefined;\n const labelledBy = parts\n ? [beforeId, parts.suffix ? afterId : undefined].filter(Boolean).join(' ')\n : undefined;\n\n return (\n <div className=\"flex flex-col gap-[6px]\">\n {parts ? (\n <div className=\"flex flex-wrap items-center gap-[6px] px-2 text-[13px]\">\n <span id={beforeId}>\n <LabelText>{parts.prefix}</LabelText>{' '}\n <Typography.CodeText variant=\"inline\">\n {phrase}\n </Typography.CodeText>\n </span>\n <Button\n variant=\"ghost\"\n size=\"small\"\n iconOnly\n aria-label={`${copyLabel} ${phrase}`}\n icon={\n copyOutcome === 'copied' ? (\n <CheckmarkIcon size={13} />\n ) : (\n <CopyIcon size={13} />\n )\n }\n onClick={onCopy}\n disabled={!canCopy}\n />\n {parts.suffix ? (\n <span id={afterId}>\n <LabelText>{parts.suffix}</LabelText>\n </span>\n ) : null}\n </div>\n ) : (\n <label id={beforeId} htmlFor={inputId} className=\"px-2 text-[13px]\">\n <LabelText>{plainLabel}</LabelText>\n </label>\n )}\n <Input\n id={inputId}\n name=\"confirmation-phrase\"\n size=\"medium\"\n value={value}\n onChange={onChange}\n aria-labelledby={labelledBy}\n placeholder={placeholder}\n requiredIndicator=\"none\"\n error={!!nearMissMessage}\n aria-describedby={message ? messageId : undefined}\n disabled={disabled}\n />\n <FieldMessage id={messageId} message={message} />\n {parts ? (\n <span role=\"status\" className=\"sr-only\">\n {copyStatusFor(copyOutcome, phrase)}\n </span>\n ) : null}\n </div>\n );\n};\n\nconst VARIANT_ICON: Record<ConfirmationDialogVariant, React.ReactNode> = {\n default: <InfoCircleFilled size={BADGE_GLYPH_SIZE} />,\n warning: <WarningCircleFilled size={BADGE_GLYPH_SIZE} />,\n destructive: <ErrorCircleFilled size={BADGE_GLYPH_SIZE} />,\n success: <CheckCircleFilled size={BADGE_GLYPH_SIZE} />,\n};\n\nexport interface ConfirmationDialogProps {\n open: boolean;\n /** Dismiss handler — cancel, close button, ESC or scrim. `loading` suppresses every\n * route except ESC, which always reaches this so a keyboard user is never stranded. */\n onClose: () => void;\n /** Runs when the confirm action is taken. Closing is left to the consumer. */\n onConfirm: () => void;\n title: React.ReactNode;\n titleAdornment?: React.ReactNode;\n badgeIcon?: React.ReactNode;\n /** The sentence saying what is about to happen. */\n description?: React.ReactNode;\n variant?: ConfirmationDialogVariant;\n /** Coloured callout below the body. Defaults to the variant's own type. */\n callout?: { type?: AlertType; message: string };\n /**\n * Requires this phrase, ends trimmed, to be typed before the confirm action enables — for a\n * consequence severe enough that a single click should not be able to cause it.\n */\n confirmPhrase?: string;\n /** Label above the type-to-confirm field. `{ prefix, suffix }` makes the phrase copyable. */\n confirmPhraseLabel?: PhraseLabel;\n /** Names the copy control, e.g. `Copy profile name`. Default: `Copy`. */\n confirmPhraseCopyLabel?: string;\n /** Runs after the phrase reaches the clipboard, with what was copied. */\n onPhraseCopied?: (phrase: string) => void;\n confirmPhrasePlaceholder?: string;\n confirmLabel?: string;\n cancelLabel?: string;\n /**\n * Disables the actions, spins the confirm button and suppresses the pointer dismissal\n * routes — but never ESC, which always reaches `onClose`.\n */\n loading?: boolean;\n tip?: { label?: string; message: string };\n size?: ModalSize;\n /** Accessible dialog name; required when `title` isn't a plain string. */\n 'aria-label'?: string;\n /** ID of a visible element naming the dialog (alternative to `aria-label`). */\n 'aria-labelledby'?: string;\n /** Extra body content between the description and the callout, e.g. an entity chip. */\n children?: React.ReactNode;\n}\n\nconst ConfirmationDialog: React.FC<ConfirmationDialogProps> = ({\n open,\n onClose,\n onConfirm,\n title,\n titleAdornment,\n badgeIcon,\n description,\n variant = 'default',\n callout,\n confirmPhrase,\n confirmPhraseLabel,\n confirmPhraseCopyLabel = 'Copy',\n onPhraseCopied,\n confirmPhrasePlaceholder,\n confirmLabel = 'Confirm',\n cancelLabel = 'Cancel',\n loading = false,\n tip,\n size = 'medium',\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n children,\n}) => {\n const [typedPhrase, setTypedPhrase] = useState('');\n const descriptionId = useId();\n const calloutId = useId();\n const base = CONFIRMATION_DIALOG_VARIANTS[variant];\n\n // On open, not close: the dialog outlives `open` by its exit transition, so resetting on\n // close empties the field in front of the user. Adjusted during render rather than from an\n // effect, or a reopen paints the previous answer once with confirm already enabled.\n const [answeredFor, setAnsweredFor] = useState({ open, confirmPhrase });\n if (answeredFor.open !== open || answeredFor.confirmPhrase !== confirmPhrase) {\n setAnsweredFor({ open, confirmPhrase });\n if (open) {\n setTypedPhrase('');\n }\n }\n\n const { parts: phraseParts, text: phraseLabel } = resolvePhraseLabel(\n confirmPhraseLabel,\n confirmPhrase,\n );\n const {\n outcome: copyOutcome,\n canCopy: canCopyPhrase,\n copy: handleCopyPhrase,\n } = usePhraseCopy(confirmPhrase, open, loading, onPhraseCopied);\n // Both sides trimmed, as copied and saved names pick up padding that never renders. A\n // whitespace-only phrase is matched as given, so an empty field cannot confirm it.\n const typed = typedPhrase.trim();\n const phrase = confirmPhrase?.trim() ?? '';\n const phraseSatisfied =\n !confirmPhrase || (phrase === '' ? typedPhrase === confirmPhrase : typed === phrase);\n const nearMissMessage = nearMissAgainst(typed, phrase);\n const confirmDisabled = loading || !phraseSatisfied;\n const hasChildren = Children.toArray(children).some(\n (child) => typeof child !== 'string' || child.trim() !== '',\n );\n const hasBody = Boolean(description) || hasChildren || Boolean(confirmPhrase);\n // The callout is often the whole consequence, so it is announced along with the description.\n const describedBy =\n [callout ? calloutId : null, description ? descriptionId : null]\n .filter(Boolean)\n .join(' ') || undefined;\n\n const footer = (\n <div className=\"flex w-full flex-wrap items-center justify-end gap-[8px]\">\n <Button variant=\"outline\" size=\"small\" onClick={onClose} disabled={loading}>\n {cancelLabel}\n </Button>\n <Button\n variant={base.confirmVariant}\n size=\"small\"\n onClick={onConfirm}\n disabled={confirmDisabled}\n loading={loading}\n // A disabled control emits no hover, so the tooltip explains the gate from the\n // wrapper Button renders for exactly this case.\n tooltip={!loading && !phraseSatisfied ? phraseLabel : undefined}\n >\n {confirmLabel}\n </Button>\n </div>\n );\n\n return (\n <Modal\n open={open}\n onClose={onClose}\n title={title}\n size={size}\n footer={footer}\n busy={loading}\n // A consequential choice is an alertdialog: it asks assistive tech to announce the\n // body, which is where the consequence is written.\n role={variant === 'destructive' ? 'alertdialog' : 'dialog'}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n aria-describedby={describedBy}\n // A choice this deliberate should not be undone by a stray click, and a scrim\n // click must not discard a phrase the customer has already typed.\n closeOnOverlayClick={variant !== 'destructive' && !confirmPhrase}\n headerDivider\n titleAdornment={titleAdornment}\n bodyPadding={false}\n tray={{ tone: base.tray, caption: tip }}\n icon={\n <IconBadge\n variant={variant}\n icon={badgeIcon ?? VARIANT_ICON[variant]}\n />\n }\n >\n {callout ? (\n <CalloutStrip\n id={calloutId}\n type={callout.type ?? base.calloutType}\n message={callout.message}\n divider={hasBody}\n />\n ) : null}\n {hasBody ? (\n <div className=\"flex flex-col gap-[12px] p-[28px]\">\n {description ? (\n <div\n id={descriptionId}\n className=\"text-[13px] leading-[1.6] text-[var(--malachite-text-secondary)]\"\n >\n {description}\n </div>\n ) : null}\n {children}\n {confirmPhrase ? (\n <PhraseField\n phrase={confirmPhrase}\n parts={phraseParts}\n plainLabel={phraseLabel}\n placeholder={confirmPhrasePlaceholder}\n value={typedPhrase}\n onChange={setTypedPhrase}\n disabled={loading}\n copyLabel={confirmPhraseCopyLabel}\n copyOutcome={copyOutcome}\n canCopy={canCopyPhrase}\n onCopy={handleCopyPhrase}\n nearMissMessage={nearMissMessage}\n />\n ) : null}\n </div>\n ) : null}\n </Modal>\n );\n};\n\nexport default ConfirmationDialog;\nexport { ConfirmationDialog };\nexport type { ConfirmationDialogVariant };\n"],"names":["BADGE_GLYPH_SIZE","collapseSpaces","value","nearMissAgainst","typed","phrase","COPY_FAILED_MESSAGE","resolvePhraseLabel","label","parts","copyStatusFor","outcome","usePhraseCopy","open","disabled","onCopied","canCopy","copy","useClipboardCopy","run","LabelText","children","jsx","Typography","PhraseField","plainLabel","placeholder","onChange","copyLabel","copyOutcome","onCopy","nearMissMessage","beforeId","useId","afterId","messageId","inputId","message","labelledBy","jsxs","Button","CheckmarkIcon","CopyIcon","Input","FieldMessage","VARIANT_ICON","InfoCircleFilled","WarningCircleFilled","ErrorCircleFilled","CheckCircleFilled","ConfirmationDialog","onClose","onConfirm","title","titleAdornment","badgeIcon","description","variant","callout","confirmPhrase","confirmPhraseLabel","confirmPhraseCopyLabel","onPhraseCopied","confirmPhrasePlaceholder","confirmLabel","cancelLabel","loading","tip","size","ariaLabel","ariaLabelledBy","typedPhrase","setTypedPhrase","useState","descriptionId","calloutId","base","CONFIRMATION_DIALOG_VARIANTS","answeredFor","setAnsweredFor","phraseParts","phraseLabel","canCopyPhrase","handleCopyPhrase","phraseSatisfied","confirmDisabled","hasChildren","Children","child","hasBody","describedBy","footer","Modal","IconBadge","CalloutStrip"],"mappings":";;;;;;;;;;;;;;;;;AAuBA,MAAMA,IAAmB,IAEnBC,IAAiB,CAACC,MAAkBA,EAAM,QAAQ,QAAQ,GAAG,GAE7DC,KAAkB,CAACC,GAAeC,MAAuC;AAC3E,MAAI,EAAAA,MAAW,MAAMD,MAAU,MAAMA,MAAUC,MAG3CJ,EAAeG,CAAK,EAAE,YAAA,MAAkBH,EAAeI,CAAM,EAAE;AAGnE,WAAOJ,EAAeG,CAAK,MAAMH,EAAeI,CAAM,IAChD,sCACA;AACV,GAIMC,KAAsB,8CAEtBC,KAAqB,CACvBC,GACAH,MACgE;AAChE,QAAMI,IAAQ,OAAOD,KAAU,YAAYA,MAAU,OAAOA,IAAQ;AACpE,SAAIC,IACO,EAAE,OAAAA,GAAO,MAAM,CAACA,EAAM,QAAQJ,GAAQI,EAAM,MAAM,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG,EAAA,IAEhF,EAAE,MAAM,OAAOD,KAAU,WAAWA,IAAQ,QAAQH,CAAM,cAAA;AACrE,GAEMK,KAAgB,CAACC,GAAsBN,MACzCM,MAAY,WAAW,GAAGN,CAAM,yBAAyB,IAEvDO,KAAgB,CAClBP,GACAQ,GACAC,GACAC,MAC+D;AAC/D,QAAM,EAAE,SAAAJ,GAAS,SAAAK,GAAS,MAAAC,MAASC,GAAiB,GAAGL,CAAI,IAAIR,CAAM,EAAE,GAEjEc,IAAM,YAAY;AACpB,IAAId,KAAW,MAAMY,EAAKZ,CAAM,KAC5B,eAAe,MAAMU,KAAA,gBAAAA,EAAWV,EAAO;AAAA,EAE/C;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;AAAA,QAACuE;AAAA,QAAA;AAAA,UACG,SAAApC;AAAA,UACA,MAAMF,KAAaV,GAAaY,CAAO;AAAA,QAAA;AAAA,MAAA;AAAA,MAI9C,UAAA;AAAA,QAAAC,IACG,gBAAApC;AAAA,UAACwE;AAAA,UAAA;AAAA,YACG,IAAInB;AAAA,YACJ,MAAMjB,EAAQ,QAAQkB,EAAK;AAAA,YAC3B,SAASlB,EAAQ;AAAA,YACjB,SAAS+B;AAAA,UAAA;AAAA,QAAA,IAEb;AAAA,QACHA,IACG,gBAAAlD,EAAC,OAAA,EAAI,WAAU,qCACV,UAAA;AAAA,UAAAiB,IACG,gBAAAlC;AAAA,YAAC;AAAA,YAAA;AAAA,cACG,IAAIoD;AAAA,cACJ,WAAU;AAAA,cAET,UAAAlB;AAAA,YAAA;AAAA,UAAA,IAEL;AAAA,UACHnC;AAAA,UACAsC,IACG,gBAAArC;AAAA,YAACE;AAAA,YAAA;AAAA,cACG,QAAQmC;AAAA,cACR,OAAOqB;AAAA,cACP,YAAYC;AAAA,cACZ,aAAalB;AAAA,cACb,OAAOQ;AAAA,cACP,UAAUC;AAAA,cACV,UAAUN;AAAA,cACV,WAAWL;AAAA,cACX,aAAAhC;AAAA,cACA,SAASqD;AAAA,cACT,QAAQC;AAAA,cACR,iBAAApD;AAAA,YAAA;AAAA,UAAA,IAEJ;AAAA,QAAA,EAAA,CACR,IACA;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGhB;"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const d = (e) => e.type !== "text" && e.type !== "divider" && e.checked !== void 0, l = (e) => d(e) && e.group ? e.group : void 0, r = (e) => {
|
|
2
|
+
const s = [];
|
|
3
|
+
return e.forEach((n) => {
|
|
4
|
+
const i = l(n), o = s[s.length - 1];
|
|
5
|
+
if (i === void 0)
|
|
6
|
+
s.push({ kind: "item", item: n, labelsNext: !1 });
|
|
7
|
+
else if ((o == null ? void 0 : o.kind) === "group" && o.name === i)
|
|
8
|
+
o.items.push(n);
|
|
9
|
+
else {
|
|
10
|
+
const t = (o == null ? void 0 : o.kind) === "item" ? o : void 0, c = (t == null ? void 0 : t.item.type) === "text" && t.item.label === i;
|
|
11
|
+
t && c && (t.labelsNext = !0), s.push({ kind: "group", name: i, items: [n], labelledByPrevious: c });
|
|
12
|
+
}
|
|
13
|
+
}), s;
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
r as groupChoices,
|
|
17
|
+
d as isChoiceItem
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=actionMenuGroups.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actionMenuGroups.js","sources":["../../src/components/actionMenuGroups.ts"],"sourcesContent":["import type { ActionMenuItem } from './actionMenuTypes';\n\ntype ChoiceItem = Extract<ActionMenuItem, { type?: 'item' }>;\n\nexport type ActionMenuEntry =\n | { kind: 'item'; item: ActionMenuItem; labelsNext: boolean }\n | { kind: 'group'; name: string; items: ActionMenuItem[]; labelledByPrevious: boolean };\n\nexport const isChoiceItem = (item: ActionMenuItem): item is ChoiceItem =>\n item.type !== 'text' && item.type !== 'divider' && item.checked !== undefined;\n\nconst groupOf = (item: ActionMenuItem): string | undefined =>\n isChoiceItem(item) && item.group ? item.group : undefined;\n\n/**\n * Consecutive choices that share a `group` become one entry, named by it; a text row just\n * before that says the same words names the group itself, so it is not read twice.\n */\nexport const groupChoices = (items: ActionMenuItem[]): ActionMenuEntry[] => {\n const entries: ActionMenuEntry[] = [];\n items.forEach((item) => {\n const name = groupOf(item);\n const last = entries[entries.length - 1];\n if (name === undefined) {\n entries.push({ kind: 'item', item, labelsNext: false });\n } else if (last?.kind === 'group' && last.name === name) {\n last.items.push(item);\n } else {\n const previous = last?.kind === 'item' ? last : undefined;\n const labelled = previous?.item.type === 'text' && previous.item.label === name;\n if (previous && labelled) {\n previous.labelsNext = true;\n }\n entries.push({ kind: 'group', name, items: [item], labelledByPrevious: labelled });\n }\n });\n return entries;\n};\n"],"names":["isChoiceItem","item","groupOf","groupChoices","items","entries","name","last","previous","labelled"],"mappings":"AAQO,MAAMA,IAAe,CAACC,MACzBA,EAAK,SAAS,UAAUA,EAAK,SAAS,aAAaA,EAAK,YAAY,QAElEC,IAAU,CAACD,MACbD,EAAaC,CAAI,KAAKA,EAAK,QAAQA,EAAK,QAAQ,QAMvCE,IAAe,CAACC,MAA+C;AACxE,QAAMC,IAA6B,CAAA;AACnC,SAAAD,EAAM,QAAQ,CAACH,MAAS;AACpB,UAAMK,IAAOJ,EAAQD,CAAI,GACnBM,IAAOF,EAAQA,EAAQ,SAAS,CAAC;AACvC,QAAIC,MAAS;AACT,MAAAD,EAAQ,KAAK,EAAE,MAAM,QAAQ,MAAAJ,GAAM,YAAY,IAAO;AAAA,cAC/CM,KAAA,gBAAAA,EAAM,UAAS,WAAWA,EAAK,SAASD;AAC/C,MAAAC,EAAK,MAAM,KAAKN,CAAI;AAAA,SACjB;AACH,YAAMO,KAAWD,KAAA,gBAAAA,EAAM,UAAS,SAASA,IAAO,QAC1CE,KAAWD,KAAA,gBAAAA,EAAU,KAAK,UAAS,UAAUA,EAAS,KAAK,UAAUF;AAC3E,MAAIE,KAAYC,MACZD,EAAS,aAAa,KAE1BH,EAAQ,KAAK,EAAE,MAAM,SAAS,MAAAC,GAAM,OAAO,CAACL,CAAI,GAAG,oBAAoBQ,EAAA,CAAU;AAAA,IACrF;AAAA,EACJ,CAAC,GACMJ;AACX;"}
|