@zvk/ui 0.1.5 → 0.1.7
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/CHANGELOG.md +48 -0
- package/README.md +5 -5
- package/dist/components/accordion/accordion.js +4 -4
- package/dist/components/alert/alert.d.ts +5 -0
- package/dist/components/alert/alert.js +8 -4
- package/dist/components/alert/index.d.ts +1 -1
- package/dist/components/alert-dialog/alert-dialog.js +9 -9
- package/dist/components/avatar/avatar.js +1 -1
- package/dist/components/badge/badge.js +1 -1
- package/dist/components/breadcrumbs/breadcrumbs.js +3 -3
- package/dist/components/button/button.js +46 -2
- package/dist/components/calendar/calendar.js +3 -3
- package/dist/components/card/card.d.ts +5 -0
- package/dist/components/card/card.js +11 -7
- package/dist/components/card/index.d.ts +1 -1
- package/dist/components/carousel/carousel.js +7 -7
- package/dist/components/checkbox/checkbox.js +4 -4
- package/dist/components/code-block/code-block.js +2 -2
- package/dist/components/collapsible/collapsible.js +4 -4
- package/dist/components/combobox/combobox.js +6 -5
- package/dist/components/command/command-filter.d.ts +0 -1
- package/dist/components/command/command-filter.js +0 -3
- package/dist/components/command/command.js +9 -9
- package/dist/components/context-menu/context-menu.d.ts +3 -1
- package/dist/components/context-menu/context-menu.js +66 -12
- package/dist/components/context-menu/index.d.ts +1 -1
- package/dist/components/conversation/conversation.js +11 -11
- package/dist/components/copy-button/copy-button.js +2 -2
- package/dist/components/date-picker/date-picker.js +1 -1
- package/dist/components/dialog/dialog.js +11 -11
- package/dist/components/dropdown-menu/dropdown-menu.d.ts +1 -1
- package/dist/components/dropdown-menu/dropdown-menu.js +20 -16
- package/dist/components/empty-state/empty-state.js +1 -1
- package/dist/components/error-boundary/error-boundary.js +1 -1
- package/dist/components/field/field.js +4 -4
- package/dist/components/file-upload-input/file-upload-input.js +2 -2
- package/dist/components/form/form.js +6 -6
- package/dist/components/hover-card/hover-card.d.ts +1 -1
- package/dist/components/hover-card/hover-card.js +7 -4
- package/dist/components/icon-button/icon-button.js +19 -1
- package/dist/components/index.d.ts +5 -5
- package/dist/components/input/input.js +1 -1
- package/dist/components/label/label.js +1 -1
- package/dist/components/menubar/index.d.ts +1 -1
- package/dist/components/menubar/menubar.d.ts +1 -1
- package/dist/components/menubar/menubar.js +42 -14
- package/dist/components/pagination/pagination.js +12 -12
- package/dist/components/popover/popover.d.ts +1 -1
- package/dist/components/popover/popover.js +30 -7
- package/dist/components/progress/progress.js +3 -3
- package/dist/components/radio-group/radio-group.js +3 -3
- package/dist/components/responsive-container/responsive-container.js +1 -1
- package/dist/components/scroll-area/scroll-area.js +4 -4
- package/dist/components/sectioned-sidebar-nav/sectioned-sidebar-nav.js +7 -7
- package/dist/components/select/select.js +66 -13
- package/dist/components/separator/separator.js +1 -1
- package/dist/components/sheet/sheet.js +12 -12
- package/dist/components/sidebar-shell/sidebar-shell.js +6 -6
- package/dist/components/skeleton/skeleton.js +1 -1
- package/dist/components/slider/slider.js +1 -1
- package/dist/components/spinner/spinner.js +1 -1
- package/dist/components/stat/stat.js +1 -1
- package/dist/components/switch/switch.js +3 -3
- package/dist/components/table/index.d.ts +1 -1
- package/dist/components/table/table.d.ts +5 -0
- package/dist/components/table/table.js +12 -8
- package/dist/components/tabs/tabs.js +4 -4
- package/dist/components/tabs-with-sidebar/tabs-with-sidebar.js +3 -3
- package/dist/components/textarea/textarea.js +1 -1
- package/dist/components/toast/toast.js +8 -8
- package/dist/components/toggle/toggle.js +1 -1
- package/dist/components/toggle-group/toggle-group.js +1 -1
- package/dist/components/tooltip/tooltip.d.ts +1 -1
- package/dist/components/tooltip/tooltip.js +6 -3
- package/dist/hooks/index.d.ts +2 -2
- package/dist/hooks/use-composed-refs.d.ts +2 -2
- package/dist/hooks/use-controllable-state.d.ts +2 -2
- package/dist/internal/floating/auto-update.js +21 -9
- package/dist/internal/floating/compute-position.js +13 -8
- package/dist/internal/floating/floating-types.d.ts +1 -0
- package/dist/internal/floating/index.d.ts +1 -0
- package/dist/internal/floating/use-floating-position.js +6 -4
- package/dist/internal/overlay-stack/overlay-stack.js +4 -1
- package/dist/styles.css +2065 -2022
- package/dist/tokens/index.d.ts +2 -2
- package/dist/tokens/index.js +1 -1
- package/dist/tokens/token-types.d.ts +5 -5
- package/dist/tokens/tokens.d.ts +16 -10
- package/dist/tokens/tokens.js +16 -10
- package/dist/utils/cn.d.ts +2 -2
- package/dist/utils/index.d.ts +1 -1
- package/package.json +14 -11
|
@@ -3,5 +3,5 @@ import * as React from "react";
|
|
|
3
3
|
import { cn } from "../../utils/cn.js";
|
|
4
4
|
export function Spinner({ className, label, ref, size = "md", tone = "primary", ...props }) {
|
|
5
5
|
const hasLabel = label !== undefined && label !== null && label !== false;
|
|
6
|
-
return (_jsx("span", { ...props, ref: ref, "aria-hidden": hasLabel ? undefined : true, "aria-live": hasLabel ? "polite" : undefined, className: cn("
|
|
6
|
+
return (_jsx("span", { ...props, ref: ref, "aria-hidden": hasLabel ? undefined : true, "aria-live": hasLabel ? "polite" : undefined, className: cn("zvk-ui-spinner", className), "data-size": size, "data-tone": tone, role: hasLabel ? "status" : undefined, children: hasLabel ? _jsx("span", { className: "zvk-ui-sr-only", children: label }) : null }));
|
|
7
7
|
}
|
|
@@ -4,5 +4,5 @@ import { cn } from "../../utils/cn.js";
|
|
|
4
4
|
export function Stat({ className, description, label, ref, size = "md", tone = "neutral", trend, value, ...props }) {
|
|
5
5
|
const showDescription = description !== undefined && description !== null && description !== false;
|
|
6
6
|
const showTrend = trend !== undefined && trend !== null && trend !== false;
|
|
7
|
-
return (_jsxs("div", { ...props, ref: ref, className: cn("
|
|
7
|
+
return (_jsxs("div", { ...props, ref: ref, className: cn("zvk-ui-stat", className), "data-size": size, "data-tone": tone, children: [_jsx("p", { className: "zvk-ui-stat__label", children: label }), _jsx("div", { className: "zvk-ui-stat__value", children: value }), showDescription ? _jsx("p", { className: "zvk-ui-stat__description", children: description }) : null, showTrend ? _jsx("div", { className: "zvk-ui-stat__trend", children: trend }) : null] }));
|
|
8
8
|
}
|
|
@@ -21,7 +21,7 @@ export function Switch({ "aria-describedby": ariaDescribedBy, className, descrip
|
|
|
21
21
|
const descriptionId = hasDescription ? `${switchId}-description` : undefined;
|
|
22
22
|
const errorId = hasError ? `${switchId}-error` : undefined;
|
|
23
23
|
const describedBy = joinIds(ariaDescribedBy, descriptionId, errorId);
|
|
24
|
-
const input = (_jsx("input", { ...props, ref: ref, "aria-describedby": describedBy, "aria-invalid": invalidState ? true : undefined, className: "
|
|
25
|
-
const content = (_jsxs(_Fragment, { children: [input, _jsx("span", { className: "
|
|
26
|
-
return (_jsxs(Field, { disabled: Boolean(disabled), invalid: invalidState, required: Boolean(required), children: [_jsx("label", { className: cn("
|
|
24
|
+
const input = (_jsx("input", { ...props, ref: ref, "aria-describedby": describedBy, "aria-invalid": invalidState ? true : undefined, className: "zvk-ui-switch__input", "data-disabled": disabled ? "true" : undefined, "data-invalid": invalidState ? "true" : undefined, "data-required": required ? "true" : undefined, disabled: disabled, id: switchId, required: required, role: "switch", type: "checkbox" }));
|
|
25
|
+
const content = (_jsxs(_Fragment, { children: [input, _jsx("span", { className: "zvk-ui-switch__track", "aria-hidden": "true", children: _jsx("span", { className: "zvk-ui-switch__thumb" }) }), hasLabel ? _jsx("span", { className: "zvk-ui-switch__label", children: label }) : null] }));
|
|
26
|
+
return (_jsxs(Field, { disabled: Boolean(disabled), invalid: invalidState, required: Boolean(required), children: [_jsx("label", { className: cn("zvk-ui-switch", className), "data-size": size, "data-disabled": disabled ? "true" : undefined, "data-invalid": invalidState ? "true" : undefined, "data-required": required ? "true" : undefined, children: content }), hasDescription ? _jsx(Field.Description, { id: descriptionId, children: description }) : null, hasError ? _jsx(Field.Error, { id: errorId, children: error }) : null] }));
|
|
27
27
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { Table } from "./table.js";
|
|
2
|
-
export type { TableBodyProps, TableCaptionProps, TableCellProps, TableFooterProps, TableHeadProps, TableHeaderProps, TableProps, TableRowProps } from "./table.js";
|
|
2
|
+
export type { TableBodyProps, TableCaptionProps, TableCellProps, TableContainerProps, TableFooterProps, TableHeadProps, TableHeaderProps, TableProps, TableRowProps } from "./table.js";
|
|
@@ -4,6 +4,9 @@ export interface TableProps extends React.TableHTMLAttributes<HTMLTableElement>
|
|
|
4
4
|
variant?: "plain" | "surface";
|
|
5
5
|
ref?: React.Ref<HTMLTableElement>;
|
|
6
6
|
}
|
|
7
|
+
export interface TableContainerProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
8
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
9
|
+
}
|
|
7
10
|
export interface TableCaptionProps extends React.HTMLAttributes<HTMLTableCaptionElement> {
|
|
8
11
|
ref?: React.Ref<HTMLTableCaptionElement>;
|
|
9
12
|
}
|
|
@@ -33,7 +36,9 @@ declare function TableFooter({ className, ref, ...props }: TableFooterProps): Re
|
|
|
33
36
|
declare function TableRow({ className, ref, ...props }: TableRowProps): React.JSX.Element;
|
|
34
37
|
declare function TableHead({ className, ref, scope, ...props }: TableHeadProps): React.JSX.Element;
|
|
35
38
|
declare function TableCell({ className, ref, ...props }: TableCellProps): React.JSX.Element;
|
|
39
|
+
declare function TableContainer({ className, ref, ...props }: TableContainerProps): React.JSX.Element;
|
|
36
40
|
export declare const Table: typeof TableRoot & {
|
|
41
|
+
Container: typeof TableContainer;
|
|
37
42
|
Caption: typeof TableCaption;
|
|
38
43
|
Header: typeof TableHeader;
|
|
39
44
|
Body: typeof TableBody;
|
|
@@ -2,30 +2,34 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import { cn } from "../../utils/cn.js";
|
|
4
4
|
function TableRoot({ className, density = "default", ref, variant = "plain", ...props }) {
|
|
5
|
-
return (_jsx("table", { ...props, ref: ref, className: cn("
|
|
5
|
+
return (_jsx("table", { ...props, ref: ref, className: cn("zvk-ui-table", className), "data-density": density, "data-variant": variant }));
|
|
6
6
|
}
|
|
7
7
|
function TableCaption({ className, ref, ...props }) {
|
|
8
|
-
return _jsx("caption", { ...props, ref: ref, className: cn("
|
|
8
|
+
return _jsx("caption", { ...props, ref: ref, className: cn("zvk-ui-table__caption", className) });
|
|
9
9
|
}
|
|
10
10
|
function TableHeader({ className, ref, ...props }) {
|
|
11
|
-
return _jsx("thead", { ...props, ref: ref, className: cn("
|
|
11
|
+
return _jsx("thead", { ...props, ref: ref, className: cn("zvk-ui-table__header", className) });
|
|
12
12
|
}
|
|
13
13
|
function TableBody({ className, ref, ...props }) {
|
|
14
|
-
return _jsx("tbody", { ...props, ref: ref, className: cn("
|
|
14
|
+
return _jsx("tbody", { ...props, ref: ref, className: cn("zvk-ui-table__body", className) });
|
|
15
15
|
}
|
|
16
16
|
function TableFooter({ className, ref, ...props }) {
|
|
17
|
-
return _jsx("tfoot", { ...props, ref: ref, className: cn("
|
|
17
|
+
return _jsx("tfoot", { ...props, ref: ref, className: cn("zvk-ui-table__footer", className) });
|
|
18
18
|
}
|
|
19
19
|
function TableRow({ className, ref, ...props }) {
|
|
20
|
-
return _jsx("tr", { ...props, ref: ref, className: cn("
|
|
20
|
+
return _jsx("tr", { ...props, ref: ref, className: cn("zvk-ui-table__row", className) });
|
|
21
21
|
}
|
|
22
22
|
function TableHead({ className, ref, scope = "col", ...props }) {
|
|
23
|
-
return _jsx("th", { ...props, ref: ref, scope: scope, className: cn("
|
|
23
|
+
return _jsx("th", { ...props, ref: ref, scope: scope, className: cn("zvk-ui-table__head", className) });
|
|
24
24
|
}
|
|
25
25
|
function TableCell({ className, ref, ...props }) {
|
|
26
|
-
return _jsx("td", { ...props, ref: ref, className: cn("
|
|
26
|
+
return _jsx("td", { ...props, ref: ref, className: cn("zvk-ui-table__cell", className) });
|
|
27
|
+
}
|
|
28
|
+
function TableContainer({ className, ref, ...props }) {
|
|
29
|
+
return _jsx("div", { ...props, ref: ref, className: cn("zvk-ui-table-container", className) });
|
|
27
30
|
}
|
|
28
31
|
export const Table = Object.assign(TableRoot, {
|
|
32
|
+
Container: TableContainer,
|
|
29
33
|
Caption: TableCaption,
|
|
30
34
|
Header: TableHeader,
|
|
31
35
|
Body: TableBody,
|
|
@@ -127,11 +127,11 @@ function TabsRoot({ children, className, defaultValue = "", disabled = false, re
|
|
|
127
127
|
setValue: setCurrentValue,
|
|
128
128
|
unregisterTrigger,
|
|
129
129
|
value: currentValue
|
|
130
|
-
}, children: _jsx("div", { ...props, ref: ref, className: cn("
|
|
130
|
+
}, children: _jsx("div", { ...props, ref: ref, className: cn("zvk-ui-tabs", className), "data-orientation": orientation, "data-state": activationMode, "data-disabled": disabled ? "true" : undefined, children: children }) }));
|
|
131
131
|
}
|
|
132
132
|
function TabsList({ className, ref, ...props }) {
|
|
133
133
|
const context = useTabsContext("Tabs.List");
|
|
134
|
-
return (_jsx("div", { ...props, ref: ref, role: "tablist", className: cn("
|
|
134
|
+
return (_jsx("div", { ...props, ref: ref, role: "tablist", className: cn("zvk-ui-tabs__list", className), "aria-orientation": context.orientation === "vertical" ? "vertical" : "horizontal" }));
|
|
135
135
|
}
|
|
136
136
|
function TabsTrigger({ className, onClick, onKeyDown, ref, value, ...props }) {
|
|
137
137
|
const context = useTabsContext("Tabs.Trigger");
|
|
@@ -200,7 +200,7 @@ function TabsTrigger({ className, onClick, onKeyDown, ref, value, ...props }) {
|
|
|
200
200
|
else if (ref) {
|
|
201
201
|
ref.current = node;
|
|
202
202
|
}
|
|
203
|
-
}, id: triggerId, role: "tab", "aria-controls": contentId, "aria-selected": isSelected, className: cn("
|
|
203
|
+
}, id: triggerId, role: "tab", "aria-controls": contentId, "aria-selected": isSelected, className: cn("zvk-ui-tabs__trigger", className), "data-state": isSelected ? "active" : "inactive", "data-disabled": isDisabled ? "true" : undefined, disabled: isDisabled, onClick: composeEventHandlers(onClick, () => {
|
|
204
204
|
if (!isDisabled && !context.disabled) {
|
|
205
205
|
context.setValue(value);
|
|
206
206
|
}
|
|
@@ -224,7 +224,7 @@ function TabsContent({ className, forceMount = false, ref, value, ...props }) {
|
|
|
224
224
|
if (!forceMount && !isSelected) {
|
|
225
225
|
return null;
|
|
226
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("
|
|
227
|
+
return (_jsx(TabsTriggerContext.Provider, { value: { value }, children: _jsx("div", { ...props, id: props.id ?? contentId, ref: ref, role: "tabpanel", "aria-labelledby": triggerId, className: cn("zvk-ui-tabs__content", className), "data-state": isSelected ? "open" : "closed", hidden: !isSelected ? true : undefined }) }));
|
|
228
228
|
}
|
|
229
229
|
export const Tabs = Object.assign(TabsRoot, {
|
|
230
230
|
List: TabsList,
|
|
@@ -4,13 +4,13 @@ import * as React from "react";
|
|
|
4
4
|
import { Tabs } from "../tabs/tabs.js";
|
|
5
5
|
import { cn } from "../../utils/cn.js";
|
|
6
6
|
function TabsWithSidebarRoot({ className, orientation = "vertical", ref, sidebarWidth = "md", ...props }) {
|
|
7
|
-
return (_jsx(Tabs, { ...props, ...(ref ? { ref } : {}), className: cn("
|
|
7
|
+
return (_jsx(Tabs, { ...props, ...(ref ? { ref } : {}), className: cn("zvk-ui-tabs-with-sidebar", className), "data-sidebar-width": sidebarWidth, orientation: orientation }));
|
|
8
8
|
}
|
|
9
9
|
function TabsWithSidebarSidebar({ className, ref, sidebarWidth = "md", ...props }) {
|
|
10
|
-
return (_jsx("div", { ...props, ref: ref, className: cn("
|
|
10
|
+
return (_jsx("div", { ...props, ref: ref, className: cn("zvk-ui-tabs-with-sidebar__sidebar", className), "data-sidebar-width": sidebarWidth }));
|
|
11
11
|
}
|
|
12
12
|
function TabsWithSidebarPanel({ className, ref, ...props }) {
|
|
13
|
-
return _jsx("div", { ...props, ref: ref, className: cn("
|
|
13
|
+
return _jsx("div", { ...props, ref: ref, className: cn("zvk-ui-tabs-with-sidebar__panel", className) });
|
|
14
14
|
}
|
|
15
15
|
export const TabsWithSidebar = Object.assign(TabsWithSidebarRoot, {
|
|
16
16
|
Sidebar: TabsWithSidebarSidebar,
|
|
@@ -20,7 +20,7 @@ export function Textarea({ "aria-describedby": ariaDescribedBy, className, descr
|
|
|
20
20
|
const descriptionId = hasDescription ? `${inputId}-description` : undefined;
|
|
21
21
|
const errorId = hasError ? `${inputId}-error` : undefined;
|
|
22
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("
|
|
23
|
+
const textarea = (_jsx("textarea", { ...props, ref: ref, "aria-describedby": describedBy, "aria-invalid": invalidState ? true : undefined, className: cn("zvk-ui-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
24
|
if (!hasLabel && !hasDescription && !hasError) {
|
|
25
25
|
return textarea;
|
|
26
26
|
}
|
|
@@ -58,7 +58,7 @@ function renderToastControl(input) {
|
|
|
58
58
|
return input;
|
|
59
59
|
}
|
|
60
60
|
export function ToastViewport({ className, placement = "top-right", ref, ...props }) {
|
|
61
|
-
return (_jsx("div", { ...props, ref: ref, "aria-label": props["aria-label"] ?? "Notifications", className: cn("
|
|
61
|
+
return (_jsx("div", { ...props, ref: ref, "aria-label": props["aria-label"] ?? "Notifications", className: cn("zvk-ui-toast-viewport", className), "data-placement": placement, role: "region" }));
|
|
62
62
|
}
|
|
63
63
|
export function createToastController() {
|
|
64
64
|
const listeners = new Set();
|
|
@@ -131,7 +131,7 @@ export function Toaster({ controller = toast, expand: _expand, offset, position
|
|
|
131
131
|
? style
|
|
132
132
|
: {
|
|
133
133
|
...style,
|
|
134
|
-
"--
|
|
134
|
+
"--zvk-ui-toast-viewport-inset": typeof offset === "number" ? `${offset}px` : offset
|
|
135
135
|
};
|
|
136
136
|
return (_jsx(ToastProvider, { ...props, controller: controller, placement: placement, ...(offsetStyle === undefined ? {} : { style: offsetStyle }) }));
|
|
137
137
|
}
|
|
@@ -143,23 +143,23 @@ function ToastProviderItem({ onDismiss, toast }) {
|
|
|
143
143
|
const timeout = window.setTimeout(() => onDismiss(toast.id), toast.duration);
|
|
144
144
|
return () => window.clearTimeout(timeout);
|
|
145
145
|
}, [onDismiss, toast.duration, toast.id, toast.version]);
|
|
146
|
-
return (_jsxs(Toast, { tone: toast.tone, children: [(toast.title || toast.description) && (_jsxs("div", { className: "
|
|
146
|
+
return (_jsxs(Toast, { tone: toast.tone, children: [(toast.title || toast.description) && (_jsxs("div", { className: "zvk-ui-toast__content", children: [toast.title && _jsx(Toast.Title, { children: toast.title }), toast.description && _jsx(Toast.Description, { children: toast.description })] })), (toast.action || toast.cancel) && (_jsxs("div", { className: "zvk-ui-toast__controls", children: [renderToastControl(toast.action), renderToastControl(toast.cancel)] })), _jsx(Toast.Close, { "aria-label": "Dismiss notification", onClick: () => onDismiss(toast.id) })] }));
|
|
147
147
|
}
|
|
148
148
|
function ToastRoot({ className, ref, role, tone = "neutral", ...props }) {
|
|
149
149
|
const toastType = toastTypeFromTone(tone);
|
|
150
|
-
return (_jsx("div", { ...props, ref: ref, className: cn("
|
|
150
|
+
return (_jsx("div", { ...props, ref: ref, className: cn("zvk-ui-toast", className), "data-sonner-toast": "", "data-tone": tone, "data-type": toastType, "data-visible": "true", role: role ?? (tone === "destructive" ? "alert" : "status") }));
|
|
151
151
|
}
|
|
152
152
|
function ToastTitle({ className, ref, ...props }) {
|
|
153
|
-
return _jsx("div", { ...props, ref: ref, className: cn("
|
|
153
|
+
return _jsx("div", { ...props, ref: ref, className: cn("zvk-ui-toast__title", className) });
|
|
154
154
|
}
|
|
155
155
|
function ToastDescription({ className, ref, ...props }) {
|
|
156
|
-
return _jsx("div", { ...props, ref: ref, className: cn("
|
|
156
|
+
return _jsx("div", { ...props, ref: ref, className: cn("zvk-ui-toast__description", className) });
|
|
157
157
|
}
|
|
158
158
|
function ToastAction({ className, ref, type = "button", ...props }) {
|
|
159
|
-
return _jsx("button", { ...props, ref: ref, className: cn("
|
|
159
|
+
return _jsx("button", { ...props, ref: ref, className: cn("zvk-ui-toast__action", className), type: type });
|
|
160
160
|
}
|
|
161
161
|
function ToastClose({ children = "×", className, ref, type = "button", ...props }) {
|
|
162
|
-
return (_jsx("button", { ...props, ref: ref, className: cn("
|
|
162
|
+
return (_jsx("button", { ...props, ref: ref, className: cn("zvk-ui-toast__close", className), type: type, children: children }));
|
|
163
163
|
}
|
|
164
164
|
export const Toast = Object.assign(ToastRoot, {
|
|
165
165
|
Title: ToastTitle,
|
|
@@ -10,7 +10,7 @@ export function Toggle({ "aria-pressed": ariaPressed, className, defaultPressed
|
|
|
10
10
|
defaultValue: defaultPressed,
|
|
11
11
|
...(onPressedChange ? { onChange: onPressedChange } : {})
|
|
12
12
|
});
|
|
13
|
-
return (_jsx("button", { ...props, ref: ref, "aria-pressed": ariaPressed ?? currentPressed, className: cn("
|
|
13
|
+
return (_jsx("button", { ...props, ref: ref, "aria-pressed": ariaPressed ?? currentPressed, className: cn("zvk-ui-toggle", className), "data-disabled": disabled ? "true" : undefined, "data-size": size, "data-state": currentPressed ? "on" : "off", "data-variant": variant, disabled: disabled, onClick: composeEventHandlers(onClick, () => {
|
|
14
14
|
if (!disabled) {
|
|
15
15
|
setPressed((value) => !value);
|
|
16
16
|
}
|
|
@@ -50,7 +50,7 @@ function ToggleGroupRoot(props) {
|
|
|
50
50
|
toggleValue
|
|
51
51
|
}), [disabled, isPressed, orientation, toggleValue]);
|
|
52
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("
|
|
53
|
+
return (_jsx(ToggleGroupContext.Provider, { value: context, children: _jsx("div", { ...domProps, className: cn("zvk-ui-toggle-group", className), "data-disabled": disabled ? "true" : undefined, "data-orientation": orientation, role: "group", children: children }) }));
|
|
54
54
|
}
|
|
55
55
|
function ToggleGroupItem({ disabled, onClick, value, ...props }) {
|
|
56
56
|
const context = useToggleGroupContext("ToggleGroup.Item");
|
|
@@ -41,7 +41,7 @@ export interface TooltipContentProps extends React.HTMLAttributes<HTMLSpanElemen
|
|
|
41
41
|
declare function TooltipProvider({ children, delayDuration }: TooltipProviderProps): React.JSX.Element;
|
|
42
42
|
declare function TooltipRoot({ children, defaultOpen, delay, disabled, onOpenChange, open: openProp, placement }: TooltipRootProps): React.JSX.Element;
|
|
43
43
|
declare function TooltipTrigger({ children, asChild: _asChild }: TooltipTriggerProps): React.ReactElement<unknown, string | React.JSXElementConstructor<any>>;
|
|
44
|
-
declare function TooltipContent({ align, alignOffset
|
|
44
|
+
declare function TooltipContent({ align, alignOffset, children, className, collisionPadding, container, forceMount, placement, ref, side, sideOffset, style, ...props }: TooltipContentProps): React.JSX.Element | null;
|
|
45
45
|
declare function TooltipWrapper({ children, content, delay, disabled, placement }: TooltipProps): React.JSX.Element;
|
|
46
46
|
export declare const Tooltip: typeof TooltipWrapper & {
|
|
47
47
|
Content: typeof TooltipContent;
|
|
@@ -9,6 +9,7 @@ import { composeEventHandlers } from "../../utils/compose-event-handlers.js";
|
|
|
9
9
|
import { cn } from "../../utils/cn.js";
|
|
10
10
|
const defaultContentPositioning = {
|
|
11
11
|
sideOffset: 8,
|
|
12
|
+
alignOffset: 0,
|
|
12
13
|
collisionPadding: 0
|
|
13
14
|
};
|
|
14
15
|
const TooltipProviderContext = React.createContext({
|
|
@@ -62,6 +63,7 @@ function TooltipRoot({ children, defaultOpen = false, delay, disabled = false, o
|
|
|
62
63
|
open,
|
|
63
64
|
placement: contentPositioning.placement ?? placement,
|
|
64
65
|
offset: contentPositioning.sideOffset,
|
|
66
|
+
alignmentOffset: contentPositioning.alignOffset,
|
|
65
67
|
collisionPadding: contentPositioning.collisionPadding,
|
|
66
68
|
flip: true,
|
|
67
69
|
shift: true
|
|
@@ -165,22 +167,23 @@ function TooltipTrigger({ children, asChild: _asChild = false }) {
|
|
|
165
167
|
}, { checkDefaultPrevented: false })
|
|
166
168
|
});
|
|
167
169
|
}
|
|
168
|
-
function TooltipContent({ align, alignOffset
|
|
170
|
+
function TooltipContent({ align, alignOffset = defaultContentPositioning.alignOffset, children, className, collisionPadding = defaultContentPositioning.collisionPadding, container, forceMount = false, placement, ref, side, sideOffset = defaultContentPositioning.sideOffset, style, ...props }) {
|
|
169
171
|
const context = useTooltipRootContext("Tooltip.Content");
|
|
170
172
|
React.useEffect(() => {
|
|
171
173
|
const resolvedPlacement = side === undefined ? placement : placementFromSideAlign(side, align, placement ?? "bottom");
|
|
172
174
|
context.setContentPositioning({
|
|
173
175
|
...(resolvedPlacement === undefined ? {} : { placement: resolvedPlacement }),
|
|
174
176
|
sideOffset,
|
|
177
|
+
alignOffset,
|
|
175
178
|
collisionPadding
|
|
176
179
|
});
|
|
177
180
|
return () => context.setContentPositioning(defaultContentPositioning);
|
|
178
|
-
}, [align, collisionPadding, context, placement, side, sideOffset]);
|
|
181
|
+
}, [align, alignOffset, collisionPadding, context, placement, side, sideOffset]);
|
|
179
182
|
if (!context.open && !forceMount) {
|
|
180
183
|
return null;
|
|
181
184
|
}
|
|
182
185
|
const placementParts = getPlacementParts(context.resolvedPlacement);
|
|
183
|
-
const content = (_jsx("span", { ...props, ref: composeRefs(ref, context.floatingRef), id: context.contentId, className: cn("
|
|
186
|
+
const content = (_jsx("span", { ...props, ref: composeRefs(ref, context.floatingRef), id: context.contentId, className: cn("zvk-ui-tooltip", className), "data-align": placementParts.align, "data-side": placementParts.side, hidden: context.open ? undefined : true, role: "tooltip", style: { ...context.floatingStyle, ...style }, children: children }));
|
|
184
187
|
return (_jsx(Portal, { ...(container === undefined ? {} : { container }), children: content }));
|
|
185
188
|
}
|
|
186
189
|
function TooltipWrapper({ children, content, delay = 0, disabled = false, placement = "bottom" }) {
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { useComposedRefs } from "./use-composed-refs.js";
|
|
2
|
-
export type {
|
|
2
|
+
export type { ZvkUiPossibleRef } from "./use-composed-refs.js";
|
|
3
3
|
export { useControllableState } from "./use-controllable-state.js";
|
|
4
|
-
export type {
|
|
4
|
+
export type { ZvkUiSetStateAction, UseControllableStateOptions } from "./use-controllable-state.js";
|
|
5
5
|
export { useDisclosure } from "./use-disclosure.js";
|
|
6
6
|
export type { UseDisclosureOptions, UseDisclosureReturn } from "./use-disclosure.js";
|
|
7
7
|
export { useEvent } from "./use-event.js";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
export type
|
|
3
|
-
export declare function useComposedRefs<Value>(...refs:
|
|
2
|
+
export type ZvkUiPossibleRef<Value> = React.Ref<Value> | undefined;
|
|
3
|
+
export declare function useComposedRefs<Value>(...refs: ZvkUiPossibleRef<Value>[]): React.RefCallback<Value>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type ZvkUiSetStateAction<Value> = Value | ((previous: Value) => Value);
|
|
2
2
|
export interface UseControllableStateOptions<Value> {
|
|
3
3
|
value?: Value;
|
|
4
4
|
defaultValue: Value;
|
|
5
5
|
onChange?: (value: Value) => void;
|
|
6
6
|
}
|
|
7
|
-
export declare function useControllableState<Value>({ value, defaultValue, onChange }: UseControllableStateOptions<Value>): readonly [Value, (next:
|
|
7
|
+
export declare function useControllableState<Value>({ value, defaultValue, onChange }: UseControllableStateOptions<Value>): readonly [Value, (next: ZvkUiSetStateAction<Value>) => void];
|
|
@@ -1,18 +1,30 @@
|
|
|
1
1
|
function hasBrowserApis() {
|
|
2
2
|
return typeof window !== "undefined" && typeof document !== "undefined";
|
|
3
3
|
}
|
|
4
|
+
function scheduleFrame(callback) {
|
|
5
|
+
if (typeof window.requestAnimationFrame === "function") {
|
|
6
|
+
const frame = window.requestAnimationFrame(callback);
|
|
7
|
+
return () => {
|
|
8
|
+
if (typeof window.cancelAnimationFrame === "function") {
|
|
9
|
+
window.cancelAnimationFrame(frame);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
const timeout = window.setTimeout(callback, 0);
|
|
14
|
+
return () => {
|
|
15
|
+
window.clearTimeout(timeout);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
4
18
|
export function autoUpdateFloating(params) {
|
|
5
19
|
const { enabled, reference, floating, update } = params;
|
|
6
20
|
if (!hasBrowserApis() || !enabled || reference === null || floating === null) {
|
|
7
21
|
return () => { };
|
|
8
22
|
}
|
|
9
|
-
let
|
|
23
|
+
let cancelScheduledUpdate = null;
|
|
10
24
|
const scheduleUpdate = () => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
frameRequest = window.requestAnimationFrame(() => {
|
|
15
|
-
frameRequest = null;
|
|
25
|
+
cancelScheduledUpdate?.();
|
|
26
|
+
cancelScheduledUpdate = scheduleFrame(() => {
|
|
27
|
+
cancelScheduledUpdate = null;
|
|
16
28
|
update();
|
|
17
29
|
});
|
|
18
30
|
};
|
|
@@ -40,9 +52,9 @@ export function autoUpdateFloating(params) {
|
|
|
40
52
|
for (const cleanup of cleanupFns) {
|
|
41
53
|
cleanup();
|
|
42
54
|
}
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
55
|
+
if (cancelScheduledUpdate !== null) {
|
|
56
|
+
cancelScheduledUpdate();
|
|
57
|
+
cancelScheduledUpdate = null;
|
|
46
58
|
}
|
|
47
59
|
};
|
|
48
60
|
}
|
|
@@ -3,7 +3,10 @@ import { detectOverflow } from "./detect-overflow.js";
|
|
|
3
3
|
function getCenteredOffset(referenceSize, floatingSize) {
|
|
4
4
|
return (referenceSize - floatingSize) / 2;
|
|
5
5
|
}
|
|
6
|
-
function
|
|
6
|
+
function applyAlignmentOffset(value, align, offset) {
|
|
7
|
+
return align === "end" ? value - offset : value + offset;
|
|
8
|
+
}
|
|
9
|
+
function getPlacementCoords(placement, reference, floating, offset, alignmentOffset) {
|
|
7
10
|
const { side, align } = parsePlacement(placement);
|
|
8
11
|
if (side === "top" || side === "bottom") {
|
|
9
12
|
const baseY = side === "top" ? reference.y - floating.height - offset : reference.y + reference.height + offset;
|
|
@@ -17,6 +20,7 @@ function getPlacementCoords(placement, reference, floating, offset) {
|
|
|
17
20
|
else {
|
|
18
21
|
x = reference.x + getCenteredOffset(reference.width, floating.width);
|
|
19
22
|
}
|
|
23
|
+
x = applyAlignmentOffset(x, align, alignmentOffset);
|
|
20
24
|
return { x, y: baseY };
|
|
21
25
|
}
|
|
22
26
|
const baseX = side === "left" ? reference.x - floating.width - offset : reference.x + reference.width + offset;
|
|
@@ -30,10 +34,11 @@ function getPlacementCoords(placement, reference, floating, offset) {
|
|
|
30
34
|
else {
|
|
31
35
|
y = reference.y + getCenteredOffset(reference.height, floating.height);
|
|
32
36
|
}
|
|
37
|
+
y = applyAlignmentOffset(y, align, alignmentOffset);
|
|
33
38
|
return { x: baseX, y };
|
|
34
39
|
}
|
|
35
|
-
function getOverflowForPlacement(placement, reference, floating, boundary, offset, collisionPadding) {
|
|
36
|
-
const { x, y } = getPlacementCoords(placement, reference, floating, offset);
|
|
40
|
+
function getOverflowForPlacement(placement, reference, floating, boundary, offset, alignmentOffset, collisionPadding) {
|
|
41
|
+
const { x, y } = getPlacementCoords(placement, reference, floating, offset, alignmentOffset);
|
|
37
42
|
return detectOverflow({
|
|
38
43
|
boundary,
|
|
39
44
|
collisionPadding,
|
|
@@ -46,22 +51,22 @@ function getOverflowForPlacement(placement, reference, floating, boundary, offse
|
|
|
46
51
|
});
|
|
47
52
|
}
|
|
48
53
|
export function computeFloatingPosition(options) {
|
|
49
|
-
const { reference, floating, boundary, placement: rawPlacement = "bottom", strategy = "absolute", offset = 0, collisionPadding = 0, matchReferenceWidth = false, maxHeight, flip = true, shift = true } = options;
|
|
54
|
+
const { reference, floating, boundary, placement: rawPlacement = "bottom", strategy = "absolute", offset = 0, alignmentOffset = 0, collisionPadding = 0, matchReferenceWidth = false, maxHeight, flip = true, shift = true } = options;
|
|
50
55
|
const parsed = parsePlacement(rawPlacement);
|
|
51
56
|
const defaultPlacement = buildPlacement(parsed.side, parsed.align);
|
|
52
57
|
let currentPlacement = defaultPlacement;
|
|
53
|
-
let basePlacement = getPlacementCoords(currentPlacement, reference, floating, offset);
|
|
58
|
+
let basePlacement = getPlacementCoords(currentPlacement, reference, floating, offset, alignmentOffset);
|
|
54
59
|
if (flip) {
|
|
55
|
-
const overflow = getOverflowForPlacement(currentPlacement, reference, floating, boundary, offset, collisionPadding);
|
|
60
|
+
const overflow = getOverflowForPlacement(currentPlacement, reference, floating, boundary, offset, alignmentOffset, collisionPadding);
|
|
56
61
|
const { side: currentSide } = parsePlacement(currentPlacement);
|
|
57
62
|
const overflowSide = overflow[currentSide];
|
|
58
63
|
if (overflowSide > 0) {
|
|
59
64
|
const oppositeSide = getOppositeSide(currentSide);
|
|
60
65
|
const oppositePlacement = buildPlacement(oppositeSide, parsed.align);
|
|
61
|
-
const oppositeOverflow = getOverflowForPlacement(oppositePlacement, reference, floating, boundary, offset, collisionPadding);
|
|
66
|
+
const oppositeOverflow = getOverflowForPlacement(oppositePlacement, reference, floating, boundary, offset, alignmentOffset, collisionPadding);
|
|
62
67
|
if (oppositeOverflow[oppositeSide] < overflowSide) {
|
|
63
68
|
currentPlacement = oppositePlacement;
|
|
64
|
-
basePlacement = getPlacementCoords(currentPlacement, reference, floating, offset);
|
|
69
|
+
basePlacement = getPlacementCoords(currentPlacement, reference, floating, offset, alignmentOffset);
|
|
65
70
|
}
|
|
66
71
|
}
|
|
67
72
|
}
|
|
@@ -6,6 +6,7 @@ export type UseFloatingPositionOptions = {
|
|
|
6
6
|
placement?: import("./floating-types.js").FloatingPlacement;
|
|
7
7
|
strategy?: import("./floating-types.js").FloatingStrategy;
|
|
8
8
|
offset?: number;
|
|
9
|
+
alignmentOffset?: number;
|
|
9
10
|
collisionPadding?: number;
|
|
10
11
|
matchReferenceWidth?: boolean;
|
|
11
12
|
maxHeight?: number;
|
|
@@ -3,7 +3,7 @@ import * as React from "react";
|
|
|
3
3
|
import { computeFloatingPosition } from "./compute-position.js";
|
|
4
4
|
import { autoUpdateFloating } from "./auto-update.js";
|
|
5
5
|
export function useFloatingPosition(options) {
|
|
6
|
-
const { open, placement = "bottom", strategy = "absolute", offset = 0, collisionPadding = 0, matchReferenceWidth = false, maxHeight, flip = true, shift = true, boundary } = options;
|
|
6
|
+
const { open, placement = "bottom", strategy = "absolute", offset = 0, alignmentOffset = 0, collisionPadding = 0, matchReferenceWidth = false, maxHeight, flip = true, shift = true, boundary } = options;
|
|
7
7
|
const [referenceEl, setReferenceEl] = React.useState(null);
|
|
8
8
|
const [floatingEl, setFloatingEl] = React.useState(null);
|
|
9
9
|
const [style, setStyle] = React.useState({
|
|
@@ -62,6 +62,7 @@ export function useFloatingPosition(options) {
|
|
|
62
62
|
placement: placement,
|
|
63
63
|
strategy: strategy,
|
|
64
64
|
offset,
|
|
65
|
+
alignmentOffset,
|
|
65
66
|
collisionPadding,
|
|
66
67
|
matchReferenceWidth,
|
|
67
68
|
...(maxHeight === undefined ? {} : { maxHeight }),
|
|
@@ -73,9 +74,9 @@ export function useFloatingPosition(options) {
|
|
|
73
74
|
left: `${computed.x}px`,
|
|
74
75
|
top: `${computed.y}px`,
|
|
75
76
|
width: matchReferenceWidth ? `${referenceEl?.offsetWidth ?? computed.referenceWidth}px` : "auto",
|
|
76
|
-
"--
|
|
77
|
-
"--
|
|
78
|
-
"--
|
|
77
|
+
"--zvk-ui-floating-reference-width": `${computed.referenceWidth}px`,
|
|
78
|
+
"--zvk-ui-floating-available-width": `${computed.availableWidth}px`,
|
|
79
|
+
"--zvk-ui-floating-available-height": `${computed.availableHeight}px`
|
|
79
80
|
});
|
|
80
81
|
setResolvedPlacement(computed.placement);
|
|
81
82
|
}, [
|
|
@@ -83,6 +84,7 @@ export function useFloatingPosition(options) {
|
|
|
83
84
|
placement,
|
|
84
85
|
strategy,
|
|
85
86
|
offset,
|
|
87
|
+
alignmentOffset,
|
|
86
88
|
collisionPadding,
|
|
87
89
|
matchReferenceWidth,
|
|
88
90
|
maxHeight,
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const overlayStack = [];
|
|
2
|
+
let nextOverlayId = 1;
|
|
2
3
|
export function pushOverlay(node) {
|
|
3
|
-
const id = `
|
|
4
|
+
const id = `zvk-ui-overlay-${nextOverlayId}`;
|
|
5
|
+
nextOverlayId += 1;
|
|
4
6
|
overlayStack.push({ id, node });
|
|
5
7
|
return id;
|
|
6
8
|
}
|
|
@@ -35,6 +37,7 @@ export function isInOverlayStack(node) {
|
|
|
35
37
|
}
|
|
36
38
|
export function resetOverlayStackForTests() {
|
|
37
39
|
overlayStack.length = 0;
|
|
40
|
+
nextOverlayId = 1;
|
|
38
41
|
}
|
|
39
42
|
export function getOverlayStackLength() {
|
|
40
43
|
return overlayStack.length;
|