@eylulg/ui 2.0.1 → 2.1.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 +9 -7
- package/dist/components/molecules/Dialog/Dialog.js +1 -1
- package/dist/components/molecules/Dialog/Dialog.js.map +1 -1
- package/dist/components/molecules/Drawer/Drawer.js +1 -1
- package/dist/components/molecules/Drawer/Drawer.js.map +1 -1
- package/dist/components/molecules/DropdownMenu/DropdownMenu.d.ts +15 -1
- package/dist/components/molecules/DropdownMenu/DropdownMenu.js +19 -4
- package/dist/components/molecules/DropdownMenu/DropdownMenu.js.map +1 -1
- package/dist/components/molecules/DropdownMenu/DropdownMenuParts.d.ts +1 -1
- package/dist/components/molecules/DropdownMenu/DropdownMenuParts.js +4 -2
- package/dist/components/molecules/DropdownMenu/DropdownMenuParts.js.map +1 -1
- package/dist/components/molecules/EmptyState/EmptyState.js +2 -2
- package/dist/components/molecules/EmptyState/EmptyState.js.map +1 -1
- package/dist/components/molecules/Popover/Popover.d.ts +2 -3
- package/dist/components/molecules/Popover/Popover.js +1 -1
- package/dist/components/molecules/Popover/Popover.js.map +1 -1
- package/dist/components/molecules/Popover/PopoverOverlay.js +2 -1
- package/dist/components/molecules/Popover/PopoverOverlay.js.map +1 -1
- package/dist/internal/lazyModule.d.ts +8 -4
- package/dist/internal/lazyModule.js +18 -8
- package/dist/internal/lazyModule.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
[](https://github.com/eylulg/ui/actions/workflows/ci.yml)
|
|
4
4
|
[](./LICENSE)
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
An accessible React 19 component library on React Aria Components and Tailwind CSS 4 design
|
|
7
|
+
tokens, with nine colour themes and a shared page frame (top nav, sidebar, theme toggle, footer),
|
|
8
|
+
organised by atomic level. Every project on [eylulg.github.io](https://eylulg.github.io/) is built
|
|
9
|
+
with it.
|
|
9
10
|
|
|
10
11
|
Storybook: https://eylulg.github.io/ui/
|
|
11
12
|
|
|
@@ -128,7 +129,7 @@ Import exactly one, after `theme.css`.
|
|
|
128
129
|
| `DatePicker, DateRangePicker` | `@eylulg/ui/date-picker` | Segmented input, calendar popover |
|
|
129
130
|
| `Dialog` | `@eylulg/ui/dialog` | Focus trap and restore, `alertdialog` role, three sizes |
|
|
130
131
|
| `Drawer` | `@eylulg/ui/drawer` | Left, right or bottom sheet |
|
|
131
|
-
| `DropdownMenu` | `@eylulg/ui/dropdown-menu` | Sections, checkbox and radio items, shortcuts, submenus
|
|
132
|
+
| `DropdownMenu` | `@eylulg/ui/dropdown-menu` | Sections, checkbox and radio items, shortcuts, submenus, opens from any element |
|
|
132
133
|
| `EmptyState` | `@eylulg/ui/empty-state` | Icon, title, description, actions |
|
|
133
134
|
| `FileDropZone` | `@eylulg/ui/file-drop-zone` | Drop or pick files, accepted types checked on both paths |
|
|
134
135
|
| `IconButton` | `@eylulg/ui/icon-button` | Takes an icon element; `aria-label` is required outside a React Aria slot |
|
|
@@ -269,9 +270,10 @@ npm run size # bundle size budget
|
|
|
269
270
|
|
|
270
271
|
## Releases
|
|
271
272
|
|
|
272
|
-
semantic-release runs on pushes to `main
|
|
273
|
-
GitHub release and
|
|
274
|
-
|
|
273
|
+
semantic-release runs on pushes to `main`. A `feat` or `fix` commit gives a new version, a tag, a
|
|
274
|
+
GitHub release and a `CHANGELOG.md` entry. The workflow then stages the package on npm through
|
|
275
|
+
trusted publishing, with provenance and no npm token. A staged version goes live once it is
|
|
276
|
+
approved on npmjs.com.
|
|
275
277
|
|
|
276
278
|
## License
|
|
277
279
|
|
|
@@ -18,7 +18,7 @@ var overlay = /*#__PURE__*/ createLazyModule(() => import("./DialogOverlay.js"))
|
|
|
18
18
|
function Dialog$1(props) {
|
|
19
19
|
const triggerState = useContext(OverlayTriggerStateContext);
|
|
20
20
|
const isWanted = props.isOpen ?? props.defaultOpen ?? triggerState?.isOpen ?? false;
|
|
21
|
-
const loaded = overlay.useModule(isWanted);
|
|
21
|
+
const loaded = overlay.useModule(isWanted, triggerState?.close);
|
|
22
22
|
return loaded ? /* @__PURE__ */ jsx(loaded.DialogOverlay, { ...props }) : null;
|
|
23
23
|
}
|
|
24
24
|
/** Wraps a trigger button and its Dialog, and preloads the dialog on hover or focus of the trigger. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dialog.js","names":["Dialog","DialogTrigger","AriaDialogTrigger"],"sources":["../../../../src/components/molecules/Dialog/Dialog.tsx"],"sourcesContent":["import { useContext } from 'react';\nimport {\n DialogTrigger as AriaDialogTrigger,\n OverlayTriggerStateContext,\n type DialogTriggerProps,\n} from 'react-aria-components';\nimport { createLazyModule } from '../../../internal/lazyModule';\nimport type { OverlayProps } from '../../../internal/OverlayParts';\nimport { PreloadOnIntent } from '../../../internal/PreloadOnIntent';\n\nexport type DialogSize = 'sm' | 'md' | 'lg';\n\nexport interface DialogProps extends OverlayProps {\n size?: DialogSize;\n /** Role \"alertdialog\" for destructive confirmations that need an explicit choice. */\n role?: 'dialog' | 'alertdialog';\n}\n\nconst overlay = /*#__PURE__*/ createLazyModule(() => import('./DialogOverlay'));\n\n/**\n * A modal dialog. Focus moves into the dialog when it opens, is trapped while\n * open and returns to the trigger on close. Place it inside a DialogTrigger\n * next to the button that opens it, or control it with isOpen.\n *\n * The modal's code loads the first time it opens, or earlier when the trigger\n * is hovered or focused, so the very first open can take a moment on a slow\n * connection.\n */\nexport function Dialog(props: DialogProps) {\n const triggerState = useContext(OverlayTriggerStateContext);\n const isWanted = props.isOpen ?? props.defaultOpen ?? triggerState?.isOpen ?? false;\n const loaded = overlay.useModule(isWanted);\n return loaded ? <loaded.DialogOverlay {...props} /> : null;\n}\n\n/** Wraps a trigger button and its Dialog, and preloads the dialog on hover or focus of the trigger. */\nexport function DialogTrigger(props: DialogTriggerProps) {\n return (\n <PreloadOnIntent preload={overlay.preload}>\n <AriaDialogTrigger {...props} />\n </PreloadOnIntent>\n );\n}\n"],"mappings":";;;;;;;AAkBA,IAAM,UAAwB,qCAAuB,OAAO,qBAAkB;;;;;;;;;;AAW9E,SAAgBA,SAAO,OAAoB;CACzC,MAAM,eAAe,WAAW,0BAA0B;CAC1D,MAAM,WAAW,MAAM,UAAU,MAAM,eAAe,cAAc,UAAU;CAC9E,MAAM,SAAS,QAAQ,UAAU,
|
|
1
|
+
{"version":3,"file":"Dialog.js","names":["Dialog","DialogTrigger","AriaDialogTrigger"],"sources":["../../../../src/components/molecules/Dialog/Dialog.tsx"],"sourcesContent":["import { useContext } from 'react';\nimport {\n DialogTrigger as AriaDialogTrigger,\n OverlayTriggerStateContext,\n type DialogTriggerProps,\n} from 'react-aria-components';\nimport { createLazyModule } from '../../../internal/lazyModule';\nimport type { OverlayProps } from '../../../internal/OverlayParts';\nimport { PreloadOnIntent } from '../../../internal/PreloadOnIntent';\n\nexport type DialogSize = 'sm' | 'md' | 'lg';\n\nexport interface DialogProps extends OverlayProps {\n size?: DialogSize;\n /** Role \"alertdialog\" for destructive confirmations that need an explicit choice. */\n role?: 'dialog' | 'alertdialog';\n}\n\nconst overlay = /*#__PURE__*/ createLazyModule(() => import('./DialogOverlay'));\n\n/**\n * A modal dialog. Focus moves into the dialog when it opens, is trapped while\n * open and returns to the trigger on close. Place it inside a DialogTrigger\n * next to the button that opens it, or control it with isOpen.\n *\n * The modal's code loads the first time it opens, or earlier when the trigger\n * is hovered or focused, so the very first open can take a moment on a slow\n * connection.\n */\nexport function Dialog(props: DialogProps) {\n const triggerState = useContext(OverlayTriggerStateContext);\n const isWanted = props.isOpen ?? props.defaultOpen ?? triggerState?.isOpen ?? false;\n const loaded = overlay.useModule(isWanted, triggerState?.close);\n return loaded ? <loaded.DialogOverlay {...props} /> : null;\n}\n\n/** Wraps a trigger button and its Dialog, and preloads the dialog on hover or focus of the trigger. */\nexport function DialogTrigger(props: DialogTriggerProps) {\n return (\n <PreloadOnIntent preload={overlay.preload}>\n <AriaDialogTrigger {...props} />\n </PreloadOnIntent>\n );\n}\n"],"mappings":";;;;;;;AAkBA,IAAM,UAAwB,qCAAuB,OAAO,qBAAkB;;;;;;;;;;AAW9E,SAAgBA,SAAO,OAAoB;CACzC,MAAM,eAAe,WAAW,0BAA0B;CAC1D,MAAM,WAAW,MAAM,UAAU,MAAM,eAAe,cAAc,UAAU;CAC9E,MAAM,SAAS,QAAQ,UAAU,UAAU,cAAc,KAAK;CAC9D,OAAO,SAAS,oBAAC,OAAO,eAAR,EAAsB,GAAI,MAAQ,CAAA,IAAI;AACxD;;AAGA,SAAgBC,gBAAc,OAA2B;CACvD,OACE,oBAAC,iBAAD;EAAiB,SAAS,QAAQ;EAChC,UAAA,oBAACC,eAAD,EAAmB,GAAI,MAAQ,CAAA;CAChB,CAAA;AAErB"}
|
|
@@ -18,7 +18,7 @@ var overlay = /*#__PURE__*/ createLazyModule(() => import("./DrawerOverlay.js"))
|
|
|
18
18
|
function Drawer(props) {
|
|
19
19
|
const triggerState = useContext(OverlayTriggerStateContext);
|
|
20
20
|
const isWanted = props.isOpen ?? props.defaultOpen ?? triggerState?.isOpen ?? false;
|
|
21
|
-
const loaded = overlay.useModule(isWanted);
|
|
21
|
+
const loaded = overlay.useModule(isWanted, triggerState?.close);
|
|
22
22
|
return loaded ? /* @__PURE__ */ jsx(loaded.DrawerOverlay, { ...props }) : null;
|
|
23
23
|
}
|
|
24
24
|
/** Wraps a trigger button and its Drawer, and preloads the drawer on hover or focus of the trigger. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Drawer.js","names":["AriaDialogTrigger"],"sources":["../../../../src/components/molecules/Drawer/Drawer.tsx"],"sourcesContent":["import { useContext } from 'react';\nimport {\n DialogTrigger as AriaDialogTrigger,\n OverlayTriggerStateContext,\n type DialogTriggerProps,\n} from 'react-aria-components';\nimport { createLazyModule } from '../../../internal/lazyModule';\nimport type { OverlayProps } from '../../../internal/OverlayParts';\nimport { PreloadOnIntent } from '../../../internal/PreloadOnIntent';\n\nexport type DrawerSide = 'left' | 'right' | 'bottom';\nexport type DrawerSize = 'sm' | 'md' | 'lg';\n\nexport interface DrawerProps extends OverlayProps {\n /** Edge the panel slides in from. */\n side?: DrawerSide;\n size?: DrawerSize;\n}\n\nconst overlay = /*#__PURE__*/ createLazyModule(() => import('./DrawerOverlay'));\n\n/**\n * A side panel (also called a sheet) on React Aria's Modal. It slides in from\n * an edge, traps focus while open, closes on Escape or a click on the\n * backdrop, and returns focus to the trigger. Use it for navigation on small\n * screens, filters and detail views.\n *\n * The panel's code loads the first time it opens, or earlier when the trigger\n * is hovered or focused.\n */\nexport function Drawer(props: DrawerProps) {\n const triggerState = useContext(OverlayTriggerStateContext);\n const isWanted = props.isOpen ?? props.defaultOpen ?? triggerState?.isOpen ?? false;\n const loaded = overlay.useModule(isWanted);\n return loaded ? <loaded.DrawerOverlay {...props} /> : null;\n}\n\n/** Wraps a trigger button and its Drawer, and preloads the drawer on hover or focus of the trigger. */\nexport function DrawerTrigger(props: DialogTriggerProps) {\n return (\n <PreloadOnIntent preload={overlay.preload}>\n <AriaDialogTrigger {...props} />\n </PreloadOnIntent>\n );\n}\n"],"mappings":";;;;;;;AAmBA,IAAM,UAAwB,qCAAuB,OAAO,qBAAkB;;;;;;;;;;AAW9E,SAAgB,OAAO,OAAoB;CACzC,MAAM,eAAe,WAAW,0BAA0B;CAC1D,MAAM,WAAW,MAAM,UAAU,MAAM,eAAe,cAAc,UAAU;CAC9E,MAAM,SAAS,QAAQ,UAAU,
|
|
1
|
+
{"version":3,"file":"Drawer.js","names":["AriaDialogTrigger"],"sources":["../../../../src/components/molecules/Drawer/Drawer.tsx"],"sourcesContent":["import { useContext } from 'react';\nimport {\n DialogTrigger as AriaDialogTrigger,\n OverlayTriggerStateContext,\n type DialogTriggerProps,\n} from 'react-aria-components';\nimport { createLazyModule } from '../../../internal/lazyModule';\nimport type { OverlayProps } from '../../../internal/OverlayParts';\nimport { PreloadOnIntent } from '../../../internal/PreloadOnIntent';\n\nexport type DrawerSide = 'left' | 'right' | 'bottom';\nexport type DrawerSize = 'sm' | 'md' | 'lg';\n\nexport interface DrawerProps extends OverlayProps {\n /** Edge the panel slides in from. */\n side?: DrawerSide;\n size?: DrawerSize;\n}\n\nconst overlay = /*#__PURE__*/ createLazyModule(() => import('./DrawerOverlay'));\n\n/**\n * A side panel (also called a sheet) on React Aria's Modal. It slides in from\n * an edge, traps focus while open, closes on Escape or a click on the\n * backdrop, and returns focus to the trigger. Use it for navigation on small\n * screens, filters and detail views.\n *\n * The panel's code loads the first time it opens, or earlier when the trigger\n * is hovered or focused.\n */\nexport function Drawer(props: DrawerProps) {\n const triggerState = useContext(OverlayTriggerStateContext);\n const isWanted = props.isOpen ?? props.defaultOpen ?? triggerState?.isOpen ?? false;\n const loaded = overlay.useModule(isWanted, triggerState?.close);\n return loaded ? <loaded.DrawerOverlay {...props} /> : null;\n}\n\n/** Wraps a trigger button and its Drawer, and preloads the drawer on hover or focus of the trigger. */\nexport function DrawerTrigger(props: DialogTriggerProps) {\n return (\n <PreloadOnIntent preload={overlay.preload}>\n <AriaDialogTrigger {...props} />\n </PreloadOnIntent>\n );\n}\n"],"mappings":";;;;;;;AAmBA,IAAM,UAAwB,qCAAuB,OAAO,qBAAkB;;;;;;;;;;AAW9E,SAAgB,OAAO,OAAoB;CACzC,MAAM,eAAe,WAAW,0BAA0B;CAC1D,MAAM,WAAW,MAAM,UAAU,MAAM,eAAe,cAAc,UAAU;CAC9E,MAAM,SAAS,QAAQ,UAAU,UAAU,cAAc,KAAK;CAC9D,OAAO,SAAS,oBAAC,OAAO,eAAR,EAAsB,GAAI,MAAQ,CAAA,IAAI;AACxD;;AAGA,SAAgB,cAAc,OAA2B;CACvD,OACE,oBAAC,iBAAD;EAAiB,SAAS,QAAQ;EAChC,UAAA,oBAACA,eAAD,EAAmB,GAAI,MAAQ,CAAA;CAChB,CAAA;AAErB"}
|
|
@@ -2,7 +2,18 @@ import { type ReactNode } from 'react';
|
|
|
2
2
|
import { type MenuItemProps, type MenuProps, type MenuSectionProps, type MenuTriggerProps, type PopoverProps } from 'react-aria-components';
|
|
3
3
|
export type DropdownMenuProps = MenuTriggerProps;
|
|
4
4
|
export interface DropdownMenuContentProps<T extends object> extends MenuProps<T> {
|
|
5
|
+
/** Where the menu opens. Defaults to below the trigger, and to the side for a submenu. */
|
|
5
6
|
placement?: PopoverProps['placement'];
|
|
7
|
+
/** Gap to the trigger in pixels. Defaults to React Aria's. */
|
|
8
|
+
offset?: PopoverProps['offset'];
|
|
9
|
+
/**
|
|
10
|
+
* Opens the menu against this element instead of a trigger inside DropdownMenu. Leave out the
|
|
11
|
+
* trigger, control the menu with `isOpen` and `onOpenChange` on DropdownMenu, and the menu
|
|
12
|
+
* loads when `isOpen` becomes true. Closing returns focus to the element that had it on open.
|
|
13
|
+
* Give the element `aria-haspopup='menu'` and `aria-expanded={isOpen}`, and the menu an
|
|
14
|
+
* `aria-label`, because there is no trigger to name it.
|
|
15
|
+
*/
|
|
16
|
+
triggerRef?: PopoverProps['triggerRef'];
|
|
6
17
|
/** Class for the floating surface. */
|
|
7
18
|
popoverClassName?: string;
|
|
8
19
|
}
|
|
@@ -34,8 +45,11 @@ export interface DropdownMenuSectionProps<T extends object> extends Omit<MenuSec
|
|
|
34
45
|
* The menu's code loads the first time it opens, or earlier when the trigger
|
|
35
46
|
* is hovered or focused, so the very first open can take a moment on a slow
|
|
36
47
|
* connection. The trigger works at once.
|
|
48
|
+
*
|
|
49
|
+
* To open it from any other element, such as a canvas node, skip the trigger and pass `isOpen`
|
|
50
|
+
* and `onOpenChange` here and `triggerRef` to DropdownMenuContent.
|
|
37
51
|
*/
|
|
38
|
-
export declare function DropdownMenu(props: DropdownMenuProps): import("react").JSX.Element;
|
|
52
|
+
export declare function DropdownMenu({ children, ...props }: DropdownMenuProps): import("react").JSX.Element;
|
|
39
53
|
export declare function DropdownMenuContent<T extends object>(props: DropdownMenuContentProps<T>): import("react").JSX.Element | null;
|
|
40
54
|
export declare const DropdownMenuItem: typeof import("./DropdownMenuParts").DropdownMenuItem;
|
|
41
55
|
/**
|
|
@@ -2,11 +2,20 @@
|
|
|
2
2
|
import { createLazyModule, lazyPart } from "../../../internal/lazyModule.js";
|
|
3
3
|
import { PreloadOnIntent } from "../../../internal/PreloadOnIntent.js";
|
|
4
4
|
import { useContext } from "react";
|
|
5
|
-
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
6
|
import { MenuTrigger, OverlayTriggerStateContext } from "react-aria-components";
|
|
7
|
+
import { usePress } from "react-aria";
|
|
7
8
|
// src/components/molecules/DropdownMenu/DropdownMenu.tsx
|
|
8
9
|
var menu = /*#__PURE__*/ createLazyModule(() => import("./DropdownMenuParts.js"));
|
|
9
10
|
/**
|
|
11
|
+
* MenuTrigger warns when nothing under it handles press. A menu opened from another element has
|
|
12
|
+
* no trigger inside, so this registers as the press target and the warning stays quiet.
|
|
13
|
+
*/
|
|
14
|
+
function PressRegistrar() {
|
|
15
|
+
usePress({});
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
10
19
|
* Wraps a trigger and a DropdownMenuContent. Opens on press, Enter, Space or
|
|
11
20
|
* the arrow keys. Inside, arrow keys move, typing jumps to a matching item,
|
|
12
21
|
* Enter activates and Escape closes and returns focus to the trigger.
|
|
@@ -14,16 +23,22 @@ var menu = /*#__PURE__*/ createLazyModule(() => import("./DropdownMenuParts.js")
|
|
|
14
23
|
* The menu's code loads the first time it opens, or earlier when the trigger
|
|
15
24
|
* is hovered or focused, so the very first open can take a moment on a slow
|
|
16
25
|
* connection. The trigger works at once.
|
|
26
|
+
*
|
|
27
|
+
* To open it from any other element, such as a canvas node, skip the trigger and pass `isOpen`
|
|
28
|
+
* and `onOpenChange` here and `triggerRef` to DropdownMenuContent.
|
|
17
29
|
*/
|
|
18
|
-
function DropdownMenu(props) {
|
|
30
|
+
function DropdownMenu({ children, ...props }) {
|
|
19
31
|
return /* @__PURE__ */ jsx(PreloadOnIntent, {
|
|
20
32
|
preload: menu.preload,
|
|
21
|
-
children: /* @__PURE__ */
|
|
33
|
+
children: /* @__PURE__ */ jsxs(MenuTrigger, {
|
|
34
|
+
...props,
|
|
35
|
+
children: [/* @__PURE__ */ jsx(PressRegistrar, {}), children]
|
|
36
|
+
})
|
|
22
37
|
});
|
|
23
38
|
}
|
|
24
39
|
function DropdownMenuContent(props) {
|
|
25
40
|
const triggerState = useContext(OverlayTriggerStateContext);
|
|
26
|
-
const parts = menu.useModule(triggerState?.isOpen ?? false);
|
|
41
|
+
const parts = menu.useModule(triggerState?.isOpen ?? false, triggerState?.close);
|
|
27
42
|
return parts ? /* @__PURE__ */ jsx(parts.DropdownMenuContent, { ...props }) : null;
|
|
28
43
|
}
|
|
29
44
|
var DropdownMenuItem = lazyPart(menu, "DropdownMenuItem");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DropdownMenu.js","names":[],"sources":["../../../../src/components/molecules/DropdownMenu/DropdownMenu.tsx"],"sourcesContent":["import { useContext, type ReactNode } from 'react';\nimport {\n MenuTrigger,\n OverlayTriggerStateContext,\n type MenuItemProps,\n type MenuProps,\n type MenuSectionProps,\n type MenuTriggerProps,\n type PopoverProps,\n} from 'react-aria-components';\nimport { createLazyModule, lazyPart } from '../../../internal/lazyModule';\nimport { PreloadOnIntent } from '../../../internal/PreloadOnIntent';\n\nexport type DropdownMenuProps = MenuTriggerProps;\n\nexport interface DropdownMenuContentProps<T extends object> extends MenuProps<T> {\n placement?: PopoverProps['placement'];\n /** Class for the floating surface. */\n popoverClassName?: string;\n}\n\nexport interface DropdownMenuItemProps<T extends object = object> extends Omit<\n MenuItemProps<T>,\n 'children'\n> {\n children: ReactNode;\n /** An icon element such as `<Pencil />`, before the label. */\n icon?: ReactNode;\n /**\n * Secondary line under the label. It becomes part of the item's accessible\n * name, which then starts with the label, so the name always contains the\n * visible text (WCAG 2.5.3).\n */\n description?: ReactNode;\n /** Keyboard shortcut hint, such as \"⌘K\". Display only. */\n shortcut?: string;\n /** Destructive styling, for delete and similar actions. */\n isDestructive?: boolean;\n}\n\nexport interface DropdownMenuSectionProps<T extends object> extends Omit<\n MenuSectionProps<T>,\n 'children'\n> {\n /** Visible group heading, also the group's accessible name. */\n title?: ReactNode;\n children: ReactNode;\n}\n\nconst menu = /*#__PURE__*/ createLazyModule(() => import('./DropdownMenuParts'));\n\n/**\n * Wraps a trigger and a DropdownMenuContent. Opens on press, Enter, Space or\n * the arrow keys. Inside, arrow keys move, typing jumps to a matching item,\n * Enter activates and Escape closes and returns focus to the trigger.\n *\n * The menu's code loads the first time it opens, or earlier when the trigger\n * is hovered or focused, so the very first open can take a moment on a slow\n * connection. The trigger works at once.\n */\nexport function DropdownMenu(props: DropdownMenuProps) {\n return (\n <PreloadOnIntent preload={menu.preload}>\n <MenuTrigger {...props} />\n </PreloadOnIntent>\n );\n}\n\nexport function DropdownMenuContent<T extends object>(props: DropdownMenuContentProps<T>) {\n const triggerState = useContext(OverlayTriggerStateContext);\n const parts = menu.useModule(triggerState?.isOpen ?? false);\n return parts ? <parts.DropdownMenuContent {...props} /> : null;\n}\n\nexport const DropdownMenuItem = lazyPart(menu, 'DropdownMenuItem');\n\n/**\n * Groups items under an optional heading. Set `selectionMode=\"multiple\"` for\n * checkbox items or `\"single\"` for a radio style group.\n */\nexport const DropdownMenuSection = lazyPart(menu, 'DropdownMenuSection');\n\nexport const DropdownMenuSeparator = lazyPart(menu, 'DropdownMenuSeparator');\n\n/** Nests a submenu: pass a DropdownMenuItem and a DropdownMenuContent. */\nexport const DropdownSubmenu = lazyPart(menu, 'DropdownSubmenu');\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"DropdownMenu.js","names":[],"sources":["../../../../src/components/molecules/DropdownMenu/DropdownMenu.tsx"],"sourcesContent":["import { useContext, type ReactNode } from 'react';\nimport { usePress } from 'react-aria';\nimport {\n MenuTrigger,\n OverlayTriggerStateContext,\n type MenuItemProps,\n type MenuProps,\n type MenuSectionProps,\n type MenuTriggerProps,\n type PopoverProps,\n} from 'react-aria-components';\nimport { createLazyModule, lazyPart } from '../../../internal/lazyModule';\nimport { PreloadOnIntent } from '../../../internal/PreloadOnIntent';\n\nexport type DropdownMenuProps = MenuTriggerProps;\n\nexport interface DropdownMenuContentProps<T extends object> extends MenuProps<T> {\n /** Where the menu opens. Defaults to below the trigger, and to the side for a submenu. */\n placement?: PopoverProps['placement'];\n /** Gap to the trigger in pixels. Defaults to React Aria's. */\n offset?: PopoverProps['offset'];\n /**\n * Opens the menu against this element instead of a trigger inside DropdownMenu. Leave out the\n * trigger, control the menu with `isOpen` and `onOpenChange` on DropdownMenu, and the menu\n * loads when `isOpen` becomes true. Closing returns focus to the element that had it on open.\n * Give the element `aria-haspopup='menu'` and `aria-expanded={isOpen}`, and the menu an\n * `aria-label`, because there is no trigger to name it.\n */\n triggerRef?: PopoverProps['triggerRef'];\n /** Class for the floating surface. */\n popoverClassName?: string;\n}\n\nexport interface DropdownMenuItemProps<T extends object = object> extends Omit<\n MenuItemProps<T>,\n 'children'\n> {\n children: ReactNode;\n /** An icon element such as `<Pencil />`, before the label. */\n icon?: ReactNode;\n /**\n * Secondary line under the label. It becomes part of the item's accessible\n * name, which then starts with the label, so the name always contains the\n * visible text (WCAG 2.5.3).\n */\n description?: ReactNode;\n /** Keyboard shortcut hint, such as \"⌘K\". Display only. */\n shortcut?: string;\n /** Destructive styling, for delete and similar actions. */\n isDestructive?: boolean;\n}\n\nexport interface DropdownMenuSectionProps<T extends object> extends Omit<\n MenuSectionProps<T>,\n 'children'\n> {\n /** Visible group heading, also the group's accessible name. */\n title?: ReactNode;\n children: ReactNode;\n}\n\nconst menu = /*#__PURE__*/ createLazyModule(() => import('./DropdownMenuParts'));\n\n/**\n * MenuTrigger warns when nothing under it handles press. A menu opened from another element has\n * no trigger inside, so this registers as the press target and the warning stays quiet.\n */\nfunction PressRegistrar() {\n usePress({});\n return null;\n}\n\n/**\n * Wraps a trigger and a DropdownMenuContent. Opens on press, Enter, Space or\n * the arrow keys. Inside, arrow keys move, typing jumps to a matching item,\n * Enter activates and Escape closes and returns focus to the trigger.\n *\n * The menu's code loads the first time it opens, or earlier when the trigger\n * is hovered or focused, so the very first open can take a moment on a slow\n * connection. The trigger works at once.\n *\n * To open it from any other element, such as a canvas node, skip the trigger and pass `isOpen`\n * and `onOpenChange` here and `triggerRef` to DropdownMenuContent.\n */\nexport function DropdownMenu({ children, ...props }: DropdownMenuProps) {\n return (\n <PreloadOnIntent preload={menu.preload}>\n <MenuTrigger {...props}>\n <PressRegistrar />\n {children}\n </MenuTrigger>\n </PreloadOnIntent>\n );\n}\n\nexport function DropdownMenuContent<T extends object>(props: DropdownMenuContentProps<T>) {\n const triggerState = useContext(OverlayTriggerStateContext);\n const parts = menu.useModule(triggerState?.isOpen ?? false, triggerState?.close);\n return parts ? <parts.DropdownMenuContent {...props} /> : null;\n}\n\nexport const DropdownMenuItem = lazyPart(menu, 'DropdownMenuItem');\n\n/**\n * Groups items under an optional heading. Set `selectionMode=\"multiple\"` for\n * checkbox items or `\"single\"` for a radio style group.\n */\nexport const DropdownMenuSection = lazyPart(menu, 'DropdownMenuSection');\n\nexport const DropdownMenuSeparator = lazyPart(menu, 'DropdownMenuSeparator');\n\n/** Nests a submenu: pass a DropdownMenuItem and a DropdownMenuContent. */\nexport const DropdownSubmenu = lazyPart(menu, 'DropdownSubmenu');\n"],"mappings":";;;;;;;;AA6DA,IAAM,OAAqB,qCAAuB,OAAO,yBAAsB;;;;;AAM/E,SAAS,iBAAiB;CACxB,SAAS,CAAC,CAAC;CACX,OAAO;AACT;;;;;;;;;;;;;AAcA,SAAgB,aAAa,EAAE,UAAU,GAAG,SAA4B;CACtE,OACE,oBAAC,iBAAD;EAAiB,SAAS,KAAK;EAC7B,UAAA,qBAAC,aAAD;GAAa,GAAI;GAAjB,UAAA,CACE,oBAAC,gBAAD,CAAiB,CAAA,GAChB,QACU;;CACE,CAAA;AAErB;AAEA,SAAgB,oBAAsC,OAAoC;CACxF,MAAM,eAAe,WAAW,0BAA0B;CAC1D,MAAM,QAAQ,KAAK,UAAU,cAAc,UAAU,OAAO,cAAc,KAAK;CAC/E,OAAO,QAAQ,oBAAC,MAAM,qBAAP,EAA2B,GAAI,MAAQ,CAAA,IAAI;AAC5D;AAEA,IAAa,mBAAmB,SAAS,MAAM,kBAAkB;;;;;AAMjE,IAAa,sBAAsB,SAAS,MAAM,qBAAqB;AAEvE,IAAa,wBAAwB,SAAS,MAAM,uBAAuB;;AAG3E,IAAa,kBAAkB,SAAS,MAAM,iBAAiB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DropdownMenuContentProps, DropdownMenuItemProps, DropdownMenuSectionProps } from './DropdownMenu';
|
|
2
|
-
export declare function DropdownMenuContent<T extends object>({ placement, popoverClassName, className, ...props }: DropdownMenuContentProps<T>): import("react").JSX.Element;
|
|
2
|
+
export declare function DropdownMenuContent<T extends object>({ placement, offset, popoverClassName, triggerRef, className, ...props }: DropdownMenuContentProps<T>): import("react").JSX.Element;
|
|
3
3
|
export declare function DropdownMenuItem<T extends object = object>({ children, icon, description, shortcut, isDestructive, className, ...props }: DropdownMenuItemProps<T>): import("react").JSX.Element;
|
|
4
4
|
export declare function DropdownMenuSection<T extends object>({ title, children, className, ...props }: DropdownMenuSectionProps<T>): import("react").JSX.Element;
|
|
5
5
|
export declare function DropdownMenuSeparator(): import("react").JSX.Element;
|
|
@@ -7,10 +7,12 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
|
7
7
|
import { Keyboard, Menu, MenuItem, MenuSection, Popover, Separator, SubmenuTrigger, composeRenderProps } from "react-aria-components";
|
|
8
8
|
import { Check, ChevronRight } from "lucide-react";
|
|
9
9
|
// src/components/molecules/DropdownMenu/DropdownMenuParts.tsx
|
|
10
|
-
function DropdownMenuContent({ placement
|
|
10
|
+
function DropdownMenuContent({ placement, offset, popoverClassName, triggerRef, className, ...props }) {
|
|
11
11
|
return /* @__PURE__ */ jsx(Popover, {
|
|
12
12
|
placement,
|
|
13
|
-
offset
|
|
13
|
+
offset,
|
|
14
|
+
triggerRef,
|
|
15
|
+
"aria-label": props["aria-label"],
|
|
14
16
|
className: cx(popoverSurface, "min-w-48 overflow-auto p-1", popoverClassName),
|
|
15
17
|
children: /* @__PURE__ */ jsx(Menu, {
|
|
16
18
|
...props,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DropdownMenuParts.js","names":["_Fragment"],"sources":["../../../../src/components/molecules/DropdownMenu/DropdownMenuParts.tsx"],"sourcesContent":["import { Check, ChevronRight } from 'lucide-react';\nimport {\n Keyboard,\n Menu,\n MenuItem,\n MenuSection,\n Popover,\n Separator,\n SubmenuTrigger,\n composeRenderProps,\n} from 'react-aria-components';\nimport { iconSlot } from '../../../internal/control';\nimport { ListItemText, ListSectionHeader, textValueOf } from '../../../internal/listParts';\nimport { listItem, listSeparator, popoverSurface } from '../../../internal/surfaces';\nimport { cx } from '../../../utils/cx';\nimport type {\n DropdownMenuContentProps,\n DropdownMenuItemProps,\n DropdownMenuSectionProps,\n} from './DropdownMenu';\n\nexport function DropdownMenuContent<T extends object>({\n placement
|
|
1
|
+
{"version":3,"file":"DropdownMenuParts.js","names":["_Fragment"],"sources":["../../../../src/components/molecules/DropdownMenu/DropdownMenuParts.tsx"],"sourcesContent":["import { Check, ChevronRight } from 'lucide-react';\nimport {\n Keyboard,\n Menu,\n MenuItem,\n MenuSection,\n Popover,\n Separator,\n SubmenuTrigger,\n composeRenderProps,\n} from 'react-aria-components';\nimport { iconSlot } from '../../../internal/control';\nimport { ListItemText, ListSectionHeader, textValueOf } from '../../../internal/listParts';\nimport { listItem, listSeparator, popoverSurface } from '../../../internal/surfaces';\nimport { cx } from '../../../utils/cx';\nimport type {\n DropdownMenuContentProps,\n DropdownMenuItemProps,\n DropdownMenuSectionProps,\n} from './DropdownMenu';\n\nexport function DropdownMenuContent<T extends object>({\n placement,\n offset,\n popoverClassName,\n triggerRef,\n className,\n ...props\n}: DropdownMenuContentProps<T>) {\n return (\n <Popover\n placement={placement}\n offset={offset}\n triggerRef={triggerRef}\n aria-label={props['aria-label']}\n className={cx(popoverSurface, 'min-w-48 overflow-auto p-1', popoverClassName)}\n >\n <Menu\n {...props}\n className={composeRenderProps(className, (consumer) =>\n cx('max-h-[inherit] outline-none', consumer),\n )}\n />\n </Popover>\n );\n}\n\nexport function DropdownMenuItem<T extends object = object>({\n children,\n icon,\n description,\n shortcut,\n isDestructive = false,\n className,\n ...props\n}: DropdownMenuItemProps<T>) {\n return (\n <MenuItem\n {...props}\n textValue={textValueOf(props.textValue, children)}\n className={composeRenderProps(className, (consumer) =>\n cx(listItem, isDestructive && 'text-error', consumer),\n )}\n >\n {({ isSelected, selectionMode, hasSubmenu }) => (\n <>\n {selectionMode !== 'none' && (\n <span className='flex size-4 shrink-0 items-center justify-center' aria-hidden='true'>\n {isSelected && <Check className='size-4 text-fg-brand' />}\n </span>\n )}\n {icon && (\n <span\n aria-hidden='true'\n className={cx(iconSlot, isDestructive ? 'text-fg-error' : 'text-fg-tertiary')}\n >\n {icon}\n </span>\n )}\n <ListItemText description={description}>{children}</ListItemText>\n {shortcut && (\n <Keyboard className='ml-4 font-mono text-xs text-tertiary'>{shortcut}</Keyboard>\n )}\n {hasSubmenu && <ChevronRight aria-hidden='true' className='size-4 text-fg-tertiary' />}\n </>\n )}\n </MenuItem>\n );\n}\n\nexport function DropdownMenuSection<T extends object>({\n title,\n children,\n className,\n ...props\n}: DropdownMenuSectionProps<T>) {\n return (\n <MenuSection {...props} className={cx('flex flex-col', className)}>\n {title && <ListSectionHeader>{title}</ListSectionHeader>}\n {children}\n </MenuSection>\n );\n}\n\nexport function DropdownMenuSeparator() {\n return <Separator className={listSeparator} />;\n}\n\nexport const DropdownSubmenu = SubmenuTrigger;\n"],"mappings":";;;;;;;;;AAqBA,SAAgB,oBAAsC,EACpD,WACA,QACA,kBACA,YACA,WACA,GAAG,SAC2B;CAC9B,OACE,oBAAC,SAAD;EACa;EACH;EACI;EACZ,cAAY,MAAM;EAClB,WAAW,GAAG,gBAAgB,8BAA8B,gBAAgB;EAE5E,UAAA,oBAAC,MAAD;GACE,GAAI;GACJ,WAAW,mBAAmB,YAAY,aACxC,GAAG,gCAAgC,QAAQ,CAC7C;EACD,CAAA;CACM,CAAA;AAEb;AAEA,SAAgB,iBAA4C,EAC1D,UACA,MACA,aACA,UACA,gBAAgB,OAChB,WACA,GAAG,SACwB;CAC3B,OACE,oBAAC,UAAD;EACE,GAAI;EACJ,WAAW,YAAY,MAAM,WAAW,QAAQ;EAChD,WAAW,mBAAmB,YAAY,aACxC,GAAG,UAAU,iBAAiB,cAAc,QAAQ,CACtD;EAEE,WAAA,EAAE,YAAY,eAAe,iBAC7B,qBAAAA,UAAA,EAAA,UAAA;GACG,kBAAkB,UACjB,oBAAC,QAAD;IAAM,WAAU;IAAmD,eAAY;IAC5E,UAAA,cAAc,oBAAC,OAAD,EAAO,WAAU,uBAAwB,CAAA;GACpD,CAAA;GAEP,QACC,oBAAC,QAAD;IACE,eAAY;IACZ,WAAW,GAAA,uCAAa,gBAAgB,kBAAkB,kBAAkB;IAE3E,UAAA;GACG,CAAA;GAER,oBAAC,cAAD;IAA2B;IAAc;GAAuB,CAAA;GAC/D,YACC,oBAAC,UAAD;IAAU,WAAU;IAAwC,UAAA;GAAmB,CAAA;GAEhF,cAAc,oBAAC,cAAD;IAAc,eAAY;IAAO,WAAU;GAA2B,CAAA;EACrF,EAAA,CAAA;CAEI,CAAA;AAEd;AAEA,SAAgB,oBAAsC,EACpD,OACA,UACA,WACA,GAAG,SAC2B;CAC9B,OACE,qBAAC,aAAD;EAAa,GAAI;EAAO,WAAW,GAAG,iBAAiB,SAAS;EAAhE,UAAA,CACG,SAAS,oBAAC,mBAAD,EAAA,UAAoB,MAAyB,CAAA,GACtD,QACU;;AAEjB;AAEA,SAAgB,wBAAwB;CACtC,OAAO,oBAAC,WAAD,EAAW,WAAW,cAAgB,CAAA;AAC/C;AAEA,IAAa,kBAAkB"}
|
|
@@ -40,9 +40,9 @@ function EmptyState({ title, description, icon, primaryAction, secondaryAction,
|
|
|
40
40
|
className: "text-sm text-tertiary",
|
|
41
41
|
children: description
|
|
42
42
|
}),
|
|
43
|
-
(primaryAction
|
|
43
|
+
(primaryAction || secondaryAction) && /* @__PURE__ */ jsxs("div", {
|
|
44
44
|
className: "mt-2 flex flex-wrap items-center justify-center gap-3",
|
|
45
|
-
children: [
|
|
45
|
+
children: [primaryAction, secondaryAction]
|
|
46
46
|
})
|
|
47
47
|
]
|
|
48
48
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EmptyState.js","names":[],"sources":["../../../../src/components/molecules/EmptyState/EmptyState.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\nimport { cx } from '../../../utils/cx';\n\nexport type EmptyStateSize = 'sm' | 'md';\n\nexport interface EmptyStateProps {\n title: ReactNode;\n description?: ReactNode;\n /** Decorative icon element such as `<Inbox />`. */\n icon?: ReactNode;\n /** The main way forward, usually a primary Button. */\n primaryAction?: ReactNode;\n /** An alternative, usually a secondary Button or a link. */\n secondaryAction?: ReactNode;\n /** Use 1 when the empty state is the whole page, such as a 404. */\n headingLevel?: 1 | 2 | 3 | 4;\n size?: EmptyStateSize;\n className?: string;\n}\n\nconst headings = { 1: 'h1', 2: 'h2', 3: 'h3', 4: 'h4' } as const;\n\nconst sizes: Record<EmptyStateSize, { root: string; icon: string; title: string }> = {\n sm: { root: 'gap-2 py-6', icon: 'size-10 [&>svg]:size-5', title: 'text-md' },\n md: { root: 'gap-3 py-12', icon: 'size-12 [&>svg]:size-6', title: 'text-lg' },\n};\n\nconst iconFrame =\n 'flex items-center justify-center rounded-xl border border-subtle bg-primary text-fg-secondary shadow-xs';\n\n/** What to show when a list, search or view has nothing in it yet, and what to do next. */\nexport function EmptyState({\n title,\n description,\n icon,\n primaryAction,\n secondaryAction,\n headingLevel = 2,\n size = 'md',\n className,\n}: EmptyStateProps) {\n const Heading = headings[headingLevel];\n return (\n <div\n className={cx(\n 'mx-auto flex max-w-md flex-col items-center px-4 text-center',\n sizes[size].root,\n className,\n )}\n >\n {icon && (\n <div aria-hidden='true' className={cx(iconFrame, sizes[size].icon)}>\n {icon}\n </div>\n )}\n <Heading className={cx('font-display font-semibold text-primary', sizes[size].title)}>\n {title}\n </Heading>\n {description && <p className='text-sm text-tertiary'>{description}</p>}\n {(primaryAction
|
|
1
|
+
{"version":3,"file":"EmptyState.js","names":[],"sources":["../../../../src/components/molecules/EmptyState/EmptyState.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\nimport { cx } from '../../../utils/cx';\n\nexport type EmptyStateSize = 'sm' | 'md';\n\nexport interface EmptyStateProps {\n title: ReactNode;\n description?: ReactNode;\n /** Decorative icon element such as `<Inbox />`. */\n icon?: ReactNode;\n /** The main way forward, usually a primary Button. */\n primaryAction?: ReactNode;\n /** An alternative, usually a secondary Button or a link. */\n secondaryAction?: ReactNode;\n /** Use 1 when the empty state is the whole page, such as a 404. */\n headingLevel?: 1 | 2 | 3 | 4;\n size?: EmptyStateSize;\n className?: string;\n}\n\nconst headings = { 1: 'h1', 2: 'h2', 3: 'h3', 4: 'h4' } as const;\n\nconst sizes: Record<EmptyStateSize, { root: string; icon: string; title: string }> = {\n sm: { root: 'gap-2 py-6', icon: 'size-10 [&>svg]:size-5', title: 'text-md' },\n md: { root: 'gap-3 py-12', icon: 'size-12 [&>svg]:size-6', title: 'text-lg' },\n};\n\nconst iconFrame =\n 'flex items-center justify-center rounded-xl border border-subtle bg-primary text-fg-secondary shadow-xs';\n\n/** What to show when a list, search or view has nothing in it yet, and what to do next. */\nexport function EmptyState({\n title,\n description,\n icon,\n primaryAction,\n secondaryAction,\n headingLevel = 2,\n size = 'md',\n className,\n}: EmptyStateProps) {\n const Heading = headings[headingLevel];\n return (\n <div\n className={cx(\n 'mx-auto flex max-w-md flex-col items-center px-4 text-center',\n sizes[size].root,\n className,\n )}\n >\n {icon && (\n <div aria-hidden='true' className={cx(iconFrame, sizes[size].icon)}>\n {icon}\n </div>\n )}\n <Heading className={cx('font-display font-semibold text-primary', sizes[size].title)}>\n {title}\n </Heading>\n {description && <p className='text-sm text-tertiary'>{description}</p>}\n {(primaryAction || secondaryAction) && (\n <div className='mt-2 flex flex-wrap items-center justify-center gap-3'>\n {primaryAction}\n {secondaryAction}\n </div>\n )}\n </div>\n );\n}\n"],"mappings":";;;;AAoBA,IAAM,WAAW;CAAE,GAAG;CAAM,GAAG;CAAM,GAAG;CAAM,GAAG;AAAK;AAEtD,IAAM,QAA+E;CACnF,IAAI;EAAE,MAAM;EAAc,MAAM;EAA0B,OAAO;CAAU;CAC3E,IAAI;EAAE,MAAM;EAAe,MAAM;EAA0B,OAAO;CAAU;AAC9E;AAEA,IAAM,YACJ;;AAGF,SAAgB,WAAW,EACzB,OACA,aACA,MACA,eACA,iBACA,eAAe,GACf,OAAO,MACP,aACkB;CAClB,MAAM,UAAU,SAAS;CACzB,OACE,qBAAC,OAAD;EACE,WAAW,GACT,gEACA,MAAM,KAAK,CAAC,MACZ,SACF;EALF,UAAA;GAOG,QACC,oBAAC,OAAD;IAAK,eAAY;IAAO,WAAW,GAAG,WAAW,MAAM,KAAK,CAAC,IAAI;IAC9D,UAAA;GACE,CAAA;GAEP,oBAAC,SAAD;IAAS,WAAW,GAAG,2CAA2C,MAAM,KAAK,CAAC,KAAK;IAChF,UAAA;GACM,CAAA;GACR,eAAe,oBAAC,KAAD;IAAG,WAAU;IAAyB,UAAA;GAAe,CAAA;IACnE,iBAAiB,oBACjB,qBAAC,OAAD;IAAK,WAAU;IAAf,UAAA,CACG,eACA,eACE;;EAEJ;;AAET"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
2
|
import { type DialogTriggerProps, type PopoverProps as AriaPopoverProps } from 'react-aria-components';
|
|
3
|
+
import type { OverlayContent } from '../../../internal/OverlayParts';
|
|
3
4
|
export interface PopoverProps extends Pick<AriaPopoverProps, 'placement' | 'offset' | 'isOpen' | 'onOpenChange' | 'triggerRef' | 'shouldFlip'> {
|
|
4
5
|
/** Visible heading, also used as the accessible name. */
|
|
5
6
|
title?: ReactNode;
|
|
@@ -8,9 +9,7 @@ export interface PopoverProps extends Pick<AriaPopoverProps, 'placement' | 'offs
|
|
|
8
9
|
/** Shows a small arrow pointing at the trigger. */
|
|
9
10
|
showArrow?: boolean;
|
|
10
11
|
/** Content, or a function that receives `close`. */
|
|
11
|
-
children:
|
|
12
|
-
close: () => void;
|
|
13
|
-
}) => ReactNode);
|
|
12
|
+
children: OverlayContent;
|
|
14
13
|
className?: string;
|
|
15
14
|
}
|
|
16
15
|
/**
|
|
@@ -18,7 +18,7 @@ var overlay = /*#__PURE__*/ createLazyModule(() => import("./PopoverOverlay.js")
|
|
|
18
18
|
function Popover$1(props) {
|
|
19
19
|
const triggerState = useContext(OverlayTriggerStateContext);
|
|
20
20
|
const isWanted = props.isOpen ?? triggerState?.isOpen ?? false;
|
|
21
|
-
const loaded = overlay.useModule(isWanted);
|
|
21
|
+
const loaded = overlay.useModule(isWanted, triggerState?.close);
|
|
22
22
|
return loaded ? /* @__PURE__ */ jsx(loaded.PopoverOverlay, { ...props }) : null;
|
|
23
23
|
}
|
|
24
24
|
/** Wraps a trigger button and its Popover, and preloads the popover on hover or focus of the trigger. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Popover.js","names":["Popover","AriaDialogTrigger"],"sources":["../../../../src/components/molecules/Popover/Popover.tsx"],"sourcesContent":["import { useContext, type ReactNode } from 'react';\nimport {\n DialogTrigger as AriaDialogTrigger,\n OverlayTriggerStateContext,\n type DialogTriggerProps,\n type PopoverProps as AriaPopoverProps,\n} from 'react-aria-components';\nimport { createLazyModule } from '../../../internal/lazyModule';\nimport { PreloadOnIntent } from '../../../internal/PreloadOnIntent';\n\nexport interface PopoverProps extends Pick<\n AriaPopoverProps,\n 'placement' | 'offset' | 'isOpen' | 'onOpenChange' | 'triggerRef' | 'shouldFlip'\n> {\n /** Visible heading, also used as the accessible name. */\n title?: ReactNode;\n /** Accessible name when there is no visible title. */\n 'aria-label'?: string;\n /** Shows a small arrow pointing at the trigger. */\n showArrow?: boolean;\n /** Content, or a function that receives `close`. */\n children:
|
|
1
|
+
{"version":3,"file":"Popover.js","names":["Popover","AriaDialogTrigger"],"sources":["../../../../src/components/molecules/Popover/Popover.tsx"],"sourcesContent":["import { useContext, type ReactNode } from 'react';\nimport {\n DialogTrigger as AriaDialogTrigger,\n OverlayTriggerStateContext,\n type DialogTriggerProps,\n type PopoverProps as AriaPopoverProps,\n} from 'react-aria-components';\nimport { createLazyModule } from '../../../internal/lazyModule';\nimport type { OverlayContent } from '../../../internal/OverlayParts';\nimport { PreloadOnIntent } from '../../../internal/PreloadOnIntent';\n\nexport interface PopoverProps extends Pick<\n AriaPopoverProps,\n 'placement' | 'offset' | 'isOpen' | 'onOpenChange' | 'triggerRef' | 'shouldFlip'\n> {\n /** Visible heading, also used as the accessible name. */\n title?: ReactNode;\n /** Accessible name when there is no visible title. */\n 'aria-label'?: string;\n /** Shows a small arrow pointing at the trigger. */\n showArrow?: boolean;\n /** Content, or a function that receives `close`. */\n children: OverlayContent;\n className?: string;\n}\n\nconst overlay = /*#__PURE__*/ createLazyModule(() => import('./PopoverOverlay'));\n\n/**\n * A non modal floating panel anchored to its trigger, for rich content such\n * as filters or details. Focus moves into the panel, Escape and clicking\n * outside close it, and focus returns to the trigger. Place it inside a\n * PopoverTrigger next to the button that opens it.\n *\n * The panel's code loads the first time it opens, or earlier when the trigger\n * is hovered or focused.\n */\nexport function Popover(props: PopoverProps) {\n const triggerState = useContext(OverlayTriggerStateContext);\n const isWanted = props.isOpen ?? triggerState?.isOpen ?? false;\n const loaded = overlay.useModule(isWanted, triggerState?.close);\n return loaded ? <loaded.PopoverOverlay {...props} /> : null;\n}\n\n/** Wraps a trigger button and its Popover, and preloads the popover on hover or focus of the trigger. */\nexport function PopoverTrigger(props: DialogTriggerProps) {\n return (\n <PreloadOnIntent preload={overlay.preload}>\n <AriaDialogTrigger {...props} />\n </PreloadOnIntent>\n );\n}\n"],"mappings":";;;;;;;AA0BA,IAAM,UAAwB,qCAAuB,OAAO,sBAAmB;;;;;;;;;;AAW/E,SAAgBA,UAAQ,OAAqB;CAC3C,MAAM,eAAe,WAAW,0BAA0B;CAC1D,MAAM,WAAW,MAAM,UAAU,cAAc,UAAU;CACzD,MAAM,SAAS,QAAQ,UAAU,UAAU,cAAc,KAAK;CAC9D,OAAO,SAAS,oBAAC,OAAO,gBAAR,EAAuB,GAAI,MAAQ,CAAA,IAAI;AACzD;;AAGA,SAAgB,eAAe,OAA2B;CACxD,OACE,oBAAC,iBAAD;EAAiB,SAAS,QAAQ;EAChC,UAAA,oBAACC,eAAD,EAAmB,GAAI,MAAQ,CAAA;CAChB,CAAA;AAErB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { resolveContent } from "../../../internal/OverlayParts.js";
|
|
2
3
|
import { popoverSurface } from "../../../internal/surfaces.js";
|
|
3
4
|
import { cx } from "../../../utils/cx.js";
|
|
4
5
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -30,7 +31,7 @@ function PopoverOverlay({ title, "aria-label": ariaLabel, showArrow = false, pla
|
|
|
30
31
|
children: title
|
|
31
32
|
}), /* @__PURE__ */ jsx("div", {
|
|
32
33
|
className: "text-sm text-secondary",
|
|
33
|
-
children:
|
|
34
|
+
children: resolveContent(children, close)
|
|
34
35
|
})] })
|
|
35
36
|
})]
|
|
36
37
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PopoverOverlay.js","names":["AriaPopover","AriaDialog","_Fragment"],"sources":["../../../../src/components/molecules/Popover/PopoverOverlay.tsx"],"sourcesContent":["import {\n Dialog as AriaDialog,\n Heading,\n OverlayArrow,\n Popover as AriaPopover,\n} from 'react-aria-components';\nimport { popoverSurface } from '../../../internal/surfaces';\nimport { cx } from '../../../utils/cx';\nimport type { PopoverProps } from './Popover';\n\n/** The floating panel behind Popover. Popover loads this module the first time it opens. */\nexport function PopoverOverlay({\n title,\n 'aria-label': ariaLabel,\n showArrow = false,\n placement = 'bottom',\n offset = 8,\n children,\n className,\n ...props\n}: PopoverProps) {\n return (\n <AriaPopover\n {...props}\n placement={placement}\n offset={offset}\n className={cx(popoverSurface, 'max-w-[calc(100vw-2rem)] min-w-48', className)}\n >\n {showArrow && (\n <OverlayArrow className='group'>\n <svg\n width={12}\n height={12}\n viewBox='0 0 12 12'\n aria-hidden='true'\n className='block fill-(--ui-bg-elevated) stroke-(--ui-border-default) group-data-[placement=bottom]:rotate-180 group-data-[placement=left]:-rotate-90 group-data-[placement=right]:rotate-90'\n >\n <path d='M0 0 L6 6 L12 0' />\n </svg>\n </OverlayArrow>\n )}\n <AriaDialog aria-label={ariaLabel} className='flex flex-col gap-2 p-4 outline-none'>\n {({ close }) => (\n <>\n {title && (\n <Heading slot='title' className='text-sm font-semibold text-primary'>\n {title}\n </Heading>\n )}\n <div className='text-sm text-secondary'
|
|
1
|
+
{"version":3,"file":"PopoverOverlay.js","names":["AriaPopover","AriaDialog","_Fragment"],"sources":["../../../../src/components/molecules/Popover/PopoverOverlay.tsx"],"sourcesContent":["import {\n Dialog as AriaDialog,\n Heading,\n OverlayArrow,\n Popover as AriaPopover,\n} from 'react-aria-components';\nimport { resolveContent } from '../../../internal/OverlayParts';\nimport { popoverSurface } from '../../../internal/surfaces';\nimport { cx } from '../../../utils/cx';\nimport type { PopoverProps } from './Popover';\n\n/** The floating panel behind Popover. Popover loads this module the first time it opens. */\nexport function PopoverOverlay({\n title,\n 'aria-label': ariaLabel,\n showArrow = false,\n placement = 'bottom',\n offset = 8,\n children,\n className,\n ...props\n}: PopoverProps) {\n return (\n <AriaPopover\n {...props}\n placement={placement}\n offset={offset}\n className={cx(popoverSurface, 'max-w-[calc(100vw-2rem)] min-w-48', className)}\n >\n {showArrow && (\n <OverlayArrow className='group'>\n <svg\n width={12}\n height={12}\n viewBox='0 0 12 12'\n aria-hidden='true'\n className='block fill-(--ui-bg-elevated) stroke-(--ui-border-default) group-data-[placement=bottom]:rotate-180 group-data-[placement=left]:-rotate-90 group-data-[placement=right]:rotate-90'\n >\n <path d='M0 0 L6 6 L12 0' />\n </svg>\n </OverlayArrow>\n )}\n <AriaDialog aria-label={ariaLabel} className='flex flex-col gap-2 p-4 outline-none'>\n {({ close }) => (\n <>\n {title && (\n <Heading slot='title' className='text-sm font-semibold text-primary'>\n {title}\n </Heading>\n )}\n <div className='text-sm text-secondary'>{resolveContent(children, close)}</div>\n </>\n )}\n </AriaDialog>\n </AriaPopover>\n );\n}\n"],"mappings":";;;;;;;;AAYA,SAAgB,eAAe,EAC7B,OACA,cAAc,WACd,YAAY,OACZ,YAAY,UACZ,SAAS,GACT,UACA,WACA,GAAG,SACY;CACf,OACE,qBAACA,SAAD;EACE,GAAI;EACO;EACH;EACR,WAAW,GAAG,gBAAgB,qCAAqC,SAAS;EAJ9E,UAAA,CAMG,aACC,oBAAC,cAAD;GAAc,WAAU;GACtB,UAAA,oBAAC,OAAD;IACE,OAAO;IACP,QAAQ;IACR,SAAQ;IACR,eAAY;IACZ,WAAU;IAEV,UAAA,oBAAC,QAAD,EAAM,GAAE,kBAAmB,CAAA;GACxB,CAAA;EACO,CAAA,GAEhB,oBAACC,QAAD;GAAY,cAAY;GAAW,WAAU;GACzC,WAAA,EAAE,YACF,qBAAAC,UAAA,EAAA,UAAA,CACG,SACC,oBAAC,SAAD;IAAS,MAAK;IAAQ,WAAU;IAC7B,UAAA;GACM,CAAA,GAEX,oBAAC,OAAD;IAAK,WAAU;IAA0B,UAAA,eAAe,UAAU,KAAK;GAAO,CAAA,CAC9E,EAAA,CAAA;EAEM,CAAA,CACD;;AAEjB"}
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
export interface LazyModule<M> {
|
|
2
2
|
/** Starts loading the module. Safe to call again, and after a failure it retries. */
|
|
3
3
|
preload: () => void;
|
|
4
|
-
/**
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* The loaded module, or undefined until it has loaded. Starts loading once `isWanted` is true.
|
|
6
|
+
* If the download fails, `onFail` runs so the caller can close what it opened. The next open
|
|
7
|
+
* tries again.
|
|
8
|
+
*/
|
|
9
|
+
useModule: (isWanted: boolean, onFail?: () => void) => M | undefined;
|
|
6
10
|
/** The module if it has loaded already. For parts that only render inside the loaded overlay. */
|
|
7
11
|
get: () => M | undefined;
|
|
8
12
|
}
|
|
9
13
|
/**
|
|
10
14
|
* Loads the code behind an overlay once and shares it between every instance
|
|
11
15
|
* on the page. `useModule` reads the shared result without Suspense, so the
|
|
12
|
-
* trigger never flashes a fallback. A failed download is
|
|
13
|
-
*
|
|
16
|
+
* trigger never flashes a fallback. A failed download is reported to the caller
|
|
17
|
+
* that needed it, and the next open tries again.
|
|
14
18
|
*/
|
|
15
19
|
export declare function createLazyModule<M>(importer: () => Promise<M>): LazyModule<M>;
|
|
16
20
|
/**
|
|
@@ -5,8 +5,8 @@ import { jsx } from "react/jsx-runtime";
|
|
|
5
5
|
/**
|
|
6
6
|
* Loads the code behind an overlay once and shares it between every instance
|
|
7
7
|
* on the page. `useModule` reads the shared result without Suspense, so the
|
|
8
|
-
* trigger never flashes a fallback. A failed download is
|
|
9
|
-
*
|
|
8
|
+
* trigger never flashes a fallback. A failed download is reported to the caller
|
|
9
|
+
* that needed it, and the next open tries again.
|
|
10
10
|
*/
|
|
11
11
|
function createLazyModule(importer) {
|
|
12
12
|
const listeners = /* @__PURE__ */ new Set();
|
|
@@ -33,16 +33,26 @@ function createLazyModule(importer) {
|
|
|
33
33
|
});
|
|
34
34
|
return pending;
|
|
35
35
|
}
|
|
36
|
+
function ignoreFailure() {}
|
|
36
37
|
function preload() {
|
|
37
|
-
load().catch(
|
|
38
|
-
console.error("Could not load the component code, it will retry on the next open.", error);
|
|
39
|
-
});
|
|
38
|
+
load().catch(ignoreFailure);
|
|
40
39
|
}
|
|
41
|
-
function useModule(isWanted) {
|
|
40
|
+
function useModule(isWanted, onFail = ignoreFailure) {
|
|
42
41
|
const module = useSyncExternalStore(subscribe, get, getServerSnapshot);
|
|
43
42
|
useEffect(() => {
|
|
44
|
-
if (isWanted
|
|
45
|
-
|
|
43
|
+
if (!isWanted || module) return;
|
|
44
|
+
let isCurrent = true;
|
|
45
|
+
load().catch(() => {
|
|
46
|
+
if (isCurrent) onFail();
|
|
47
|
+
});
|
|
48
|
+
return () => {
|
|
49
|
+
isCurrent = false;
|
|
50
|
+
};
|
|
51
|
+
}, [
|
|
52
|
+
isWanted,
|
|
53
|
+
module,
|
|
54
|
+
onFail
|
|
55
|
+
]);
|
|
46
56
|
return module;
|
|
47
57
|
}
|
|
48
58
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazyModule.js","names":[],"sources":["../../src/internal/lazyModule.tsx"],"sourcesContent":["import { useEffect, useSyncExternalStore, type ComponentType } from 'react';\n\nexport interface LazyModule<M> {\n /** Starts loading the module. Safe to call again, and after a failure it retries. */\n preload: () => void;\n
|
|
1
|
+
{"version":3,"file":"lazyModule.js","names":[],"sources":["../../src/internal/lazyModule.tsx"],"sourcesContent":["import { useEffect, useSyncExternalStore, type ComponentType } from 'react';\n\nexport interface LazyModule<M> {\n /** Starts loading the module. Safe to call again, and after a failure it retries. */\n preload: () => void;\n /**\n * The loaded module, or undefined until it has loaded. Starts loading once `isWanted` is true.\n * If the download fails, `onFail` runs so the caller can close what it opened. The next open\n * tries again.\n */\n useModule: (isWanted: boolean, onFail?: () => void) => M | undefined;\n /** The module if it has loaded already. For parts that only render inside the loaded overlay. */\n get: () => M | undefined;\n}\n\n/**\n * Loads the code behind an overlay once and shares it between every instance\n * on the page. `useModule` reads the shared result without Suspense, so the\n * trigger never flashes a fallback. A failed download is reported to the caller\n * that needed it, and the next open tries again.\n */\nexport function createLazyModule<M>(importer: () => Promise<M>): LazyModule<M> {\n const listeners = new Set<() => void>();\n let loaded: M | undefined;\n let pending: Promise<M> | undefined;\n\n function subscribe(listener: () => void) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n }\n\n function get() {\n return loaded;\n }\n\n function getServerSnapshot() {\n return undefined;\n }\n\n function load(): Promise<M> {\n pending ??= importer().then(\n (module) => {\n loaded = module;\n for (const listener of listeners) listener();\n return module;\n },\n (error: unknown) => {\n pending = undefined;\n throw error;\n },\n );\n return pending;\n }\n\n function ignoreFailure() {\n // A preload is a guess. The open that needs the module retries and reports through onFail.\n }\n\n function preload() {\n load().catch(ignoreFailure);\n }\n\n function useModule(isWanted: boolean, onFail: () => void = ignoreFailure) {\n const module = useSyncExternalStore(subscribe, get, getServerSnapshot);\n\n useEffect(() => {\n if (!isWanted || module) return;\n let isCurrent = true;\n load().catch(() => {\n if (isCurrent) onFail();\n });\n return () => {\n isCurrent = false;\n };\n }, [isWanted, module, onFail]);\n\n return module;\n }\n\n return { preload, useModule, get };\n}\n\n/**\n * A component that renders the named export of a lazy module once it has\n * loaded, and nothing before. For parts that only render inside an overlay that\n * already waited for the module.\n */\nexport function lazyPart<M, K extends keyof M>(module: LazyModule<M>, name: K): M[K] {\n function LazyPart(props: object) {\n const Part = module.get()?.[name] as ComponentType<object> | undefined;\n return Part ? <Part {...props} /> : null;\n }\n return LazyPart as M[K];\n}\n"],"mappings":";;;;;;;;;;AAqBA,SAAgB,iBAAoB,UAA2C;CAC7E,MAAM,4BAAY,IAAI,IAAgB;CACtC,IAAI;CACJ,IAAI;CAEJ,SAAS,UAAU,UAAsB;EACvC,UAAU,IAAI,QAAQ;EACtB,aAAa;GACX,UAAU,OAAO,QAAQ;EAC3B;CACF;CAEA,SAAS,MAAM;EACb,OAAO;CACT;CAEA,SAAS,oBAAoB,CAE7B;CAEA,SAAS,OAAmB;EAC1B,YAAY,SAAS,CAAC,CAAC,MACpB,WAAW;GACV,SAAS;GACT,KAAK,MAAM,YAAY,WAAW,SAAS;GAC3C,OAAO;EACT,IACC,UAAmB;GAClB,UAAU,KAAA;GACV,MAAM;EACR,CACF;EACA,OAAO;CACT;CAEA,SAAS,gBAAgB,CAEzB;CAEA,SAAS,UAAU;EACjB,KAAK,CAAC,CAAC,MAAM,aAAa;CAC5B;CAEA,SAAS,UAAU,UAAmB,SAAqB,eAAe;EACxE,MAAM,SAAS,qBAAqB,WAAW,KAAK,iBAAiB;EAErE,gBAAgB;GACd,IAAI,CAAC,YAAY,QAAQ;GACzB,IAAI,YAAY;GAChB,KAAK,CAAC,CAAC,YAAY;IACjB,IAAI,WAAW,OAAO;GACxB,CAAC;GACD,aAAa;IACX,YAAY;GACd;EACF,GAAG;GAAC;GAAU;GAAQ;EAAM,CAAC;EAE7B,OAAO;CACT;CAEA,OAAO;EAAE;EAAS;EAAW;CAAI;AACnC;;;;;;AAOA,SAAgB,SAA+B,QAAuB,MAAe;CACnF,SAAS,SAAS,OAAe;EAC/B,MAAM,OAAO,OAAO,IAAI,CAAC,GAAG;EAC5B,OAAO,OAAO,oBAAC,MAAD,EAAM,GAAI,MAAQ,CAAA,IAAI;CACtC;CACA,OAAO;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eylulg/ui",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Accessible React 19 design system built with atomic design on React Aria Components and Tailwind CSS 4 tokens.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Eylül Güneş (https://github.com/eylulg)",
|