@krelborn/stylesui 0.8.1 → 0.9.0
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/README.md +2 -2
- package/dist/accessibility/idSegment.js +1 -2
- package/dist/collections/index.d.ts +3 -0
- package/dist/collections/optionId.js +6 -0
- package/dist/{components/Listbox → collections}/renderedOptions.d.ts +7 -0
- package/dist/{components/Listbox → collections}/renderedOptions.js +6 -4
- package/dist/collections/targetIndexForKey.js +1 -2
- package/dist/collections/typeAhead.js +0 -1
- package/dist/components/Accordion/Accordion.css +1 -0
- package/dist/components/Accordion/Accordion.d.ts +90 -0
- package/dist/components/Accordion/Accordion.js +47 -0
- package/dist/components/Accordion/Accordion.module.js +19 -0
- package/dist/components/Accordion/AccordionContext.d.ts +40 -0
- package/dist/components/Accordion/AccordionContext.js +4 -0
- package/dist/components/Accordion/AccordionItem.d.ts +51 -0
- package/dist/components/Accordion/AccordionItem.js +69 -0
- package/dist/components/Accordion/AccordionToggleContent.d.ts +30 -0
- package/dist/components/Accordion/AccordionToggleContent.js +44 -0
- package/dist/components/Accordion/accordionIds.d.ts +24 -0
- package/dist/components/Accordion/accordionIds.js +12 -0
- package/dist/components/Accordion/index.d.ts +4 -0
- package/dist/components/Accordion/useAccordionContext.d.ts +9 -0
- package/dist/components/Accordion/useAccordionContext.js +10 -0
- package/dist/components/Accordion/useFindablePanel.d.ts +25 -0
- package/dist/components/Accordion/useFindablePanel.js +36 -0
- package/dist/components/Accordion/useFragmentTargetReveal.d.ts +27 -0
- package/dist/components/Accordion/useFragmentTargetReveal.js +36 -0
- package/dist/components/Accordion/useHasOpened.d.ts +7 -0
- package/dist/components/Accordion/useHasOpened.js +7 -0
- package/dist/components/Alert/Alert.js +1 -2
- package/dist/components/Alert/Alert.module.js +1 -2
- package/dist/components/Alert/AlertIcon.js +1 -2
- package/dist/components/Avatar/Avatar.js +1 -2
- package/dist/components/Avatar/Avatar.module.js +1 -2
- package/dist/components/Avatar/initialsOf.js +1 -2
- package/dist/components/AvatarGroup/AvatarGroup.js +1 -2
- package/dist/components/AvatarGroup/AvatarGroup.module.js +1 -2
- package/dist/components/Badge/Badge.js +1 -2
- package/dist/components/Badge/Badge.module.js +1 -2
- package/dist/components/Box/Box.js +1 -2
- package/dist/components/Box/Box.module.js +1 -2
- package/dist/components/Button/Button.js +2 -7
- package/dist/components/Button/Button.module.js +1 -2
- package/dist/components/Card/Card.js +1 -2
- package/dist/components/Card/Card.module.js +1 -2
- package/dist/components/Center/Center.js +6 -7
- package/dist/components/Center/Center.module.js +1 -2
- package/dist/components/Checkbox/Checkbox.js +1 -2
- package/dist/components/ChoiceControl/ChoiceControl.js +1 -2
- package/dist/components/ChoiceControl/ChoiceControl.module.js +1 -2
- package/dist/components/Cluster/Cluster.js +1 -2
- package/dist/components/Code/Code.js +1 -2
- package/dist/components/Code/Code.module.js +1 -2
- package/dist/components/Combobox/Autocomplete.d.ts +83 -0
- package/dist/components/Combobox/Autocomplete.js +102 -0
- package/dist/components/Combobox/Combobox.css +1 -0
- package/dist/components/Combobox/Combobox.d.ts +59 -0
- package/dist/components/Combobox/Combobox.js +82 -0
- package/dist/components/Combobox/Combobox.module.js +17 -0
- package/dist/components/Combobox/ComboboxContext.d.ts +88 -0
- package/dist/components/Combobox/ComboboxContext.js +4 -0
- package/dist/components/Combobox/ComboboxFieldValue.d.ts +17 -0
- package/dist/components/Combobox/ComboboxFieldValue.js +33 -0
- package/dist/components/Combobox/ComboboxOption.d.ts +51 -0
- package/dist/components/Combobox/ComboboxOption.js +74 -0
- package/dist/components/Combobox/ComboboxOptionContent.d.ts +32 -0
- package/dist/components/Combobox/ComboboxOptionContent.js +51 -0
- package/dist/components/Combobox/ComboboxPopup.d.ts +50 -0
- package/dist/components/Combobox/ComboboxPopup.js +59 -0
- package/dist/components/Combobox/autocompleteKeys.d.ts +31 -0
- package/dist/components/Combobox/autocompleteKeys.js +25 -0
- package/dist/components/Combobox/comboboxKeys.d.ts +10 -0
- package/dist/components/Combobox/comboboxKeys.js +22 -0
- package/dist/components/Combobox/containsText.d.ts +9 -0
- package/dist/components/Combobox/containsText.js +8 -0
- package/dist/components/Combobox/index.d.ts +6 -0
- package/dist/components/Combobox/isAltArrow.d.ts +9 -0
- package/dist/components/Combobox/isAltArrow.js +5 -0
- package/dist/components/Combobox/isOptionShown.d.ts +10 -0
- package/dist/components/Combobox/isOptionShown.js +5 -0
- package/dist/components/Combobox/useAutocompleteText.d.ts +56 -0
- package/dist/components/Combobox/useAutocompleteText.js +27 -0
- package/dist/components/Combobox/useComboboxContext.d.ts +9 -0
- package/dist/components/Combobox/useComboboxContext.js +10 -0
- package/dist/components/Combobox/useComboboxList.d.ts +129 -0
- package/dist/components/Combobox/useComboboxList.js +138 -0
- package/dist/components/Combobox/useComboboxOption.d.ts +35 -0
- package/dist/components/Combobox/useComboboxOption.js +46 -0
- package/dist/components/Combobox/useComboboxSelection.d.ts +45 -0
- package/dist/components/Combobox/useComboboxSelection.js +17 -0
- package/dist/components/Combobox/useResultsAnnouncement.d.ts +23 -0
- package/dist/components/Combobox/useResultsAnnouncement.js +24 -0
- package/dist/components/ContextMenu/index.d.ts +2 -0
- package/dist/components/ContextMenu/useContextMenu.d.ts +112 -0
- package/dist/components/ContextMenu/useContextMenu.js +202 -0
- package/dist/components/ContextMenu/watchLongPress.d.ts +35 -0
- package/dist/components/ContextMenu/watchLongPress.js +38 -0
- package/dist/components/Counter/Counter.js +5 -6
- package/dist/components/Counter/Counter.module.js +1 -2
- package/dist/components/Cover/Cover.js +8 -9
- package/dist/components/Cover/Cover.module.js +1 -2
- package/dist/components/Divider/Divider.js +1 -2
- package/dist/components/Divider/Divider.module.js +1 -2
- package/dist/components/Field/Field.js +11 -10
- package/dist/components/Field/Field.module.js +1 -2
- package/dist/components/Fieldset/Fieldset.js +1 -2
- package/dist/components/Fieldset/Fieldset.module.js +1 -2
- package/dist/components/Frame/Frame.js +5 -6
- package/dist/components/Frame/Frame.module.js +1 -2
- package/dist/components/Grid/Grid.js +9 -10
- package/dist/components/Grid/Grid.module.js +1 -2
- package/dist/components/Heading/Heading.js +1 -2
- package/dist/components/Heading/Heading.module.js +1 -2
- package/dist/components/HorizontalFlow/HorizontalFlow.js +6 -7
- package/dist/components/HorizontalFlow/HorizontalFlow.module.js +1 -2
- package/dist/components/Icon/AddIcon.js +1 -2
- package/dist/components/Icon/CheckIcon.d.ts +11 -0
- package/dist/components/Icon/CheckIcon.js +18 -0
- package/dist/components/Icon/ChevronDownIcon.js +1 -2
- package/dist/components/Icon/ChevronRightIcon.d.ts +11 -0
- package/dist/components/Icon/ChevronRightIcon.js +19 -0
- package/dist/components/Icon/CloseIcon.js +1 -2
- package/dist/components/Icon/ColorModeIcon.js +1 -2
- package/dist/components/Icon/DeleteIcon.js +1 -2
- package/dist/components/Icon/Icon.js +1 -2
- package/dist/components/Icon/Icon.module.js +1 -2
- package/dist/components/Icon/InfoIcon.js +1 -2
- package/dist/components/Icon/MenuIcon.d.ts +12 -0
- package/dist/components/Icon/MenuIcon.js +28 -0
- package/dist/components/Icon/MoreHorizontalIcon.js +1 -2
- package/dist/components/Icon/MoreVerticalIcon.js +1 -2
- package/dist/components/Icon/PaletteIcon.js +1 -2
- package/dist/components/Icon/RefreshIcon.js +1 -2
- package/dist/components/Icon/RemoveIcon.js +1 -2
- package/dist/components/Icon/SendIcon.js +1 -2
- package/dist/components/Icon/index.d.ts +3 -0
- package/dist/components/IconButton/IconButton.js +1 -2
- package/dist/components/IconButton/IconButton.module.js +1 -2
- package/dist/components/Kbd/Kbd.js +1 -2
- package/dist/components/Kbd/Kbd.module.js +1 -2
- package/dist/components/Link/Link.js +1 -2
- package/dist/components/Link/Link.module.js +1 -2
- package/dist/components/Listbox/Listbox.js +9 -10
- package/dist/components/Listbox/Listbox.module.js +1 -2
- package/dist/components/Listbox/ListboxContext.js +1 -2
- package/dist/components/Listbox/ListboxOption.js +7 -8
- package/dist/components/Listbox/useListbox.js +22 -23
- package/dist/components/Listbox/useListboxContext.js +1 -2
- package/dist/components/Menu/Menu.d.ts +70 -0
- package/dist/components/Menu/Menu.js +76 -0
- package/dist/components/Menu/MenuContext.d.ts +29 -0
- package/dist/components/Menu/MenuContext.js +4 -0
- package/dist/components/Menu/MenuGroup.d.ts +22 -0
- package/dist/components/Menu/MenuGroup.js +32 -0
- package/dist/components/Menu/MenuItem.d.ts +77 -0
- package/dist/components/Menu/MenuItem.js +54 -0
- package/dist/components/Menu/MenuItemCheckbox.d.ts +61 -0
- package/dist/components/Menu/MenuItemCheckbox.js +37 -0
- package/dist/components/Menu/MenuItemRadio.d.ts +47 -0
- package/dist/components/Menu/MenuItemRadio.js +39 -0
- package/dist/components/Menu/MenuRadioGroup.d.ts +34 -0
- package/dist/components/Menu/MenuRadioGroup.js +27 -0
- package/dist/components/Menu/MenuRadioGroupContext.d.ts +17 -0
- package/dist/components/Menu/MenuRadioGroupContext.js +4 -0
- package/dist/components/Menu/MenuSeparator.d.ts +16 -0
- package/dist/components/Menu/MenuSeparator.js +20 -0
- package/dist/components/Menu/Submenu.d.ts +36 -0
- package/dist/components/Menu/Submenu.js +122 -0
- package/dist/components/Menu/index.d.ts +18 -0
- package/dist/components/Menu/useMenu.d.ts +18 -0
- package/dist/components/Menu/useMenu.js +20 -0
- package/dist/components/Menu/useMenuButton.d.ts +124 -0
- package/dist/components/Menu/useMenuButton.js +92 -0
- package/dist/components/Menu/useMenuContext.d.ts +9 -0
- package/dist/components/Menu/useMenuContext.js +10 -0
- package/dist/components/Menu/useMenuItemContent.d.ts +55 -0
- package/dist/components/Menu/useMenuItemContent.js +66 -0
- package/dist/components/Menu/useMenuPointer.d.ts +27 -0
- package/dist/components/Menu/useMenuPointer.js +56 -0
- package/dist/components/Menu/useMenuRadioGroupContext.d.ts +9 -0
- package/dist/components/Menu/useMenuRadioGroupContext.js +10 -0
- package/dist/components/MenuSurface/MenuSurface.css +1 -0
- package/dist/components/MenuSurface/MenuSurface.module.js +16 -0
- package/dist/components/Menubar/Menubar.css +1 -0
- package/dist/components/Menubar/Menubar.d.ts +23 -0
- package/dist/components/Menubar/Menubar.js +67 -0
- package/dist/components/Menubar/Menubar.module.js +7 -0
- package/dist/components/Menubar/MenubarContext.d.ts +29 -0
- package/dist/components/Menubar/MenubarContext.js +4 -0
- package/dist/components/Menubar/MenubarMenu.d.ts +26 -0
- package/dist/components/Menubar/MenubarMenu.js +88 -0
- package/dist/components/Menubar/findOpenMenubarItem.d.ts +7 -0
- package/dist/components/Menubar/findOpenMenubarItem.js +6 -0
- package/dist/components/Menubar/index.d.ts +4 -0
- package/dist/components/Menubar/menubarItems.d.ts +7 -0
- package/dist/components/Menubar/menubarItems.js +5 -0
- package/dist/components/Menubar/useMenubarContext.d.ts +9 -0
- package/dist/components/Menubar/useMenubarContext.js +10 -0
- package/dist/components/NavBar/NavBar.css +1 -0
- package/dist/components/NavBar/NavBar.d.ts +53 -0
- package/dist/components/NavBar/NavBar.js +97 -0
- package/dist/components/NavBar/NavBar.module.js +22 -0
- package/dist/components/NavBar/NavBarContext.d.ts +21 -0
- package/dist/components/NavBar/NavBarContext.js +4 -0
- package/dist/components/NavBar/NavBarItem.d.ts +32 -0
- package/dist/components/NavBar/NavBarItem.js +18 -0
- package/dist/components/NavBar/NavBarMenu.d.ts +32 -0
- package/dist/components/NavBar/NavBarMenu.js +84 -0
- package/dist/components/NavBar/NavBarMenuGroup.d.ts +25 -0
- package/dist/components/NavBar/NavBarMenuGroup.js +40 -0
- package/dist/components/NavBar/NavBarMenuItem.d.ts +36 -0
- package/dist/components/NavBar/NavBarMenuItem.js +49 -0
- package/dist/components/NavBar/index.d.ts +10 -0
- package/dist/components/NavBar/isNavBarCollapsed.d.ts +8 -0
- package/dist/components/NavBar/isNavBarCollapsed.js +5 -0
- package/dist/components/NavBar/leavesPageInPlace.d.ts +12 -0
- package/dist/components/NavBar/leavesPageInPlace.js +29 -0
- package/dist/components/NavBar/renderNavBarLink.d.ts +12 -0
- package/dist/components/NavBar/renderNavBarLink.js +16 -0
- package/dist/components/NavBar/useLayoutSwitch.d.ts +26 -0
- package/dist/components/NavBar/useLayoutSwitch.js +25 -0
- package/dist/components/NavBar/useNavBarContext.d.ts +9 -0
- package/dist/components/NavBar/useNavBarContext.js +10 -0
- package/dist/components/NavList/NavList.js +1 -2
- package/dist/components/NavList/NavList.module.js +1 -2
- package/dist/components/NavList/NavListGroup.js +1 -2
- package/dist/components/NavList/NavListItem.d.ts +4 -8
- package/dist/components/NavList/NavListItem.js +1 -2
- package/dist/components/Overlay/Overlay.js +6 -7
- package/dist/components/Overlay/Overlay.module.js +1 -2
- package/dist/components/PageLayout/PageLayout.js +6 -7
- package/dist/components/PageLayout/PageLayout.module.js +1 -2
- package/dist/components/Popover/Popover.js +1 -2
- package/dist/components/Popover/Popover.module.js +1 -2
- package/dist/components/Popover/usePopover.js +44 -39
- package/dist/components/Prose/Prose.js +1 -2
- package/dist/components/Prose/Prose.module.js +1 -2
- package/dist/components/Radio/Radio.js +1 -2
- package/dist/components/RadioGroup/RadioGroup.js +5 -6
- package/dist/components/RadioGroup/RadioGroup.module.js +1 -2
- package/dist/components/RequiredIndicator/RequiredIndicator.js +1 -2
- package/dist/components/RequiredIndicator/RequiredIndicator.module.js +1 -2
- package/dist/components/Row/Row.js +1 -2
- package/dist/components/SegmentedControl/Segment.js +1 -2
- package/dist/components/SegmentedControl/SegmentedControl.js +1 -2
- package/dist/components/SegmentedControl/SegmentedControl.module.js +1 -2
- package/dist/components/Select/Select.js +1 -2
- package/dist/components/Sidebar/Sidebar.js +7 -8
- package/dist/components/Sidebar/Sidebar.module.js +1 -2
- package/dist/components/SkipLink/SkipLink.js +1 -2
- package/dist/components/SkipLink/SkipLink.module.js +1 -2
- package/dist/components/Spinner/Spinner.js +1 -2
- package/dist/components/Spinner/Spinner.module.js +1 -2
- package/dist/components/Stack/Stack.js +8 -9
- package/dist/components/Stack/Stack.module.js +1 -2
- package/dist/components/StatusDot/StatusDot.js +1 -2
- package/dist/components/StatusDot/StatusDot.module.js +1 -2
- package/dist/components/Switch/Switch.js +1 -2
- package/dist/components/Switcher/Switcher.js +9 -10
- package/dist/components/Switcher/Switcher.module.js +1 -2
- package/dist/components/Tabs/Tab.js +12 -13
- package/dist/components/Tabs/TabList.js +1 -2
- package/dist/components/Tabs/TabPanel.js +1 -2
- package/dist/components/Tabs/Tabs.js +1 -2
- package/dist/components/Tabs/Tabs.module.js +1 -2
- package/dist/components/Tabs/TabsContext.js +1 -2
- package/dist/components/Tabs/tabIds.js +1 -2
- package/dist/components/Tabs/useTabsContext.js +1 -2
- package/dist/components/Text/Text.js +1 -2
- package/dist/components/Text/Text.module.js +1 -2
- package/dist/components/TextControl/TextControl.d.ts +3 -3
- package/dist/components/TextControl/TextControl.js +14 -10
- package/dist/components/TextControl/TextControl.module.js +1 -2
- package/dist/components/TextInput/TextInput.js +1 -2
- package/dist/components/Textarea/Textarea.js +1 -2
- package/dist/components/Theme/Theme.js +1 -2
- package/dist/components/Tooltip/Tooltip.js +1 -2
- package/dist/components/Tooltip/Tooltip.module.js +1 -2
- package/dist/components/Tooltip/tooltipCoordinator.js +1 -2
- package/dist/components/Tooltip/useTooltip.js +1 -2
- package/dist/components/VisuallyHidden/VisuallyHidden.js +1 -2
- package/dist/components/VisuallyHidden/VisuallyHidden.module.js +1 -2
- package/dist/errors/MissingContextError.js +1 -2
- package/dist/errors/PopoverRefusedError.js +1 -2
- package/dist/forms/FieldContext.d.ts +5 -0
- package/dist/forms/FieldContext.js +1 -2
- package/dist/forms/RadioGroupContext.js +1 -2
- package/dist/forms/hasContent.js +1 -2
- package/dist/forms/useFieldControl.js +1 -2
- package/dist/forms/useRadioGroupItem.js +1 -2
- package/dist/index.d.ts +13 -1
- package/dist/index.js +90 -65
- package/dist/layout/listRole.js +1 -2
- package/dist/layout/spaceValue.js +1 -2
- package/dist/layout/withCustomProperties.js +1 -2
- package/dist/links/LinkOrButtonProps.d.ts +17 -0
- package/dist/links/index.d.ts +1 -0
- package/dist/menus/closeWhenFocusLeaves.d.ts +9 -0
- package/dist/menus/closeWhenFocusLeaves.js +11 -0
- package/dist/menus/focusItem.d.ts +6 -0
- package/dist/menus/focusItem.js +9 -0
- package/dist/menus/focusOnOpening.d.ts +11 -0
- package/dist/menus/focusOnOpening.js +11 -0
- package/dist/menus/hasModifier.d.ts +7 -0
- package/dist/menus/hasModifier.js +5 -0
- package/dist/menus/index.d.ts +11 -0
- package/dist/menus/itemText.d.ts +8 -0
- package/dist/menus/itemText.js +6 -0
- package/dist/menus/leaveMenuOnTab.d.ts +9 -0
- package/dist/menus/leaveMenuOnTab.js +6 -0
- package/dist/menus/pointerIntent.d.ts +36 -0
- package/dist/menus/pointerIntent.js +68 -0
- package/dist/menus/renderedItems.d.ts +8 -0
- package/dist/menus/renderedItems.js +4 -0
- package/dist/menus/watchRemovals.d.ts +8 -0
- package/dist/menus/watchRemovals.js +23 -0
- package/dist/overlays/anchorNameFor.js +1 -2
- package/dist/overlays/mergeProps.js +1 -2
- package/dist/overlays/syncPopover.js +1 -2
- package/dist/overlays/useOverlay.js +2 -9
- package/package.json +10 -10
- package/dist/components/Listbox/optionId.js +0 -7
- /package/dist/{components/Listbox → collections}/optionId.d.ts +0 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { JSX, ReactNode } from "react";
|
|
2
|
+
import type { MenuGroupProps } from "./MenuGroup";
|
|
3
|
+
/**
|
|
4
|
+
* Props for `MenuRadioGroup`: its label and selection plus every `MenuGroup` prop
|
|
5
|
+
*/
|
|
6
|
+
export interface MenuRadioGroupProps extends Omit<MenuGroupProps, "defaultValue" | "label" | "onChange"> {
|
|
7
|
+
/**
|
|
8
|
+
* The value of the item checked at first when uncontrolled
|
|
9
|
+
*/
|
|
10
|
+
defaultValue?: string;
|
|
11
|
+
/**
|
|
12
|
+
* A heading shown above the group's items, which names the group
|
|
13
|
+
*/
|
|
14
|
+
label: ReactNode;
|
|
15
|
+
/**
|
|
16
|
+
* Called with the value of the item the user checks, when it differs from the checked one
|
|
17
|
+
*/
|
|
18
|
+
onValueChange?: (value: string) => void;
|
|
19
|
+
/**
|
|
20
|
+
* Controls which item is checked. Without it, the group holds its own choice, starting from `defaultValue`.
|
|
21
|
+
*/
|
|
22
|
+
value?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A named group of `MenuItemRadio`s in a `Menu`, of which one is checked, such as a sort order. A click or Enter
|
|
26
|
+
* checks an item and closes every open menu; Space checks it and leaves them open.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* <MenuRadioGroup label="Sort by" onValueChange={setSortOrder} value={sortOrder}>
|
|
30
|
+
* <MenuItemRadio value="name">Name</MenuItemRadio>
|
|
31
|
+
* <MenuItemRadio value="modified">Date modified</MenuItemRadio>
|
|
32
|
+
* </MenuRadioGroup>
|
|
33
|
+
*/
|
|
34
|
+
export declare function MenuRadioGroup({ defaultValue, onValueChange, value, ...rest }: MenuRadioGroupProps): JSX.Element;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { MenuGroup as e } from "./MenuGroup.js";
|
|
2
|
+
import { MenuRadioGroupContext as t } from "./MenuRadioGroupContext.js";
|
|
3
|
+
import { useState as n } from "react";
|
|
4
|
+
import { c as r } from "react/compiler-runtime";
|
|
5
|
+
import { jsx as i } from "react/jsx-runtime";
|
|
6
|
+
// src/components/Menu/MenuRadioGroup.tsx
|
|
7
|
+
function a(a) {
|
|
8
|
+
let o = r(17), s, c, l, u;
|
|
9
|
+
o[0] === a ? (s = o[1], c = o[2], l = o[3], u = o[4]) : ({defaultValue: s, onValueChange: c, value: u, ...l} = a, o[0] = a, o[1] = s, o[2] = c, o[3] = l, o[4] = u);
|
|
10
|
+
let [d, f] = n(s), p = u ?? d, m;
|
|
11
|
+
o[5] !== p || o[6] !== c || o[7] !== u ? (m = function(e) {
|
|
12
|
+
e !== p && (u === void 0 && f(e), c?.(e));
|
|
13
|
+
}, o[5] = p, o[6] = c, o[7] = u, o[8] = m) : m = o[8];
|
|
14
|
+
let h = m, g;
|
|
15
|
+
o[9] !== p || o[10] !== h ? (g = {
|
|
16
|
+
select: h,
|
|
17
|
+
value: p
|
|
18
|
+
}, o[9] = p, o[10] = h, o[11] = g) : g = o[11];
|
|
19
|
+
let _;
|
|
20
|
+
o[12] === l ? _ = o[13] : (_ = /* @__PURE__ */ i(e, { ...l }), o[12] = l, o[13] = _);
|
|
21
|
+
let v;
|
|
22
|
+
return o[14] !== g || o[15] !== _ ? (v = /* @__PURE__ */ i(t.Provider, {
|
|
23
|
+
value: g,
|
|
24
|
+
children: _
|
|
25
|
+
}), o[14] = g, o[15] = _, o[16] = v) : v = o[16], v;
|
|
26
|
+
}
|
|
27
|
+
export { a as MenuRadioGroup };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* State a `MenuRadioGroup` shares with its radio items
|
|
3
|
+
*/
|
|
4
|
+
export interface MenuRadioGroupContextValue {
|
|
5
|
+
/**
|
|
6
|
+
* Checks the item with the given value, reporting it to `onValueChange` when it differs from the checked one
|
|
7
|
+
*/
|
|
8
|
+
select: (value: string) => void;
|
|
9
|
+
/**
|
|
10
|
+
* The checked item's value, if any
|
|
11
|
+
*/
|
|
12
|
+
value: string | undefined;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Carries a `MenuRadioGroup`'s state to its radio items; null outside a `MenuRadioGroup`
|
|
16
|
+
*/
|
|
17
|
+
export declare const MenuRadioGroupContext: import("react").Context<MenuRadioGroupContextValue | null>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { JSX } from "react";
|
|
2
|
+
import type { BoxProps } from "../Box";
|
|
3
|
+
/**
|
|
4
|
+
* Props for `MenuSeparator`: every `hr` prop except children
|
|
5
|
+
*/
|
|
6
|
+
export interface MenuSeparatorProps extends Omit<BoxProps<"hr">, "as" | "children" | "dangerouslySetInnerHTML"> {
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* A rule across a `Menu` between groups of items. The arrow keys pass over it.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* <MenuItem onClick={archive}>Archive</MenuItem>
|
|
13
|
+
* <MenuSeparator />
|
|
14
|
+
* <MenuItem onClick={remove} tone="danger">Delete…</MenuItem>
|
|
15
|
+
*/
|
|
16
|
+
export declare function MenuSeparator({ className, ...rest }: MenuSeparatorProps): JSX.Element;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Box as e } from "../Box/Box.js";
|
|
2
|
+
import t from "../MenuSurface/MenuSurface.module.js";
|
|
3
|
+
import { useMenuContext as n } from "./useMenuContext.js";
|
|
4
|
+
import { clsx as r } from "clsx";
|
|
5
|
+
import { c as i } from "react/compiler-runtime";
|
|
6
|
+
import { jsx as a } from "react/jsx-runtime";
|
|
7
|
+
// src/components/Menu/MenuSeparator.tsx
|
|
8
|
+
function o(o) {
|
|
9
|
+
let s = i(8), c, l;
|
|
10
|
+
s[0] === o ? (c = s[1], l = s[2]) : ({className: c, ...l} = o, s[0] = o, s[1] = c, s[2] = l), n("MenuSeparator");
|
|
11
|
+
let u;
|
|
12
|
+
s[3] === c ? u = s[4] : (u = r(t.separator, c), s[3] = c, s[4] = u);
|
|
13
|
+
let d;
|
|
14
|
+
return s[5] !== l || s[6] !== u ? (d = /* @__PURE__ */ a(e, {
|
|
15
|
+
...l,
|
|
16
|
+
as: "hr",
|
|
17
|
+
className: u
|
|
18
|
+
}), s[5] = l, s[6] = u, s[7] = d) : d = s[7], d;
|
|
19
|
+
}
|
|
20
|
+
export { o as MenuSeparator };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { JSX, ReactNode } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Props for `Submenu`
|
|
4
|
+
*/
|
|
5
|
+
export interface SubmenuProps {
|
|
6
|
+
/**
|
|
7
|
+
* The submenu's items
|
|
8
|
+
*/
|
|
9
|
+
children?: ReactNode;
|
|
10
|
+
/**
|
|
11
|
+
* Whether the submenu cannot be opened. Its item stays reachable with the arrow keys, so its label is read. Defaults
|
|
12
|
+
* to `false`.
|
|
13
|
+
*/
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* An icon before the label, hidden from assistive technology
|
|
17
|
+
*/
|
|
18
|
+
icon?: ReactNode;
|
|
19
|
+
/**
|
|
20
|
+
* The label of the item that opens the submenu, which names both
|
|
21
|
+
*/
|
|
22
|
+
label: ReactNode;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* An item in a `Menu` that opens another menu beside it, such as "Move to" opening a list of folders. Right Arrow
|
|
26
|
+
* (Left Arrow in right-to-left text), Enter or Space opens it on its first item, and a click opens it with focus left
|
|
27
|
+
* on its item. Left Arrow (Right Arrow in right-to-left text) or Escape closes it and returns focus to its item.
|
|
28
|
+
* Choosing an item inside closes every open menu. Its items are any menu parts, including another `Submenu`.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* <Submenu label="Move to">
|
|
32
|
+
* <MenuItem onClick={() => move("inbox")}>Inbox</MenuItem>
|
|
33
|
+
* <MenuItem onClick={() => move("projects")}>Projects</MenuItem>
|
|
34
|
+
* </Submenu>
|
|
35
|
+
*/
|
|
36
|
+
export declare function Submenu({ children, disabled, icon, label }: SubmenuProps): JSX.Element;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { focusItem as e } from "../../menus/focusItem.js";
|
|
2
|
+
import { hasModifier as t } from "../../menus/hasModifier.js";
|
|
3
|
+
import { renderedItems as n } from "../../menus/renderedItems.js";
|
|
4
|
+
import { anchorNameFor as r } from "../../overlays/anchorNameFor.js";
|
|
5
|
+
import { Box as i } from "../Box/Box.js";
|
|
6
|
+
import { ChevronRightIcon as a } from "../Icon/ChevronRightIcon.js";
|
|
7
|
+
import o from "../MenuSurface/MenuSurface.module.js";
|
|
8
|
+
import { Menu as s } from "./Menu.js";
|
|
9
|
+
import { useMenuContext as c } from "./useMenuContext.js";
|
|
10
|
+
import { useMenuItemContent as l } from "./useMenuItemContent.js";
|
|
11
|
+
import { useEffect as u, useId as d, useRef as f, useState as p } from "react";
|
|
12
|
+
import { jsx as m, jsxs as h } from "react/jsx-runtime";
|
|
13
|
+
// src/components/Menu/Submenu.tsx
|
|
14
|
+
var g = 100;
|
|
15
|
+
function _({ children: e, disabled: n = !1, icon: _, label: S }) {
|
|
16
|
+
let C = c("Submenu"), w = d(), T = d(), E = r(T), [D, O] = p(!1), k = f(!1), A = f(void 0), j = l({
|
|
17
|
+
describedBy: void 0,
|
|
18
|
+
description: void 0,
|
|
19
|
+
label: S,
|
|
20
|
+
leading: _,
|
|
21
|
+
trailing: /* @__PURE__ */ m(a, {})
|
|
22
|
+
});
|
|
23
|
+
u(() => () => clearTimeout(A.current), []), n && D && O(!1);
|
|
24
|
+
function M(e, t) {
|
|
25
|
+
let r = e.getElementById(T);
|
|
26
|
+
n || r === null || (D && t && y(r), k.current = t, O(!0));
|
|
27
|
+
}
|
|
28
|
+
function N(e) {
|
|
29
|
+
M(e.currentTarget.ownerDocument, e.detail === 0);
|
|
30
|
+
}
|
|
31
|
+
function P(e) {
|
|
32
|
+
let t = e.currentTarget.ownerDocument;
|
|
33
|
+
e.pointerType !== "touch" && !D && A.current === void 0 && (A.current = setTimeout(() => {
|
|
34
|
+
A.current = void 0, M(t, !1);
|
|
35
|
+
}, g));
|
|
36
|
+
}
|
|
37
|
+
function F(e) {
|
|
38
|
+
let t = e.currentTarget.ownerDocument.getElementById(T);
|
|
39
|
+
V(), D && t !== null && C.startPointerGrace({
|
|
40
|
+
x: e.clientX,
|
|
41
|
+
y: e.clientY
|
|
42
|
+
}, t);
|
|
43
|
+
}
|
|
44
|
+
function I(e) {
|
|
45
|
+
e.key === b(e.currentTarget) && !t(e) && (e.preventDefault(), M(e.currentTarget.ownerDocument, !0));
|
|
46
|
+
}
|
|
47
|
+
function L(e) {
|
|
48
|
+
e.defaultPrevented || e.key !== x(e.currentTarget) || t(e) || (e.preventDefault(), O(!1), e.currentTarget.ownerDocument.getElementById(w)?.focus());
|
|
49
|
+
}
|
|
50
|
+
function R(e) {
|
|
51
|
+
v(e);
|
|
52
|
+
}
|
|
53
|
+
function z(e) {
|
|
54
|
+
let t = e.currentTarget;
|
|
55
|
+
v(e), e.target === t && (e.newState === "open" ? (O(!0), k.current && y(t)) : (O(!1), H(t)), k.current = !1);
|
|
56
|
+
}
|
|
57
|
+
function B(e) {
|
|
58
|
+
let t = e.relatedTarget;
|
|
59
|
+
t !== null && e.currentTarget.contains(t) || V(), t !== null && !e.currentTarget.contains(t) && O(!1);
|
|
60
|
+
}
|
|
61
|
+
function V() {
|
|
62
|
+
clearTimeout(A.current), A.current = void 0;
|
|
63
|
+
}
|
|
64
|
+
function H(e) {
|
|
65
|
+
let t = e.ownerDocument, n = t.getElementById(w), r = t.activeElement, i = r === null || r === t.body || e.contains(r);
|
|
66
|
+
n?.closest("[role=\"menu\"]")?.matches(":popover-open") === !0 && i && n.focus();
|
|
67
|
+
}
|
|
68
|
+
return /* @__PURE__ */ h(i, {
|
|
69
|
+
className: o.submenu,
|
|
70
|
+
onBlur: B,
|
|
71
|
+
role: "none",
|
|
72
|
+
children: [/* @__PURE__ */ m(i, {
|
|
73
|
+
as: "button",
|
|
74
|
+
className: o.item,
|
|
75
|
+
id: w,
|
|
76
|
+
onClick: N,
|
|
77
|
+
onKeyDown: I,
|
|
78
|
+
onPointerLeave: F,
|
|
79
|
+
onPointerMove: P,
|
|
80
|
+
popoverTarget: n ? void 0 : T,
|
|
81
|
+
popoverTargetAction: "show",
|
|
82
|
+
role: "menuitem",
|
|
83
|
+
style: { anchorName: E },
|
|
84
|
+
tabIndex: -1,
|
|
85
|
+
type: "button",
|
|
86
|
+
"aria-controls": T,
|
|
87
|
+
"aria-disabled": n ? !0 : void 0,
|
|
88
|
+
"aria-expanded": D,
|
|
89
|
+
"aria-haspopup": "menu",
|
|
90
|
+
"aria-labelledby": j.labelId,
|
|
91
|
+
"data-leading": j.hasLeading ? !0 : void 0,
|
|
92
|
+
children: j.content
|
|
93
|
+
}), /* @__PURE__ */ m(s, {
|
|
94
|
+
anchorName: E,
|
|
95
|
+
className: o.submenuMenu,
|
|
96
|
+
close: C.closeAll,
|
|
97
|
+
density: C.density,
|
|
98
|
+
id: T,
|
|
99
|
+
onBeforeToggle: R,
|
|
100
|
+
onKeyDown: L,
|
|
101
|
+
onToggle: z,
|
|
102
|
+
open: D,
|
|
103
|
+
placement: "end",
|
|
104
|
+
"aria-labelledby": j.labelId,
|
|
105
|
+
children: e
|
|
106
|
+
})]
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
function v(e) {
|
|
110
|
+
e.stopPropagation();
|
|
111
|
+
}
|
|
112
|
+
function y(t) {
|
|
113
|
+
let r = n(t).at(0);
|
|
114
|
+
r === void 0 ? t.focus() : e(r);
|
|
115
|
+
}
|
|
116
|
+
function b(e) {
|
|
117
|
+
return e.matches(":dir(rtl)") ? "ArrowLeft" : "ArrowRight";
|
|
118
|
+
}
|
|
119
|
+
function x(e) {
|
|
120
|
+
return e.matches(":dir(rtl)") ? "ArrowRight" : "ArrowLeft";
|
|
121
|
+
}
|
|
122
|
+
export { _ as Submenu };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { Menu } from "./Menu";
|
|
2
|
+
export type { MenuDensity, MenuOverlayProps, MenuProps } from "./Menu";
|
|
3
|
+
export { MenuGroup } from "./MenuGroup";
|
|
4
|
+
export type { MenuGroupProps } from "./MenuGroup";
|
|
5
|
+
export { MenuItem } from "./MenuItem";
|
|
6
|
+
export type { MenuItemElement, MenuItemProps } from "./MenuItem";
|
|
7
|
+
export { MenuItemCheckbox } from "./MenuItemCheckbox";
|
|
8
|
+
export type { MenuItemCheckboxProps } from "./MenuItemCheckbox";
|
|
9
|
+
export { MenuItemRadio } from "./MenuItemRadio";
|
|
10
|
+
export type { MenuItemRadioProps } from "./MenuItemRadio";
|
|
11
|
+
export { MenuRadioGroup } from "./MenuRadioGroup";
|
|
12
|
+
export type { MenuRadioGroupProps } from "./MenuRadioGroup";
|
|
13
|
+
export { MenuSeparator } from "./MenuSeparator";
|
|
14
|
+
export type { MenuSeparatorProps } from "./MenuSeparator";
|
|
15
|
+
export { Submenu } from "./Submenu";
|
|
16
|
+
export type { SubmenuProps } from "./Submenu";
|
|
17
|
+
export { useMenu } from "./useMenu";
|
|
18
|
+
export type { UseMenuOptions, UseMenuResult } from "./useMenu";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { UseMenuOptions, UseMenuResult } from "./useMenuButton";
|
|
2
|
+
export type { UseMenuOptions, UseMenuResult } from "./useMenuButton";
|
|
3
|
+
/**
|
|
4
|
+
* Connects a `Menu` to the button that opens it. Clicking the button toggles the menu, and Escape or a click outside
|
|
5
|
+
* closes it, all handled by the browser. Opened from the keyboard, or by a controlled `open`, focus moves to the first
|
|
6
|
+
* item; opened with a pointer, to the menu itself, so no item is highlighted under a pointer still on the button.
|
|
7
|
+
* Closing the menu with focus inside returns focus to the button.
|
|
8
|
+
*
|
|
9
|
+
* @param options open state, the change callback and placement
|
|
10
|
+
* @returns prop getters for the trigger and the `Menu`, whether it is open, and `close`
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const menu = useMenu({ placement: "bottom-end" });
|
|
14
|
+
*
|
|
15
|
+
* <IconButton {...menu.getTriggerProps()} label="Row actions"><MoreHorizontalIcon /></IconButton>
|
|
16
|
+
* <Menu {...menu.getMenuProps({ "aria-label": "Row actions" })}>…</Menu>
|
|
17
|
+
*/
|
|
18
|
+
export declare function useMenu(options?: UseMenuOptions): UseMenuResult;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useMenuButton as e } from "./useMenuButton.js";
|
|
2
|
+
import { c as t } from "react/compiler-runtime";
|
|
3
|
+
// src/components/Menu/useMenu.ts
|
|
4
|
+
function n(n) {
|
|
5
|
+
let r = t(9), i;
|
|
6
|
+
r[0] === n ? i = r[1] : (i = n === void 0 ? {} : n, r[0] = n, r[1] = i);
|
|
7
|
+
let a = i, o;
|
|
8
|
+
r[2] === a ? o = r[3] : (o = {
|
|
9
|
+
...a,
|
|
10
|
+
pointerOpeningFocus: "menu"
|
|
11
|
+
}, r[2] = a, r[3] = o);
|
|
12
|
+
let { close: s, getMenuProps: c, getTriggerProps: l, open: u } = e(o), d;
|
|
13
|
+
return r[4] !== s || r[5] !== c || r[6] !== l || r[7] !== u ? (d = {
|
|
14
|
+
close: s,
|
|
15
|
+
getMenuProps: c,
|
|
16
|
+
getTriggerProps: l,
|
|
17
|
+
open: u
|
|
18
|
+
}, r[4] = s, r[5] = c, r[6] = l, r[7] = u, r[8] = d) : d = r[8], d;
|
|
19
|
+
}
|
|
20
|
+
export { n as useMenu };
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { CSSProperties, KeyboardEvent, MouseEvent } from "react";
|
|
2
|
+
import type { OpeningFocus } from "../../menus";
|
|
3
|
+
import type { OverlayPlacement } from "../../overlays";
|
|
4
|
+
import type { MenuOverlayProps } from "./Menu";
|
|
5
|
+
/**
|
|
6
|
+
* Options for `useMenu`
|
|
7
|
+
*/
|
|
8
|
+
export interface UseMenuOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Whether the menu starts open when uncontrolled. Defaults to `false`.
|
|
11
|
+
*/
|
|
12
|
+
defaultOpen?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Called with the new open state when the menu opens or closes; when controlled, also with `true` when the user
|
|
15
|
+
* asks to open it
|
|
16
|
+
*/
|
|
17
|
+
onOpenChange?: (open: boolean) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Controls whether the menu is open. The hook then cancels openings and reports them through `onOpenChange`; a close
|
|
20
|
+
* the browser makes is reported after it happens, and the menu shows again if `open` stays true.
|
|
21
|
+
*/
|
|
22
|
+
open?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Side of the trigger the menu opens on. It flips to the opposite side when there is no room. Defaults to
|
|
25
|
+
* `bottom-start`.
|
|
26
|
+
*/
|
|
27
|
+
placement?: OverlayPlacement;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Props `getTriggerProps` sets on the trigger
|
|
31
|
+
*/
|
|
32
|
+
interface MenuTriggerProps {
|
|
33
|
+
/**
|
|
34
|
+
* The menu's id
|
|
35
|
+
*/
|
|
36
|
+
"aria-controls": string;
|
|
37
|
+
/**
|
|
38
|
+
* Whether the menu is open
|
|
39
|
+
*/
|
|
40
|
+
"aria-expanded": boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Says the trigger opens a menu
|
|
43
|
+
*/
|
|
44
|
+
"aria-haspopup": "menu";
|
|
45
|
+
/**
|
|
46
|
+
* The trigger's id, which names the menu
|
|
47
|
+
*/
|
|
48
|
+
id: string;
|
|
49
|
+
/**
|
|
50
|
+
* Notes whether a pointer or the keyboard is opening the menu
|
|
51
|
+
*/
|
|
52
|
+
onClick: (event: MouseEvent<HTMLElement>) => void;
|
|
53
|
+
/**
|
|
54
|
+
* Opens the menu on its first item with Down, or its last with Up
|
|
55
|
+
*/
|
|
56
|
+
onKeyDown: (event: KeyboardEvent<HTMLElement>) => void;
|
|
57
|
+
/**
|
|
58
|
+
* The menu's id, which makes the button open and close it without script
|
|
59
|
+
*/
|
|
60
|
+
popoverTarget: string;
|
|
61
|
+
/**
|
|
62
|
+
* Names the trigger as the menu's anchor
|
|
63
|
+
*/
|
|
64
|
+
style: CSSProperties;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Where focus goes as a menu button's menu opens: its first or last item, the menu itself, or the trigger, which keeps
|
|
68
|
+
* it
|
|
69
|
+
*/
|
|
70
|
+
export type MenuButtonOpeningFocus = OpeningFocus | "trigger";
|
|
71
|
+
/**
|
|
72
|
+
* Options for `useMenuButton`
|
|
73
|
+
*/
|
|
74
|
+
export interface UseMenuButtonOptions extends UseMenuOptions {
|
|
75
|
+
/**
|
|
76
|
+
* Where focus goes when a pointer's click opens the menu
|
|
77
|
+
*/
|
|
78
|
+
pointerOpeningFocus: MenuButtonOpeningFocus;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Prop getters for a menu's trigger and the `Menu`, whether it is open, and a way to close it
|
|
82
|
+
*/
|
|
83
|
+
export interface UseMenuResult {
|
|
84
|
+
/**
|
|
85
|
+
* Closes the menu, returning focus to the trigger as choosing an item does, and reports `false` through
|
|
86
|
+
* `onOpenChange`
|
|
87
|
+
*/
|
|
88
|
+
close: () => void;
|
|
89
|
+
/**
|
|
90
|
+
* Returns the props to spread on the `Menu`, merged with any given. The menu is named by its trigger unless an
|
|
91
|
+
* `aria-label` is given, which an `IconButton` trigger needs.
|
|
92
|
+
*/
|
|
93
|
+
getMenuProps: <Props extends object>(props?: Props & Partial<MenuOverlayProps>) => Omit<Props, keyof MenuOverlayProps> & MenuOverlayProps;
|
|
94
|
+
/**
|
|
95
|
+
* Returns the props to spread on the trigger, which must be a button, merged with any given: where both set a
|
|
96
|
+
* handler, both run, the given one first, and `style` objects merge
|
|
97
|
+
*/
|
|
98
|
+
getTriggerProps: <Props extends object>(props?: Props & Partial<MenuTriggerProps>) => Omit<Props, keyof MenuTriggerProps> & MenuTriggerProps;
|
|
99
|
+
/**
|
|
100
|
+
* Whether the menu is open
|
|
101
|
+
*/
|
|
102
|
+
open: boolean;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* What `useMenuButton` returns: `useMenu`'s result and a way to open the menu with focus where its caller chooses
|
|
106
|
+
*/
|
|
107
|
+
export interface UseMenuButtonResult extends UseMenuResult {
|
|
108
|
+
/**
|
|
109
|
+
* Opens the menu, or moves focus in if it is already open
|
|
110
|
+
*
|
|
111
|
+
* @param trigger the trigger, which finds the menu in its document
|
|
112
|
+
* @param openingFocus where focus goes
|
|
113
|
+
*/
|
|
114
|
+
show: (trigger: HTMLElement, openingFocus: MenuButtonOpeningFocus) => void;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Connects a `Menu` to the button that opens it, as `useMenu` does, with where focus goes when a pointer opens the menu
|
|
118
|
+
* left to the caller
|
|
119
|
+
*
|
|
120
|
+
* @param options open state, the change callback, placement and where a pointer's opening puts focus
|
|
121
|
+
* @returns `useMenu`'s result and `show`
|
|
122
|
+
*/
|
|
123
|
+
export declare function useMenuButton({ defaultOpen, onOpenChange, open, placement, pointerOpeningFocus, }: UseMenuButtonOptions): UseMenuButtonResult;
|
|
124
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { closeWhenFocusLeaves as e } from "../../menus/closeWhenFocusLeaves.js";
|
|
2
|
+
import { focusOnOpening as t } from "../../menus/focusOnOpening.js";
|
|
3
|
+
import { hasModifier as n } from "../../menus/hasModifier.js";
|
|
4
|
+
import { leaveMenuOnTab as r } from "../../menus/leaveMenuOnTab.js";
|
|
5
|
+
import { watchRemovals as i } from "../../menus/watchRemovals.js";
|
|
6
|
+
import { mergeProps as a } from "../../overlays/mergeProps.js";
|
|
7
|
+
import { syncPopover as o } from "../../overlays/syncPopover.js";
|
|
8
|
+
import { usePopover as s } from "../Popover/usePopover.js";
|
|
9
|
+
import { useEffect as c, useId as l, useRef as u } from "react";
|
|
10
|
+
// src/components/Menu/useMenuButton.ts
|
|
11
|
+
var d = {
|
|
12
|
+
ArrowDown: "first",
|
|
13
|
+
ArrowUp: "last"
|
|
14
|
+
};
|
|
15
|
+
function f({ defaultOpen: f, onOpenChange: m, open: h, placement: g = "bottom-start", pointerOpeningFocus: _ }) {
|
|
16
|
+
let v = l(), y = s({
|
|
17
|
+
defaultOpen: f,
|
|
18
|
+
onOpenChange: m,
|
|
19
|
+
open: h,
|
|
20
|
+
placement: g
|
|
21
|
+
}), b = u("first"), x = u(null), S = y.getTriggerProps().popoverTarget;
|
|
22
|
+
c(() => () => x.current?.(), []);
|
|
23
|
+
function C(e) {
|
|
24
|
+
b.current = e.detail === 0 ? "first" : _;
|
|
25
|
+
let t = e.currentTarget.ownerDocument.getElementById(S);
|
|
26
|
+
e.defaultPrevented && t !== null && k(t);
|
|
27
|
+
}
|
|
28
|
+
function w(e) {
|
|
29
|
+
let t = d[e.key], r = e.currentTarget.ownerDocument.getElementById(S);
|
|
30
|
+
t === void 0 || r === null || e.defaultPrevented || n(e) || (e.preventDefault(), E(r, t));
|
|
31
|
+
}
|
|
32
|
+
function T(e, t) {
|
|
33
|
+
let n = e.ownerDocument.getElementById(S);
|
|
34
|
+
n !== null && E(n, t);
|
|
35
|
+
}
|
|
36
|
+
function E(e, t) {
|
|
37
|
+
e.matches(":popover-open") ? D(e, t) : (b.current = t, o(e, !0));
|
|
38
|
+
}
|
|
39
|
+
function D(e, n) {
|
|
40
|
+
n === "trigger" ? e.ownerDocument.getElementById(v)?.focus() : t(e, n);
|
|
41
|
+
}
|
|
42
|
+
function O(e) {
|
|
43
|
+
let t = e.currentTarget;
|
|
44
|
+
e.newState === "open" && e.target === t && k(t);
|
|
45
|
+
}
|
|
46
|
+
function k(e) {
|
|
47
|
+
setTimeout(() => {
|
|
48
|
+
e.matches(":popover-open") || (b.current = "first");
|
|
49
|
+
}, 0);
|
|
50
|
+
}
|
|
51
|
+
function A(e) {
|
|
52
|
+
let t = e.currentTarget;
|
|
53
|
+
e.target === t && (x.current?.(), x.current = null, e.newState === "open" && (x.current = i(t), D(t, b.current)), b.current = "first");
|
|
54
|
+
}
|
|
55
|
+
function j(e) {
|
|
56
|
+
r(e, e.currentTarget.ownerDocument.getElementById(v), y.close);
|
|
57
|
+
}
|
|
58
|
+
function M(t) {
|
|
59
|
+
e(t.currentTarget, t.relatedTarget, (e) => e.id === v);
|
|
60
|
+
}
|
|
61
|
+
function N(e) {
|
|
62
|
+
let t = a(e, {
|
|
63
|
+
"aria-labelledby": p(e) ? void 0 : v,
|
|
64
|
+
close: y.close,
|
|
65
|
+
onBeforeToggle: O,
|
|
66
|
+
onBlur: M,
|
|
67
|
+
onKeyDown: j,
|
|
68
|
+
onToggle: A
|
|
69
|
+
});
|
|
70
|
+
return y.getOverlayProps(t);
|
|
71
|
+
}
|
|
72
|
+
function P(e) {
|
|
73
|
+
let t = a(e, {
|
|
74
|
+
"aria-haspopup": "menu",
|
|
75
|
+
id: v,
|
|
76
|
+
onClick: C,
|
|
77
|
+
onKeyDown: w
|
|
78
|
+
});
|
|
79
|
+
return y.getTriggerProps(t);
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
close: y.close,
|
|
83
|
+
getMenuProps: N,
|
|
84
|
+
getTriggerProps: P,
|
|
85
|
+
open: y.open,
|
|
86
|
+
show: T
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function p(e) {
|
|
90
|
+
return e !== void 0 && "aria-label" in e && typeof e["aria-label"] == "string" && e["aria-label"] !== "";
|
|
91
|
+
}
|
|
92
|
+
export { f as useMenuButton };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { MenuContextValue } from "./MenuContext";
|
|
2
|
+
/**
|
|
3
|
+
* Reads the state of the surrounding `Menu`
|
|
4
|
+
*
|
|
5
|
+
* @param part the name of the part reading it, for the error message
|
|
6
|
+
* @returns the surrounding `Menu`'s state
|
|
7
|
+
* @throws MissingContextError when the part is not inside a `Menu`
|
|
8
|
+
*/
|
|
9
|
+
export declare function useMenuContext(part: string): MenuContextValue;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MissingContextError as e } from "../../errors/MissingContextError.js";
|
|
2
|
+
import { MenuContext as t } from "./MenuContext.js";
|
|
3
|
+
import { useContext as n } from "react";
|
|
4
|
+
// src/components/Menu/useMenuContext.ts
|
|
5
|
+
function r(r) {
|
|
6
|
+
let i = n(t);
|
|
7
|
+
if (i === null) throw new e(r, "Menu");
|
|
8
|
+
return i;
|
|
9
|
+
}
|
|
10
|
+
export { r as useMenuContext };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { JSX, ReactNode } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* What a menu item shows
|
|
4
|
+
*/
|
|
5
|
+
interface MenuItemContentOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The consumer's own `aria-describedby`, listed after the description
|
|
8
|
+
*/
|
|
9
|
+
describedBy: string | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* A line of muted text below the label
|
|
12
|
+
*/
|
|
13
|
+
description: ReactNode;
|
|
14
|
+
/**
|
|
15
|
+
* The label
|
|
16
|
+
*/
|
|
17
|
+
label: ReactNode;
|
|
18
|
+
/**
|
|
19
|
+
* What sits in the leading slot, such as an icon or a check; nothing leaves the item without one
|
|
20
|
+
*/
|
|
21
|
+
leading: ReactNode;
|
|
22
|
+
/**
|
|
23
|
+
* What sits after the label, such as a shortcut or a submenu's chevron
|
|
24
|
+
*/
|
|
25
|
+
trailing: ReactNode;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A menu item's content and the ids that name and describe it
|
|
29
|
+
*/
|
|
30
|
+
interface MenuItemContent {
|
|
31
|
+
/**
|
|
32
|
+
* The leading slot, label, description and trailing slot, in that order
|
|
33
|
+
*/
|
|
34
|
+
content: JSX.Element;
|
|
35
|
+
/**
|
|
36
|
+
* The ids for the item's `aria-describedby`: the description's, then the consumer's; undefined for neither
|
|
37
|
+
*/
|
|
38
|
+
describedBy: string | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Whether the item has a leading slot, for its `data-leading`, which gives its menu an icon column
|
|
41
|
+
*/
|
|
42
|
+
hasLeading: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* The id for the item's `aria-labelledby`, which names it by its label alone
|
|
45
|
+
*/
|
|
46
|
+
labelId: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Lays out the content every kind of menu item shares
|
|
50
|
+
*
|
|
51
|
+
* @param options the label, description, leading and trailing slots and the consumer's `aria-describedby`
|
|
52
|
+
* @returns the content and the ids to name and describe the item by
|
|
53
|
+
*/
|
|
54
|
+
export declare function useMenuItemContent({ describedBy, description, label, leading, trailing, }: MenuItemContentOptions): MenuItemContent;
|
|
55
|
+
export {};
|