@omer-x/tailwind-ui-kit 1.0.0-alpha.37 → 1.0.0-alpha.39
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 +182 -3
- package/dist/components/form/BaseRadio.d.ts +30 -0
- package/dist/components/form/BaseRadio.js +22 -0
- package/dist/components/form/BaseRadioGroup.d.ts +28 -0
- package/dist/components/form/BaseRadioGroup.js +21 -0
- package/dist/components/form/FieldRoot.js +5 -1
- package/dist/components/form/InsideFieldContext.d.ts +2 -0
- package/dist/components/form/InsideFieldContext.js +5 -0
- package/dist/components/form/index.d.ts +3 -1
- package/dist/components/form/index.js +3 -1
- package/dist/components/menu/BaseContextMenu.d.ts +22 -12
- package/dist/components/menu/BaseMenu.d.ts +171 -0
- package/dist/components/menu/BaseMenu.js +62 -0
- package/dist/components/menu/BaseMenuClear.d.ts +16 -0
- package/dist/components/menu/BaseMenuClear.js +10 -0
- package/dist/components/menu/BaseMenuEmpty.d.ts +8 -0
- package/dist/components/menu/BaseMenuEmpty.js +7 -0
- package/dist/components/menu/BaseMenuInput.d.ts +15 -0
- package/dist/components/menu/BaseMenuInput.js +10 -0
- package/dist/components/menu/BaseMenuList.d.ts +11 -0
- package/dist/components/menu/BaseMenuList.js +14 -0
- package/dist/components/menu/BaseMenuPopup.d.ts +52 -6
- package/dist/components/menu/BaseMenuPopup.js +6 -1
- package/dist/components/menu/BaseMenuSubmenu.d.ts +3 -18
- package/dist/components/menu/BaseMenuSubmenu.js +16 -4
- package/dist/components/menu/BaseMenuTrigger.d.ts +26 -0
- package/dist/components/menu/BaseMenuTrigger.js +11 -0
- package/dist/components/menu/BaseMenuViewport.d.ts +18 -0
- package/dist/components/menu/BaseMenuViewport.js +11 -0
- package/dist/components/menu/createMenuHandle.d.ts +30 -0
- package/dist/components/menu/createMenuHandle.js +27 -0
- package/dist/components/menu/index.d.ts +9 -2
- package/dist/components/menu/index.js +4 -1
- package/dist/components/menu/menuTypes.d.ts +69 -0
- package/dist/components/menu/menuTypes.js +16 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -212,6 +212,67 @@ With `BaseForm`'s `onlyDirty`, give the group an array default (`defaultValues={
|
|
|
212
212
|
</BaseCheckboxGroup>
|
|
213
213
|
```
|
|
214
214
|
|
|
215
|
+
#### `BaseRadioGroup`
|
|
216
|
+
|
|
217
|
+
A Base UI [`Radio Group`](https://base-ui.com/react/components/radio-group): shared state for the `BaseRadio`s inside it. Only one radio is selected at a time, and its `value` is submitted under the group's `name`. Arrow keys move the selection.
|
|
218
|
+
|
|
219
|
+
| Prop | Type | Default | Description |
|
|
220
|
+
|------|------|---------|-------------|
|
|
221
|
+
| `name` | `string` | | Submitted name of the group |
|
|
222
|
+
| `value` | `string` | | The `value` of the selected radio, when controlled |
|
|
223
|
+
| `defaultValue` | `string` | | The `value` of the radio selected at first |
|
|
224
|
+
| `onValueChange` | `(value: string, event: Event) => void` | | Called with the selected `value` and the DOM event that changed it |
|
|
225
|
+
| `disabled` | `boolean` | | Disables every radio in the group |
|
|
226
|
+
| `readOnly` | `boolean` | | Keeps the selection from changing |
|
|
227
|
+
| `required` | `boolean` | | A radio must be selected before the form submits |
|
|
228
|
+
| `form` | `string` | | The `id` of a `<form>` to submit with, when the group isn't inside it |
|
|
229
|
+
| `inputRef` | `Ref<HTMLInputElement>` | | The hidden `<input>` of the selected (or first enabled) radio |
|
|
230
|
+
| `className` | `string` | | Classes for the group `<div>` (default `flex flex-col gap-2`) |
|
|
231
|
+
| `render` | `RenderProp<"div", RadioGroupState>` | | Render another element for the group |
|
|
232
|
+
| …rest | | | `<div>` props. Give the group an accessible name with `aria-label` or `aria-labelledby` (inside `BaseFormField`, its `label` names the group) |
|
|
233
|
+
|
|
234
|
+
Render functions get `RadioGroupState`: `{ disabled, readOnly, required }`. The group sets `data-disabled`, `data-readonly` and `data-required`.
|
|
235
|
+
|
|
236
|
+
Inside `BaseForm`, use it alone with a `name`, or in `BaseFormField`'s `children` to get the field's name, label, `required` from the schema and server errors. With `onlyDirty`, give it a string default (`defaultValues={{ plan: "free" }}`). It is sent only when the selection differs from it.
|
|
237
|
+
|
|
238
|
+
```tsx
|
|
239
|
+
<BaseFormField name="plan" label="Plan" schema={Schema.shape.plan}>
|
|
240
|
+
{constraints => (
|
|
241
|
+
<BaseRadioGroup required={constraints.required} defaultValue="free">
|
|
242
|
+
<BaseRadio value="free" label="Free" />
|
|
243
|
+
<BaseRadio value="pro" label="Pro" />
|
|
244
|
+
</BaseRadioGroup>
|
|
245
|
+
)}
|
|
246
|
+
</BaseFormField>
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
#### `BaseRadio`
|
|
250
|
+
|
|
251
|
+
A Base UI [`Radio`](https://base-ui.com/react/components/radio-group) with its label, for use inside `BaseRadioGroup`.
|
|
252
|
+
|
|
253
|
+
| Prop | Type | Default | Description |
|
|
254
|
+
|------|------|---------|-------------|
|
|
255
|
+
| `label` | `ReactNode` | | Text next to the radio (required) |
|
|
256
|
+
| `value` | `string` | | Submitted under the group's `name` when selected (required) |
|
|
257
|
+
| `labelClassName` | `string` | | Classes for the `<label>` around the radio and its text (default `flex items-center gap-2 text-sm font-normal`) |
|
|
258
|
+
| `icon` | `ReactNode` | | Shown inside the radio when selected, e.g. a dot (`<span className="size-1.5 rounded-full bg-white" />`). The kit bundles none |
|
|
259
|
+
| `renderIndicator` | `RenderProp<"span", RadioState>` | | Style the indicator that holds the icon |
|
|
260
|
+
| `keepIndicatorMounted` | `boolean` | `false` | Keep the indicator in the DOM when not selected (e.g. to animate it out) |
|
|
261
|
+
| `className` | `string` | | Classes for the radio (default is a `size-4` `rounded-full` box with a focus ring offset) |
|
|
262
|
+
| `render` | `RenderProp<"span", RadioState>` | | Render another element for the radio |
|
|
263
|
+
| …rest | | | `disabled`, `readOnly`, `required`, `inputRef`, `nativeButton`, and `<span>` props |
|
|
264
|
+
|
|
265
|
+
Render functions get `RadioState`: `{ checked, disabled, readOnly, required }`. The radio and the indicator set `data-checked` / `data-unchecked`, `data-disabled`, `data-readonly` and `data-required`. The indicator also sets `data-starting-style` / `data-ending-style` while it enters and leaves. The `<label>` sets `data-disabled` when the radio itself is `disabled`.
|
|
266
|
+
|
|
267
|
+
```tsx
|
|
268
|
+
<BaseRadio
|
|
269
|
+
value="pro"
|
|
270
|
+
label="Pro"
|
|
271
|
+
className="border border-neutral-400 data-checked:border-blue-600 data-checked:bg-blue-600"
|
|
272
|
+
icon={<span className="size-1.5 rounded-full bg-white" />}
|
|
273
|
+
/>
|
|
274
|
+
```
|
|
275
|
+
|
|
215
276
|
#### `BaseFieldset`
|
|
216
277
|
|
|
217
278
|
A Base UI [`Fieldset`](https://base-ui.com/react/components/fieldset): a native `<fieldset>` that groups related controls under a stylable legend. The legend is linked to the fieldset (`aria-labelledby`), so screen readers announce it as the group's name.
|
|
@@ -671,7 +732,7 @@ import { BaseContextMenu } from "@omer-x/tailwind-ui-kit/menu";
|
|
|
671
732
|
</BaseContextMenu>
|
|
672
733
|
```
|
|
673
734
|
|
|
674
|
-
Like `BaseDialog`, the parts use dot notation, so build menus in a `"use client"` file. Every part except the root and `Trigger` is shared with
|
|
735
|
+
Like `BaseDialog`, the parts use dot notation, so build menus in a `"use client"` file. Every part except the root and `Trigger` is shared with `BaseMenu`, so one set of popup and item styles themes both.
|
|
675
736
|
|
|
676
737
|
| Part | Renders | Description |
|
|
677
738
|
|------|---------|-------------|
|
|
@@ -720,8 +781,12 @@ Items (`Item`, `LinkItem`, `SubmenuTrigger`, `CheckboxItem`, `RadioItem`) share
|
|
|
720
781
|
| Prop | Type | Default | Description |
|
|
721
782
|
|------|------|---------|-------------|
|
|
722
783
|
| `side` / `align` | `MenuSide` / `MenuAlign` | at the pointer | Where the popup sits against its anchor (`"top"`, `"bottom"`, `"left"`, `"right"`, `"inline-start"`, `"inline-end"` / `"start"`, `"center"`, `"end"`). Submenus default to `"inline-end"` / `"start"` |
|
|
723
|
-
| `sideOffset` / `alignOffset` | `number` | | Offsets from the anchor, in pixels |
|
|
724
|
-
| `collisionPadding` | `number` | `5` | Space kept from the viewport edges |
|
|
784
|
+
| `sideOffset` / `alignOffset` | `number \| MenuOffsetFunction` | | Offsets from the anchor, in pixels, or a function of the placement and sizes |
|
|
785
|
+
| `collisionPadding` | `number \| { top, right, bottom, left }` | `5` | Space kept from the viewport edges |
|
|
786
|
+
| `collisionBoundary` / `collisionAvoidance` | | `"clipping-ancestors"` | The area the popup stays inside, and how it avoids its edges (flip or shift) |
|
|
787
|
+
| `anchor` | `Element \| RefObject \| () => Element \| null` | the trigger | The element the popup is placed against |
|
|
788
|
+
| `disableAnchorTracking` | `boolean` | `false` | Stops following the anchor when it moves |
|
|
789
|
+
| `arrowPadding` | `number` | `5` | Minimum distance between an `Arrow` and the popup's corners |
|
|
725
790
|
| `sticky` | `boolean` | `false` | Stays in view while the anchor scrolls away |
|
|
726
791
|
| `positionMethod` | `"absolute" \| "fixed"` | `"absolute"` | Use `"fixed"` when the anchor is inside a fixed container |
|
|
727
792
|
| `positionerClassName` / `renderPositioner` | `string` / `RenderProp<"div", MenuPositionerState>` | | Style or replace the positioner, the `<div>` around the popup that places it (`z-50`) |
|
|
@@ -745,6 +810,120 @@ Data attributes: the popup has `data-open` / `data-closed`, `data-side`, `data-a
|
|
|
745
810
|
</BaseContextMenu.Submenu>
|
|
746
811
|
```
|
|
747
812
|
|
|
813
|
+
|
|
814
|
+
#### `BaseMenu`
|
|
815
|
+
|
|
816
|
+
A Base UI [`Menu`](https://base-ui.com/react/components/menu): a list of actions opened from a button, with keyboard navigation, submenus, checkbox and radio items, and optional filtering. It uses the same `Popup`, `Arrow`, items, groups and submenus as `BaseContextMenu` (see above), so one set of styles themes both. A simple menu needs no more than this:
|
|
817
|
+
|
|
818
|
+
```tsx
|
|
819
|
+
import { BaseMenu } from "@omer-x/tailwind-ui-kit/menu";
|
|
820
|
+
|
|
821
|
+
<BaseMenu>
|
|
822
|
+
<BaseMenu.Trigger render={<Button />}>Actions</BaseMenu.Trigger>
|
|
823
|
+
<BaseMenu.Popup sideOffset={4} className="rounded-md border bg-white shadow-lg">
|
|
824
|
+
<BaseMenu.Item className="data-highlighted:bg-neutral-100" onClick={edit}>Edit</BaseMenu.Item>
|
|
825
|
+
<BaseMenu.Separator className="bg-neutral-200" />
|
|
826
|
+
<BaseMenu.Item className="data-highlighted:bg-neutral-100" onClick={remove}>Delete</BaseMenu.Item>
|
|
827
|
+
</BaseMenu.Popup>
|
|
828
|
+
</BaseMenu>
|
|
829
|
+
```
|
|
830
|
+
|
|
831
|
+
Parts besides the shared ones (`Popup`, `Arrow`, `Item`, `LinkItem`, `Separator`, `Group`, `GroupLabel`, `RadioGroup`, `RadioItem`, `CheckboxItem`, `Submenu`, `SubmenuTrigger`):
|
|
832
|
+
|
|
833
|
+
| Part | Renders | Description |
|
|
834
|
+
|------|---------|-------------|
|
|
835
|
+
| `BaseMenu` | nothing | Groups the parts and holds the open state |
|
|
836
|
+
| `BaseMenu.Trigger` | `<button>` | Opens the menu. `data-popup-open` while its menu is open. Takes `handle`, `payload`, `openOnHover` (also open on hover), `delay` / `closeDelay` (hover delays in ms, default `100` / `0`) and `nativeButton` |
|
|
837
|
+
| `BaseMenu.Input` | `<input>` | The search box of a `filterable` menu (`role="searchbox"`) |
|
|
838
|
+
| `BaseMenu.Clear` | `<button>` | Clears the search box. Only rendered while there's a query. A pointer shortcut: out of the tab order and `aria-hidden` |
|
|
839
|
+
| `BaseMenu.Empty` | `<div>` | Shown only when no item matches (`role="status"`). Not rendered otherwise |
|
|
840
|
+
| `BaseMenu.List` | `<div>` | Holds the items when the popup has other content too (the search box). Scrolls when the popup runs out of space (`min-h-0 flex-1 overflow-y-auto`) |
|
|
841
|
+
| `BaseMenu.Viewport` | `<div>` | Animates the content when one menu is opened by several triggers and its content depends on the trigger. `data-activation-direction`, `data-transitioning` |
|
|
842
|
+
|
|
843
|
+
The popup is placed below the trigger and centered by default (`side="bottom"`, `align="center"`).
|
|
844
|
+
|
|
845
|
+
`BaseMenu` props:
|
|
846
|
+
|
|
847
|
+
| Prop | Type | Default | Description |
|
|
848
|
+
|------|------|---------|-------------|
|
|
849
|
+
| `open` / `defaultOpen` | `boolean` | `false` | Controlled / initial open state |
|
|
850
|
+
| `onOpenChange` | `(open, event) => void` | | Called with the new state and the DOM event that changed it (`undefined` when changed from code) |
|
|
851
|
+
| `onOpenChangeComplete` | `(open) => void` | | Called after the open or close transition ends |
|
|
852
|
+
| `modal` | `boolean` | `true` | Locks page scroll and blocks outside pointer input while open. Menus opened by hover never are |
|
|
853
|
+
| `disabled` | `boolean` | `false` | |
|
|
854
|
+
| `loopFocus` | `boolean` | `true` | Arrow keys wrap from the last item to the first |
|
|
855
|
+
| `highlightItemOnHover` | `boolean` | `true` | Turn it off to style `:hover` apart from `data-highlighted` |
|
|
856
|
+
| `orientation` | `"vertical" \| "horizontal"` | `"vertical"` | Which arrow keys move between items |
|
|
857
|
+
| `onItemHighlighted` | `(item, { reason, label }) => void` | | The highlighted element (or `undefined`). `reason` is `"keyboard"`, `"pointer"` or `"none"` |
|
|
858
|
+
| `actionsRef` | `RefObject<MenuActions>` | | `actionsRef.current?.close()` |
|
|
859
|
+
| `handle` | `MenuHandle<Payload>` | | Connects triggers outside the menu and opens it from code (see below) |
|
|
860
|
+
| `triggerId` / `defaultTriggerId` | `string \| null` | | The trigger a controlled / initially open menu belongs to |
|
|
861
|
+
| `children` | `ReactNode \| ({ payload }) => ReactNode` | | The parts, or a function that gets the payload of the trigger that opened the menu |
|
|
862
|
+
| `filterable` | `boolean` | `false` | Adds filtering (see below) |
|
|
863
|
+
|
|
864
|
+
`Submenu` also takes `orientation`, `onItemHighlighted`, `actionsRef` and the filtering props.
|
|
865
|
+
|
|
866
|
+
**Router links.** `LinkItem` renders an `<a>`. Pass your router's link as `render`, and it gets the item's props and behavior:
|
|
867
|
+
|
|
868
|
+
```tsx
|
|
869
|
+
import Link from "next/link";
|
|
870
|
+
|
|
871
|
+
<BaseMenu.LinkItem render={<Link href="/settings" />}>Settings</BaseMenu.LinkItem>
|
|
872
|
+
```
|
|
873
|
+
|
|
874
|
+
**Filtering.** `filterable` (on `BaseMenu` or a `Submenu`) lets the user filter the items by typing in an `Input`. Put the items in a `List`; items that don't match are removed. The popup becomes a `role="dialog"` holding the search box and the `role="menu"` list. Make the popup a flex column (`flex flex-col`) so only the list scrolls:
|
|
875
|
+
|
|
876
|
+
```tsx
|
|
877
|
+
<BaseMenu filterable>
|
|
878
|
+
<BaseMenu.Trigger render={<Button />}>Labels</BaseMenu.Trigger>
|
|
879
|
+
<BaseMenu.Popup className="flex flex-col">
|
|
880
|
+
<BaseMenu.Input aria-label="Search labels" placeholder="Search labels" />
|
|
881
|
+
<BaseMenu.Empty className="py-1.5">No labels found</BaseMenu.Empty>
|
|
882
|
+
<BaseMenu.List>
|
|
883
|
+
{labels.map(label => <BaseMenu.CheckboxItem key={label}>{label}</BaseMenu.CheckboxItem>)}
|
|
884
|
+
</BaseMenu.List>
|
|
885
|
+
</BaseMenu.Popup>
|
|
886
|
+
</BaseMenu>
|
|
887
|
+
```
|
|
888
|
+
|
|
889
|
+
| Prop | Type | Description |
|
|
890
|
+
|------|------|-------------|
|
|
891
|
+
| `filter` | `(text, query) => boolean \| null` | Decides what matches, from the item's `label` (or text) and the trimmed query. Defaults to "contains", ignoring case, accents and punctuation. `null` shows every item (filter them yourself) |
|
|
892
|
+
| `autoHighlight` | `boolean \| "always"` | Highlights the first match while there's a query (`"always"`: also without one) |
|
|
893
|
+
| `locale` | `Intl.LocalesArgument` | Locale of the default filter |
|
|
894
|
+
| `query` / `defaultQuery` | `string` | The query, controlled / uncontrolled. It's cleared when the menu closes |
|
|
895
|
+
| `onQueryChange` | `(query, event) => void` | Called with the new query and the DOM event |
|
|
896
|
+
|
|
897
|
+
#### `createMenuHandle`
|
|
898
|
+
|
|
899
|
+
Opens one menu from triggers anywhere on the page, or from code. Each trigger can pass a `payload`, which the menu's function children receive:
|
|
900
|
+
|
|
901
|
+
```tsx
|
|
902
|
+
import { BaseMenu, createMenuHandle } from "@omer-x/tailwind-ui-kit/menu";
|
|
903
|
+
|
|
904
|
+
const rowMenu = createMenuHandle<{ id: string, name: string }>();
|
|
905
|
+
|
|
906
|
+
// triggers anywhere on the page
|
|
907
|
+
<BaseMenu.Trigger id={`row-${row.id}`} handle={rowMenu} payload={row} render={<Button />}>Options</BaseMenu.Trigger>
|
|
908
|
+
|
|
909
|
+
// one menu on the page
|
|
910
|
+
<BaseMenu handle={rowMenu}>
|
|
911
|
+
{({ payload }) => payload && (
|
|
912
|
+
<BaseMenu.Popup>
|
|
913
|
+
<BaseMenu.Item onClick={() => rename(payload.id)}>Rename {payload.name}</BaseMenu.Item>
|
|
914
|
+
</BaseMenu.Popup>
|
|
915
|
+
)}
|
|
916
|
+
</BaseMenu>
|
|
917
|
+
|
|
918
|
+
// from code
|
|
919
|
+
rowMenu.open(`row-${id}`);
|
|
920
|
+
```
|
|
921
|
+
|
|
922
|
+
A `MenuHandle<Payload>` has `open(triggerId)`, `close()` and `isOpen`. Unlike the dialog handles, it has no `openWithPayload`: a menu is placed against its trigger, so `open` needs the `id` of a trigger with the same handle (it throws when there's none).
|
|
923
|
+
|
|
924
|
+
- Calls are **ignored while the menu isn't mounted**. Keep the `BaseMenu` with the handle rendered.
|
|
925
|
+
- Call them **from event handlers or effects, never during render**.
|
|
926
|
+
|
|
748
927
|
### `@omer-x/tailwind-ui-kit/disclosure`
|
|
749
928
|
|
|
750
929
|
#### `BaseAccordion`
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps, ReactNode, Ref } from "react";
|
|
3
|
+
export type RadioState = {
|
|
4
|
+
checked: boolean;
|
|
5
|
+
disabled: boolean;
|
|
6
|
+
readOnly: boolean;
|
|
7
|
+
required: boolean;
|
|
8
|
+
};
|
|
9
|
+
type BaseRadioProps = Omit<ComponentProps<"span">, "onChange" | "defaultValue"> & {
|
|
10
|
+
label: ReactNode;
|
|
11
|
+
/** Submitted under the group's `name` when this radio is selected. */
|
|
12
|
+
value: string;
|
|
13
|
+
render?: RenderProp<"span", RadioState>;
|
|
14
|
+
/** Classes for the `<label>` around the radio and its text. */
|
|
15
|
+
labelClassName?: string;
|
|
16
|
+
/** Shown inside the radio when selected, e.g. a dot. */
|
|
17
|
+
icon?: ReactNode;
|
|
18
|
+
renderIndicator?: RenderProp<"span", RadioState>;
|
|
19
|
+
/** Keep the indicator in the DOM when not selected, e.g. to animate it out with CSS. */
|
|
20
|
+
keepIndicatorMounted?: boolean;
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
readOnly?: boolean;
|
|
23
|
+
required?: boolean;
|
|
24
|
+
/** A ref to the hidden `<input>` of this radio. */
|
|
25
|
+
inputRef?: Ref<HTMLInputElement>;
|
|
26
|
+
/** Set to `true` when `render` renders a `<button>`. */
|
|
27
|
+
nativeButton?: boolean;
|
|
28
|
+
};
|
|
29
|
+
declare const BaseRadio: ({ label, labelClassName, icon, renderIndicator, keepIndicatorMounted, className, ...otherProps }: BaseRadioProps) => import("react").JSX.Element;
|
|
30
|
+
export { BaseRadio as default };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Field } from "@base-ui/react/field";
|
|
3
|
+
import { Radio } from "@base-ui/react/radio";
|
|
4
|
+
import { cn } from "cn";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
// src/components/form/BaseRadio.tsx
|
|
7
|
+
const BaseRadio = ({ label, labelClassName, icon, renderIndicator, keepIndicatorMounted, className, ...otherProps }) => /* @__PURE__ */ jsxs(Field.Item, {
|
|
8
|
+
disabled: otherProps.disabled,
|
|
9
|
+
render: /* @__PURE__ */ jsx("label", {}),
|
|
10
|
+
className: cn("flex items-center gap-2 text-sm font-normal", labelClassName),
|
|
11
|
+
children: [/* @__PURE__ */ jsx(Radio.Root, {
|
|
12
|
+
...otherProps,
|
|
13
|
+
className: cn("flex", "size-4", "shrink-0", "items-center", "justify-center", "rounded-full", "transition-colors", "duration-150", "ease-[ease]", "focus-visible:outline-2", "focus-visible:outline-offset-2", className),
|
|
14
|
+
children: /* @__PURE__ */ jsx(Radio.Indicator, {
|
|
15
|
+
keepMounted: keepIndicatorMounted,
|
|
16
|
+
className: "flex size-full items-center justify-center",
|
|
17
|
+
render: renderIndicator,
|
|
18
|
+
children: icon
|
|
19
|
+
})
|
|
20
|
+
}), label]
|
|
21
|
+
});
|
|
22
|
+
export { BaseRadio as default };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ComponentProps, Ref } from "react";
|
|
2
|
+
import { RenderProp } from "../../utils/render.js";
|
|
3
|
+
export type RadioGroupState = {
|
|
4
|
+
disabled: boolean;
|
|
5
|
+
readOnly: boolean;
|
|
6
|
+
required: boolean;
|
|
7
|
+
};
|
|
8
|
+
type BaseRadioGroupProps = Omit<ComponentProps<"div">, "onChange" | "defaultValue"> & {
|
|
9
|
+
render?: RenderProp<"div", RadioGroupState>;
|
|
10
|
+
/** Submitted name of the group. The selected radio's `value` is sent under it. */
|
|
11
|
+
name?: string;
|
|
12
|
+
/** The `value` of the selected radio, when controlled. */
|
|
13
|
+
value?: string;
|
|
14
|
+
/** The `value` of the radio selected at first. */
|
|
15
|
+
defaultValue?: string;
|
|
16
|
+
/** Called with the selected radio's `value` and the DOM event that changed it. */
|
|
17
|
+
onValueChange?: (value: string, event: Event) => void;
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
readOnly?: boolean;
|
|
20
|
+
/** The user must select a radio before the form submits. */
|
|
21
|
+
required?: boolean;
|
|
22
|
+
/** The `id` of a `<form>` to submit with, when the group isn't inside it. */
|
|
23
|
+
form?: string;
|
|
24
|
+
/** A ref to the hidden `<input>` of the selected (or first enabled) radio. */
|
|
25
|
+
inputRef?: Ref<HTMLInputElement>;
|
|
26
|
+
};
|
|
27
|
+
declare const BaseRadioGroup: ({ onValueChange, className, ...otherProps }: BaseRadioGroupProps) => import("react").JSX.Element;
|
|
28
|
+
export { BaseRadioGroup as default };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Field } from "@base-ui/react/field";
|
|
3
|
+
import { RadioGroup } from "@base-ui/react/radio-group";
|
|
4
|
+
import { cn } from "cn";
|
|
5
|
+
import { use } from "react";
|
|
6
|
+
import { InsideFieldContext } from "./InsideFieldContext.js";
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
// src/components/form/BaseRadioGroup.tsx
|
|
9
|
+
const BaseRadioGroup = ({ onValueChange, className, ...otherProps }) => {
|
|
10
|
+
const group = /* @__PURE__ */ jsx(RadioGroup, {
|
|
11
|
+
...otherProps,
|
|
12
|
+
onValueChange: onValueChange && ((value, details) => onValueChange(value, details.event)),
|
|
13
|
+
className: cn("flex flex-col gap-2", className)
|
|
14
|
+
});
|
|
15
|
+
if (use(InsideFieldContext)) return group;
|
|
16
|
+
return /* @__PURE__ */ jsx(Field.Root, {
|
|
17
|
+
className: "contents",
|
|
18
|
+
children: group
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
export { BaseRadioGroup as default };
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { Field } from "@base-ui/react/field";
|
|
3
3
|
import { use, useEffect } from "react";
|
|
4
4
|
import { FormContext } from "./FormContext.js";
|
|
5
|
+
import { InsideFieldContext } from "./InsideFieldContext.js";
|
|
5
6
|
import { jsx } from "react/jsx-runtime";
|
|
6
7
|
// src/components/form/FieldRoot.tsx
|
|
7
8
|
const FieldRoot = ({ name, className, children }) => {
|
|
@@ -15,7 +16,10 @@ const FieldRoot = ({ name, className, children }) => {
|
|
|
15
16
|
return /* @__PURE__ */ jsx(Field.Root, {
|
|
16
17
|
name,
|
|
17
18
|
className,
|
|
18
|
-
children
|
|
19
|
+
children: /* @__PURE__ */ jsx(InsideFieldContext, {
|
|
20
|
+
value: true,
|
|
21
|
+
children
|
|
22
|
+
})
|
|
19
23
|
});
|
|
20
24
|
};
|
|
21
25
|
export { FieldRoot as default };
|
|
@@ -16,4 +16,6 @@ import { AutocompleteArrowState, AutocompleteBackdropState, AutocompleteCollisio
|
|
|
16
16
|
import { AutocompleteSeparatorState } from "./BaseAutocompleteSeparator.js";
|
|
17
17
|
import { InputSize } from "./inputSizes.js";
|
|
18
18
|
import BaseFieldset, { FieldsetState } from "./BaseFieldset.js";
|
|
19
|
-
|
|
19
|
+
import BaseRadioGroup, { RadioGroupState } from "./BaseRadioGroup.js";
|
|
20
|
+
import BaseRadio, { RadioState } from "./BaseRadio.js";
|
|
21
|
+
export { type AutocompleteActions, type AutocompleteAlign, type AutocompleteArrowState, type AutocompleteBackdropState, type AutocompleteClearState, type AutocompleteCollisionAvoidance, type AutocompleteFilter, type AutocompleteFocusTarget, type AutocompleteHighlightReason, type AutocompleteInputState, type AutocompleteInteractionType, type AutocompleteItemGroup, type AutocompleteItemState, type AutocompleteListState, type AutocompleteOffsetFunction, type AutocompletePopupState, type AutocompletePositionerState, type AutocompleteSeparatorState, type AutocompleteSide, _default as BaseAutocomplete, BaseCheckbox, BaseCheckboxGroup, BaseFieldset, BaseForm, BaseFormField, BaseInput, BaseRadio, BaseRadioGroup, BaseSwitch, type CheckboxGroupState, type CheckboxState, type DisplayedFormMessage, type FieldConstraints, type FieldState, type FieldsetState, type InputSize, type MessageFormatter, type RadioGroupState, type RadioState, type SwitchState, type UseAutocompleteFilterOptions, useAutocompleteFilter, useFormMessages };
|
|
@@ -8,4 +8,6 @@ import useFormMessages from "./useFormMessages.js";
|
|
|
8
8
|
import BaseAutocomplete_default from "./BaseAutocomplete.js";
|
|
9
9
|
import useAutocompleteFilter from "./useAutocompleteFilter.js";
|
|
10
10
|
import BaseFieldset from "./BaseFieldset.js";
|
|
11
|
-
|
|
11
|
+
import BaseRadioGroup from "./BaseRadioGroup.js";
|
|
12
|
+
import BaseRadio from "./BaseRadio.js";
|
|
13
|
+
export { BaseAutocomplete_default as BaseAutocomplete, BaseCheckbox, BaseCheckboxGroup, BaseFieldset, BaseForm, BaseFormField, BaseInput, BaseRadio, BaseRadioGroup, BaseSwitch, useAutocompleteFilter, useFormMessages };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RenderProp } from "../../utils/render.js";
|
|
2
2
|
import { ContextMenuTriggerState } from "./BaseContextMenuTrigger.js";
|
|
3
3
|
import "../../utils/index.js";
|
|
4
|
-
import { MenuAlign, MenuBackdropState, MenuFocusTarget, MenuPopupState, MenuPositionerState, MenuSide } from "./BaseMenuPopup.js";
|
|
4
|
+
import { MenuAlign, MenuBackdropState, MenuCollisionAvoidance, MenuFocusTarget, MenuOffsetFunction, MenuPopupState, MenuPositionerState, MenuSide } from "./BaseMenuPopup.js";
|
|
5
5
|
import { MenuArrowState } from "./BaseMenuArrow.js";
|
|
6
6
|
import { MenuItemState } from "./BaseMenuItem.js";
|
|
7
7
|
import { MenuLinkItemState } from "./BaseMenuLinkItem.js";
|
|
@@ -9,6 +9,7 @@ import { MenuSeparatorState } from "./BaseMenuSeparator.js";
|
|
|
9
9
|
import { MenuRadioGroupState } from "./BaseMenuRadioGroup.js";
|
|
10
10
|
import { MenuRadioItemState } from "./BaseMenuRadioItem.js";
|
|
11
11
|
import { MenuCheckboxItemState } from "./BaseMenuCheckboxItem.js";
|
|
12
|
+
import { MenuRootSharedProps } from "./menuTypes.js";
|
|
12
13
|
import { MenuSubmenuTriggerState } from "./BaseMenuSubmenuTrigger.js";
|
|
13
14
|
import { ReactNode } from "react";
|
|
14
15
|
type BaseContextMenuProps = {
|
|
@@ -42,13 +43,28 @@ declare const _default: (({ onOpenChange, ...otherProps }: BaseContextMenuProps)
|
|
|
42
43
|
Trigger: (props: import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
|
|
43
44
|
render?: RenderProp<"div", ContextMenuTriggerState>;
|
|
44
45
|
}) => import("react").JSX.Element;
|
|
45
|
-
Popup: ({ side, align, sideOffset, alignOffset, collisionPadding, sticky, positionMethod, positionerClassName, renderPositioner, container, keepMounted, backdrop, renderBackdrop, className, ...otherProps }: import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
|
|
46
|
+
Popup: ({ side, align, sideOffset, alignOffset, collisionPadding, collisionBoundary, collisionAvoidance, anchor, disableAnchorTracking, arrowPadding, sticky, positionMethod, positionerClassName, renderPositioner, container, keepMounted, backdrop, renderBackdrop, className, ...otherProps }: import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
|
|
46
47
|
render?: RenderProp<"div", MenuPopupState>;
|
|
47
48
|
side?: MenuSide;
|
|
48
49
|
align?: MenuAlign;
|
|
49
|
-
sideOffset?: number;
|
|
50
|
-
alignOffset?: number;
|
|
51
|
-
collisionPadding?: number
|
|
50
|
+
sideOffset?: number | MenuOffsetFunction;
|
|
51
|
+
alignOffset?: number | MenuOffsetFunction;
|
|
52
|
+
collisionPadding?: number | {
|
|
53
|
+
top?: number;
|
|
54
|
+
right?: number;
|
|
55
|
+
bottom?: number;
|
|
56
|
+
left?: number;
|
|
57
|
+
};
|
|
58
|
+
collisionBoundary?: "clipping-ancestors" | Element | Element[] | {
|
|
59
|
+
x: number;
|
|
60
|
+
y: number;
|
|
61
|
+
width: number;
|
|
62
|
+
height: number;
|
|
63
|
+
};
|
|
64
|
+
collisionAvoidance?: MenuCollisionAvoidance;
|
|
65
|
+
anchor?: Element | import("react").RefObject<Element | null> | (() => Element | null) | null;
|
|
66
|
+
disableAnchorTracking?: boolean;
|
|
67
|
+
arrowPadding?: number;
|
|
52
68
|
sticky?: boolean;
|
|
53
69
|
positionMethod?: "absolute" | "fixed";
|
|
54
70
|
positionerClassName?: string;
|
|
@@ -114,14 +130,8 @@ declare const _default: (({ onOpenChange, ...otherProps }: BaseContextMenuProps)
|
|
|
114
130
|
closeOnClick?: boolean;
|
|
115
131
|
nativeButton?: boolean;
|
|
116
132
|
}) => import("react").JSX.Element;
|
|
117
|
-
Submenu: (
|
|
118
|
-
open?: boolean;
|
|
119
|
-
defaultOpen?: boolean;
|
|
133
|
+
Submenu: (props: MenuRootSharedProps & {
|
|
120
134
|
onOpenChange?: (open: boolean, event: Event | undefined) => void;
|
|
121
|
-
onOpenChangeComplete?: (open: boolean) => void;
|
|
122
|
-
disabled?: boolean;
|
|
123
|
-
loopFocus?: boolean;
|
|
124
|
-
highlightItemOnHover?: boolean;
|
|
125
135
|
closeParentOnEsc?: boolean;
|
|
126
136
|
children?: ReactNode;
|
|
127
137
|
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { MenuTriggerState } from "./BaseMenuTrigger.js";
|
|
3
|
+
import "../../utils/index.js";
|
|
4
|
+
import { MenuAlign, MenuBackdropState, MenuCollisionAvoidance, MenuFocusTarget, MenuOffsetFunction, MenuPopupState, MenuPositionerState, MenuSide } from "./BaseMenuPopup.js";
|
|
5
|
+
import { MenuArrowState } from "./BaseMenuArrow.js";
|
|
6
|
+
import { MenuViewportState } from "./BaseMenuViewport.js";
|
|
7
|
+
import { MenuItemState } from "./BaseMenuItem.js";
|
|
8
|
+
import { MenuLinkItemState } from "./BaseMenuLinkItem.js";
|
|
9
|
+
import { MenuCheckboxItemState } from "./BaseMenuCheckboxItem.js";
|
|
10
|
+
import { MenuRadioGroupState } from "./BaseMenuRadioGroup.js";
|
|
11
|
+
import { MenuRadioItemState } from "./BaseMenuRadioItem.js";
|
|
12
|
+
import { MenuSeparatorState } from "./BaseMenuSeparator.js";
|
|
13
|
+
import { MenuSubmenuTriggerState } from "./BaseMenuSubmenuTrigger.js";
|
|
14
|
+
import { MenuInputState } from "./BaseMenuInput.js";
|
|
15
|
+
import { MenuClearState } from "./BaseMenuClear.js";
|
|
16
|
+
import { MenuHandle } from "./createMenuHandle.js";
|
|
17
|
+
import { MenuRootSharedProps } from "./menuTypes.js";
|
|
18
|
+
import { ReactNode } from "react";
|
|
19
|
+
type BaseMenuProps<Payload = unknown> = MenuRootSharedProps & {
|
|
20
|
+
/** Called with the new state and the DOM event that changed it (none when it was changed from code). */
|
|
21
|
+
onOpenChange?: (open: boolean, event: Event | undefined) => void;
|
|
22
|
+
/**
|
|
23
|
+
* - `true`: page scroll is locked and the rest of the page ignores the pointer.
|
|
24
|
+
* - `false`: the rest of the page stays usable.
|
|
25
|
+
*
|
|
26
|
+
* Menus opened by hover are never modal.
|
|
27
|
+
* @default true
|
|
28
|
+
*/
|
|
29
|
+
modal?: boolean;
|
|
30
|
+
/** Connects triggers placed outside the menu, and opens it from code. Create one with `createMenuHandle()`. */
|
|
31
|
+
handle?: MenuHandle<Payload>;
|
|
32
|
+
/** The `id` of the trigger the menu belongs to, for a controlled menu with several triggers. */
|
|
33
|
+
triggerId?: string | null;
|
|
34
|
+
/** The `id` of the trigger an initially open menu belongs to. */
|
|
35
|
+
defaultTriggerId?: string | null;
|
|
36
|
+
/** The menu's parts, or a function that gets the payload of the trigger that opened it. */
|
|
37
|
+
children?: ReactNode | ((context: {
|
|
38
|
+
payload: Payload | undefined;
|
|
39
|
+
}) => ReactNode);
|
|
40
|
+
};
|
|
41
|
+
declare const _default: (<Payload>(props: BaseMenuProps<Payload>) => import("react").JSX.Element) & {
|
|
42
|
+
Trigger: <Payload>({ handle, ...otherProps }: import("react").ClassAttributes<HTMLButtonElement> & import("react").ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
43
|
+
render?: RenderProp<"button", MenuTriggerState>;
|
|
44
|
+
handle?: MenuHandle<Payload> | undefined;
|
|
45
|
+
payload?: Payload | undefined;
|
|
46
|
+
openOnHover?: boolean;
|
|
47
|
+
delay?: number;
|
|
48
|
+
closeDelay?: number;
|
|
49
|
+
nativeButton?: boolean;
|
|
50
|
+
}) => import("react").JSX.Element;
|
|
51
|
+
Popup: ({ side, align, sideOffset, alignOffset, collisionPadding, collisionBoundary, collisionAvoidance, anchor, disableAnchorTracking, arrowPadding, sticky, positionMethod, positionerClassName, renderPositioner, container, keepMounted, backdrop, renderBackdrop, className, ...otherProps }: import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
|
|
52
|
+
render?: RenderProp<"div", MenuPopupState>;
|
|
53
|
+
side?: MenuSide;
|
|
54
|
+
align?: MenuAlign;
|
|
55
|
+
sideOffset?: number | MenuOffsetFunction;
|
|
56
|
+
alignOffset?: number | MenuOffsetFunction;
|
|
57
|
+
collisionPadding?: number | {
|
|
58
|
+
top?: number;
|
|
59
|
+
right?: number;
|
|
60
|
+
bottom?: number;
|
|
61
|
+
left?: number;
|
|
62
|
+
};
|
|
63
|
+
collisionBoundary?: "clipping-ancestors" | Element | Element[] | {
|
|
64
|
+
x: number;
|
|
65
|
+
y: number;
|
|
66
|
+
width: number;
|
|
67
|
+
height: number;
|
|
68
|
+
};
|
|
69
|
+
collisionAvoidance?: MenuCollisionAvoidance;
|
|
70
|
+
anchor?: Element | import("react").RefObject<Element | null> | (() => Element | null) | null;
|
|
71
|
+
disableAnchorTracking?: boolean;
|
|
72
|
+
arrowPadding?: number;
|
|
73
|
+
sticky?: boolean;
|
|
74
|
+
positionMethod?: "absolute" | "fixed";
|
|
75
|
+
positionerClassName?: string;
|
|
76
|
+
renderPositioner?: RenderProp<"div", MenuPositionerState>;
|
|
77
|
+
finalFocus?: MenuFocusTarget;
|
|
78
|
+
container?: HTMLElement | ShadowRoot | import("react").RefObject<HTMLElement | ShadowRoot | null> | null;
|
|
79
|
+
keepMounted?: boolean;
|
|
80
|
+
backdrop?: boolean;
|
|
81
|
+
renderBackdrop?: RenderProp<"div", MenuBackdropState>;
|
|
82
|
+
}) => import("react").JSX.Element;
|
|
83
|
+
Arrow: (props: import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
|
|
84
|
+
render?: RenderProp<"div", MenuArrowState>;
|
|
85
|
+
}) => import("react").JSX.Element;
|
|
86
|
+
Viewport: (props: import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
|
|
87
|
+
render?: RenderProp<"div", MenuViewportState>;
|
|
88
|
+
}) => import("react").JSX.Element;
|
|
89
|
+
Item: ({ className, ...otherProps }: import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
|
|
90
|
+
render?: RenderProp<"div", MenuItemState>;
|
|
91
|
+
disabled?: boolean;
|
|
92
|
+
label?: string;
|
|
93
|
+
closeOnClick?: boolean;
|
|
94
|
+
nativeButton?: boolean;
|
|
95
|
+
}) => import("react").JSX.Element;
|
|
96
|
+
LinkItem: ({ className, ...otherProps }: import("react").ClassAttributes<HTMLAnchorElement> & import("react").AnchorHTMLAttributes<HTMLAnchorElement> & {
|
|
97
|
+
render?: RenderProp<"a", MenuLinkItemState>;
|
|
98
|
+
label?: string;
|
|
99
|
+
closeOnClick?: boolean;
|
|
100
|
+
}) => import("react").JSX.Element;
|
|
101
|
+
CheckboxItem: ({ indicator, renderIndicator, keepIndicatorMounted, onCheckedChange, className, children, ...otherProps }: Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "defaultChecked"> & {
|
|
102
|
+
render?: RenderProp<"div", MenuCheckboxItemState>;
|
|
103
|
+
checked?: boolean;
|
|
104
|
+
defaultChecked?: boolean;
|
|
105
|
+
onCheckedChange?: (checked: boolean, event: Event) => void;
|
|
106
|
+
indicator?: ReactNode;
|
|
107
|
+
renderIndicator?: RenderProp<"span", MenuCheckboxItemState>;
|
|
108
|
+
keepIndicatorMounted?: boolean;
|
|
109
|
+
disabled?: boolean;
|
|
110
|
+
label?: string;
|
|
111
|
+
closeOnClick?: boolean;
|
|
112
|
+
nativeButton?: boolean;
|
|
113
|
+
}) => import("react").JSX.Element;
|
|
114
|
+
RadioGroup: <Value>({ onValueChange, ...otherProps }: Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "defaultValue"> & {
|
|
115
|
+
render?: RenderProp<"div", MenuRadioGroupState>;
|
|
116
|
+
value?: Value | undefined;
|
|
117
|
+
defaultValue?: Value | undefined;
|
|
118
|
+
onValueChange?: ((value: Value, event: Event) => void) | undefined;
|
|
119
|
+
disabled?: boolean;
|
|
120
|
+
}) => import("react").JSX.Element;
|
|
121
|
+
RadioItem: <Value>({ indicator, renderIndicator, keepIndicatorMounted, className, children, ...otherProps }: import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
|
|
122
|
+
value: Value;
|
|
123
|
+
render?: RenderProp<"div", MenuRadioItemState>;
|
|
124
|
+
indicator?: ReactNode;
|
|
125
|
+
renderIndicator?: RenderProp<"span", MenuRadioItemState>;
|
|
126
|
+
keepIndicatorMounted?: boolean;
|
|
127
|
+
disabled?: boolean;
|
|
128
|
+
label?: string;
|
|
129
|
+
closeOnClick?: boolean;
|
|
130
|
+
nativeButton?: boolean;
|
|
131
|
+
}) => import("react").JSX.Element;
|
|
132
|
+
Group: (props: import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
|
|
133
|
+
render?: RenderProp<"div">;
|
|
134
|
+
}) => import("react").JSX.Element;
|
|
135
|
+
GroupLabel: ({ className, ...otherProps }: import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
|
|
136
|
+
render?: RenderProp<"div">;
|
|
137
|
+
}) => import("react").JSX.Element;
|
|
138
|
+
Separator: ({ className, ...otherProps }: import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
|
|
139
|
+
render?: RenderProp<"div", MenuSeparatorState>;
|
|
140
|
+
}) => import("react").JSX.Element;
|
|
141
|
+
Submenu: (props: MenuRootSharedProps & {
|
|
142
|
+
onOpenChange?: (open: boolean, event: Event | undefined) => void;
|
|
143
|
+
closeParentOnEsc?: boolean;
|
|
144
|
+
children?: ReactNode;
|
|
145
|
+
}) => import("react").JSX.Element;
|
|
146
|
+
SubmenuTrigger: ({ icon, iconClassName, className, children, ...otherProps }: import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
|
|
147
|
+
render?: RenderProp<"div", MenuSubmenuTriggerState>;
|
|
148
|
+
icon?: ReactNode;
|
|
149
|
+
iconClassName?: string;
|
|
150
|
+
disabled?: boolean;
|
|
151
|
+
label?: string;
|
|
152
|
+
openOnHover?: boolean;
|
|
153
|
+
delay?: number;
|
|
154
|
+
closeDelay?: number;
|
|
155
|
+
nativeButton?: boolean;
|
|
156
|
+
}) => import("react").JSX.Element;
|
|
157
|
+
Input: (props: Omit<import("react").DetailedHTMLProps<import("react").InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "value" | "defaultValue"> & {
|
|
158
|
+
render?: RenderProp<"input", MenuInputState>;
|
|
159
|
+
}) => import("react").JSX.Element;
|
|
160
|
+
Clear: (props: import("react").ClassAttributes<HTMLButtonElement> & import("react").ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
161
|
+
render?: RenderProp<"button", MenuClearState>;
|
|
162
|
+
nativeButton?: boolean;
|
|
163
|
+
}) => import("react").JSX.Element;
|
|
164
|
+
Empty: (props: import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
|
|
165
|
+
render?: RenderProp<"div">;
|
|
166
|
+
}) => import("react").JSX.Element;
|
|
167
|
+
List: ({ className, ...otherProps }: import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
|
|
168
|
+
render?: RenderProp<"div">;
|
|
169
|
+
}) => import("react").JSX.Element;
|
|
170
|
+
};
|
|
171
|
+
export { _default as default };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Menu } from "@base-ui/react/menu";
|
|
3
|
+
import BaseMenuArrow from "./BaseMenuArrow.js";
|
|
4
|
+
import BaseMenuCheckboxItem from "./BaseMenuCheckboxItem.js";
|
|
5
|
+
import BaseMenuClear from "./BaseMenuClear.js";
|
|
6
|
+
import BaseMenuEmpty from "./BaseMenuEmpty.js";
|
|
7
|
+
import BaseMenuGroup from "./BaseMenuGroup.js";
|
|
8
|
+
import BaseMenuGroupLabel from "./BaseMenuGroupLabel.js";
|
|
9
|
+
import BaseMenuInput from "./BaseMenuInput.js";
|
|
10
|
+
import BaseMenuItem from "./BaseMenuItem.js";
|
|
11
|
+
import BaseMenuLinkItem from "./BaseMenuLinkItem.js";
|
|
12
|
+
import BaseMenuList from "./BaseMenuList.js";
|
|
13
|
+
import BaseMenuPopup from "./BaseMenuPopup.js";
|
|
14
|
+
import BaseMenuRadioGroup from "./BaseMenuRadioGroup.js";
|
|
15
|
+
import BaseMenuRadioItem from "./BaseMenuRadioItem.js";
|
|
16
|
+
import BaseMenuSeparator from "./BaseMenuSeparator.js";
|
|
17
|
+
import BaseMenuSubmenu from "./BaseMenuSubmenu.js";
|
|
18
|
+
import BaseMenuSubmenuTrigger from "./BaseMenuSubmenuTrigger.js";
|
|
19
|
+
import BaseMenuTrigger from "./BaseMenuTrigger.js";
|
|
20
|
+
import BaseMenuViewport from "./BaseMenuViewport.js";
|
|
21
|
+
import { toBaseUIHandle } from "./createMenuHandle.js";
|
|
22
|
+
import { splitFilterProps } from "./menuTypes.js";
|
|
23
|
+
import { jsx } from "react/jsx-runtime";
|
|
24
|
+
// src/components/menu/BaseMenu.tsx
|
|
25
|
+
/** Groups the parts of a menu and holds its open state. Renders no element. */
|
|
26
|
+
const BaseMenu = (props) => {
|
|
27
|
+
const { filterProps, rootProps: { handle, onOpenChange, onItemHighlighted, ...otherProps } } = splitFilterProps(props);
|
|
28
|
+
const root = /* @__PURE__ */ jsx(Menu.Root, {
|
|
29
|
+
...otherProps,
|
|
30
|
+
handle: handle && toBaseUIHandle(handle),
|
|
31
|
+
onOpenChange: onOpenChange && ((open, details) => onOpenChange(open, details.event)),
|
|
32
|
+
onItemHighlighted: onItemHighlighted && ((item, details) => onItemHighlighted(item, {
|
|
33
|
+
reason: details.reason,
|
|
34
|
+
label: details.label
|
|
35
|
+
}))
|
|
36
|
+
});
|
|
37
|
+
return filterProps ? /* @__PURE__ */ jsx(Menu.FilterProvider, {
|
|
38
|
+
...filterProps,
|
|
39
|
+
children: root
|
|
40
|
+
}) : root;
|
|
41
|
+
};
|
|
42
|
+
var BaseMenu_default = Object.assign(BaseMenu, {
|
|
43
|
+
Trigger: BaseMenuTrigger,
|
|
44
|
+
Popup: BaseMenuPopup,
|
|
45
|
+
Arrow: BaseMenuArrow,
|
|
46
|
+
Viewport: BaseMenuViewport,
|
|
47
|
+
Item: BaseMenuItem,
|
|
48
|
+
LinkItem: BaseMenuLinkItem,
|
|
49
|
+
CheckboxItem: BaseMenuCheckboxItem,
|
|
50
|
+
RadioGroup: BaseMenuRadioGroup,
|
|
51
|
+
RadioItem: BaseMenuRadioItem,
|
|
52
|
+
Group: BaseMenuGroup,
|
|
53
|
+
GroupLabel: BaseMenuGroupLabel,
|
|
54
|
+
Separator: BaseMenuSeparator,
|
|
55
|
+
Submenu: BaseMenuSubmenu,
|
|
56
|
+
SubmenuTrigger: BaseMenuSubmenuTrigger,
|
|
57
|
+
Input: BaseMenuInput,
|
|
58
|
+
Clear: BaseMenuClear,
|
|
59
|
+
Empty: BaseMenuEmpty,
|
|
60
|
+
List: BaseMenuList
|
|
61
|
+
});
|
|
62
|
+
export { BaseMenu_default as default };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
export type MenuClearState = {
|
|
4
|
+
disabled: boolean;
|
|
5
|
+
};
|
|
6
|
+
type BaseMenuClearProps = ComponentProps<"button"> & {
|
|
7
|
+
render?: RenderProp<"button", MenuClearState>;
|
|
8
|
+
/** Set to `false` when `render` doesn't render a `<button>`. */
|
|
9
|
+
nativeButton?: boolean;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* A button that clears the search box of a `filterable` menu. Renders a `<button>`, only while there's a query.
|
|
13
|
+
* It's a pointer shortcut: out of the tab order and hidden from assistive technology (`aria-hidden`).
|
|
14
|
+
*/
|
|
15
|
+
declare const BaseMenuClear: (props: BaseMenuClearProps) => import("react").JSX.Element;
|
|
16
|
+
export { BaseMenuClear as default };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Menu } from "@base-ui/react/menu";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// src/components/menu/BaseMenuClear.tsx
|
|
5
|
+
/**
|
|
6
|
+
* A button that clears the search box of a `filterable` menu. Renders a `<button>`, only while there's a query.
|
|
7
|
+
* It's a pointer shortcut: out of the tab order and hidden from assistive technology (`aria-hidden`).
|
|
8
|
+
*/
|
|
9
|
+
const BaseMenuClear = (props) => /* @__PURE__ */ jsx(Menu.Clear, { ...props });
|
|
10
|
+
export { BaseMenuClear as default };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
type BaseMenuEmptyProps = ComponentProps<"div"> & {
|
|
4
|
+
render?: RenderProp<"div">;
|
|
5
|
+
};
|
|
6
|
+
/** Shown only when no item of a `filterable` menu matches. Renders a `<div>` with `role="status"`, only then. */
|
|
7
|
+
declare const BaseMenuEmpty: (props: BaseMenuEmptyProps) => import("react").JSX.Element;
|
|
8
|
+
export { BaseMenuEmpty as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Menu } from "@base-ui/react/menu";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// src/components/menu/BaseMenuEmpty.tsx
|
|
5
|
+
/** Shown only when no item of a `filterable` menu matches. Renders a `<div>` with `role="status"`, only then. */
|
|
6
|
+
const BaseMenuEmpty = (props) => /* @__PURE__ */ jsx(Menu.Empty, { ...props });
|
|
7
|
+
export { BaseMenuEmpty as default };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
export type MenuInputState = {
|
|
4
|
+
/** Whether the input shows its focus. Cleared while an item is highlighted with the arrow keys. */
|
|
5
|
+
highlighted: boolean;
|
|
6
|
+
};
|
|
7
|
+
type BaseMenuInputProps = Omit<ComponentProps<"input">, "value" | "defaultValue"> & {
|
|
8
|
+
render?: RenderProp<"input", MenuInputState>;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* The search box of a `filterable` menu: put it in the popup, outside the `List`. Typing filters the items.
|
|
12
|
+
* Renders an `<input>`, with `data-highlighted` while it has the visual focus.
|
|
13
|
+
*/
|
|
14
|
+
declare const BaseMenuInput: (props: BaseMenuInputProps) => import("react").JSX.Element;
|
|
15
|
+
export { BaseMenuInput as default };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Menu } from "@base-ui/react/menu";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// src/components/menu/BaseMenuInput.tsx
|
|
5
|
+
/**
|
|
6
|
+
* The search box of a `filterable` menu: put it in the popup, outside the `List`. Typing filters the items.
|
|
7
|
+
* Renders an `<input>`, with `data-highlighted` while it has the visual focus.
|
|
8
|
+
*/
|
|
9
|
+
const BaseMenuInput = (props) => /* @__PURE__ */ jsx(Menu.Input, { ...props });
|
|
10
|
+
export { BaseMenuInput as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
type BaseMenuListProps = ComponentProps<"div"> & {
|
|
4
|
+
render?: RenderProp<"div">;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Holds the items when the popup has other content too, like the search box of a `filterable` menu.
|
|
8
|
+
* Scrolls when the popup runs out of space. Renders a `<div>`.
|
|
9
|
+
*/
|
|
10
|
+
declare const BaseMenuList: ({ className, ...otherProps }: BaseMenuListProps) => import("react").JSX.Element;
|
|
11
|
+
export { BaseMenuList as default };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Menu } from "@base-ui/react/menu";
|
|
3
|
+
import { cn } from "cn";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
// src/components/menu/BaseMenuList.tsx
|
|
6
|
+
/**
|
|
7
|
+
* Holds the items when the popup has other content too, like the search box of a `filterable` menu.
|
|
8
|
+
* Scrolls when the popup runs out of space. Renders a `<div>`.
|
|
9
|
+
*/
|
|
10
|
+
const BaseMenuList = ({ className, ...otherProps }) => /* @__PURE__ */ jsx(Menu.List, {
|
|
11
|
+
...otherProps,
|
|
12
|
+
className: cn("min-h-0 flex-1 overflow-y-auto overscroll-contain", className)
|
|
13
|
+
});
|
|
14
|
+
export { BaseMenuList as default };
|
|
@@ -25,21 +25,67 @@ export type MenuInteractionType = "mouse" | "touch" | "pen" | "keyboard" | "";
|
|
|
25
25
|
* - a function: return an element, `true` / `null` for the default, or `false` / `undefined` to not move focus.
|
|
26
26
|
*/
|
|
27
27
|
export type MenuFocusTarget = boolean | RefObject<HTMLElement | null> | ((interactionType: MenuInteractionType) => boolean | HTMLElement | null | void);
|
|
28
|
+
/** Computes an offset from the popup's placement and the sizes of the anchor and the popup. */
|
|
29
|
+
export type MenuOffsetFunction = (data: {
|
|
30
|
+
side: MenuSide;
|
|
31
|
+
align: MenuAlign;
|
|
32
|
+
anchor: {
|
|
33
|
+
width: number;
|
|
34
|
+
height: number;
|
|
35
|
+
};
|
|
36
|
+
positioner: {
|
|
37
|
+
width: number;
|
|
38
|
+
height: number;
|
|
39
|
+
};
|
|
40
|
+
}) => number;
|
|
41
|
+
/** How the popup avoids the edges of `collisionBoundary`. */
|
|
42
|
+
export type MenuCollisionAvoidance = {
|
|
43
|
+
side?: "flip" | "none";
|
|
44
|
+
align?: "flip" | "shift" | "none";
|
|
45
|
+
fallbackAxisSide?: "start" | "end" | "none";
|
|
46
|
+
} | {
|
|
47
|
+
side?: "shift" | "none";
|
|
48
|
+
align?: "shift" | "none";
|
|
49
|
+
fallbackAxisSide?: "start" | "end" | "none";
|
|
50
|
+
};
|
|
51
|
+
type Rect = {
|
|
52
|
+
x: number;
|
|
53
|
+
y: number;
|
|
54
|
+
width: number;
|
|
55
|
+
height: number;
|
|
56
|
+
};
|
|
28
57
|
type BaseMenuPopupProps = ComponentProps<"div"> & {
|
|
29
58
|
render?: RenderProp<"div", MenuPopupState>;
|
|
30
59
|
/** The side of the anchor the popup is placed on. It flips when there's no room. Submenus default to `"inline-end"`. */
|
|
31
60
|
side?: MenuSide;
|
|
32
61
|
/** How the popup is aligned to that side. Submenus default to `"start"`. */
|
|
33
62
|
align?: MenuAlign;
|
|
34
|
-
/** The gap between the anchor and the popup, in pixels. */
|
|
35
|
-
sideOffset?: number;
|
|
36
|
-
/** Moves the popup along the anchor's side, in pixels. */
|
|
37
|
-
alignOffset?: number;
|
|
63
|
+
/** The gap between the anchor and the popup, in pixels, or a function of the placement and sizes. */
|
|
64
|
+
sideOffset?: number | MenuOffsetFunction;
|
|
65
|
+
/** Moves the popup along the anchor's side, in pixels, or a function of the placement and sizes. */
|
|
66
|
+
alignOffset?: number | MenuOffsetFunction;
|
|
38
67
|
/**
|
|
39
68
|
* The space kept between the popup and the edges of the viewport, in pixels.
|
|
40
69
|
* @default 5
|
|
41
70
|
*/
|
|
42
|
-
collisionPadding?: number
|
|
71
|
+
collisionPadding?: number | {
|
|
72
|
+
top?: number;
|
|
73
|
+
right?: number;
|
|
74
|
+
bottom?: number;
|
|
75
|
+
left?: number;
|
|
76
|
+
};
|
|
77
|
+
/** The area the popup stays inside. @default "clipping-ancestors" */
|
|
78
|
+
collisionBoundary?: "clipping-ancestors" | Element | Element[] | Rect;
|
|
79
|
+
collisionAvoidance?: MenuCollisionAvoidance;
|
|
80
|
+
/** The element the popup is placed against. Defaults to the trigger. */
|
|
81
|
+
anchor?: Element | RefObject<Element | null> | (() => Element | null) | null;
|
|
82
|
+
/** Stops following the anchor when it moves (e.g. on scroll). */
|
|
83
|
+
disableAnchorTracking?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* The minimum distance between an `Arrow` and the popup's corners, in pixels.
|
|
86
|
+
* @default 5
|
|
87
|
+
*/
|
|
88
|
+
arrowPadding?: number;
|
|
43
89
|
/** Keeps the popup in view while its anchor scrolls out of view. */
|
|
44
90
|
sticky?: boolean;
|
|
45
91
|
/**
|
|
@@ -66,5 +112,5 @@ type BaseMenuPopupProps = ComponentProps<"div"> & {
|
|
|
66
112
|
* The menu's popup, with its portal and positioner (and an optional backdrop).
|
|
67
113
|
* Renders a `<div>` with `data-side`, `data-align`, `data-open` / `data-closed` and transition attributes.
|
|
68
114
|
*/
|
|
69
|
-
declare const BaseMenuPopup: ({ side, align, sideOffset, alignOffset, collisionPadding, sticky, positionMethod, positionerClassName, renderPositioner, container, keepMounted, backdrop, renderBackdrop, className, ...otherProps }: BaseMenuPopupProps) => import("react").JSX.Element;
|
|
115
|
+
declare const BaseMenuPopup: ({ side, align, sideOffset, alignOffset, collisionPadding, collisionBoundary, collisionAvoidance, anchor, disableAnchorTracking, arrowPadding, sticky, positionMethod, positionerClassName, renderPositioner, container, keepMounted, backdrop, renderBackdrop, className, ...otherProps }: BaseMenuPopupProps) => import("react").JSX.Element;
|
|
70
116
|
export { BaseMenuPopup as default };
|
|
@@ -8,7 +8,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
8
8
|
* The menu's popup, with its portal and positioner (and an optional backdrop).
|
|
9
9
|
* Renders a `<div>` with `data-side`, `data-align`, `data-open` / `data-closed` and transition attributes.
|
|
10
10
|
*/
|
|
11
|
-
const BaseMenuPopup = ({ side, align, sideOffset, alignOffset, collisionPadding, sticky, positionMethod, positionerClassName, renderPositioner, container, keepMounted, backdrop = false, renderBackdrop, className, ...otherProps }) => {
|
|
11
|
+
const BaseMenuPopup = ({ side, align, sideOffset, alignOffset, collisionPadding, collisionBoundary, collisionAvoidance, anchor, disableAnchorTracking, arrowPadding, sticky, positionMethod, positionerClassName, renderPositioner, container, keepMounted, backdrop = false, renderBackdrop, className, ...otherProps }) => {
|
|
12
12
|
const backdropElement = splitClassName(renderBackdrop);
|
|
13
13
|
const positionerElement = splitClassName(renderPositioner);
|
|
14
14
|
return /* @__PURE__ */ jsxs(Menu.Portal, {
|
|
@@ -23,6 +23,11 @@ const BaseMenuPopup = ({ side, align, sideOffset, alignOffset, collisionPadding,
|
|
|
23
23
|
sideOffset,
|
|
24
24
|
alignOffset,
|
|
25
25
|
collisionPadding,
|
|
26
|
+
collisionBoundary,
|
|
27
|
+
collisionAvoidance,
|
|
28
|
+
anchor,
|
|
29
|
+
disableAnchorTracking,
|
|
30
|
+
arrowPadding,
|
|
26
31
|
sticky,
|
|
27
32
|
positionMethod,
|
|
28
33
|
render: positionerElement.render,
|
|
@@ -1,28 +1,13 @@
|
|
|
1
|
+
import { MenuRootSharedProps } from "./menuTypes.js";
|
|
1
2
|
import { ReactNode } from "react";
|
|
2
|
-
type BaseMenuSubmenuProps = {
|
|
3
|
-
open?: boolean;
|
|
4
|
-
defaultOpen?: boolean;
|
|
3
|
+
type BaseMenuSubmenuProps = MenuRootSharedProps & {
|
|
5
4
|
/** Called with the new state and the DOM event that changed it (none when it was changed from code). */
|
|
6
5
|
onOpenChange?: (open: boolean, event: Event | undefined) => void;
|
|
7
|
-
/** Called after the open or close transition ends. */
|
|
8
|
-
onOpenChangeComplete?: (open: boolean) => void;
|
|
9
|
-
/** Ignores user interaction. */
|
|
10
|
-
disabled?: boolean;
|
|
11
|
-
/**
|
|
12
|
-
* Moves focus from the last item back to the first with the arrow keys, and the other way around.
|
|
13
|
-
* @default true
|
|
14
|
-
*/
|
|
15
|
-
loopFocus?: boolean;
|
|
16
|
-
/**
|
|
17
|
-
* Highlights items under the pointer. Turn it off to style `:hover` apart from `data-highlighted`.
|
|
18
|
-
* @default true
|
|
19
|
-
*/
|
|
20
|
-
highlightItemOnHover?: boolean;
|
|
21
6
|
/** Closes the whole menu on Escape, instead of only the submenu. */
|
|
22
7
|
closeParentOnEsc?: boolean;
|
|
23
8
|
/** A `SubmenuTrigger` and a `Popup`. */
|
|
24
9
|
children?: ReactNode;
|
|
25
10
|
};
|
|
26
11
|
/** Groups a submenu's trigger and popup. Put it among the items of a menu. Renders no element. */
|
|
27
|
-
declare const BaseMenuSubmenu: (
|
|
12
|
+
declare const BaseMenuSubmenu: (props: BaseMenuSubmenuProps) => import("react").JSX.Element;
|
|
28
13
|
export { BaseMenuSubmenu as default };
|
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Menu } from "@base-ui/react/menu";
|
|
3
|
+
import { splitFilterProps } from "./menuTypes.js";
|
|
3
4
|
import { jsx } from "react/jsx-runtime";
|
|
4
5
|
// src/components/menu/BaseMenuSubmenu.tsx
|
|
5
6
|
/** Groups a submenu's trigger and popup. Put it among the items of a menu. Renders no element. */
|
|
6
|
-
const BaseMenuSubmenu = (
|
|
7
|
-
...otherProps
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const BaseMenuSubmenu = (props) => {
|
|
8
|
+
const { filterProps, rootProps: { onOpenChange, onItemHighlighted, ...otherProps } } = splitFilterProps(props);
|
|
9
|
+
const root = /* @__PURE__ */ jsx(Menu.SubmenuRoot, {
|
|
10
|
+
...otherProps,
|
|
11
|
+
onOpenChange: onOpenChange && ((open, details) => onOpenChange(open, details.event)),
|
|
12
|
+
onItemHighlighted: onItemHighlighted && ((item, details) => onItemHighlighted(item, {
|
|
13
|
+
reason: details.reason,
|
|
14
|
+
label: details.label
|
|
15
|
+
}))
|
|
16
|
+
});
|
|
17
|
+
return filterProps ? /* @__PURE__ */ jsx(Menu.FilterProvider, {
|
|
18
|
+
...filterProps,
|
|
19
|
+
children: root
|
|
20
|
+
}) : root;
|
|
21
|
+
};
|
|
10
22
|
export { BaseMenuSubmenu as default };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { MenuHandle } from "./createMenuHandle.js";
|
|
2
|
+
import { RenderProp } from "../../utils/render.js";
|
|
3
|
+
import { ComponentProps } from "react";
|
|
4
|
+
export type MenuTriggerState = {
|
|
5
|
+
disabled: boolean;
|
|
6
|
+
/** Whether the menu is open and was opened by this trigger. */
|
|
7
|
+
open: boolean;
|
|
8
|
+
};
|
|
9
|
+
type BaseMenuTriggerProps<Payload = unknown> = ComponentProps<"button"> & {
|
|
10
|
+
render?: RenderProp<"button", MenuTriggerState>;
|
|
11
|
+
/** Connects a trigger placed outside its `BaseMenu`. Create one with `createMenuHandle()`. */
|
|
12
|
+
handle?: MenuHandle<Payload>;
|
|
13
|
+
/** Passed to the menu's function children when this trigger opens it. */
|
|
14
|
+
payload?: Payload;
|
|
15
|
+
/** Also opens the menu when the trigger is hovered. */
|
|
16
|
+
openOnHover?: boolean;
|
|
17
|
+
/** With `openOnHover`, the wait before opening, in milliseconds. @default 100 */
|
|
18
|
+
delay?: number;
|
|
19
|
+
/** With `openOnHover`, the wait before closing, in milliseconds. @default 0 */
|
|
20
|
+
closeDelay?: number;
|
|
21
|
+
/** Set to `false` when `render` doesn't render a `<button>`. */
|
|
22
|
+
nativeButton?: boolean;
|
|
23
|
+
};
|
|
24
|
+
/** A button that opens the menu. Renders a `<button>`, with `data-popup-open` while its menu is open. */
|
|
25
|
+
declare const BaseMenuTrigger: <Payload>({ handle, ...otherProps }: BaseMenuTriggerProps<Payload>) => import("react").JSX.Element;
|
|
26
|
+
export { BaseMenuTrigger as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Menu } from "@base-ui/react/menu";
|
|
3
|
+
import { toBaseUIHandle } from "./createMenuHandle.js";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
// src/components/menu/BaseMenuTrigger.tsx
|
|
6
|
+
/** A button that opens the menu. Renders a `<button>`, with `data-popup-open` while its menu is open. */
|
|
7
|
+
const BaseMenuTrigger = ({ handle, ...otherProps }) => /* @__PURE__ */ jsx(Menu.Trigger, {
|
|
8
|
+
...otherProps,
|
|
9
|
+
handle: handle && toBaseUIHandle(handle)
|
|
10
|
+
});
|
|
11
|
+
export { BaseMenuTrigger as default };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
export type MenuViewportState = {
|
|
4
|
+
/** The direction the new trigger is in, relative to the previous one (e.g. `"right"`). */
|
|
5
|
+
activationDirection: string | undefined;
|
|
6
|
+
/** Whether the content is changing from one trigger's to another's. */
|
|
7
|
+
transitioning: boolean;
|
|
8
|
+
};
|
|
9
|
+
type BaseMenuViewportProps = ComponentProps<"div"> & {
|
|
10
|
+
render?: RenderProp<"div", MenuViewportState>;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Animates the popup's content when one menu is opened by several triggers and its content depends
|
|
14
|
+
* on the trigger. Wrap the content in it, inside the popup. Renders a `<div>`, with
|
|
15
|
+
* `data-activation-direction` and `data-transitioning`.
|
|
16
|
+
*/
|
|
17
|
+
declare const BaseMenuViewport: (props: BaseMenuViewportProps) => import("react").JSX.Element;
|
|
18
|
+
export { BaseMenuViewport as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Menu } from "@base-ui/react/menu";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// src/components/menu/BaseMenuViewport.tsx
|
|
5
|
+
/**
|
|
6
|
+
* Animates the popup's content when one menu is opened by several triggers and its content depends
|
|
7
|
+
* on the trigger. Wrap the content in it, inside the popup. Renders a `<div>`, with
|
|
8
|
+
* `data-activation-direction` and `data-transitioning`.
|
|
9
|
+
*/
|
|
10
|
+
const BaseMenuViewport = (props) => /* @__PURE__ */ jsx(Menu.Viewport, { ...props });
|
|
11
|
+
export { BaseMenuViewport as default };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Carries a handle's payload type. Type-only: it doesn't exist at runtime. */
|
|
2
|
+
declare const payloadType: unique symbol;
|
|
3
|
+
/**
|
|
4
|
+
* Opens and closes a menu from anywhere: from triggers outside the menu and from code.
|
|
5
|
+
* Create one with `createMenuHandle()` and pass it to `BaseMenu` and its triggers.
|
|
6
|
+
*
|
|
7
|
+
* A menu is placed against a trigger, so it can only be opened through one: there is no `openWithPayload`.
|
|
8
|
+
* Calls are ignored while no `BaseMenu` with this handle is mounted.
|
|
9
|
+
* Call the methods from event handlers or effects, never during render.
|
|
10
|
+
*/
|
|
11
|
+
export type MenuHandle<Payload = unknown> = {
|
|
12
|
+
/** Opens the menu as if the trigger with this `id` was pressed. The trigger must use the same handle. */
|
|
13
|
+
open: (triggerId: string) => void;
|
|
14
|
+
close: () => void;
|
|
15
|
+
/** Whether the menu is open. `false` while no `BaseMenu` with this handle is mounted. */
|
|
16
|
+
readonly isOpen: boolean;
|
|
17
|
+
/** Types the payload of triggers and of `BaseMenu`'s function children. Never set. */
|
|
18
|
+
readonly [payloadType]?: Payload;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Returns the Base UI handle behind a kit handle. Internal: not exported to apps.
|
|
22
|
+
* Its return type doesn't name Base UI so the declaration files don't either. Callers cast it.
|
|
23
|
+
*/
|
|
24
|
+
export declare function toBaseUIHandle<Payload>(handle: MenuHandle<Payload>): object | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a handle to open a menu from triggers outside it, or from code.
|
|
27
|
+
* Pass the payload type to type the payload of triggers and of `BaseMenu`'s function children.
|
|
28
|
+
*/
|
|
29
|
+
export default function createMenuHandle<Payload = unknown>(): MenuHandle<Payload>;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Menu } from "@base-ui/react/menu";
|
|
2
|
+
// src/components/menu/createMenuHandle.ts
|
|
3
|
+
const baseUIHandles = /* @__PURE__ */ new WeakMap();
|
|
4
|
+
/**
|
|
5
|
+
* Returns the Base UI handle behind a kit handle. Internal: not exported to apps.
|
|
6
|
+
* Its return type doesn't name Base UI so the declaration files don't either. Callers cast it.
|
|
7
|
+
*/
|
|
8
|
+
function toBaseUIHandle(handle) {
|
|
9
|
+
return baseUIHandles.get(handle);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Creates a handle to open a menu from triggers outside it, or from code.
|
|
13
|
+
* Pass the payload type to type the payload of triggers and of `BaseMenu`'s function children.
|
|
14
|
+
*/
|
|
15
|
+
function createMenuHandle() {
|
|
16
|
+
const baseUIHandle = Menu.createHandle();
|
|
17
|
+
const handle = {
|
|
18
|
+
open: (triggerId) => baseUIHandle.open(triggerId),
|
|
19
|
+
close: () => baseUIHandle.close(),
|
|
20
|
+
get isOpen() {
|
|
21
|
+
return baseUIHandle.isOpen;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
baseUIHandles.set(handle, baseUIHandle);
|
|
25
|
+
return handle;
|
|
26
|
+
}
|
|
27
|
+
export { createMenuHandle as default, toBaseUIHandle };
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import _default from "./BaseContextMenu.js";
|
|
2
|
+
import _default$1 from "./BaseMenu.js";
|
|
3
|
+
import createMenuHandle, { MenuHandle } from "./createMenuHandle.js";
|
|
4
|
+
import { MenuActions, MenuHighlightReason } from "./menuTypes.js";
|
|
2
5
|
import { ContextMenuTriggerState } from "./BaseContextMenuTrigger.js";
|
|
6
|
+
import { MenuTriggerState } from "./BaseMenuTrigger.js";
|
|
3
7
|
import { MenuArrowState } from "./BaseMenuArrow.js";
|
|
4
8
|
import { MenuCheckboxItemState } from "./BaseMenuCheckboxItem.js";
|
|
5
9
|
import { MenuItemState } from "./BaseMenuItem.js";
|
|
6
10
|
import { MenuLinkItemState } from "./BaseMenuLinkItem.js";
|
|
7
|
-
import { MenuAlign, MenuBackdropState, MenuFocusTarget, MenuInteractionType, MenuPopupState, MenuPositionerState, MenuSide } from "./BaseMenuPopup.js";
|
|
11
|
+
import { MenuAlign, MenuBackdropState, MenuCollisionAvoidance, MenuFocusTarget, MenuInteractionType, MenuOffsetFunction, MenuPopupState, MenuPositionerState, MenuSide } from "./BaseMenuPopup.js";
|
|
8
12
|
import { MenuRadioGroupState } from "./BaseMenuRadioGroup.js";
|
|
9
13
|
import { MenuRadioItemState } from "./BaseMenuRadioItem.js";
|
|
10
14
|
import { MenuSeparatorState } from "./BaseMenuSeparator.js";
|
|
11
15
|
import { MenuSubmenuTriggerState } from "./BaseMenuSubmenuTrigger.js";
|
|
12
|
-
|
|
16
|
+
import { MenuViewportState } from "./BaseMenuViewport.js";
|
|
17
|
+
import { MenuInputState } from "./BaseMenuInput.js";
|
|
18
|
+
import { MenuClearState } from "./BaseMenuClear.js";
|
|
19
|
+
export { _default as BaseContextMenu, _default$1 as BaseMenu, type ContextMenuTriggerState, type MenuActions, type MenuAlign, type MenuArrowState, type MenuBackdropState, type MenuCheckboxItemState, type MenuClearState, type MenuCollisionAvoidance, type MenuFocusTarget, type MenuHandle, type MenuHighlightReason, type MenuInputState, type MenuInteractionType, type MenuItemState, type MenuLinkItemState, type MenuOffsetFunction, type MenuPopupState, type MenuPositionerState, type MenuRadioGroupState, type MenuRadioItemState, type MenuSeparatorState, type MenuSide, type MenuSubmenuTriggerState, type MenuTriggerState, type MenuViewportState, createMenuHandle };
|
|
@@ -1 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import BaseContextMenu_default from "./BaseContextMenu.js";
|
|
2
|
+
import BaseMenu_default from "./BaseMenu.js";
|
|
3
|
+
import createMenuHandle from "./createMenuHandle.js";
|
|
4
|
+
export { BaseContextMenu_default as BaseContextMenu, BaseMenu_default as BaseMenu, createMenuHandle };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { RefObject } from "react";
|
|
2
|
+
/** Why the highlighted item changed: arrow keys, the pointer, or anything else (filtering, opening, …). */
|
|
3
|
+
export type MenuHighlightReason = "keyboard" | "pointer" | "none";
|
|
4
|
+
/** Imperative actions, through `actionsRef`. */
|
|
5
|
+
export type MenuActions = {
|
|
6
|
+
/** Closes the menu. */
|
|
7
|
+
close: () => void;
|
|
8
|
+
};
|
|
9
|
+
/** Props shared by `BaseMenu` and `BaseMenu.Submenu`. */
|
|
10
|
+
export type MenuRootSharedProps = {
|
|
11
|
+
open?: boolean;
|
|
12
|
+
defaultOpen?: boolean;
|
|
13
|
+
/** Called after the open or close transition ends. */
|
|
14
|
+
onOpenChangeComplete?: (open: boolean) => void;
|
|
15
|
+
/** Wraps keyboard navigation from the last item to the first and back. @default true */
|
|
16
|
+
loopFocus?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Set to `false` to stop the pointer from highlighting items, so `:hover` and `data-highlighted` can differ.
|
|
19
|
+
* @default true
|
|
20
|
+
*/
|
|
21
|
+
highlightItemOnHover?: boolean;
|
|
22
|
+
/** Whether the arrow keys move up/down (`vertical`) or left/right (`horizontal`). @default "vertical" */
|
|
23
|
+
orientation?: "horizontal" | "vertical";
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
/** Called when an item is highlighted, or with `undefined` when none is. `label` is the item's `label` or text. */
|
|
26
|
+
onItemHighlighted?: (item: HTMLElement | undefined, details: {
|
|
27
|
+
reason: MenuHighlightReason;
|
|
28
|
+
label: string | undefined;
|
|
29
|
+
}) => void;
|
|
30
|
+
/** Imperative actions, e.g. `actionsRef.current?.close()`. */
|
|
31
|
+
actionsRef?: RefObject<MenuActions | null>;
|
|
32
|
+
/**
|
|
33
|
+
* Lets the user filter the items by typing in a `BaseMenu.Input`. Put the items in a `BaseMenu.List`.
|
|
34
|
+
* The `filter`, `autoHighlight`, `locale` and `query` props only apply with it.
|
|
35
|
+
*/
|
|
36
|
+
filterable?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Decides whether an item matches. Gets the item's `label` (or its text) and the trimmed query.
|
|
39
|
+
* Defaults to "contains", ignoring case, accents and punctuation. `null` shows every item (filter them yourself).
|
|
40
|
+
*/
|
|
41
|
+
filter?: ((text: string, query: string) => boolean) | null;
|
|
42
|
+
/**
|
|
43
|
+
* Highlights the first match while the query isn't empty, or `"always"` (also when it is).
|
|
44
|
+
* @default false
|
|
45
|
+
*/
|
|
46
|
+
autoHighlight?: boolean | "always";
|
|
47
|
+
/** The locale used by the default filter. Defaults to the user's locale. */
|
|
48
|
+
locale?: Intl.LocalesArgument;
|
|
49
|
+
/** The filter query, controlled. It's cleared (through `onQueryChange`) when the menu closes. */
|
|
50
|
+
query?: string;
|
|
51
|
+
/** The initial filter query, uncontrolled. */
|
|
52
|
+
defaultQuery?: string;
|
|
53
|
+
/** Called with the new query and the DOM event that changed it (none when it was changed from code). */
|
|
54
|
+
onQueryChange?: (query: string, event: Event | undefined) => void;
|
|
55
|
+
};
|
|
56
|
+
/** Splits the filtering props off a root's other props, in Base UI's shape. Internal: not exported to apps. */
|
|
57
|
+
export declare function splitFilterProps<Props extends MenuRootSharedProps>({ filterable, filter, autoHighlight, locale, query, defaultQuery, onQueryChange, ...rootProps }: Props): {
|
|
58
|
+
filterProps: {
|
|
59
|
+
filter: ((text: string, query: string) => boolean) | null | undefined;
|
|
60
|
+
autoHighlight: boolean | "always" | undefined;
|
|
61
|
+
locale: Intl.LocalesArgument;
|
|
62
|
+
value: string | undefined;
|
|
63
|
+
defaultValue: string | undefined;
|
|
64
|
+
onValueChange: ((value: string, details: {
|
|
65
|
+
event: Event | undefined;
|
|
66
|
+
}) => void) | undefined;
|
|
67
|
+
} | null;
|
|
68
|
+
rootProps: Omit<Props, "filter" | "locale" | "autoHighlight" | "filterable" | "query" | "defaultQuery" | "onQueryChange">;
|
|
69
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// src/components/menu/menuTypes.ts
|
|
2
|
+
/** Splits the filtering props off a root's other props, in Base UI's shape. Internal: not exported to apps. */
|
|
3
|
+
function splitFilterProps({ filterable, filter, autoHighlight, locale, query, defaultQuery, onQueryChange, ...rootProps }) {
|
|
4
|
+
return {
|
|
5
|
+
filterProps: filterable ? {
|
|
6
|
+
filter,
|
|
7
|
+
autoHighlight,
|
|
8
|
+
locale,
|
|
9
|
+
value: query,
|
|
10
|
+
defaultValue: defaultQuery,
|
|
11
|
+
onValueChange: onQueryChange && ((value, details) => onQueryChange(value, details.event))
|
|
12
|
+
} : null,
|
|
13
|
+
rootProps
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export { splitFilterProps };
|