@zvk/ui 0.1.7 → 0.1.9

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.
Files changed (59) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +3 -3
  3. package/dist/components/alert-dialog/alert-dialog.d.ts +1 -1
  4. package/dist/components/alert-dialog/alert-dialog.js +18 -10
  5. package/dist/components/combobox/combobox.js +3 -1
  6. package/dist/components/command/command-filter.js +1 -1
  7. package/dist/components/command/command.d.ts +5 -0
  8. package/dist/components/command/command.js +9 -2
  9. package/dist/components/command/index.d.ts +1 -1
  10. package/dist/components/context-menu/context-menu.js +1 -1
  11. package/dist/components/date-range-picker/date-range-picker.d.ts +27 -0
  12. package/dist/components/date-range-picker/date-range-picker.js +193 -0
  13. package/dist/components/date-range-picker/index.d.ts +2 -0
  14. package/dist/components/date-range-picker/index.js +2 -0
  15. package/dist/components/dialog/dialog.d.ts +1 -1
  16. package/dist/components/dialog/dialog.js +19 -14
  17. package/dist/components/dropdown-menu/dropdown-menu.d.ts +2 -2
  18. package/dist/components/dropdown-menu/dropdown-menu.js +24 -19
  19. package/dist/components/file-dropzone/file-dropzone.d.ts +25 -0
  20. package/dist/components/file-dropzone/file-dropzone.js +171 -0
  21. package/dist/components/file-dropzone/index.d.ts +2 -0
  22. package/dist/components/file-dropzone/index.js +2 -0
  23. package/dist/components/form/form.d.ts +16 -1
  24. package/dist/components/form/form.js +13 -2
  25. package/dist/components/form/index.d.ts +1 -1
  26. package/dist/components/hover-card/hover-card.d.ts +1 -1
  27. package/dist/components/hover-card/hover-card.js +12 -3
  28. package/dist/components/index.d.ts +6 -0
  29. package/dist/components/index.js +3 -0
  30. package/dist/components/kbd/index.d.ts +2 -0
  31. package/dist/components/kbd/index.js +1 -0
  32. package/dist/components/kbd/kbd.d.ts +15 -0
  33. package/dist/components/kbd/kbd.js +10 -0
  34. package/dist/components/menubar/menubar.js +1 -1
  35. package/dist/components/popover/popover.d.ts +1 -1
  36. package/dist/components/popover/popover.js +14 -24
  37. package/dist/components/select/select.d.ts +1 -1
  38. package/dist/components/select/select.js +88 -8
  39. package/dist/components/sheet/sheet.d.ts +1 -1
  40. package/dist/components/sheet/sheet.js +17 -12
  41. package/dist/components/table/index.d.ts +1 -1
  42. package/dist/components/table/table.d.ts +37 -0
  43. package/dist/components/table/table.js +30 -2
  44. package/dist/components/toast/index.d.ts +1 -1
  45. package/dist/components/toast/toast.d.ts +18 -0
  46. package/dist/components/toast/toast.js +60 -0
  47. package/dist/components/tooltip/tooltip.d.ts +1 -1
  48. package/dist/components/tooltip/tooltip.js +12 -3
  49. package/dist/internal/floating/transform-origin.d.ts +2 -0
  50. package/dist/internal/floating/transform-origin.js +22 -0
  51. package/dist/internal/presence/index.d.ts +2 -0
  52. package/dist/internal/presence/index.js +2 -0
  53. package/dist/internal/presence/use-presence.d.ts +18 -0
  54. package/dist/internal/presence/use-presence.js +119 -0
  55. package/dist/styles.css +1710 -224
  56. package/dist/tokens/token-types.d.ts +4 -0
  57. package/dist/tokens/tokens.d.ts +41 -5
  58. package/dist/tokens/tokens.js +45 -9
  59. package/package.json +136 -61
@@ -4,6 +4,7 @@ import * as React from "react";
4
4
  import { Portal } from "../../internal/portal/index.js";
5
5
  import { useFloatingPosition } from "../../internal/floating/index.js";
6
6
  import { placementFromSideAlign } from "../../internal/floating/placement-aliases.js";
7
+ import { usePresence } from "../../internal/presence/index.js";
7
8
  import { useControllableState } from "../../hooks/use-controllable-state.js";
8
9
  import { composeEventHandlers } from "../../utils/compose-event-handlers.js";
9
10
  import { cn } from "../../utils/cn.js";
@@ -12,6 +13,7 @@ const defaultContentPositioning = {
12
13
  alignOffset: 0,
13
14
  collisionPadding: 0
14
15
  };
16
+ const tooltipExitDurationMs = 80;
15
17
  const TooltipProviderContext = React.createContext({
16
18
  delayDuration: 0
17
19
  });
