@zvk/ui 0.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/LICENSE.md +26 -0
- package/README.md +31 -0
- package/dist/components/accordion/accordion.d.ts +43 -0
- package/dist/components/accordion/accordion.js +207 -0
- package/dist/components/accordion/index.d.ts +2 -0
- package/dist/components/accordion/index.js +2 -0
- package/dist/components/alert/alert.d.ts +24 -0
- package/dist/components/alert/alert.js +17 -0
- package/dist/components/alert/index.d.ts +2 -0
- package/dist/components/alert/index.js +1 -0
- package/dist/components/alert-dialog/alert-dialog.d.ts +46 -0
- package/dist/components/alert-dialog/alert-dialog.js +112 -0
- package/dist/components/alert-dialog/index.d.ts +2 -0
- package/dist/components/alert-dialog/index.js +2 -0
- package/dist/components/avatar/avatar.d.ts +14 -0
- package/dist/components/avatar/avatar.js +22 -0
- package/dist/components/avatar/index.d.ts +2 -0
- package/dist/components/avatar/index.js +2 -0
- package/dist/components/badge/badge.d.ts +11 -0
- package/dist/components/badge/badge.js +6 -0
- package/dist/components/badge/index.d.ts +2 -0
- package/dist/components/badge/index.js +1 -0
- package/dist/components/breadcrumbs/breadcrumbs.d.ts +24 -0
- package/dist/components/breadcrumbs/breadcrumbs.js +18 -0
- package/dist/components/breadcrumbs/index.d.ts +2 -0
- package/dist/components/breadcrumbs/index.js +1 -0
- package/dist/components/button/button.d.ts +13 -0
- package/dist/components/button/button.js +8 -0
- package/dist/components/button/index.d.ts +2 -0
- package/dist/components/button/index.js +1 -0
- package/dist/components/card/card.d.ts +31 -0
- package/dist/components/card/card.js +28 -0
- package/dist/components/card/index.d.ts +2 -0
- package/dist/components/card/index.js +1 -0
- package/dist/components/checkbox/checkbox.d.ts +11 -0
- package/dist/components/checkbox/checkbox.js +30 -0
- package/dist/components/checkbox/index.d.ts +2 -0
- package/dist/components/checkbox/index.js +2 -0
- package/dist/components/code-block/code-block.d.ts +10 -0
- package/dist/components/code-block/code-block.js +16 -0
- package/dist/components/code-block/index.d.ts +2 -0
- package/dist/components/code-block/index.js +1 -0
- package/dist/components/collapsible/collapsible.d.ts +23 -0
- package/dist/components/collapsible/collapsible.js +52 -0
- package/dist/components/collapsible/index.d.ts +2 -0
- package/dist/components/collapsible/index.js +2 -0
- package/dist/components/combobox/combobox.d.ts +20 -0
- package/dist/components/combobox/combobox.js +121 -0
- package/dist/components/combobox/index.d.ts +2 -0
- package/dist/components/combobox/index.js +2 -0
- package/dist/components/command/command-dialog.d.ts +2 -0
- package/dist/components/command/command-dialog.js +1 -0
- package/dist/components/command/command-filter.d.ts +7 -0
- package/dist/components/command/command-filter.js +14 -0
- package/dist/components/command/command.d.ts +55 -0
- package/dist/components/command/command.js +200 -0
- package/dist/components/command/index.d.ts +2 -0
- package/dist/components/command/index.js +2 -0
- package/dist/components/context-menu/context-menu.d.ts +34 -0
- package/dist/components/context-menu/context-menu.js +154 -0
- package/dist/components/context-menu/index.d.ts +2 -0
- package/dist/components/context-menu/index.js +2 -0
- package/dist/components/conversation/conversation.d.ts +60 -0
- package/dist/components/conversation/conversation.js +49 -0
- package/dist/components/conversation/index.d.ts +2 -0
- package/dist/components/conversation/index.js +1 -0
- package/dist/components/copy-button/copy-button.d.ts +23 -0
- package/dist/components/copy-button/copy-button.js +50 -0
- package/dist/components/copy-button/index.d.ts +2 -0
- package/dist/components/copy-button/index.js +2 -0
- package/dist/components/dialog/dialog.d.ts +62 -0
- package/dist/components/dialog/dialog.js +141 -0
- package/dist/components/dialog/index.d.ts +2 -0
- package/dist/components/dialog/index.js +2 -0
- package/dist/components/dropdown-menu/dropdown-menu.d.ts +43 -0
- package/dist/components/dropdown-menu/dropdown-menu.js +286 -0
- package/dist/components/dropdown-menu/index.d.ts +2 -0
- package/dist/components/dropdown-menu/index.js +2 -0
- package/dist/components/empty-state/empty-state.d.ts +13 -0
- package/dist/components/empty-state/empty-state.js +34 -0
- package/dist/components/empty-state/index.d.ts +2 -0
- package/dist/components/empty-state/index.js +1 -0
- package/dist/components/error-boundary/error-boundary.d.ts +29 -0
- package/dist/components/error-boundary/error-boundary.js +43 -0
- package/dist/components/error-boundary/index.d.ts +2 -0
- package/dist/components/error-boundary/index.js +2 -0
- package/dist/components/field/field.d.ts +23 -0
- package/dist/components/field/field.js +20 -0
- package/dist/components/field/index.d.ts +2 -0
- package/dist/components/field/index.js +1 -0
- package/dist/components/file-upload-input/file-upload-input.d.ts +13 -0
- package/dist/components/file-upload-input/file-upload-input.js +41 -0
- package/dist/components/file-upload-input/index.d.ts +2 -0
- package/dist/components/file-upload-input/index.js +2 -0
- package/dist/components/form/form.d.ts +30 -0
- package/dist/components/form/form.js +88 -0
- package/dist/components/form/index.d.ts +2 -0
- package/dist/components/form/index.js +2 -0
- package/dist/components/icon-button/icon-button.d.ts +10 -0
- package/dist/components/icon-button/icon-button.js +8 -0
- package/dist/components/icon-button/index.d.ts +2 -0
- package/dist/components/icon-button/index.js +1 -0
- package/dist/components/index.d.ts +102 -0
- package/dist/components/index.js +51 -0
- package/dist/components/input/index.d.ts +2 -0
- package/dist/components/input/index.js +1 -0
- package/dist/components/input/input.d.ts +11 -0
- package/dist/components/input/input.js +27 -0
- package/dist/components/label/index.d.ts +2 -0
- package/dist/components/label/index.js +1 -0
- package/dist/components/label/label.d.ts +9 -0
- package/dist/components/label/label.js +6 -0
- package/dist/components/menubar/index.d.ts +2 -0
- package/dist/components/menubar/index.js +2 -0
- package/dist/components/menubar/menubar.d.ts +39 -0
- package/dist/components/menubar/menubar.js +214 -0
- package/dist/components/pagination/index.d.ts +2 -0
- package/dist/components/pagination/index.js +1 -0
- package/dist/components/pagination/pagination.d.ts +21 -0
- package/dist/components/pagination/pagination.js +92 -0
- package/dist/components/popover/index.d.ts +2 -0
- package/dist/components/popover/index.js +2 -0
- package/dist/components/popover/popover.d.ts +28 -0
- package/dist/components/popover/popover.js +164 -0
- package/dist/components/progress/index.d.ts +2 -0
- package/dist/components/progress/index.js +1 -0
- package/dist/components/progress/progress.d.ts +24 -0
- package/dist/components/progress/progress.js +29 -0
- package/dist/components/radio-group/index.d.ts +2 -0
- package/dist/components/radio-group/index.js +2 -0
- package/dist/components/radio-group/radio-group.d.ts +42 -0
- package/dist/components/radio-group/radio-group.js +69 -0
- package/dist/components/responsive-container/index.d.ts +2 -0
- package/dist/components/responsive-container/index.js +1 -0
- package/dist/components/responsive-container/responsive-container.d.ts +10 -0
- package/dist/components/responsive-container/responsive-container.js +6 -0
- package/dist/components/scroll-area/index.d.ts +2 -0
- package/dist/components/scroll-area/index.js +2 -0
- package/dist/components/scroll-area/scroll-area.d.ts +21 -0
- package/dist/components/scroll-area/scroll-area.js +23 -0
- package/dist/components/sectioned-sidebar-nav/index.d.ts +2 -0
- package/dist/components/sectioned-sidebar-nav/index.js +1 -0
- package/dist/components/sectioned-sidebar-nav/sectioned-sidebar-nav.d.ts +39 -0
- package/dist/components/sectioned-sidebar-nav/sectioned-sidebar-nav.js +37 -0
- package/dist/components/select/index.d.ts +2 -0
- package/dist/components/select/index.js +2 -0
- package/dist/components/select/select.d.ts +46 -0
- package/dist/components/select/select.js +239 -0
- package/dist/components/separator/index.d.ts +2 -0
- package/dist/components/separator/index.js +1 -0
- package/dist/components/separator/separator.d.ts +8 -0
- package/dist/components/separator/separator.js +6 -0
- package/dist/components/sheet/index.d.ts +2 -0
- package/dist/components/sheet/index.js +2 -0
- package/dist/components/sheet/sheet.d.ts +49 -0
- package/dist/components/sheet/sheet.js +116 -0
- package/dist/components/sidebar-shell/index.d.ts +2 -0
- package/dist/components/sidebar-shell/index.js +1 -0
- package/dist/components/sidebar-shell/sidebar-shell.d.ts +35 -0
- package/dist/components/sidebar-shell/sidebar-shell.js +28 -0
- package/dist/components/skeleton/index.d.ts +2 -0
- package/dist/components/skeleton/index.js +1 -0
- package/dist/components/skeleton/skeleton.d.ts +10 -0
- package/dist/components/skeleton/skeleton.js +16 -0
- package/dist/components/slider/index.d.ts +2 -0
- package/dist/components/slider/index.js +2 -0
- package/dist/components/slider/slider.d.ts +12 -0
- package/dist/components/slider/slider.js +30 -0
- package/dist/components/spinner/index.d.ts +2 -0
- package/dist/components/spinner/index.js +1 -0
- package/dist/components/spinner/spinner.d.ts +10 -0
- package/dist/components/spinner/spinner.js +7 -0
- package/dist/components/stat/index.d.ts +2 -0
- package/dist/components/stat/index.js +1 -0
- package/dist/components/stat/stat.d.ts +13 -0
- package/dist/components/stat/stat.js +8 -0
- package/dist/components/switch/index.d.ts +2 -0
- package/dist/components/switch/index.js +2 -0
- package/dist/components/switch/switch.d.ts +11 -0
- package/dist/components/switch/switch.js +27 -0
- package/dist/components/table/index.d.ts +2 -0
- package/dist/components/table/index.js +1 -0
- package/dist/components/table/table.d.ts +45 -0
- package/dist/components/table/table.js +36 -0
- package/dist/components/tabs/index.d.ts +2 -0
- package/dist/components/tabs/index.js +2 -0
- package/dist/components/tabs/tabs.d.ts +34 -0
- package/dist/components/tabs/tabs.js +233 -0
- package/dist/components/tabs-with-sidebar/index.d.ts +2 -0
- package/dist/components/tabs-with-sidebar/index.js +2 -0
- package/dist/components/tabs-with-sidebar/tabs-with-sidebar.d.ts +21 -0
- package/dist/components/tabs-with-sidebar/tabs-with-sidebar.js +18 -0
- package/dist/components/textarea/index.d.ts +2 -0
- package/dist/components/textarea/index.js +2 -0
- package/dist/components/textarea/textarea.d.ts +11 -0
- package/dist/components/textarea/textarea.js +28 -0
- package/dist/components/toast/index.d.ts +2 -0
- package/dist/components/toast/index.js +1 -0
- package/dist/components/toast/toast.d.ts +33 -0
- package/dist/components/toast/toast.js +27 -0
- package/dist/components/toggle/index.d.ts +2 -0
- package/dist/components/toggle/index.js +2 -0
- package/dist/components/toggle/toggle.d.ts +12 -0
- package/dist/components/toggle/toggle.js +18 -0
- package/dist/components/toggle-group/index.d.ts +2 -0
- package/dist/components/toggle-group/index.js +2 -0
- package/dist/components/toggle-group/toggle-group.d.ts +28 -0
- package/dist/components/toggle-group/toggle-group.js +67 -0
- package/dist/components/tooltip/index.d.ts +2 -0
- package/dist/components/tooltip/index.js +2 -0
- package/dist/components/tooltip/tooltip.d.ts +10 -0
- package/dist/components/tooltip/tooltip.js +100 -0
- package/dist/hooks/index.d.ts +7 -0
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/use-composed-refs.d.ts +3 -0
- package/dist/hooks/use-composed-refs.js +18 -0
- package/dist/hooks/use-controllable-state.d.ts +7 -0
- package/dist/hooks/use-controllable-state.js +30 -0
- package/dist/hooks/use-disclosure.d.ts +13 -0
- package/dist/hooks/use-disclosure.js +20 -0
- package/dist/hooks/use-event.d.ts +1 -0
- package/dist/hooks/use-event.js +11 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/internal/collection/collection.d.ts +18 -0
- package/dist/internal/collection/collection.js +54 -0
- package/dist/internal/collection/index.d.ts +2 -0
- package/dist/internal/collection/index.js +1 -0
- package/dist/internal/dismissable-layer/dismissable-layer.d.ts +13 -0
- package/dist/internal/dismissable-layer/dismissable-layer.js +73 -0
- package/dist/internal/dismissable-layer/index.d.ts +2 -0
- package/dist/internal/dismissable-layer/index.js +1 -0
- package/dist/internal/floating/auto-update.d.ts +9 -0
- package/dist/internal/floating/auto-update.js +48 -0
- package/dist/internal/floating/compute-position.d.ts +2 -0
- package/dist/internal/floating/compute-position.js +96 -0
- package/dist/internal/floating/detect-overflow.d.ts +13 -0
- package/dist/internal/floating/detect-overflow.js +13 -0
- package/dist/internal/floating/floating-types.d.ts +42 -0
- package/dist/internal/floating/floating-types.js +1 -0
- package/dist/internal/floating/index.d.ts +27 -0
- package/dist/internal/floating/index.js +5 -0
- package/dist/internal/floating/middleware.d.ts +11 -0
- package/dist/internal/floating/middleware.js +42 -0
- package/dist/internal/floating/use-floating-position.d.ts +2 -0
- package/dist/internal/floating/use-floating-position.js +113 -0
- package/dist/internal/focus/focus-scope.d.ts +10 -0
- package/dist/internal/focus/focus-scope.js +68 -0
- package/dist/internal/focus/focus-utils.d.ts +9 -0
- package/dist/internal/focus/focus-utils.js +94 -0
- package/dist/internal/focus/index.d.ts +3 -0
- package/dist/internal/focus/index.js +2 -0
- package/dist/internal/overlay-stack/index.d.ts +1 -0
- package/dist/internal/overlay-stack/index.js +1 -0
- package/dist/internal/overlay-stack/overlay-stack.d.ts +12 -0
- package/dist/internal/overlay-stack/overlay-stack.js +41 -0
- package/dist/internal/portal/index.d.ts +2 -0
- package/dist/internal/portal/index.js +1 -0
- package/dist/internal/portal/portal.d.ts +7 -0
- package/dist/internal/portal/portal.js +19 -0
- package/dist/internal/scroll-lock/index.d.ts +1 -0
- package/dist/internal/scroll-lock/index.js +1 -0
- package/dist/internal/scroll-lock/scroll-lock.d.ts +4 -0
- package/dist/internal/scroll-lock/scroll-lock.js +69 -0
- package/dist/styles.css +3852 -0
- package/dist/tokens/index.d.ts +2 -0
- package/dist/tokens/index.js +1 -0
- package/dist/tokens/token-types.d.ts +23 -0
- package/dist/tokens/token-types.js +1 -0
- package/dist/tokens/tokens.d.ts +139 -0
- package/dist/tokens/tokens.js +139 -0
- package/dist/utils/cn.d.ts +2 -0
- package/dist/utils/cn.js +3 -0
- package/dist/utils/compose-event-handlers.d.ts +6 -0
- package/dist/utils/compose-event-handlers.js +8 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +2 -0
- package/package.json +282 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { PortalProps } from "../../internal/portal/index.js";
|
|
3
|
+
export interface DialogProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
4
|
+
defaultOpen?: boolean;
|
|
5
|
+
disableEscapeKeyDown?: boolean;
|
|
6
|
+
disableOutsidePointerDown?: boolean;
|
|
7
|
+
onOpenChange?: (next: boolean) => void;
|
|
8
|
+
open?: boolean;
|
|
9
|
+
container?: PortalProps["container"];
|
|
10
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
11
|
+
}
|
|
12
|
+
export interface DialogTriggerProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
13
|
+
ref?: React.Ref<HTMLButtonElement>;
|
|
14
|
+
}
|
|
15
|
+
export interface DialogContentProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
16
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
17
|
+
}
|
|
18
|
+
export interface DialogHeaderProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
19
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
20
|
+
}
|
|
21
|
+
export interface DialogTitleProps extends React.HTMLAttributes<HTMLHeadingElement> {
|
|
22
|
+
ref?: React.Ref<HTMLHeadingElement>;
|
|
23
|
+
}
|
|
24
|
+
export interface DialogDescriptionProps extends React.HTMLAttributes<HTMLParagraphElement> {
|
|
25
|
+
ref?: React.Ref<HTMLParagraphElement>;
|
|
26
|
+
}
|
|
27
|
+
export interface DialogFooterProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
28
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
29
|
+
}
|
|
30
|
+
export interface DialogOverlayProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
31
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
32
|
+
}
|
|
33
|
+
export interface DialogCloseProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
34
|
+
ref?: React.Ref<HTMLButtonElement>;
|
|
35
|
+
}
|
|
36
|
+
interface DialogPortalProps {
|
|
37
|
+
children: React.ReactNode;
|
|
38
|
+
container: PortalProps["container"] | undefined;
|
|
39
|
+
}
|
|
40
|
+
declare function DialogRoot({ children, className, container, defaultOpen, disableEscapeKeyDown, disableOutsidePointerDown, onOpenChange, open: openProp, ref, ...props }: DialogProps): React.JSX.Element;
|
|
41
|
+
declare function DialogPortal({ container, children }: DialogPortalProps): React.JSX.Element;
|
|
42
|
+
declare function DialogOverlay({ className, ref, ...props }: DialogOverlayProps): React.JSX.Element;
|
|
43
|
+
declare function DialogContent({ className, children, ref, ...props }: DialogContentProps): React.JSX.Element | null;
|
|
44
|
+
declare function DialogHeader({ className, ref, ...props }: DialogHeaderProps): React.JSX.Element;
|
|
45
|
+
declare function DialogTitle({ className, ref, ...props }: DialogTitleProps): React.JSX.Element;
|
|
46
|
+
declare function DialogDescription({ className, ref, ...props }: DialogDescriptionProps): React.JSX.Element;
|
|
47
|
+
declare function DialogFooter({ className, ref, ...props }: DialogFooterProps): React.JSX.Element;
|
|
48
|
+
declare function DialogTrigger({ className, disabled, onClick, ref, type, ...props }: DialogTriggerProps): React.JSX.Element;
|
|
49
|
+
declare function DialogClose({ className, onClick, ref, type, ...props }: DialogCloseProps): React.JSX.Element;
|
|
50
|
+
type DialogComponent = typeof DialogRoot & {
|
|
51
|
+
Close: typeof DialogClose;
|
|
52
|
+
Content: typeof DialogContent;
|
|
53
|
+
Description: typeof DialogDescription;
|
|
54
|
+
Footer: typeof DialogFooter;
|
|
55
|
+
Header: typeof DialogHeader;
|
|
56
|
+
Overlay: typeof DialogOverlay;
|
|
57
|
+
Portal: typeof DialogPortal;
|
|
58
|
+
Title: typeof DialogTitle;
|
|
59
|
+
Trigger: typeof DialogTrigger;
|
|
60
|
+
};
|
|
61
|
+
export declare const Dialog: DialogComponent;
|
|
62
|
+
export {};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { composeEventHandlers } from "../../utils/compose-event-handlers.js";
|
|
5
|
+
import { cn } from "../../utils/cn.js";
|
|
6
|
+
import { useControllableState } from "../../hooks/use-controllable-state.js";
|
|
7
|
+
import { DismissableLayer } from "../../internal/dismissable-layer/dismissable-layer.js";
|
|
8
|
+
import { FocusScope } from "../../internal/focus/focus-scope.js";
|
|
9
|
+
import { lockScroll, unlockScroll } from "../../internal/scroll-lock/scroll-lock.js";
|
|
10
|
+
import { Portal } from "../../internal/portal/index.js";
|
|
11
|
+
const DialogContext = React.createContext(null);
|
|
12
|
+
function useDialogContext(calledBy) {
|
|
13
|
+
const context = React.useContext(DialogContext);
|
|
14
|
+
if (context === null) {
|
|
15
|
+
throw new Error(`"${calledBy}" must be used inside a <Dialog />`);
|
|
16
|
+
}
|
|
17
|
+
return context;
|
|
18
|
+
}
|
|
19
|
+
function composeRefs(...refs) {
|
|
20
|
+
return (node) => {
|
|
21
|
+
for (const ref of refs) {
|
|
22
|
+
if (typeof ref === "function") {
|
|
23
|
+
ref(node);
|
|
24
|
+
}
|
|
25
|
+
else if (ref && "current" in ref) {
|
|
26
|
+
ref.current = node;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function DialogRoot({ children, className, container, defaultOpen = false, disableEscapeKeyDown = false, disableOutsidePointerDown = false, onOpenChange, open: openProp, ref, ...props }) {
|
|
32
|
+
const [open, setOpen] = useControllableState({
|
|
33
|
+
...(openProp !== undefined ? { value: openProp } : {}),
|
|
34
|
+
defaultValue: defaultOpen,
|
|
35
|
+
...(onOpenChange ? { onChange: onOpenChange } : {})
|
|
36
|
+
});
|
|
37
|
+
const instanceId = React.useId();
|
|
38
|
+
const triggerRef = React.useRef(null);
|
|
39
|
+
const [labelledBy, setLabelledBy] = React.useState();
|
|
40
|
+
const [describedBy, setDescribedBy] = React.useState();
|
|
41
|
+
const registerTitle = React.useCallback((id) => {
|
|
42
|
+
setLabelledBy(id);
|
|
43
|
+
return () => {
|
|
44
|
+
setLabelledBy((current) => (current === id ? undefined : current));
|
|
45
|
+
};
|
|
46
|
+
}, []);
|
|
47
|
+
const registerDescription = React.useCallback((id) => {
|
|
48
|
+
setDescribedBy(id);
|
|
49
|
+
return () => {
|
|
50
|
+
setDescribedBy((current) => (current === id ? undefined : current));
|
|
51
|
+
};
|
|
52
|
+
}, []);
|
|
53
|
+
React.useLayoutEffect(() => {
|
|
54
|
+
if (!open) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
lockScroll();
|
|
58
|
+
return () => {
|
|
59
|
+
unlockScroll();
|
|
60
|
+
};
|
|
61
|
+
}, [open]);
|
|
62
|
+
return (_jsx(DialogContext.Provider, { value: {
|
|
63
|
+
close: () => {
|
|
64
|
+
setOpen(false);
|
|
65
|
+
},
|
|
66
|
+
open,
|
|
67
|
+
setOpen,
|
|
68
|
+
container,
|
|
69
|
+
contentId: `${instanceId}-content`,
|
|
70
|
+
describedBy,
|
|
71
|
+
descriptionId: `${instanceId}-description`,
|
|
72
|
+
labelledBy,
|
|
73
|
+
registerDescription,
|
|
74
|
+
registerTitle,
|
|
75
|
+
titleId: `${instanceId}-title`,
|
|
76
|
+
triggerRef,
|
|
77
|
+
disableOutsidePointerDown,
|
|
78
|
+
disableEscapeKeyDown
|
|
79
|
+
}, children: _jsx("div", { ...props, ref: ref, className: cn("liano-dialog", className), "data-state": open ? "open" : "closed", children: children }) }));
|
|
80
|
+
}
|
|
81
|
+
function DialogPortal({ container, children }) {
|
|
82
|
+
if (container === undefined) {
|
|
83
|
+
return _jsx(Portal, { children: children });
|
|
84
|
+
}
|
|
85
|
+
return _jsx(Portal, { container: container, children: children });
|
|
86
|
+
}
|
|
87
|
+
function DialogOverlay({ className, ref, ...props }) {
|
|
88
|
+
return _jsx("div", { ...props, ref: ref, className: cn("liano-dialog__overlay", className) });
|
|
89
|
+
}
|
|
90
|
+
function DialogContent({ className, children, ref, ...props }) {
|
|
91
|
+
const { close, container, contentId, describedBy, disableEscapeKeyDown, disableOutsidePointerDown, labelledBy, open } = useDialogContext("Dialog.Content");
|
|
92
|
+
if (!open) {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
return (_jsxs(DialogPortal, { container: container, children: [_jsx(DialogOverlay, { "aria-hidden": true }), _jsx(DismissableLayer, { open: open, disableEscapeKeyDown: disableEscapeKeyDown, disableOutsidePointerDown: disableOutsidePointerDown, onDismiss: close, children: _jsx(FocusScope, { trapped: true, active: open, children: _jsx("div", { ...props, ref: ref, id: contentId, role: "dialog", "aria-modal": true, "aria-labelledby": labelledBy, "aria-describedby": describedBy, className: cn("liano-dialog__content", className), "data-state": open ? "open" : "closed", children: children }) }) })] }));
|
|
96
|
+
}
|
|
97
|
+
function DialogHeader({ className, ref, ...props }) {
|
|
98
|
+
return _jsx("div", { ...props, ref: ref, className: cn("liano-dialog__header", className) });
|
|
99
|
+
}
|
|
100
|
+
function DialogTitle({ className, ref, ...props }) {
|
|
101
|
+
const { registerTitle, titleId } = useDialogContext("Dialog.Title");
|
|
102
|
+
const resolvedId = props.id ?? titleId;
|
|
103
|
+
React.useLayoutEffect(() => registerTitle(resolvedId), [registerTitle, resolvedId]);
|
|
104
|
+
return _jsx("h2", { ...props, ref: ref, id: resolvedId, className: cn("liano-dialog__title", className) });
|
|
105
|
+
}
|
|
106
|
+
function DialogDescription({ className, ref, ...props }) {
|
|
107
|
+
const { descriptionId, registerDescription } = useDialogContext("Dialog.Description");
|
|
108
|
+
const resolvedId = props.id ?? descriptionId;
|
|
109
|
+
React.useLayoutEffect(() => registerDescription(resolvedId), [registerDescription, resolvedId]);
|
|
110
|
+
return (_jsx("p", { ...props, ref: ref, id: resolvedId, className: cn("liano-dialog__description", className) }));
|
|
111
|
+
}
|
|
112
|
+
function DialogFooter({ className, ref, ...props }) {
|
|
113
|
+
return _jsx("div", { ...props, ref: ref, className: cn("liano-dialog__footer", className) });
|
|
114
|
+
}
|
|
115
|
+
function DialogTrigger({ className, disabled, onClick, ref, type = "button", ...props }) {
|
|
116
|
+
const { open, setOpen, contentId, triggerRef } = useDialogContext("Dialog.Trigger");
|
|
117
|
+
const handleClick = () => {
|
|
118
|
+
if (disabled) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
setOpen(true);
|
|
122
|
+
};
|
|
123
|
+
return (_jsx("button", { ...props, ref: composeRefs(ref, triggerRef), type: type, disabled: disabled, "aria-controls": contentId, "aria-expanded": open ? "true" : "false", "data-state": open ? "open" : "closed", className: cn("liano-dialog__trigger", className), onClick: composeEventHandlers(onClick, handleClick) }));
|
|
124
|
+
}
|
|
125
|
+
function DialogClose({ className, onClick, ref, type = "button", ...props }) {
|
|
126
|
+
const { close } = useDialogContext("Dialog.Close");
|
|
127
|
+
return (_jsx("button", { ...props, ref: ref, type: type, className: cn("liano-dialog__close", className), onClick: composeEventHandlers(onClick, () => {
|
|
128
|
+
close();
|
|
129
|
+
}) }));
|
|
130
|
+
}
|
|
131
|
+
export const Dialog = Object.assign(DialogRoot, {
|
|
132
|
+
Close: DialogClose,
|
|
133
|
+
Content: DialogContent,
|
|
134
|
+
Description: DialogDescription,
|
|
135
|
+
Footer: DialogFooter,
|
|
136
|
+
Header: DialogHeader,
|
|
137
|
+
Overlay: DialogOverlay,
|
|
138
|
+
Portal: DialogPortal,
|
|
139
|
+
Title: DialogTitle,
|
|
140
|
+
Trigger: DialogTrigger
|
|
141
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { PortalProps } from "../../internal/portal/index.js";
|
|
3
|
+
import type { FloatingPlacement } from "../../internal/floating/floating-types.js";
|
|
4
|
+
export interface DropdownMenuProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
5
|
+
container?: PortalProps["container"];
|
|
6
|
+
open?: boolean;
|
|
7
|
+
defaultOpen?: boolean;
|
|
8
|
+
onOpenChange?: (open: boolean) => void;
|
|
9
|
+
placement?: FloatingPlacement;
|
|
10
|
+
sideOffset?: number;
|
|
11
|
+
collisionPadding?: number;
|
|
12
|
+
matchTriggerWidth?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface DropdownMenuTriggerProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
15
|
+
ref?: React.Ref<HTMLButtonElement>;
|
|
16
|
+
}
|
|
17
|
+
export interface DropdownMenuContentProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
18
|
+
sideOffset?: number;
|
|
19
|
+
collisionPadding?: number;
|
|
20
|
+
matchTriggerWidth?: boolean;
|
|
21
|
+
forceMount?: boolean;
|
|
22
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
23
|
+
}
|
|
24
|
+
export interface DropdownMenuItemProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
25
|
+
onSelect?: (event: React.SyntheticEvent<HTMLElement>) => void;
|
|
26
|
+
ref?: React.Ref<HTMLButtonElement>;
|
|
27
|
+
}
|
|
28
|
+
export interface DropdownMenuSeparatorProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
29
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
30
|
+
}
|
|
31
|
+
declare function DropdownMenuRoot({ children, className, container, defaultOpen, onOpenChange, open: openProp, placement, sideOffset, collisionPadding, matchTriggerWidth, ...props }: DropdownMenuProps): React.JSX.Element;
|
|
32
|
+
declare function DropdownMenuTrigger({ className, disabled, onClick, ref, type, ...props }: DropdownMenuTriggerProps): React.JSX.Element;
|
|
33
|
+
declare function DropdownMenuContent({ children, className, forceMount, sideOffset, collisionPadding, matchTriggerWidth, ref, onKeyDown, ...props }: DropdownMenuContentProps): React.JSX.Element | null;
|
|
34
|
+
declare function DropdownMenuItem({ children, className, disabled, onClick, onSelect, onKeyDown, ref, ...props }: DropdownMenuItemProps): React.JSX.Element;
|
|
35
|
+
declare function DropdownMenuSeparator({ className, ref, ...props }: DropdownMenuSeparatorProps): React.JSX.Element;
|
|
36
|
+
type DropdownMenuComponent = typeof DropdownMenuRoot & {
|
|
37
|
+
Content: typeof DropdownMenuContent;
|
|
38
|
+
Item: typeof DropdownMenuItem;
|
|
39
|
+
Separator: typeof DropdownMenuSeparator;
|
|
40
|
+
Trigger: typeof DropdownMenuTrigger;
|
|
41
|
+
};
|
|
42
|
+
export declare const DropdownMenu: DropdownMenuComponent;
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { composeEventHandlers } from "../../utils/compose-event-handlers.js";
|
|
5
|
+
import { cn } from "../../utils/cn.js";
|
|
6
|
+
import { useControllableState } from "../../hooks/use-controllable-state.js";
|
|
7
|
+
import { Portal } from "../../internal/portal/index.js";
|
|
8
|
+
import { DismissableLayer } from "../../internal/dismissable-layer/dismissable-layer.js";
|
|
9
|
+
import { useFloatingPosition } from "../../internal/floating/index.js";
|
|
10
|
+
const defaultContentPositioning = {
|
|
11
|
+
sideOffset: 8,
|
|
12
|
+
collisionPadding: 0,
|
|
13
|
+
matchTriggerWidth: false
|
|
14
|
+
};
|
|
15
|
+
const DropdownMenuContext = React.createContext(null);
|
|
16
|
+
function useDropdownMenuContext(calledBy) {
|
|
17
|
+
const context = React.useContext(DropdownMenuContext);
|
|
18
|
+
if (context === null) {
|
|
19
|
+
throw new Error(`"${calledBy}" must be used within a <DropdownMenu />`);
|
|
20
|
+
}
|
|
21
|
+
return context;
|
|
22
|
+
}
|
|
23
|
+
function composeRefs(...refs) {
|
|
24
|
+
return (node) => {
|
|
25
|
+
for (const ref of refs) {
|
|
26
|
+
if (typeof ref === "function") {
|
|
27
|
+
ref(node);
|
|
28
|
+
}
|
|
29
|
+
else if (ref && "current" in ref) {
|
|
30
|
+
ref.current = node;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function filterEnabledItems(items) {
|
|
36
|
+
return items.filter((item) => !item.disabled && item.ref !== null);
|
|
37
|
+
}
|
|
38
|
+
function DropdownMenuRoot({ children, className, container, defaultOpen = false, onOpenChange, open: openProp, placement = "bottom", sideOffset = 8, collisionPadding = 0, matchTriggerWidth = false, ...props }) {
|
|
39
|
+
const [open, setOpen] = useControllableState({
|
|
40
|
+
...(openProp !== undefined ? { value: openProp } : {}),
|
|
41
|
+
defaultValue: defaultOpen,
|
|
42
|
+
...(onOpenChange ? { onChange: onOpenChange } : {})
|
|
43
|
+
});
|
|
44
|
+
const instanceId = React.useId();
|
|
45
|
+
const triggerRef = React.useRef(null);
|
|
46
|
+
const triggerId = `${instanceId}-trigger`;
|
|
47
|
+
const contentId = `${instanceId}-content`;
|
|
48
|
+
const itemRegistry = React.useRef(new Map());
|
|
49
|
+
const itemOrder = React.useRef([]);
|
|
50
|
+
const wasOpenRef = React.useRef(false);
|
|
51
|
+
const [contentPositioning, setContentPositioning] = React.useState({
|
|
52
|
+
sideOffset,
|
|
53
|
+
collisionPadding,
|
|
54
|
+
matchTriggerWidth
|
|
55
|
+
});
|
|
56
|
+
const floating = useFloatingPosition({
|
|
57
|
+
open,
|
|
58
|
+
placement,
|
|
59
|
+
strategy: "absolute",
|
|
60
|
+
offset: contentPositioning.sideOffset,
|
|
61
|
+
collisionPadding: contentPositioning.collisionPadding,
|
|
62
|
+
matchReferenceWidth: contentPositioning.matchTriggerWidth
|
|
63
|
+
});
|
|
64
|
+
const getEnabledItems = React.useCallback(() => {
|
|
65
|
+
const ordered = itemOrder.current
|
|
66
|
+
.map((id) => itemRegistry.current.get(id))
|
|
67
|
+
.filter((item) => item !== undefined && item !== null)
|
|
68
|
+
.map((item, index) => {
|
|
69
|
+
const id = itemOrder.current[index] ?? "";
|
|
70
|
+
return {
|
|
71
|
+
id,
|
|
72
|
+
ref: item.ref,
|
|
73
|
+
disabled: item.disabled,
|
|
74
|
+
...(item.onSelect ? { onSelect: item.onSelect } : {})
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
return filterEnabledItems(ordered);
|
|
78
|
+
}, []);
|
|
79
|
+
const registerItem = React.useCallback((item) => {
|
|
80
|
+
if (!itemOrder.current.includes(item.id)) {
|
|
81
|
+
itemOrder.current.push(item.id);
|
|
82
|
+
}
|
|
83
|
+
itemRegistry.current.set(item.id, {
|
|
84
|
+
id: item.id,
|
|
85
|
+
ref: item.ref,
|
|
86
|
+
disabled: item.disabled,
|
|
87
|
+
...(item.onSelect ? { onSelect: item.onSelect } : {})
|
|
88
|
+
});
|
|
89
|
+
}, []);
|
|
90
|
+
const unregisterItem = React.useCallback((id) => {
|
|
91
|
+
itemRegistry.current.delete(id);
|
|
92
|
+
itemOrder.current = itemOrder.current.filter((itemId) => itemId !== id);
|
|
93
|
+
}, []);
|
|
94
|
+
React.useEffect(() => {
|
|
95
|
+
if (wasOpenRef.current && !open) {
|
|
96
|
+
triggerRef.current?.focus();
|
|
97
|
+
}
|
|
98
|
+
wasOpenRef.current = open;
|
|
99
|
+
}, [open]);
|
|
100
|
+
React.useLayoutEffect(() => {
|
|
101
|
+
if (open && triggerRef.current !== null) {
|
|
102
|
+
const focusFirstItem = () => {
|
|
103
|
+
const first = getEnabledItems()[0];
|
|
104
|
+
first?.ref?.focus();
|
|
105
|
+
};
|
|
106
|
+
queueMicrotask(focusFirstItem);
|
|
107
|
+
}
|
|
108
|
+
}, [open, getEnabledItems]);
|
|
109
|
+
return (_jsx(DropdownMenuContext.Provider, { value: {
|
|
110
|
+
contentId,
|
|
111
|
+
updateContentPositioning: setContentPositioning,
|
|
112
|
+
open,
|
|
113
|
+
setOpen,
|
|
114
|
+
triggerId,
|
|
115
|
+
triggerRef,
|
|
116
|
+
referenceRef: floating.referenceRef,
|
|
117
|
+
floatingRef: floating.floatingRef,
|
|
118
|
+
floatingStyle: floating.floatingStyle,
|
|
119
|
+
getEnabledItems,
|
|
120
|
+
registerItem,
|
|
121
|
+
unregisterItem,
|
|
122
|
+
...(container === undefined ? {} : { container })
|
|
123
|
+
}, children: _jsx("div", { ...props, className: cn("liano-dropdown-menu", className), "data-state": open ? "open" : "closed", children: children }) }));
|
|
124
|
+
}
|
|
125
|
+
function DropdownMenuTrigger({ className, disabled, onClick, ref, type = "button", ...props }) {
|
|
126
|
+
const { contentId, open, setOpen, triggerRef, triggerId, referenceRef, getEnabledItems } = useDropdownMenuContext("DropdownMenu.Trigger");
|
|
127
|
+
return (_jsx("button", { ...props, ref: composeRefs(ref, triggerRef, referenceRef), type: type, disabled: disabled, id: triggerId, role: "button", "aria-haspopup": "menu", "aria-expanded": open ? "true" : "false", "aria-controls": contentId, className: cn("liano-dropdown-menu__trigger", className), onClick: composeEventHandlers(onClick, () => {
|
|
128
|
+
if (disabled) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const nextOpen = !open;
|
|
132
|
+
setOpen(nextOpen);
|
|
133
|
+
if (!nextOpen) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
queueMicrotask(() => {
|
|
137
|
+
const first = getEnabledItems()[0];
|
|
138
|
+
first?.ref?.focus();
|
|
139
|
+
});
|
|
140
|
+
}) }));
|
|
141
|
+
}
|
|
142
|
+
function DropdownMenuContent({ children, className, forceMount = false, sideOffset = defaultContentPositioning.sideOffset, collisionPadding = defaultContentPositioning.collisionPadding, matchTriggerWidth = defaultContentPositioning.matchTriggerWidth, ref, onKeyDown, ...props }) {
|
|
143
|
+
const { container, contentId, open, setOpen, updateContentPositioning, triggerId, floatingRef, floatingStyle, getEnabledItems } = useDropdownMenuContext("DropdownMenu.Content");
|
|
144
|
+
const focusItem = React.useCallback((index, items) => {
|
|
145
|
+
if (items.length === 0) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const clampedIndex = ((index % items.length) + items.length) % items.length;
|
|
149
|
+
items[clampedIndex]?.ref?.focus();
|
|
150
|
+
}, []);
|
|
151
|
+
const findCurrentIndex = React.useCallback((items) => {
|
|
152
|
+
const activeElement = document.activeElement;
|
|
153
|
+
if (!(activeElement instanceof HTMLElement)) {
|
|
154
|
+
return -1;
|
|
155
|
+
}
|
|
156
|
+
return items.findIndex((item) => item.ref === activeElement);
|
|
157
|
+
}, []);
|
|
158
|
+
const moveFocus = React.useCallback((direction) => {
|
|
159
|
+
const enabledItems = getEnabledItems();
|
|
160
|
+
if (enabledItems.length === 0) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const current = findCurrentIndex(enabledItems);
|
|
164
|
+
if (direction === "next") {
|
|
165
|
+
focusItem(current + 1, enabledItems);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
focusItem(current - 1, enabledItems);
|
|
169
|
+
}, [focusItem, findCurrentIndex, getEnabledItems]);
|
|
170
|
+
const moveToBoundary = React.useCallback((isEnd) => {
|
|
171
|
+
const enabledItems = getEnabledItems();
|
|
172
|
+
if (enabledItems.length === 0) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (isEnd) {
|
|
176
|
+
enabledItems.at(-1)?.ref?.focus();
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
enabledItems[0]?.ref?.focus();
|
|
180
|
+
}, [getEnabledItems]);
|
|
181
|
+
React.useEffect(() => {
|
|
182
|
+
updateContentPositioning({
|
|
183
|
+
sideOffset,
|
|
184
|
+
collisionPadding,
|
|
185
|
+
matchTriggerWidth
|
|
186
|
+
});
|
|
187
|
+
return () => {
|
|
188
|
+
updateContentPositioning(defaultContentPositioning);
|
|
189
|
+
};
|
|
190
|
+
}, [collisionPadding, matchTriggerWidth, sideOffset, updateContentPositioning]);
|
|
191
|
+
if (!open && !forceMount) {
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
const content = (_jsx("div", { ...props, ref: (node) => {
|
|
195
|
+
floatingRef(node);
|
|
196
|
+
if (typeof ref === "function") {
|
|
197
|
+
ref(node);
|
|
198
|
+
}
|
|
199
|
+
else if (ref) {
|
|
200
|
+
ref.current = node;
|
|
201
|
+
}
|
|
202
|
+
}, id: contentId, role: "menu", "aria-labelledby": triggerId, className: cn("liano-dropdown-menu__content", className), style: floatingStyle, "data-state": open ? "open" : "closed", hidden: open ? undefined : true, onKeyDown: composeEventHandlers(onKeyDown, (event) => {
|
|
203
|
+
if (event.key === "ArrowDown") {
|
|
204
|
+
event.preventDefault();
|
|
205
|
+
moveFocus("next");
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (event.key === "ArrowUp") {
|
|
209
|
+
event.preventDefault();
|
|
210
|
+
moveFocus("prev");
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
if (event.key === "Home") {
|
|
214
|
+
event.preventDefault();
|
|
215
|
+
moveToBoundary(false);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
if (event.key === "End") {
|
|
219
|
+
event.preventDefault();
|
|
220
|
+
moveToBoundary(true);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
if (event.key === "Escape") {
|
|
224
|
+
setOpen(false);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
if (event.key === "Enter" || event.key === " " || event.key === "Space" || event.key === "Spacebar") {
|
|
228
|
+
event.preventDefault();
|
|
229
|
+
}
|
|
230
|
+
}), tabIndex: -1, children: children }));
|
|
231
|
+
if (!open) {
|
|
232
|
+
return (_jsx(Portal, { ...(container === undefined ? {} : { container }), children: content }));
|
|
233
|
+
}
|
|
234
|
+
return (_jsx(Portal, { ...(container === undefined ? {} : { container }), children: _jsx(DismissableLayer, { open: open, onDismiss: () => {
|
|
235
|
+
setOpen(false);
|
|
236
|
+
}, children: content }) }));
|
|
237
|
+
}
|
|
238
|
+
function DropdownMenuItem({ children, className, disabled, onClick, onSelect, onKeyDown, ref, ...props }) {
|
|
239
|
+
const context = useDropdownMenuContext("DropdownMenu.Item");
|
|
240
|
+
const itemRef = React.useRef(null);
|
|
241
|
+
const itemId = React.useId();
|
|
242
|
+
const isDisabled = disabled === true;
|
|
243
|
+
React.useLayoutEffect(() => {
|
|
244
|
+
const itemRecord = {
|
|
245
|
+
id: itemId,
|
|
246
|
+
ref: itemRef.current,
|
|
247
|
+
disabled: isDisabled,
|
|
248
|
+
...(onSelect ? { onSelect } : {})
|
|
249
|
+
};
|
|
250
|
+
context.registerItem(itemRecord);
|
|
251
|
+
return () => context.unregisterItem(itemId);
|
|
252
|
+
}, [context, isDisabled, itemId, onSelect]);
|
|
253
|
+
return (_jsx("button", { ...props, ref: (node) => {
|
|
254
|
+
itemRef.current = node;
|
|
255
|
+
if (typeof ref === "function") {
|
|
256
|
+
ref(node);
|
|
257
|
+
}
|
|
258
|
+
else if (ref) {
|
|
259
|
+
ref.current = node;
|
|
260
|
+
}
|
|
261
|
+
}, type: "button", role: "menuitem", disabled: isDisabled, "aria-disabled": isDisabled ? "true" : undefined, className: cn("liano-dropdown-menu__item", className), "data-state": isDisabled ? "disabled" : "enabled", onClick: composeEventHandlers(onClick, (event) => {
|
|
262
|
+
if (isDisabled) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
onSelect?.(event);
|
|
266
|
+
context.setOpen(false);
|
|
267
|
+
}), onKeyDown: composeEventHandlers(onKeyDown, (event) => {
|
|
268
|
+
if (event.key === " " || event.key === "Space" || event.key === "Enter" || event.key === "Spacebar") {
|
|
269
|
+
event.preventDefault();
|
|
270
|
+
if (isDisabled) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
onSelect?.(event);
|
|
274
|
+
context.setOpen(false);
|
|
275
|
+
}
|
|
276
|
+
}), children: children }));
|
|
277
|
+
}
|
|
278
|
+
function DropdownMenuSeparator({ className, ref, ...props }) {
|
|
279
|
+
return (_jsx("div", { ...props, ref: ref, role: "separator", "aria-hidden": "true", className: cn("liano-dropdown-menu__separator", className) }));
|
|
280
|
+
}
|
|
281
|
+
export const DropdownMenu = Object.assign(DropdownMenuRoot, {
|
|
282
|
+
Content: DropdownMenuContent,
|
|
283
|
+
Item: DropdownMenuItem,
|
|
284
|
+
Separator: DropdownMenuSeparator,
|
|
285
|
+
Trigger: DropdownMenuTrigger
|
|
286
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export type EmptyStateSize = "sm" | "md" | "lg";
|
|
3
|
+
export type EmptyStateAlign = "start" | "center";
|
|
4
|
+
export interface EmptyStateProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "title"> {
|
|
5
|
+
icon?: React.ReactNode;
|
|
6
|
+
title: React.ReactNode;
|
|
7
|
+
description?: React.ReactNode;
|
|
8
|
+
actions?: React.ReactNode;
|
|
9
|
+
size?: EmptyStateSize;
|
|
10
|
+
align?: EmptyStateAlign;
|
|
11
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
12
|
+
}
|
|
13
|
+
export declare function EmptyState({ actions, align, children: _children, className, description, icon, ref, size, title, ...props }: EmptyStateProps): React.JSX.Element;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { cn } from "../../utils/cn.js";
|
|
4
|
+
function hasRenderableNode(value) {
|
|
5
|
+
if (value === null || value === undefined || value === false) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "bigint") {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
if (React.isValidElement(value)) {
|
|
12
|
+
const props = value.props;
|
|
13
|
+
if (props["aria-hidden"] === true || props["aria-hidden"] === "true") {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
if (typeof props["aria-label"] === "string" && props["aria-label"].trim() !== "") {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
if (typeof props["aria-labelledby"] === "string" && props["aria-labelledby"].trim() !== "") {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
if (typeof props["title"] === "string" && props["title"].trim() !== "") {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
return React.Children.toArray(props.children).some(hasRenderableNode);
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
export function EmptyState({ actions, align = "center", children: _children, className, description, icon, ref, size = "md", title, ...props }) {
|
|
30
|
+
const hasIcon = hasRenderableNode(icon);
|
|
31
|
+
const showDescription = description !== null && description !== undefined;
|
|
32
|
+
const showActions = actions !== null && actions !== undefined;
|
|
33
|
+
return (_jsxs("div", { ...props, ref: ref, className: cn("liano-empty-state", className), "data-align": align, "data-size": size, children: [icon ? _jsx("div", { "aria-hidden": hasIcon ? undefined : true, className: "liano-empty-state__icon", children: icon }) : null, _jsx("h3", { className: "liano-empty-state__title", children: title }), showDescription ? _jsx("p", { className: "liano-empty-state__description", children: description }) : null, showActions ? _jsx("div", { className: "liano-empty-state__actions", children: actions }) : null] }));
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { EmptyState } from "./empty-state.js";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export interface ErrorBoundaryFallbackProps {
|
|
3
|
+
error: Error;
|
|
4
|
+
reset: () => void;
|
|
5
|
+
}
|
|
6
|
+
export interface ErrorBoundaryProps {
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
fallback?: React.ReactNode | ((props: ErrorBoundaryFallbackProps) => React.ReactNode);
|
|
9
|
+
onError?: (error: Error, info: React.ErrorInfo) => void;
|
|
10
|
+
resetKeys?: readonly unknown[];
|
|
11
|
+
}
|
|
12
|
+
export interface ErrorBoundaryState {
|
|
13
|
+
error: Error | null;
|
|
14
|
+
}
|
|
15
|
+
export interface ErrorFallbackProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "title"> {
|
|
16
|
+
title?: React.ReactNode;
|
|
17
|
+
error?: Error;
|
|
18
|
+
action?: React.ReactNode;
|
|
19
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
20
|
+
}
|
|
21
|
+
export declare class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
|
22
|
+
state: ErrorBoundaryState;
|
|
23
|
+
static getDerivedStateFromError(error: Error): ErrorBoundaryState;
|
|
24
|
+
componentDidCatch(error: Error, info: React.ErrorInfo): void;
|
|
25
|
+
componentDidUpdate(previousProps: ErrorBoundaryProps): void;
|
|
26
|
+
reset: () => void;
|
|
27
|
+
render(): string | number | bigint | boolean | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined> | React.JSX.Element | null | undefined;
|
|
28
|
+
}
|
|
29
|
+
export declare function ErrorFallback({ action, className, error, ref, title, ...props }: ErrorFallbackProps): React.JSX.Element;
|