@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,233 @@
|
|
|
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 { useControllableState } from "../../hooks/use-controllable-state.js";
|
|
6
|
+
import { cn } from "../../utils/cn.js";
|
|
7
|
+
const TabsRootContext = React.createContext(null);
|
|
8
|
+
const TabsTriggerContext = React.createContext(null);
|
|
9
|
+
function useTabsContext(calledBy) {
|
|
10
|
+
const context = React.useContext(TabsRootContext);
|
|
11
|
+
if (!context) {
|
|
12
|
+
throw new Error(`"${calledBy}" must be used within <Tabs />`);
|
|
13
|
+
}
|
|
14
|
+
return context;
|
|
15
|
+
}
|
|
16
|
+
function useTabsTriggerContext(calledBy) {
|
|
17
|
+
const context = React.useContext(TabsTriggerContext);
|
|
18
|
+
if (!context) {
|
|
19
|
+
throw new Error(`"${calledBy}" must be used within <Tabs.Trigger />`);
|
|
20
|
+
}
|
|
21
|
+
return context;
|
|
22
|
+
}
|
|
23
|
+
function getSafeValueId(value) {
|
|
24
|
+
return value.replace(/[^a-zA-Z0-9._:-]/g, "-");
|
|
25
|
+
}
|
|
26
|
+
function getNextEnabledTabIndex(currentIndex, direction, triggers) {
|
|
27
|
+
if (triggers.length === 0) {
|
|
28
|
+
return -1;
|
|
29
|
+
}
|
|
30
|
+
for (let step = 1; step <= triggers.length; step += 1) {
|
|
31
|
+
const nextIndex = (currentIndex + step * direction + triggers.length) % triggers.length;
|
|
32
|
+
if (!triggers[nextIndex]?.disabled) {
|
|
33
|
+
return nextIndex;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return currentIndex;
|
|
37
|
+
}
|
|
38
|
+
function getFirstEnabledTabIndex(triggers) {
|
|
39
|
+
return triggers.findIndex((trigger) => !trigger.disabled);
|
|
40
|
+
}
|
|
41
|
+
function getLastEnabledTabIndex(triggers) {
|
|
42
|
+
for (let index = triggers.length - 1; index >= 0; index -= 1) {
|
|
43
|
+
if (!triggers[index]?.disabled) {
|
|
44
|
+
return index;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return -1;
|
|
48
|
+
}
|
|
49
|
+
function TabsRoot({ children, className, defaultValue = "", disabled = false, ref, activationMode = "automatic", onValueChange, orientation = "horizontal", value, ...props }) {
|
|
50
|
+
const [currentValue, setCurrentValue] = useControllableState({
|
|
51
|
+
...(value !== undefined ? { value } : {}),
|
|
52
|
+
defaultValue,
|
|
53
|
+
...(onValueChange ? { onChange: onValueChange } : {})
|
|
54
|
+
});
|
|
55
|
+
const triggerRegistry = React.useRef(new Map());
|
|
56
|
+
const triggerOrder = React.useRef([]);
|
|
57
|
+
const valueMetadata = React.useRef(new Map());
|
|
58
|
+
const [contentIdOverrides, setContentIdOverrides] = React.useState(() => new Map());
|
|
59
|
+
const instanceId = React.useId();
|
|
60
|
+
const getMetadata = React.useCallback((tabValue) => {
|
|
61
|
+
const existing = valueMetadata.current.get(tabValue);
|
|
62
|
+
if (existing) {
|
|
63
|
+
return existing;
|
|
64
|
+
}
|
|
65
|
+
const safeValue = getSafeValueId(tabValue);
|
|
66
|
+
const metadata = {
|
|
67
|
+
triggerId: `${instanceId}-trigger-${safeValue}`,
|
|
68
|
+
contentId: `${instanceId}-content-${safeValue}`
|
|
69
|
+
};
|
|
70
|
+
valueMetadata.current.set(tabValue, metadata);
|
|
71
|
+
return metadata;
|
|
72
|
+
}, [instanceId]);
|
|
73
|
+
const setContentIdForValue = React.useCallback((tabValue, id) => {
|
|
74
|
+
setContentIdOverrides((current) => {
|
|
75
|
+
if (current.get(tabValue) === id) {
|
|
76
|
+
return current;
|
|
77
|
+
}
|
|
78
|
+
const next = new Map(current);
|
|
79
|
+
next.set(tabValue, id);
|
|
80
|
+
return next;
|
|
81
|
+
});
|
|
82
|
+
}, []);
|
|
83
|
+
const resetContentIdForValue = React.useCallback((tabValue, id) => {
|
|
84
|
+
setContentIdOverrides((current) => {
|
|
85
|
+
if (current.get(tabValue) !== id) {
|
|
86
|
+
return current;
|
|
87
|
+
}
|
|
88
|
+
const next = new Map(current);
|
|
89
|
+
next.delete(tabValue);
|
|
90
|
+
return next;
|
|
91
|
+
});
|
|
92
|
+
}, []);
|
|
93
|
+
const registerTrigger = React.useCallback((triggerValue, triggerRef, isDisabled) => {
|
|
94
|
+
if (!triggerRegistry.current.has(triggerValue)) {
|
|
95
|
+
triggerOrder.current.push(triggerValue);
|
|
96
|
+
}
|
|
97
|
+
triggerRegistry.current.set(triggerValue, {
|
|
98
|
+
ref: triggerRef,
|
|
99
|
+
disabled: isDisabled
|
|
100
|
+
});
|
|
101
|
+
getMetadata(triggerValue);
|
|
102
|
+
}, [getMetadata]);
|
|
103
|
+
const unregisterTrigger = React.useCallback((triggerValue) => {
|
|
104
|
+
triggerRegistry.current.delete(triggerValue);
|
|
105
|
+
triggerOrder.current = triggerOrder.current.filter((registeredValue) => registeredValue !== triggerValue);
|
|
106
|
+
}, []);
|
|
107
|
+
const getOrderedTriggers = React.useCallback(() => triggerOrder.current
|
|
108
|
+
.map((registeredValue) => ({
|
|
109
|
+
value: registeredValue,
|
|
110
|
+
...triggerRegistry.current.get(registeredValue)
|
|
111
|
+
}))
|
|
112
|
+
.filter((trigger) => Boolean(trigger.ref) && trigger.ref !== null), []);
|
|
113
|
+
return (_jsx(TabsRootContext.Provider, { value: {
|
|
114
|
+
activationMode,
|
|
115
|
+
disabled,
|
|
116
|
+
getOrderedTriggers,
|
|
117
|
+
getContentIdForValue(tabValue) {
|
|
118
|
+
return contentIdOverrides.get(tabValue) ?? getMetadata(tabValue).contentId;
|
|
119
|
+
},
|
|
120
|
+
getTriggerIdForValue(tabValue) {
|
|
121
|
+
return getMetadata(tabValue).triggerId;
|
|
122
|
+
},
|
|
123
|
+
orientation,
|
|
124
|
+
registerTrigger,
|
|
125
|
+
resetContentIdForValue,
|
|
126
|
+
setContentIdForValue,
|
|
127
|
+
setValue: setCurrentValue,
|
|
128
|
+
unregisterTrigger,
|
|
129
|
+
value: currentValue
|
|
130
|
+
}, children: _jsx("div", { ...props, ref: ref, className: cn("liano-tabs", className), "data-orientation": orientation, "data-state": activationMode, "data-disabled": disabled ? "true" : undefined, children: children }) }));
|
|
131
|
+
}
|
|
132
|
+
function TabsList({ className, ref, ...props }) {
|
|
133
|
+
const context = useTabsContext("Tabs.List");
|
|
134
|
+
return (_jsx("div", { ...props, ref: ref, role: "tablist", className: cn("liano-tabs__list", className), "aria-orientation": context.orientation === "vertical" ? "vertical" : "horizontal" }));
|
|
135
|
+
}
|
|
136
|
+
function TabsTrigger({ className, onClick, onKeyDown, ref, value, ...props }) {
|
|
137
|
+
const context = useTabsContext("Tabs.Trigger");
|
|
138
|
+
const triggerRef = React.useRef(null);
|
|
139
|
+
const triggerContext = React.useMemo(() => ({ value }), [value]);
|
|
140
|
+
const triggerId = context.getTriggerIdForValue(value);
|
|
141
|
+
const contentId = context.getContentIdForValue(value);
|
|
142
|
+
const isSelected = context.value === value;
|
|
143
|
+
const isDisabled = context.disabled || props.disabled === true;
|
|
144
|
+
React.useLayoutEffect(() => {
|
|
145
|
+
context.registerTrigger(value, triggerRef.current, isDisabled);
|
|
146
|
+
return () => context.unregisterTrigger(value);
|
|
147
|
+
}, [context, isDisabled, value]);
|
|
148
|
+
const moveFocusTo = (nextValue) => {
|
|
149
|
+
const triggers = context.getOrderedTriggers();
|
|
150
|
+
const target = triggers.find((trigger) => trigger.value === nextValue);
|
|
151
|
+
target?.ref?.focus();
|
|
152
|
+
};
|
|
153
|
+
const handleKeyDown = (event) => {
|
|
154
|
+
if (isDisabled) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const triggers = context.getOrderedTriggers();
|
|
158
|
+
const currentIndex = triggers.findIndex((trigger) => trigger.value === value);
|
|
159
|
+
if (currentIndex === -1) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
let nextIndex = -1;
|
|
163
|
+
const isHorizontal = context.orientation === "horizontal";
|
|
164
|
+
const prevKey = isHorizontal ? "ArrowLeft" : "ArrowUp";
|
|
165
|
+
const nextKey = isHorizontal ? "ArrowRight" : "ArrowDown";
|
|
166
|
+
if (event.key === prevKey) {
|
|
167
|
+
nextIndex = getNextEnabledTabIndex(currentIndex, -1, triggers);
|
|
168
|
+
}
|
|
169
|
+
else if (event.key === nextKey) {
|
|
170
|
+
nextIndex = getNextEnabledTabIndex(currentIndex, 1, triggers);
|
|
171
|
+
}
|
|
172
|
+
else if (event.key === "Home") {
|
|
173
|
+
nextIndex = getFirstEnabledTabIndex(triggers);
|
|
174
|
+
}
|
|
175
|
+
else if (event.key === "End") {
|
|
176
|
+
nextIndex = getLastEnabledTabIndex(triggers);
|
|
177
|
+
}
|
|
178
|
+
else if ((event.key === "Enter" || event.key === " ") && context.activationMode === "manual") {
|
|
179
|
+
event.preventDefault();
|
|
180
|
+
context.setValue(value);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (nextIndex === -1) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
event.preventDefault();
|
|
189
|
+
const nextValue = triggers[nextIndex]?.value;
|
|
190
|
+
moveFocusTo(nextValue);
|
|
191
|
+
if (context.activationMode === "automatic" && nextValue) {
|
|
192
|
+
context.setValue(nextValue);
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
return (_jsx(TabsTriggerContext.Provider, { value: triggerContext, children: _jsx("button", { ...props, ref: (node) => {
|
|
196
|
+
triggerRef.current = node;
|
|
197
|
+
if (typeof ref === "function") {
|
|
198
|
+
ref(node);
|
|
199
|
+
}
|
|
200
|
+
else if (ref) {
|
|
201
|
+
ref.current = node;
|
|
202
|
+
}
|
|
203
|
+
}, id: triggerId, role: "tab", "aria-controls": contentId, "aria-selected": isSelected, className: cn("liano-tabs__trigger", className), "data-state": isSelected ? "active" : "inactive", "data-disabled": isDisabled ? "true" : undefined, disabled: isDisabled, onClick: composeEventHandlers(onClick, () => {
|
|
204
|
+
if (!isDisabled && !context.disabled) {
|
|
205
|
+
context.setValue(value);
|
|
206
|
+
}
|
|
207
|
+
}), onKeyDown: composeEventHandlers(onKeyDown, handleKeyDown), tabIndex: isSelected ? 0 : -1, type: "button" }) }));
|
|
208
|
+
}
|
|
209
|
+
function TabsContent({ className, forceMount = false, ref, value, ...props }) {
|
|
210
|
+
const context = useTabsContext("Tabs.Content");
|
|
211
|
+
const { getContentIdForValue, resetContentIdForValue, setContentIdForValue } = context;
|
|
212
|
+
const isSelected = context.value === value;
|
|
213
|
+
const triggerId = context.getTriggerIdForValue(value);
|
|
214
|
+
const contentId = props.id ?? getContentIdForValue(value);
|
|
215
|
+
React.useLayoutEffect(() => {
|
|
216
|
+
if (props.id === undefined) {
|
|
217
|
+
return undefined;
|
|
218
|
+
}
|
|
219
|
+
setContentIdForValue(value, contentId);
|
|
220
|
+
return () => {
|
|
221
|
+
resetContentIdForValue(value, contentId);
|
|
222
|
+
};
|
|
223
|
+
}, [contentId, props.id, resetContentIdForValue, setContentIdForValue, value]);
|
|
224
|
+
if (!forceMount && !isSelected) {
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
return (_jsx(TabsTriggerContext.Provider, { value: { value }, children: _jsx("div", { ...props, id: props.id ?? contentId, ref: ref, role: "tabpanel", "aria-labelledby": triggerId, className: cn("liano-tabs__content", className), "data-state": isSelected ? "open" : "closed", hidden: !isSelected ? true : undefined }) }));
|
|
228
|
+
}
|
|
229
|
+
export const Tabs = Object.assign(TabsRoot, {
|
|
230
|
+
List: TabsList,
|
|
231
|
+
Trigger: TabsTrigger,
|
|
232
|
+
Content: TabsContent
|
|
233
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { type TabsProps } from "../tabs/tabs.js";
|
|
3
|
+
export type TabsWithSidebarWidth = "sm" | "md" | "lg";
|
|
4
|
+
export interface TabsWithSidebarProps extends TabsProps {
|
|
5
|
+
sidebarWidth?: TabsWithSidebarWidth;
|
|
6
|
+
}
|
|
7
|
+
export interface TabsWithSidebarSidebarProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
8
|
+
sidebarWidth?: TabsWithSidebarWidth;
|
|
9
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
10
|
+
}
|
|
11
|
+
export interface TabsWithSidebarPanelProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
12
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
13
|
+
}
|
|
14
|
+
declare function TabsWithSidebarRoot({ className, orientation, ref, sidebarWidth, ...props }: TabsWithSidebarProps): React.JSX.Element;
|
|
15
|
+
declare function TabsWithSidebarSidebar({ className, ref, sidebarWidth, ...props }: TabsWithSidebarSidebarProps): React.JSX.Element;
|
|
16
|
+
declare function TabsWithSidebarPanel({ className, ref, ...props }: TabsWithSidebarPanelProps): React.JSX.Element;
|
|
17
|
+
export declare const TabsWithSidebar: typeof TabsWithSidebarRoot & {
|
|
18
|
+
Sidebar: typeof TabsWithSidebarSidebar;
|
|
19
|
+
Panel: typeof TabsWithSidebarPanel;
|
|
20
|
+
};
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Tabs } from "../tabs/tabs.js";
|
|
5
|
+
import { cn } from "../../utils/cn.js";
|
|
6
|
+
function TabsWithSidebarRoot({ className, orientation = "vertical", ref, sidebarWidth = "md", ...props }) {
|
|
7
|
+
return (_jsx(Tabs, { ...props, ...(ref ? { ref } : {}), className: cn("liano-tabs-with-sidebar", className), "data-sidebar-width": sidebarWidth, orientation: orientation }));
|
|
8
|
+
}
|
|
9
|
+
function TabsWithSidebarSidebar({ className, ref, sidebarWidth = "md", ...props }) {
|
|
10
|
+
return (_jsx("div", { ...props, ref: ref, className: cn("liano-tabs-with-sidebar__sidebar", className), "data-sidebar-width": sidebarWidth }));
|
|
11
|
+
}
|
|
12
|
+
function TabsWithSidebarPanel({ className, ref, ...props }) {
|
|
13
|
+
return _jsx("div", { ...props, ref: ref, className: cn("liano-tabs-with-sidebar__panel", className) });
|
|
14
|
+
}
|
|
15
|
+
export const TabsWithSidebar = Object.assign(TabsWithSidebarRoot, {
|
|
16
|
+
Sidebar: TabsWithSidebarSidebar,
|
|
17
|
+
Panel: TabsWithSidebarPanel
|
|
18
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export type TextareaSize = "sm" | "md" | "lg";
|
|
3
|
+
export interface TextareaProps extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {
|
|
4
|
+
label?: React.ReactNode;
|
|
5
|
+
description?: React.ReactNode;
|
|
6
|
+
error?: React.ReactNode;
|
|
7
|
+
invalid?: boolean;
|
|
8
|
+
size?: TextareaSize;
|
|
9
|
+
ref?: React.Ref<HTMLTextAreaElement>;
|
|
10
|
+
}
|
|
11
|
+
export declare function Textarea({ "aria-describedby": ariaDescribedBy, className, description, disabled, error, id, invalid, label, ref, required, rows, size, ...props }: TextareaProps): React.JSX.Element;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Field } from "../field/field.js";
|
|
5
|
+
import { cn } from "../../utils/cn.js";
|
|
6
|
+
function hasRenderableNode(value) {
|
|
7
|
+
return value !== undefined && value !== null && value !== false;
|
|
8
|
+
}
|
|
9
|
+
function joinIds(...ids) {
|
|
10
|
+
const value = ids.filter(Boolean).join(" ");
|
|
11
|
+
return value.length > 0 ? value : undefined;
|
|
12
|
+
}
|
|
13
|
+
export function Textarea({ "aria-describedby": ariaDescribedBy, className, description, disabled, error, id, invalid, label, ref, required, rows, size = "md", ...props }) {
|
|
14
|
+
const generatedId = React.useId();
|
|
15
|
+
const inputId = id ?? generatedId;
|
|
16
|
+
const hasLabel = hasRenderableNode(label);
|
|
17
|
+
const hasDescription = hasRenderableNode(description);
|
|
18
|
+
const hasError = hasRenderableNode(error);
|
|
19
|
+
const invalidState = invalid || Boolean(hasError);
|
|
20
|
+
const descriptionId = hasDescription ? `${inputId}-description` : undefined;
|
|
21
|
+
const errorId = hasError ? `${inputId}-error` : undefined;
|
|
22
|
+
const describedBy = joinIds(ariaDescribedBy, descriptionId, errorId);
|
|
23
|
+
const textarea = (_jsx("textarea", { ...props, ref: ref, "aria-describedby": describedBy, "aria-invalid": invalidState ? true : undefined, className: cn("liano-textarea", className), "data-disabled": disabled ? "true" : undefined, "data-invalid": invalidState ? "true" : undefined, "data-required": required ? "true" : undefined, "data-size": size, disabled: disabled, id: inputId, required: required, rows: rows }));
|
|
24
|
+
if (!hasLabel && !hasDescription && !hasError) {
|
|
25
|
+
return textarea;
|
|
26
|
+
}
|
|
27
|
+
return (_jsxs(Field, { disabled: Boolean(disabled), invalid: invalidState, required: Boolean(required), children: [hasLabel ? _jsx(Field.Label, { htmlFor: inputId, children: label }) : null, textarea, hasDescription ? _jsx(Field.Description, { id: descriptionId, children: description }) : null, hasError ? _jsx(Field.Error, { id: errorId, children: error }) : null] }));
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Toast, ToastViewport } from "./toast.js";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export type ToastTone = "neutral" | "success" | "warning" | "destructive" | "info";
|
|
3
|
+
export type ToastPlacement = "top-right" | "top-left" | "bottom-right" | "bottom-left";
|
|
4
|
+
export interface ToastViewportProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
5
|
+
placement?: ToastPlacement;
|
|
6
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
7
|
+
}
|
|
8
|
+
export interface ToastProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
9
|
+
tone?: ToastTone;
|
|
10
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
11
|
+
}
|
|
12
|
+
export interface ToastTextProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
13
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
14
|
+
}
|
|
15
|
+
export interface ToastActionProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
16
|
+
ref?: React.Ref<HTMLButtonElement>;
|
|
17
|
+
}
|
|
18
|
+
export interface ToastCloseProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
19
|
+
ref?: React.Ref<HTMLButtonElement>;
|
|
20
|
+
}
|
|
21
|
+
export declare function ToastViewport({ className, placement, ref, ...props }: ToastViewportProps): React.ReactElement;
|
|
22
|
+
declare function ToastRoot({ className, ref, role, tone, ...props }: ToastProps): React.JSX.Element;
|
|
23
|
+
declare function ToastTitle({ className, ref, ...props }: ToastTextProps): React.JSX.Element;
|
|
24
|
+
declare function ToastDescription({ className, ref, ...props }: ToastTextProps): React.JSX.Element;
|
|
25
|
+
declare function ToastAction({ className, ref, type, ...props }: ToastActionProps): React.JSX.Element;
|
|
26
|
+
declare function ToastClose({ children, className, ref, type, ...props }: ToastCloseProps): React.JSX.Element;
|
|
27
|
+
export declare const Toast: typeof ToastRoot & {
|
|
28
|
+
Title: typeof ToastTitle;
|
|
29
|
+
Description: typeof ToastDescription;
|
|
30
|
+
Action: typeof ToastAction;
|
|
31
|
+
Close: typeof ToastClose;
|
|
32
|
+
};
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { cn } from "../../utils/cn.js";
|
|
4
|
+
export function ToastViewport({ className, placement = "top-right", ref, ...props }) {
|
|
5
|
+
return (_jsx("div", { ...props, ref: ref, "aria-label": props["aria-label"] ?? "Notifications", className: cn("liano-toast-viewport", className), "data-placement": placement, role: "region" }));
|
|
6
|
+
}
|
|
7
|
+
function ToastRoot({ className, ref, role, tone = "neutral", ...props }) {
|
|
8
|
+
return (_jsx("div", { ...props, ref: ref, className: cn("liano-toast", className), "data-tone": tone, role: role ?? (tone === "destructive" ? "alert" : "status") }));
|
|
9
|
+
}
|
|
10
|
+
function ToastTitle({ className, ref, ...props }) {
|
|
11
|
+
return _jsx("div", { ...props, ref: ref, className: cn("liano-toast__title", className) });
|
|
12
|
+
}
|
|
13
|
+
function ToastDescription({ className, ref, ...props }) {
|
|
14
|
+
return _jsx("div", { ...props, ref: ref, className: cn("liano-toast__description", className) });
|
|
15
|
+
}
|
|
16
|
+
function ToastAction({ className, ref, type = "button", ...props }) {
|
|
17
|
+
return _jsx("button", { ...props, ref: ref, className: cn("liano-toast__action", className), type: type });
|
|
18
|
+
}
|
|
19
|
+
function ToastClose({ children = "×", className, ref, type = "button", ...props }) {
|
|
20
|
+
return (_jsx("button", { ...props, ref: ref, className: cn("liano-toast__close", className), type: type, children: children }));
|
|
21
|
+
}
|
|
22
|
+
export const Toast = Object.assign(ToastRoot, {
|
|
23
|
+
Title: ToastTitle,
|
|
24
|
+
Description: ToastDescription,
|
|
25
|
+
Action: ToastAction,
|
|
26
|
+
Close: ToastClose
|
|
27
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export type ToggleSize = "sm" | "md" | "lg";
|
|
3
|
+
export type ToggleVariant = "default" | "outline" | "ghost";
|
|
4
|
+
export interface ToggleProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "value"> {
|
|
5
|
+
pressed?: boolean;
|
|
6
|
+
defaultPressed?: boolean;
|
|
7
|
+
onPressedChange?: (pressed: boolean) => void;
|
|
8
|
+
size?: ToggleSize;
|
|
9
|
+
variant?: ToggleVariant;
|
|
10
|
+
ref?: React.Ref<HTMLButtonElement>;
|
|
11
|
+
}
|
|
12
|
+
export declare function Toggle({ "aria-pressed": ariaPressed, className, defaultPressed, disabled, onClick, onPressedChange, pressed, ref, size, type, variant, ...props }: ToggleProps): React.JSX.Element;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { useControllableState } from "../../hooks/use-controllable-state.js";
|
|
5
|
+
import { composeEventHandlers } from "../../utils/compose-event-handlers.js";
|
|
6
|
+
import { cn } from "../../utils/cn.js";
|
|
7
|
+
export function Toggle({ "aria-pressed": ariaPressed, className, defaultPressed = false, disabled, onClick, onPressedChange, pressed, ref, size = "md", type = "button", variant = "default", ...props }) {
|
|
8
|
+
const [currentPressed, setPressed] = useControllableState({
|
|
9
|
+
...(pressed !== undefined ? { value: pressed } : {}),
|
|
10
|
+
defaultValue: defaultPressed,
|
|
11
|
+
...(onPressedChange ? { onChange: onPressedChange } : {})
|
|
12
|
+
});
|
|
13
|
+
return (_jsx("button", { ...props, ref: ref, "aria-pressed": ariaPressed ?? currentPressed, className: cn("liano-toggle", className), "data-disabled": disabled ? "true" : undefined, "data-size": size, "data-state": currentPressed ? "on" : "off", "data-variant": variant, disabled: disabled, onClick: composeEventHandlers(onClick, () => {
|
|
14
|
+
if (!disabled) {
|
|
15
|
+
setPressed((value) => !value);
|
|
16
|
+
}
|
|
17
|
+
}), type: type }));
|
|
18
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { type ToggleProps } from "../toggle/toggle.js";
|
|
3
|
+
export interface ToggleGroupSingleProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
4
|
+
type: "single";
|
|
5
|
+
value?: string;
|
|
6
|
+
defaultValue?: string;
|
|
7
|
+
onValueChange?: (value: string) => void;
|
|
8
|
+
orientation?: "horizontal" | "vertical";
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface ToggleGroupMultipleProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
12
|
+
type: "multiple";
|
|
13
|
+
value?: readonly string[];
|
|
14
|
+
defaultValue?: readonly string[];
|
|
15
|
+
onValueChange?: (value: string[]) => void;
|
|
16
|
+
orientation?: "horizontal" | "vertical";
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export type ToggleGroupProps = ToggleGroupSingleProps | ToggleGroupMultipleProps;
|
|
20
|
+
export interface ToggleGroupItemProps extends Omit<ToggleProps, "pressed" | "defaultPressed" | "onPressedChange"> {
|
|
21
|
+
value: string;
|
|
22
|
+
}
|
|
23
|
+
declare function ToggleGroupRoot(props: ToggleGroupProps): React.JSX.Element;
|
|
24
|
+
declare function ToggleGroupItem({ disabled, onClick, value, ...props }: ToggleGroupItemProps): React.JSX.Element;
|
|
25
|
+
export declare const ToggleGroup: typeof ToggleGroupRoot & {
|
|
26
|
+
Item: typeof ToggleGroupItem;
|
|
27
|
+
};
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { useControllableState } from "../../hooks/use-controllable-state.js";
|
|
5
|
+
import { cn } from "../../utils/cn.js";
|
|
6
|
+
import { Toggle } from "../toggle/toggle.js";
|
|
7
|
+
const ToggleGroupContext = React.createContext(null);
|
|
8
|
+
function useToggleGroupContext(calledBy) {
|
|
9
|
+
const context = React.useContext(ToggleGroupContext);
|
|
10
|
+
if (!context) {
|
|
11
|
+
throw new Error(`"${calledBy}" must be used within a <ToggleGroup />`);
|
|
12
|
+
}
|
|
13
|
+
return context;
|
|
14
|
+
}
|
|
15
|
+
function ToggleGroupRoot(props) {
|
|
16
|
+
const { children, className, disabled, orientation = "horizontal", type } = props;
|
|
17
|
+
const singleValueProp = type === "single" && props.value !== undefined ? props.value : undefined;
|
|
18
|
+
const singleDefaultValue = type === "single" ? props.defaultValue ?? "" : "";
|
|
19
|
+
const singleOnValueChange = type === "single" ? props.onValueChange : undefined;
|
|
20
|
+
const multipleValueProp = type === "multiple" && props.value !== undefined ? [...props.value] : undefined;
|
|
21
|
+
const multipleDefaultValue = type === "multiple" ? [...(props.defaultValue ?? [])] : [];
|
|
22
|
+
const multipleOnValueChange = type === "multiple" ? props.onValueChange : undefined;
|
|
23
|
+
const [singleValue, setSingleValue] = useControllableState({
|
|
24
|
+
...(singleValueProp !== undefined ? { value: singleValueProp } : {}),
|
|
25
|
+
defaultValue: singleDefaultValue,
|
|
26
|
+
...(singleOnValueChange ? { onChange: singleOnValueChange } : {})
|
|
27
|
+
});
|
|
28
|
+
const [multipleValue, setMultipleValue] = useControllableState({
|
|
29
|
+
...(multipleValueProp !== undefined ? { value: multipleValueProp } : {}),
|
|
30
|
+
defaultValue: multipleDefaultValue,
|
|
31
|
+
...(multipleOnValueChange ? { onChange: multipleOnValueChange } : {})
|
|
32
|
+
});
|
|
33
|
+
const isPressed = React.useCallback((itemValue) => type === "single" ? singleValue === itemValue : multipleValue.includes(itemValue), [multipleValue, singleValue, type]);
|
|
34
|
+
const toggleValue = React.useCallback((itemValue) => {
|
|
35
|
+
if (type === "single") {
|
|
36
|
+
setSingleValue((value) => value === itemValue ? "" : itemValue);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
setMultipleValue((value) => {
|
|
40
|
+
if (value.includes(itemValue)) {
|
|
41
|
+
return value.filter((entry) => entry !== itemValue);
|
|
42
|
+
}
|
|
43
|
+
return [...value, itemValue];
|
|
44
|
+
});
|
|
45
|
+
}, [setMultipleValue, setSingleValue, type]);
|
|
46
|
+
const context = React.useMemo(() => ({
|
|
47
|
+
...(disabled !== undefined ? { disabled } : {}),
|
|
48
|
+
isPressed,
|
|
49
|
+
orientation,
|
|
50
|
+
toggleValue
|
|
51
|
+
}), [disabled, isPressed, orientation, toggleValue]);
|
|
52
|
+
const { children: _children, className: _className, defaultValue: _defaultValue, disabled: _disabled, onValueChange: _onValueChange, orientation: _orientation, type: _type, value: _value, ...domProps } = props;
|
|
53
|
+
return (_jsx(ToggleGroupContext.Provider, { value: context, children: _jsx("div", { ...domProps, className: cn("liano-toggle-group", className), "data-disabled": disabled ? "true" : undefined, "data-orientation": orientation, role: "group", children: children }) }));
|
|
54
|
+
}
|
|
55
|
+
function ToggleGroupItem({ disabled, onClick, value, ...props }) {
|
|
56
|
+
const context = useToggleGroupContext("ToggleGroup.Item");
|
|
57
|
+
const isDisabled = Boolean(context.disabled) || Boolean(disabled);
|
|
58
|
+
return (_jsx(Toggle, { ...props, disabled: isDisabled, onClick: (event) => {
|
|
59
|
+
onClick?.(event);
|
|
60
|
+
if (!event.defaultPrevented && !isDisabled) {
|
|
61
|
+
context.toggleValue(value);
|
|
62
|
+
}
|
|
63
|
+
}, pressed: context.isPressed(value) }));
|
|
64
|
+
}
|
|
65
|
+
export const ToggleGroup = Object.assign(ToggleGroupRoot, {
|
|
66
|
+
Item: ToggleGroupItem
|
|
67
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { FloatingPlacement } from "../../internal/floating/index.js";
|
|
3
|
+
export interface TooltipProps {
|
|
4
|
+
children: React.ReactElement;
|
|
5
|
+
content: React.ReactNode;
|
|
6
|
+
placement?: FloatingPlacement;
|
|
7
|
+
delay?: number;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function Tooltip({ children, content, delay, disabled, placement }: TooltipProps): React.JSX.Element;
|