@@ -167,8 +169,11 @@ function TooltipTrigger({ children, asChild: _asChild = false }) {
167
169
  }, { checkDefaultPrevented: false })
168
170
  });
169
171
  }
170
- function TooltipContent({ align, alignOffset = defaultContentPositioning.alignOffset, children, className, collisionPadding = defaultContentPositioning.collisionPadding, container, forceMount = false, placement, ref, side, sideOffset = defaultContentPositioning.sideOffset, style, ...props }) {
172
+ function TooltipContent({ align, alignOffset = defaultContentPositioning.alignOffset, children, className, collisionPadding = defaultContentPositioning.collisionPadding, container, forceMount = false, onAnimationEnd, placement, ref, side, sideOffset = defaultContentPositioning.sideOffset, style, ...props }) {
171
173
  const context = useTooltipRootContext("Tooltip.Content");
174
+ const presence = usePresence({ open: context.open, forceMount, exitDurationMs: tooltipExitDurationMs });
175
+ const wasOpenRef = React.useRef(context.open);
176
+ const isClosing = wasOpenRef.current && !context.open;
172
177
  React.useEffect(() => {
173
178
  const resolvedPlacement = side === undefined ? placement : placementFromSideAlign(side, align, placement ?? "bottom");
174
179
  context.setContentPositioning({
@@ -179,11 +184,15 @@ function TooltipContent({ align, alignOffset = defaultContentPositioning.alignOf
179
184
  });
180
185
  return () => context.setContentPositioning(defaultContentPositioning);
181
186
  }, [align, alignOffset, collisionPadding, context, placement, side, sideOffset]);
182
- if (!context.open && !forceMount) {
187
+ React.useEffect(() => {
188
+ wasOpenRef.current = context.open;
189
+ }, [context.open]);
190
+ if (!presence.present) {
183
191
  return null;
184
192
  }
185
193
  const placementParts = getPlacementParts(context.resolvedPlacement);
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 }));
194
+ const hidden = presence.inert && !isClosing && presence.motionState !== "exiting" ? true : undefined;
195
+ const content = (_jsx("span", { ...props, ref: composeRefs(ref, context.floatingRef), "aria-hidden": presence.inert ? true : undefined, id: context.contentId, inert: presence.inert ? true : undefined, className: cn("zvk-ui-tooltip", className), "data-align": placementParts.align, "data-side": placementParts.side, "data-state": presence.state, hidden: hidden, onAnimationEnd: composeEventHandlers(onAnimationEnd, presence.onExitComplete), role: "tooltip", style: { ...context.floatingStyle, ...style }, children: children }));
187
196
  return (_jsx(Portal, { ...(container === undefined ? {} : { container }), children: content }));
188
197
  }
189
198
  function TooltipWrapper({ children, content, delay = 0, disabled = false, placement = "bottom" }) {
@@ -0,0 +1,2 @@
1
+ import type { FloatingPlacement } from "./floating-types.js";
2
+ export declare function getFloatingTransformOrigin(placement: FloatingPlacement): string;
@@ -0,0 +1,22 @@
1
+ import { getOppositeSide } from "./middleware.js";
2
+ import { placementParts } from "./placement-aliases.js";
3
+ export function getFloatingTransformOrigin(placement) {
4
+ const { side, align } = placementParts(placement);
5
+ const anchor = getOppositeSide(side);
6
+ if (side === "top" || side === "bottom") {
7
+ if (align === "start") {
8
+ return `${anchor} left`;
9
+ }
10
+ if (align === "end") {
11
+ return `${anchor} right`;
12
+ }
13
+ return `${anchor} center`;
14
+ }
15
+ if (align === "start") {
16
+ return `${anchor} top`;
17
+ }
18
+ if (align === "end") {
19
+ return `${anchor} bottom`;
20
+ }
21
+ return `${anchor} center`;
22
+ }
@@ -0,0 +1,2 @@
1
+ export { usePresence } from "./use-presence.js";
2
+ export type { PresenceExitEvent, PresenceMotionState, PresenceState, UsePresenceOptions, UsePresenceResult } from "./use-presence.js";
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ export { usePresence } from "./use-presence.js";
@@ -0,0 +1,18 @@
1
+ import * as React from "react";
2
+ export type PresenceState = "open" | "closed";
3
+ export type PresenceMotionState = "idle" | "entering" | "exiting";
4
+ export type PresenceExitEvent = React.AnimationEvent<HTMLElement> | React.TransitionEvent<HTMLElement>;
5
+ export interface UsePresenceOptions {
6
+ open: boolean;
7
+ forceMount?: boolean;
8
+ exitDurationMs?: number;
9
+ disabled?: boolean;
10
+ }
11
+ export interface UsePresenceResult {
12
+ present: boolean;
13
+ state: PresenceState;
14
+ motionState: PresenceMotionState;
15
+ inert: boolean;
16
+ onExitComplete: (event: PresenceExitEvent) => void;
17
+ }
18
+ export declare function usePresence({ open, forceMount, exitDurationMs, disabled }: UsePresenceOptions): UsePresenceResult;
@@ -0,0 +1,119 @@
1
+ "use client";
2
+ import * as React from "react";
3
+ const defaultExitDurationMs = 180;
4
+ function normalizeDuration(durationMs) {
5
+ return Math.max(0, durationMs ?? defaultExitDurationMs);
6
+ }
7
+ export function usePresence({ open, forceMount = false, exitDurationMs, disabled = false }) {
8
+ const [present, setPresentState] = React.useState(() => open || forceMount);
9
+ const [motionState, setMotionState] = React.useState(() => open && !disabled ? "entering" : "idle");
10
+ const exitTimerRef = React.useRef(null);
11
+ const enterTimerRef = React.useRef(null);
12
+ const mountedRef = React.useRef(false);
13
+ const openRef = React.useRef(open);
14
+ const forceMountRef = React.useRef(forceMount);
15
+ const wasOpenRef = React.useRef(open);
16
+ const motionStateRef = React.useRef(motionState);
17
+ openRef.current = open;
18
+ forceMountRef.current = forceMount;
19
+ motionStateRef.current = motionState;
20
+ const clearExitTimer = React.useCallback(() => {
21
+ if (exitTimerRef.current !== null) {
22
+ clearTimeout(exitTimerRef.current);
23
+ exitTimerRef.current = null;
24
+ }
25
+ }, []);
26
+ const clearEnterTimer = React.useCallback(() => {
27
+ if (enterTimerRef.current !== null) {
28
+ clearTimeout(enterTimerRef.current);
29
+ enterTimerRef.current = null;
30
+ }
31
+ }, []);
32
+ const setPresent = React.useCallback((nextPresent) => {
33
+ if (!mountedRef.current) {
34
+ return;
35
+ }
36
+ setPresentState(nextPresent);
37
+ }, []);
38
+ const setSafeMotionState = React.useCallback((nextMotionState) => {
39
+ if (!mountedRef.current) {
40
+ return;
41
+ }
42
+ motionStateRef.current = nextMotionState;
43
+ setMotionState(nextMotionState);
44
+ }, []);
45
+ const completeExit = React.useCallback(() => {
46
+ if (openRef.current) {
47
+ return;
48
+ }
49
+ clearExitTimer();
50
+ setPresent(forceMountRef.current);
51
+ setSafeMotionState("idle");
52
+ }, [clearExitTimer, setPresent, setSafeMotionState]);
53
+ React.useEffect(() => {
54
+ mountedRef.current = true;
55
+ return () => {
56
+ mountedRef.current = false;
57
+ clearEnterTimer();
58
+ clearExitTimer();
59
+ };
60
+ }, [clearEnterTimer, clearExitTimer]);
61
+ React.useEffect(() => {
62
+ const durationMs = normalizeDuration(exitDurationMs);
63
+ clearEnterTimer();
64
+ clearExitTimer();
65
+ if (open) {
66
+ wasOpenRef.current = true;
67
+ setPresent(true);
68
+ if (disabled) {
69
+ setSafeMotionState("idle");
70
+ return;
71
+ }
72
+ setSafeMotionState("entering");
73
+ enterTimerRef.current = setTimeout(() => {
74
+ enterTimerRef.current = null;
75
+ if (openRef.current) {
76
+ setSafeMotionState("idle");
77
+ }
78
+ }, 0);
79
+ return;
80
+ }
81
+ if (!wasOpenRef.current) {
82
+ setPresent(forceMount);
83
+ setSafeMotionState("idle");
84
+ return;
85
+ }
86
+ wasOpenRef.current = false;
87
+ if (disabled || durationMs === 0) {
88
+ setPresent(forceMount);
89
+ setSafeMotionState("idle");
90
+ return;
91
+ }
92
+ setPresent(true);
93
+ setSafeMotionState("exiting");
94
+ exitTimerRef.current = setTimeout(completeExit, durationMs);
95
+ }, [
96
+ clearEnterTimer,
97
+ clearExitTimer,
98
+ completeExit,
99
+ disabled,
100
+ exitDurationMs,
101
+ forceMount,
102
+ open,
103
+ setPresent,
104
+ setSafeMotionState
105
+ ]);
106
+ const onExitComplete = React.useCallback((event) => {
107
+ if (event.currentTarget !== event.target || motionStateRef.current !== "exiting") {
108
+ return;
109
+ }
110
+ completeExit();
111
+ }, [completeExit]);
112
+ return {
113
+ present,
114
+ state: open ? "open" : "closed",
115
+ motionState,
116
+ inert: present && !open,
117
+ onExitComplete
118
+ };
119
+ }