@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,214 @@
|
|
|
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 { createCollection } from "../../internal/collection/index.js";
|
|
8
|
+
import { DismissableLayer } from "../../internal/dismissable-layer/index.js";
|
|
9
|
+
import { Portal } from "../../internal/portal/index.js";
|
|
10
|
+
const MenubarContext = React.createContext(null);
|
|
11
|
+
const MenuContext = React.createContext(null);
|
|
12
|
+
function useMenubarContext(calledBy) {
|
|
13
|
+
const context = React.useContext(MenubarContext);
|
|
14
|
+
if (context === null) {
|
|
15
|
+
throw new Error(`"${calledBy}" must be used inside a <Menubar />`);
|
|
16
|
+
}
|
|
17
|
+
return context;
|
|
18
|
+
}
|
|
19
|
+
function useMenuContext(calledBy) {
|
|
20
|
+
const context = React.useContext(MenuContext);
|
|
21
|
+
if (context === null) {
|
|
22
|
+
throw new Error(`"${calledBy}" must be used inside a <Menubar.Menu />`);
|
|
23
|
+
}
|
|
24
|
+
return context;
|
|
25
|
+
}
|
|
26
|
+
function textFromNode(node) {
|
|
27
|
+
if (typeof node === "string" || typeof node === "number") {
|
|
28
|
+
return String(node);
|
|
29
|
+
}
|
|
30
|
+
if (Array.isArray(node)) {
|
|
31
|
+
return node.map(textFromNode).join("");
|
|
32
|
+
}
|
|
33
|
+
return "";
|
|
34
|
+
}
|
|
35
|
+
function focusRecord(records, index) {
|
|
36
|
+
const enabled = records.filter((record) => record.data.disabled !== true && record.data.ref !== null);
|
|
37
|
+
if (enabled.length === 0) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const wrapped = ((index % enabled.length) + enabled.length) % enabled.length;
|
|
41
|
+
enabled[wrapped]?.data.ref?.focus();
|
|
42
|
+
}
|
|
43
|
+
function activeIndex(records) {
|
|
44
|
+
const enabled = records.filter((record) => record.data.disabled !== true && record.data.ref !== null);
|
|
45
|
+
return enabled.findIndex((record) => record.data.ref === document.activeElement);
|
|
46
|
+
}
|
|
47
|
+
function MenubarRoot({ children, className, defaultValue, onKeyDown, onValueChange, ref, value, ...props }) {
|
|
48
|
+
const [openValue, setOpenValue] = useControllableState({
|
|
49
|
+
...(value !== undefined ? { value } : {}),
|
|
50
|
+
defaultValue,
|
|
51
|
+
...(onValueChange ? { onChange: onValueChange } : {})
|
|
52
|
+
});
|
|
53
|
+
const triggerCollection = React.useRef(createCollection());
|
|
54
|
+
const registerTrigger = React.useCallback((id, item) => {
|
|
55
|
+
triggerCollection.current.register(id, item);
|
|
56
|
+
}, []);
|
|
57
|
+
const unregisterTrigger = React.useCallback((id) => {
|
|
58
|
+
triggerCollection.current.unregister(id);
|
|
59
|
+
}, []);
|
|
60
|
+
const getTriggers = React.useCallback(() => triggerCollection.current.items(), []);
|
|
61
|
+
const contextValue = React.useMemo(() => ({
|
|
62
|
+
getTriggers,
|
|
63
|
+
openValue,
|
|
64
|
+
registerTrigger,
|
|
65
|
+
setOpenValue,
|
|
66
|
+
unregisterTrigger
|
|
67
|
+
}), [getTriggers, openValue, registerTrigger, setOpenValue, unregisterTrigger]);
|
|
68
|
+
return (_jsx(MenubarContext.Provider, { value: contextValue, children: _jsx("div", { ...props, ref: ref, role: "menubar", className: cn("liano-menubar", className), onKeyDown: composeEventHandlers(onKeyDown, (event) => {
|
|
69
|
+
const triggers = getTriggers();
|
|
70
|
+
const index = activeIndex(triggers);
|
|
71
|
+
if (event.key === "ArrowRight") {
|
|
72
|
+
event.preventDefault();
|
|
73
|
+
focusRecord(triggers, index + 1);
|
|
74
|
+
}
|
|
75
|
+
if (event.key === "ArrowLeft") {
|
|
76
|
+
event.preventDefault();
|
|
77
|
+
focusRecord(triggers, index - 1);
|
|
78
|
+
}
|
|
79
|
+
}), children: children }) }));
|
|
80
|
+
}
|
|
81
|
+
function MenubarMenu({ children, value }) {
|
|
82
|
+
const menubar = useMenubarContext("Menubar.Menu");
|
|
83
|
+
const itemCollection = React.useRef(createCollection());
|
|
84
|
+
const [label, setLabel] = React.useState(value);
|
|
85
|
+
const generatedId = React.useId();
|
|
86
|
+
const triggerId = `${generatedId}-trigger`;
|
|
87
|
+
const contentId = `${generatedId}-content`;
|
|
88
|
+
const open = menubar.openValue === value;
|
|
89
|
+
const registerItem = React.useCallback((id, item) => {
|
|
90
|
+
itemCollection.current.register(id, item);
|
|
91
|
+
}, []);
|
|
92
|
+
const unregisterItem = React.useCallback((id) => {
|
|
93
|
+
itemCollection.current.unregister(id);
|
|
94
|
+
}, []);
|
|
95
|
+
const getItems = React.useCallback(() => itemCollection.current.items(), []);
|
|
96
|
+
const contextValue = React.useMemo(() => ({
|
|
97
|
+
contentId,
|
|
98
|
+
getItems,
|
|
99
|
+
label,
|
|
100
|
+
open,
|
|
101
|
+
registerItem,
|
|
102
|
+
setLabel,
|
|
103
|
+
triggerId,
|
|
104
|
+
value,
|
|
105
|
+
unregisterItem
|
|
106
|
+
}), [contentId, getItems, label, open, registerItem, triggerId, value, unregisterItem]);
|
|
107
|
+
React.useLayoutEffect(() => {
|
|
108
|
+
if (!open) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
focusRecord(getItems(), 0);
|
|
112
|
+
}, [getItems, open]);
|
|
113
|
+
return _jsx(MenuContext.Provider, { value: contextValue, children: children });
|
|
114
|
+
}
|
|
115
|
+
function MenubarTrigger({ children, className, disabled, onClick, onKeyDown, ref, type = "button", ...props }) {
|
|
116
|
+
const menubar = useMenubarContext("Menubar.Trigger");
|
|
117
|
+
const menu = useMenuContext("Menubar.Trigger");
|
|
118
|
+
const triggerRef = React.useRef(null);
|
|
119
|
+
const itemId = React.useId();
|
|
120
|
+
const label = textFromNode(children) || menu.value;
|
|
121
|
+
React.useLayoutEffect(() => {
|
|
122
|
+
menu.setLabel(label);
|
|
123
|
+
menubar.registerTrigger(itemId, { disabled, ref: triggerRef.current, value: menu.value });
|
|
124
|
+
return () => menubar.unregisterTrigger(itemId);
|
|
125
|
+
}, [disabled, itemId, label, menu, menubar]);
|
|
126
|
+
return (_jsx("button", { ...props, ref: (node) => {
|
|
127
|
+
triggerRef.current = node;
|
|
128
|
+
if (typeof ref === "function") {
|
|
129
|
+
ref(node);
|
|
130
|
+
}
|
|
131
|
+
else if (ref) {
|
|
132
|
+
ref.current = node;
|
|
133
|
+
}
|
|
134
|
+
}, id: menu.triggerId, type: type, role: "menuitem", disabled: disabled, "aria-controls": menu.contentId, "aria-expanded": menu.open ? "true" : "false", "aria-haspopup": "menu", className: cn("liano-menubar__trigger", className), "data-state": menu.open ? "open" : "closed", onClick: composeEventHandlers(onClick, () => {
|
|
135
|
+
if (!disabled) {
|
|
136
|
+
menubar.setOpenValue(menu.open ? undefined : menu.value);
|
|
137
|
+
}
|
|
138
|
+
}), onKeyDown: composeEventHandlers(onKeyDown, (event) => {
|
|
139
|
+
if (event.key === "ArrowDown" || event.key === "Enter" || event.key === " ") {
|
|
140
|
+
event.preventDefault();
|
|
141
|
+
menubar.setOpenValue(menu.value);
|
|
142
|
+
}
|
|
143
|
+
}), children: children }));
|
|
144
|
+
}
|
|
145
|
+
function MenubarContent({ children, className, onKeyDown, ref, ...props }) {
|
|
146
|
+
const menubar = useMenubarContext("Menubar.Content");
|
|
147
|
+
const menu = useMenuContext("Menubar.Content");
|
|
148
|
+
if (!menu.open) {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
return (_jsx(Portal, { children: _jsx(DismissableLayer, { open: menu.open, onDismiss: () => menubar.setOpenValue(undefined), children: _jsx("div", { ...props, ref: ref, id: menu.contentId, role: "menu", "aria-label": menu.label, "aria-labelledby": menu.triggerId, className: cn("liano-menubar__content", className), onKeyDown: composeEventHandlers(onKeyDown, (event) => {
|
|
152
|
+
const items = menu.getItems();
|
|
153
|
+
const index = activeIndex(items);
|
|
154
|
+
if (event.key === "ArrowDown") {
|
|
155
|
+
event.preventDefault();
|
|
156
|
+
focusRecord(items, index + 1);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (event.key === "ArrowUp") {
|
|
160
|
+
event.preventDefault();
|
|
161
|
+
focusRecord(items, index - 1);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (event.key === "Escape") {
|
|
165
|
+
menubar.setOpenValue(undefined);
|
|
166
|
+
}
|
|
167
|
+
}), children: children }) }) }));
|
|
168
|
+
}
|
|
169
|
+
function MenubarItem({ children, className, disabled, onClick, onKeyDown, onSelect, ref, type = "button", ...props }) {
|
|
170
|
+
const menubar = useMenubarContext("Menubar.Item");
|
|
171
|
+
const menu = useMenuContext("Menubar.Item");
|
|
172
|
+
const { getItems, open, registerItem, unregisterItem } = menu;
|
|
173
|
+
const itemId = React.useId();
|
|
174
|
+
const itemRef = React.useRef(null);
|
|
175
|
+
React.useLayoutEffect(() => {
|
|
176
|
+
registerItem(itemId, { disabled, ref: itemRef.current });
|
|
177
|
+
const firstEnabled = getItems().find((item) => item.data.disabled !== true && item.data.ref !== null);
|
|
178
|
+
if (open && firstEnabled?.id === itemId) {
|
|
179
|
+
itemRef.current?.focus();
|
|
180
|
+
}
|
|
181
|
+
return () => unregisterItem(itemId);
|
|
182
|
+
}, [disabled, getItems, itemId, open, registerItem, unregisterItem]);
|
|
183
|
+
const select = (event) => {
|
|
184
|
+
if (disabled) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
onSelect?.(event);
|
|
188
|
+
menubar.setOpenValue(undefined);
|
|
189
|
+
};
|
|
190
|
+
return (_jsx("button", { ...props, ref: (node) => {
|
|
191
|
+
itemRef.current = node;
|
|
192
|
+
if (typeof ref === "function") {
|
|
193
|
+
ref(node);
|
|
194
|
+
}
|
|
195
|
+
else if (ref) {
|
|
196
|
+
ref.current = node;
|
|
197
|
+
}
|
|
198
|
+
}, type: type, role: "menuitem", disabled: disabled, "aria-disabled": disabled ? "true" : undefined, className: cn("liano-menubar__item", className), "data-disabled": disabled ? "true" : undefined, onClick: composeEventHandlers(onClick, select), onKeyDown: composeEventHandlers(onKeyDown, (event) => {
|
|
199
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
200
|
+
event.preventDefault();
|
|
201
|
+
select(event);
|
|
202
|
+
}
|
|
203
|
+
}), children: children }));
|
|
204
|
+
}
|
|
205
|
+
function MenubarSeparator({ className, ref, ...props }) {
|
|
206
|
+
return _jsx("div", { ...props, ref: ref, role: "separator", "aria-hidden": "true", className: cn("liano-menubar__separator", className) });
|
|
207
|
+
}
|
|
208
|
+
export const Menubar = Object.assign(MenubarRoot, {
|
|
209
|
+
Content: MenubarContent,
|
|
210
|
+
Item: MenubarItem,
|
|
211
|
+
Menu: MenubarMenu,
|
|
212
|
+
Separator: MenubarSeparator,
|
|
213
|
+
Trigger: MenubarTrigger
|
|
214
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Pagination } from "./pagination.js";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export interface PaginationProps extends React.HTMLAttributes<HTMLElement> {
|
|
3
|
+
page: number;
|
|
4
|
+
pageCount: number;
|
|
5
|
+
onPageChange?: (page: number) => void;
|
|
6
|
+
getPageHref?: (page: number) => string;
|
|
7
|
+
siblingCount?: number;
|
|
8
|
+
boundaryCount?: number;
|
|
9
|
+
label?: string;
|
|
10
|
+
previousLabel?: React.ReactNode;
|
|
11
|
+
nextLabel?: React.ReactNode;
|
|
12
|
+
ref?: React.Ref<HTMLElement>;
|
|
13
|
+
}
|
|
14
|
+
export type PaginationRangeItem = number | "ellipsis-start" | "ellipsis-end";
|
|
15
|
+
export declare function getPaginationRange({ page, pageCount, siblingCount, boundaryCount }: {
|
|
16
|
+
page: number;
|
|
17
|
+
pageCount: number;
|
|
18
|
+
siblingCount?: number;
|
|
19
|
+
boundaryCount?: number;
|
|
20
|
+
}): PaginationRangeItem[];
|
|
21
|
+
export declare function Pagination({ className, label, onPageChange, getPageHref, page, pageCount, siblingCount, boundaryCount, previousLabel, nextLabel, ref, ...props }: PaginationProps): React.JSX.Element;
|
|
@@ -0,0 +1,92 @@
|
|
|
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
|
+
const clamp = (value) => (Number.isFinite(value) ? Math.floor(value) : 1);
|
|
5
|
+
const normalizeCount = (value, fallback) => {
|
|
6
|
+
const normalized = clamp(value ?? fallback);
|
|
7
|
+
return normalized < 0 ? 0 : normalized;
|
|
8
|
+
};
|
|
9
|
+
function createRange(start, end) {
|
|
10
|
+
if (end < start) {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
return Array.from({ length: end - start + 1 }, (_, index) => start + index);
|
|
14
|
+
}
|
|
15
|
+
export function getPaginationRange({ page, pageCount, siblingCount = 1, boundaryCount = 1 }) {
|
|
16
|
+
const safePageCount = Math.max(normalizeCount(pageCount, 0), 0);
|
|
17
|
+
if (safePageCount === 0) {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
const safePage = Math.max(1, Math.min(clamp(page), safePageCount));
|
|
21
|
+
const safeSiblingCount = Math.max(0, normalizeCount(siblingCount, 1));
|
|
22
|
+
const safeBoundaryCount = Math.max(0, normalizeCount(boundaryCount, 1));
|
|
23
|
+
const leftBoundaryRange = createRange(1, Math.min(safeBoundaryCount, safePageCount));
|
|
24
|
+
const rightBoundaryStart = Math.max(safePageCount - safeBoundaryCount + 1, safeBoundaryCount + 1);
|
|
25
|
+
const rightBoundaryRange = createRange(rightBoundaryStart, safePageCount);
|
|
26
|
+
const middleStart = Math.max(safePage - safeSiblingCount, 1);
|
|
27
|
+
const middleEnd = Math.min(safePage + safeSiblingCount, safePageCount);
|
|
28
|
+
const middleRange = createRange(middleStart, middleEnd);
|
|
29
|
+
const merged = [...leftBoundaryRange, ...middleRange, ...rightBoundaryRange]
|
|
30
|
+
.filter((value, index, values) => values.indexOf(value) === index)
|
|
31
|
+
.sort((a, b) => a - b);
|
|
32
|
+
const range = [];
|
|
33
|
+
merged.forEach((value, index) => {
|
|
34
|
+
const previous = index === 0 ? undefined : merged[index - 1];
|
|
35
|
+
if (previous === undefined) {
|
|
36
|
+
range.push(value);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (value - previous === 1) {
|
|
40
|
+
range.push(value);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
range.push(previous < safePage ? "ellipsis-start" : "ellipsis-end");
|
|
44
|
+
range.push(value);
|
|
45
|
+
});
|
|
46
|
+
return range;
|
|
47
|
+
}
|
|
48
|
+
function renderPrevious({ hasHrefMode, page, label, pageCount, onPageChange, getPageHref }) {
|
|
49
|
+
const targetPage = page - 1;
|
|
50
|
+
if (hasHrefMode && targetPage >= 1) {
|
|
51
|
+
return (_jsx("a", { className: "liano-pagination__item", href: getPageHref?.(targetPage), children: label }));
|
|
52
|
+
}
|
|
53
|
+
if (hasHrefMode && targetPage < 1) {
|
|
54
|
+
return (_jsx("span", { className: "liano-pagination__item liano-pagination__item--disabled", "aria-hidden": "true", children: label }));
|
|
55
|
+
}
|
|
56
|
+
return (_jsx("button", { className: "liano-pagination__item", disabled: targetPage < 1, onClick: () => onPageChange?.(Math.max(1, targetPage)), type: "button", children: label }));
|
|
57
|
+
}
|
|
58
|
+
function renderNext({ hasHrefMode, page, label, pageCount, onPageChange, getPageHref }) {
|
|
59
|
+
const targetPage = page + 1;
|
|
60
|
+
if (hasHrefMode && targetPage <= pageCount) {
|
|
61
|
+
return (_jsx("a", { className: "liano-pagination__item", href: getPageHref?.(targetPage), children: label }));
|
|
62
|
+
}
|
|
63
|
+
if (hasHrefMode && targetPage > pageCount) {
|
|
64
|
+
return (_jsx("span", { className: "liano-pagination__item liano-pagination__item--disabled", "aria-hidden": "true", children: label }));
|
|
65
|
+
}
|
|
66
|
+
return (_jsx("button", { className: "liano-pagination__item", disabled: targetPage > pageCount, onClick: () => onPageChange?.(Math.min(pageCount, targetPage)), type: "button", children: label }));
|
|
67
|
+
}
|
|
68
|
+
function renderPageItem({ hasHrefMode, item, page, onPageChange, getPageHref }) {
|
|
69
|
+
if (item === page) {
|
|
70
|
+
if (hasHrefMode) {
|
|
71
|
+
return (_jsx("a", { "aria-current": "page", className: "liano-pagination__item liano-pagination__item--current", href: getPageHref?.(item), children: item }));
|
|
72
|
+
}
|
|
73
|
+
return (_jsx("button", { "aria-current": "page", className: "liano-pagination__item liano-pagination__item--current", disabled: true, type: "button", children: item }));
|
|
74
|
+
}
|
|
75
|
+
if (hasHrefMode) {
|
|
76
|
+
return (_jsx("a", { className: "liano-pagination__item", href: getPageHref?.(item), children: item }));
|
|
77
|
+
}
|
|
78
|
+
return (_jsx("button", { className: "liano-pagination__item", onClick: () => onPageChange?.(item), type: "button", children: item }));
|
|
79
|
+
}
|
|
80
|
+
export function Pagination({ className, label = "Pagination", onPageChange, getPageHref, page, pageCount, siblingCount = 1, boundaryCount = 1, previousLabel = "Previous", nextLabel = "Next", ref, ...props }) {
|
|
81
|
+
const safePageCount = Math.max(normalizeCount(pageCount, 1), 0);
|
|
82
|
+
const safePage = Math.max(1, Math.min(clamp(page), safePageCount || 1));
|
|
83
|
+
const range = getPaginationRange({ page, pageCount, siblingCount, boundaryCount });
|
|
84
|
+
const isLinkMode = typeof getPageHref === "function";
|
|
85
|
+
return (_jsx("nav", { ...props, ref: ref, "aria-label": props["aria-label"] ?? label, className: cn("liano-pagination", className), children: _jsxs("ol", { className: "liano-pagination__list", children: [_jsx("li", { children: renderPrevious({ hasHrefMode: isLinkMode, label: previousLabel, onPageChange, page: safePage, pageCount: safePageCount, getPageHref }) }), range.map((item) => (_jsx("li", { children: typeof item === "number" ? (renderPageItem({
|
|
86
|
+
getPageHref,
|
|
87
|
+
hasHrefMode: isLinkMode,
|
|
88
|
+
item,
|
|
89
|
+
onPageChange,
|
|
90
|
+
page: safePage
|
|
91
|
+
})) : (_jsx("span", { "aria-hidden": "true", className: "liano-pagination__ellipsis", children: "\u2026" })) }, `${item}-${typeof item === "number" ? item : item}`))), _jsx("li", { children: renderNext({ hasHrefMode: isLinkMode, label: nextLabel, onPageChange, page: safePage, pageCount: safePageCount, getPageHref }) })] }) }));
|
|
92
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { FloatingPlacement } from "../../internal/floating/floating-types.js";
|
|
3
|
+
export interface PopoverProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
4
|
+
open?: boolean;
|
|
5
|
+
defaultOpen?: boolean;
|
|
6
|
+
onOpenChange?: (open: boolean) => void;
|
|
7
|
+
placement?: FloatingPlacement;
|
|
8
|
+
modal?: false;
|
|
9
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
10
|
+
}
|
|
11
|
+
export interface PopoverTriggerProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
12
|
+
ref?: React.Ref<HTMLButtonElement>;
|
|
13
|
+
}
|
|
14
|
+
export interface PopoverContentProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
15
|
+
sideOffset?: number;
|
|
16
|
+
collisionPadding?: number;
|
|
17
|
+
matchTriggerWidth?: boolean;
|
|
18
|
+
forceMount?: boolean;
|
|
19
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
20
|
+
}
|
|
21
|
+
declare function PopoverRoot({ children, className, defaultOpen, modal, onOpenChange, open, placement, ref, ...props }: PopoverProps): React.JSX.Element;
|
|
22
|
+
declare function PopoverTrigger({ className, onClick, ref, type, ...props }: PopoverTriggerProps): React.JSX.Element;
|
|
23
|
+
declare function PopoverContent({ className, forceMount, id, ref, sideOffset, collisionPadding, matchTriggerWidth, style, ...props }: PopoverContentProps): React.JSX.Element | null;
|
|
24
|
+
export declare const Popover: typeof PopoverRoot & {
|
|
25
|
+
Trigger: typeof PopoverTrigger;
|
|
26
|
+
Content: typeof PopoverContent;
|
|
27
|
+
};
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,164 @@
|
|
|
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 { useDisclosure } from "../../hooks/use-disclosure.js";
|
|
6
|
+
import { cn } from "../../utils/cn.js";
|
|
7
|
+
import { Portal } from "../../internal/portal/index.js";
|
|
8
|
+
import { DismissableLayer } from "../../internal/dismissable-layer/index.js";
|
|
9
|
+
import { useFloatingPosition } from "../../internal/floating/index.js";
|
|
10
|
+
const defaultPositioning = {
|
|
11
|
+
sideOffset: 0,
|
|
12
|
+
collisionPadding: 0,
|
|
13
|
+
matchTriggerWidth: false
|
|
14
|
+
};
|
|
15
|
+
const PopoverContext = React.createContext(null);
|
|
16
|
+
function usePopoverContext(calledBy) {
|
|
17
|
+
const context = React.useContext(PopoverContext);
|
|
18
|
+
if (!context) {
|
|
19
|
+
throw new Error(`"${calledBy}" must be used within a <Popover />`);
|
|
20
|
+
}
|
|
21
|
+
return context;
|
|
22
|
+
}
|
|
23
|
+
function mergeRef(ref, node) {
|
|
24
|
+
if (typeof ref === "function") {
|
|
25
|
+
ref(node);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (ref && "current" in ref) {
|
|
29
|
+
ref.current = node;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function getTransformOrigin(placement) {
|
|
33
|
+
const [side, align = "center"] = placement.split("-");
|
|
34
|
+
const anchor = side === "top" ? "bottom" : side === "bottom" ? "top" : side === "left" ? "right" : "left";
|
|
35
|
+
if (side === "top" || side === "bottom") {
|
|
36
|
+
if (align === "start") {
|
|
37
|
+
return `${anchor} left`;
|
|
38
|
+
}
|
|
39
|
+
if (align === "end") {
|
|
40
|
+
return `${anchor} right`;
|
|
41
|
+
}
|
|
42
|
+
return `${anchor} center`;
|
|
43
|
+
}
|
|
44
|
+
if (align === "start") {
|
|
45
|
+
return `${anchor} top`;
|
|
46
|
+
}
|
|
47
|
+
if (align === "end") {
|
|
48
|
+
return `${anchor} bottom`;
|
|
49
|
+
}
|
|
50
|
+
return `${anchor} center`;
|
|
51
|
+
}
|
|
52
|
+
function getPlacementParts(placement) {
|
|
53
|
+
const [side, align = "center"] = placement.split("-");
|
|
54
|
+
return { side, align };
|
|
55
|
+
}
|
|
56
|
+
function PopoverRoot({ children, className, defaultOpen = false, modal = false, onOpenChange, open, placement = "bottom", ref, ...props }) {
|
|
57
|
+
const defaultContentId = `${React.useId()}-content`;
|
|
58
|
+
const [contentId, setContentId] = React.useState(defaultContentId);
|
|
59
|
+
const [contentPositioning, setContentPositioning] = React.useState(defaultPositioning);
|
|
60
|
+
const updateContentPositioning = React.useCallback((positioning) => {
|
|
61
|
+
setContentPositioning(positioning);
|
|
62
|
+
}, []);
|
|
63
|
+
const { open: isOpen, setOpen } = useDisclosure({
|
|
64
|
+
...(open !== undefined ? { open } : {}),
|
|
65
|
+
defaultOpen,
|
|
66
|
+
...(onOpenChange ? { onOpenChange } : {})
|
|
67
|
+
});
|
|
68
|
+
const referenceElement = React.useRef(null);
|
|
69
|
+
const { floatingStyle, floatingRef, referenceRef, placement: resolvedPlacement, updatePosition } = useFloatingPosition({
|
|
70
|
+
open: isOpen,
|
|
71
|
+
placement,
|
|
72
|
+
offset: contentPositioning.sideOffset,
|
|
73
|
+
collisionPadding: contentPositioning.collisionPadding,
|
|
74
|
+
matchReferenceWidth: contentPositioning.matchTriggerWidth
|
|
75
|
+
});
|
|
76
|
+
const handleRef = React.useCallback((node) => {
|
|
77
|
+
mergeRef(ref, node);
|
|
78
|
+
}, [ref]);
|
|
79
|
+
const setReferenceRef = React.useCallback((node) => {
|
|
80
|
+
referenceElement.current = node;
|
|
81
|
+
referenceRef(node);
|
|
82
|
+
}, [referenceRef]);
|
|
83
|
+
return (_jsx(PopoverContext.Provider, { value: {
|
|
84
|
+
contentId,
|
|
85
|
+
defaultContentId,
|
|
86
|
+
placement: resolvedPlacement,
|
|
87
|
+
modal,
|
|
88
|
+
open: isOpen,
|
|
89
|
+
setContentId,
|
|
90
|
+
setOpen,
|
|
91
|
+
referenceRef: setReferenceRef,
|
|
92
|
+
referenceElement,
|
|
93
|
+
floatingRef,
|
|
94
|
+
floatingStyle,
|
|
95
|
+
floatingPlacement: resolvedPlacement,
|
|
96
|
+
updatePosition,
|
|
97
|
+
updateContentPositioning
|
|
98
|
+
}, children: _jsx("div", { ...props, ref: handleRef, className: cn("liano-popover", className), "data-state": isOpen ? "open" : "closed", children: children }) }));
|
|
99
|
+
}
|
|
100
|
+
function PopoverTrigger({ className, onClick, ref, type = "button", ...props }) {
|
|
101
|
+
const context = usePopoverContext("Popover.Trigger");
|
|
102
|
+
const handleClick = () => {
|
|
103
|
+
context.setOpen((value) => !value);
|
|
104
|
+
};
|
|
105
|
+
const handleRef = React.useCallback((node) => {
|
|
106
|
+
context.referenceRef(node);
|
|
107
|
+
mergeRef(ref, node);
|
|
108
|
+
}, [context.referenceRef, ref]);
|
|
109
|
+
return (_jsx("button", { ...props, ref: handleRef, type: type, className: cn("liano-popover__trigger", className), "aria-expanded": context.open, "aria-controls": context.contentId, "aria-haspopup": "dialog", "data-state": context.open ? "open" : "closed", onClick: composeEventHandlers(onClick, handleClick) }));
|
|
110
|
+
}
|
|
111
|
+
function PopoverContent({ className, forceMount = false, id, ref, sideOffset = 0, collisionPadding = 0, matchTriggerWidth = false, style, ...props }) {
|
|
112
|
+
const context = usePopoverContext("Popover.Content");
|
|
113
|
+
const { defaultContentId, setContentId } = context;
|
|
114
|
+
const transformOrigin = getTransformOrigin(context.floatingPlacement);
|
|
115
|
+
const placementParts = getPlacementParts(context.floatingPlacement);
|
|
116
|
+
const contentId = id ?? defaultContentId;
|
|
117
|
+
const handleRef = React.useCallback((node) => {
|
|
118
|
+
context.floatingRef(node);
|
|
119
|
+
mergeRef(ref, node);
|
|
120
|
+
}, [context.floatingRef, ref]);
|
|
121
|
+
const contentStyle = React.useMemo(() => ({
|
|
122
|
+
...context.floatingStyle,
|
|
123
|
+
...style,
|
|
124
|
+
"--liano-popover-transform-origin": transformOrigin
|
|
125
|
+
}), [context.floatingStyle, style, transformOrigin]);
|
|
126
|
+
React.useLayoutEffect(() => {
|
|
127
|
+
setContentId(contentId);
|
|
128
|
+
return () => {
|
|
129
|
+
setContentId(defaultContentId);
|
|
130
|
+
};
|
|
131
|
+
}, [contentId, defaultContentId, setContentId]);
|
|
132
|
+
const close = () => {
|
|
133
|
+
context.setOpen(false);
|
|
134
|
+
};
|
|
135
|
+
const ignoreTriggerPointerDown = React.useCallback((event) => {
|
|
136
|
+
const pointerEvent = event.detail;
|
|
137
|
+
const target = pointerEvent?.target;
|
|
138
|
+
if (target && context.referenceElement.current?.contains(target)) {
|
|
139
|
+
event.preventDefault();
|
|
140
|
+
}
|
|
141
|
+
}, [context.referenceElement]);
|
|
142
|
+
React.useEffect(() => {
|
|
143
|
+
context.updateContentPositioning({
|
|
144
|
+
sideOffset,
|
|
145
|
+
collisionPadding,
|
|
146
|
+
matchTriggerWidth
|
|
147
|
+
});
|
|
148
|
+
return () => {
|
|
149
|
+
context.updateContentPositioning(defaultPositioning);
|
|
150
|
+
};
|
|
151
|
+
}, [context.updateContentPositioning, collisionPadding, matchTriggerWidth, sideOffset]);
|
|
152
|
+
if (!forceMount && !context.open) {
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
const content = (_jsx("div", { ...props, ref: handleRef, id: contentId, role: "dialog", className: cn("liano-popover__content", className), "data-align": placementParts.align, "data-side": placementParts.side, "data-state": context.open ? "open" : "closed", hidden: context.open ? undefined : true, style: contentStyle }));
|
|
156
|
+
if (!context.open) {
|
|
157
|
+
return _jsx(Portal, { children: content });
|
|
158
|
+
}
|
|
159
|
+
return (_jsx(Portal, { children: _jsx(DismissableLayer, { open: true, onDismiss: close, modal: context.modal, onPointerDownOutside: ignoreTriggerPointerDown, children: content }) }));
|
|
160
|
+
}
|
|
161
|
+
export const Popover = Object.assign(PopoverRoot, {
|
|
162
|
+
Trigger: PopoverTrigger,
|
|
163
|
+
Content: PopoverContent
|
|
164
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Progress, getProgressState } from "./progress.js";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export type ProgressSize = "sm" | "md";
|
|
3
|
+
export type ProgressTone = "primary" | "success" | "warning" | "destructive" | "neutral";
|
|
4
|
+
export interface ProgressProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
5
|
+
value?: number;
|
|
6
|
+
max?: number;
|
|
7
|
+
label?: React.ReactNode;
|
|
8
|
+
showValue?: boolean;
|
|
9
|
+
size?: ProgressSize;
|
|
10
|
+
tone?: ProgressTone;
|
|
11
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
12
|
+
}
|
|
13
|
+
export interface ProgressState {
|
|
14
|
+
indeterminate: boolean;
|
|
15
|
+
max: number;
|
|
16
|
+
percentage: number | undefined;
|
|
17
|
+
value: number | undefined;
|
|
18
|
+
}
|
|
19
|
+
export interface ProgressStateInput {
|
|
20
|
+
max?: number | undefined;
|
|
21
|
+
value?: number | undefined;
|
|
22
|
+
}
|
|
23
|
+
export declare function getProgressState({ max, value }: ProgressStateInput): ProgressState;
|
|
24
|
+
export declare function Progress({ "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, className, label, max, ref, showValue, size, tone, value, ...props }: ProgressProps): React.JSX.Element;
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
export function getProgressState({ max = 100, value }) {
|
|
5
|
+
const normalizedMax = Number.isFinite(max) && max > 0 ? max : 1;
|
|
6
|
+
if (value === undefined || !Number.isFinite(value)) {
|
|
7
|
+
return {
|
|
8
|
+
indeterminate: true,
|
|
9
|
+
max: normalizedMax,
|
|
10
|
+
percentage: undefined,
|
|
11
|
+
value: undefined
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
const normalizedValue = Math.min(Math.max(value, 0), normalizedMax);
|
|
15
|
+
return {
|
|
16
|
+
indeterminate: false,
|
|
17
|
+
max: normalizedMax,
|
|
18
|
+
percentage: (normalizedValue / normalizedMax) * 100,
|
|
19
|
+
value: normalizedValue
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export function Progress({ "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, className, label, max, ref, showValue, size = "md", tone = "primary", value, ...props }) {
|
|
23
|
+
const state = getProgressState({ max, value });
|
|
24
|
+
const valueText = state.percentage === undefined ? undefined : `${Math.round(state.percentage)}%`;
|
|
25
|
+
return (_jsxs("div", { className: "liano-progress-group", children: [label ? _jsx("span", { className: "liano-progress__label", children: label }) : null, _jsx("div", { ...props, ref: ref, "aria-label": ariaLabel ?? (typeof label === "string" ? label : undefined), "aria-labelledby": ariaLabelledBy, "aria-valuemax": state.indeterminate ? undefined : state.max, "aria-valuemin": state.indeterminate ? undefined : 0, "aria-valuenow": state.value, className: cn("liano-progress", className), "data-indeterminate": state.indeterminate ? "true" : undefined, "data-size": size, "data-tone": tone, role: "progressbar", style: {
|
|
26
|
+
...props.style,
|
|
27
|
+
"--liano-progress-value": state.percentage === undefined ? undefined : `${state.percentage}%`
|
|
28
|
+
}, children: _jsx("span", { className: "liano-progress__track", children: _jsx("span", { className: "liano-progress__indicator" }) }) }), showValue && valueText ? _jsx("span", { className: "liano-progress__value", children: valueText }) : null] }));
|
|
29
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export type RadioGroupOrientation = "vertical" | "horizontal";
|
|
3
|
+
export type RadioGroupSize = "sm" | "md" | "lg";
|
|
4
|
+
export interface RadioGroupOption {
|
|
5
|
+
value: string;
|
|
6
|
+
label: React.ReactNode;
|
|
7
|
+
description?: React.ReactNode;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
}
|
|
10
|
+
interface RadioGroupBaseProps extends Omit<React.FieldsetHTMLAttributes<HTMLFieldSetElement>, "onChange"> {
|
|
11
|
+
label: React.ReactNode;
|
|
12
|
+
description?: React.ReactNode;
|
|
13
|
+
error?: React.ReactNode;
|
|
14
|
+
name: string;
|
|
15
|
+
value?: string;
|
|
16
|
+
defaultValue?: string;
|
|
17
|
+
onValueChange?: (value: string, event: React.ChangeEvent<HTMLInputElement>) => void;
|
|
18
|
+
invalid?: boolean;
|
|
19
|
+
orientation?: RadioGroupOrientation;
|
|
20
|
+
required?: boolean;
|
|
21
|
+
size?: RadioGroupSize;
|
|
22
|
+
ref?: React.Ref<HTMLFieldSetElement>;
|
|
23
|
+
}
|
|
24
|
+
export type RadioGroupProps = RadioGroupBaseProps & ({
|
|
25
|
+
options: readonly RadioGroupOption[];
|
|
26
|
+
children?: React.ReactNode;
|
|
27
|
+
} | {
|
|
28
|
+
options?: undefined;
|
|
29
|
+
children: React.ReactNode;
|
|
30
|
+
});
|
|
31
|
+
export interface RadioGroupItemProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "type" | "name" | "onChange"> {
|
|
32
|
+
value: string;
|
|
33
|
+
label?: React.ReactNode;
|
|
34
|
+
description?: React.ReactNode;
|
|
35
|
+
ref?: React.Ref<HTMLInputElement>;
|
|
36
|
+
}
|
|
37
|
+
export declare function RadioGroupItem({ disabled, value, ...props }: RadioGroupItemProps): React.JSX.Element;
|
|
38
|
+
declare function RadioGroupRoot({ "aria-describedby": ariaDescribedBy, children, className, description, disabled, error, id, invalid, label, name, onValueChange, options, orientation, ref, required, size, value, defaultValue, ...props }: RadioGroupProps): React.JSX.Element;
|
|
39
|
+
export declare const RadioGroup: typeof RadioGroupRoot & {
|
|
40
|
+
Item: typeof RadioGroupItem;
|
|
41
|
+
};
|
|
42
|
+
export {};
|