nish-ui 2.0.2 → 2.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.
Files changed (62) hide show
  1. package/README.md +18 -8
  2. package/dist/chart.js +1 -1
  3. package/dist/elements-all.js +13 -13
  4. package/dist/elements-charts.js +1 -1
  5. package/dist/elements-data.js +1 -1
  6. package/dist/elements-forms.js +1 -1
  7. package/dist/elements.js +3 -3
  8. package/dist/esm/components/app-shell.js +145 -45
  9. package/dist/esm/components/breadcrumbs.js +1 -1
  10. package/dist/esm/components/calendar-classes.js +325 -0
  11. package/dist/esm/components/calendar.js +263 -0
  12. package/dist/esm/components/canvas/route.js +56 -20
  13. package/dist/esm/components/carousel-classes.js +27 -0
  14. package/dist/esm/components/carousel.js +317 -0
  15. package/dist/esm/components/command.js +2 -27
  16. package/dist/esm/components/context-menu.js +199 -0
  17. package/dist/esm/components/date-picker.js +208 -0
  18. package/dist/esm/components/display-classes.js +10 -13
  19. package/dist/esm/components/display.js +22 -19
  20. package/dist/esm/components/drawer.js +139 -0
  21. package/dist/esm/components/filters.js +1 -1
  22. package/dist/esm/components/flow.js +1 -1
  23. package/dist/esm/components/hover-card.js +221 -0
  24. package/dist/esm/components/icons.js +17 -0
  25. package/dist/esm/components/inbox.js +2 -1
  26. package/dist/esm/components/lazy-module.js +53 -0
  27. package/dist/esm/components/menu.js +344 -0
  28. package/dist/esm/components/modal.js +173 -0
  29. package/dist/esm/components/more-sheet.js +52 -0
  30. package/dist/esm/components/multi-select.js +420 -0
  31. package/dist/esm/components/nav-items.js +138 -0
  32. package/dist/esm/components/nav.js +13 -174
  33. package/dist/esm/components/navigate.js +33 -0
  34. package/dist/esm/components/overlay-core.js +221 -0
  35. package/dist/esm/components/overlay-dialog.js +255 -0
  36. package/dist/esm/components/overlay-position.js +163 -0
  37. package/dist/esm/components/overlay.js +7 -1441
  38. package/dist/esm/components/popover.js +92 -0
  39. package/dist/esm/components/segmented.js +2 -1
  40. package/dist/esm/components/split.js +1 -1
  41. package/dist/esm/components/strings.js +25 -0
  42. package/dist/esm/components/tooltip.js +177 -0
  43. package/dist/esm/components/tree-view-classes.js +57 -0
  44. package/dist/esm/components/tree-view.js +319 -0
  45. package/dist/esm/components/virtual-table.js +245 -0
  46. package/dist/esm/components/virtual.js +291 -0
  47. package/dist/esm/inbox.js +12 -0
  48. package/dist/esm/index.js +61 -2
  49. package/dist/esm/runtime.js +1 -1
  50. package/dist/esm/service-tokens.js +6 -0
  51. package/dist/esm/theme.js +2 -2
  52. package/dist/esm/virtual-range.js +73 -0
  53. package/dist/format.js +1 -1
  54. package/dist/inbox.d.ts +238 -0
  55. package/dist/index.d.ts +1030 -777
  56. package/dist/nish-components.css +2 -0
  57. package/dist/nish-components.min.css +1 -1
  58. package/dist/service-tokens.d.ts +60 -0
  59. package/dist/theme.d.ts +50 -0
  60. package/dist/theme.global.js +28 -3
  61. package/dist/theme.js +28 -3
  62. package/package.json +17 -1
@@ -0,0 +1,92 @@
1
+ "use client";
2
+
3
+ // src/components/popover.tsx
4
+ import { useEffect } from "react";
5
+ import { createPortal } from "react-dom";
6
+ import { cn } from "../cn.js";
7
+ import { useIsClient } from "./client.js";
8
+ import { useLatest } from "./latest.js";
9
+ import { useNishConfig } from "./provider.js";
10
+ import { focusables, layerHost, useMergedRef } from "./overlay-core.js";
11
+ import { useAnchoredPosition, floatingStyle, useDismiss, useReturnFocus } from "./overlay-position.js";
12
+ import { jsx } from "react/jsx-runtime";
13
+ function Popover({
14
+ open,
15
+ onOpenChange,
16
+ dismissOnOutside = true,
17
+ anchor,
18
+ side = "bottom",
19
+ align = "start",
20
+ width,
21
+ "aria-label": ariaLabel,
22
+ className,
23
+ children,
24
+ ref,
25
+ style,
26
+ onKeyDown: userKeyDown,
27
+ ...rest
28
+ }) {
29
+ const config = useNishConfig();
30
+ const isClient = useIsClient();
31
+ const [panelRef, setPanelRef] = useMergedRef(ref);
32
+ const pos = useAnchoredPosition(anchor, panelRef, open, side, align);
33
+ const onOpenChangeRef = useLatest(onOpenChange);
34
+ const outsideRef = useLatest(dismissOnOutside);
35
+ useDismiss(open, panelRef, anchor, (reason) => {
36
+ if (reason === "outside" && !outsideRef.current) return;
37
+ onOpenChangeRef.current(false, reason);
38
+ });
39
+ useReturnFocus(open, panelRef, anchor);
40
+ useEffect(() => {
41
+ if (!open) return;
42
+ const t = window.setTimeout(() => {
43
+ const p = panelRef.current;
44
+ if (p && !p.contains(document.activeElement)) (p.querySelector("[data-autofocus],[autofocus]") ?? p).focus();
45
+ }, 0);
46
+ return () => window.clearTimeout(t);
47
+ }, [open, panelRef]);
48
+ if (!open || !isClient) return null;
49
+ function onKeyDown(e) {
50
+ userKeyDown?.(e);
51
+ if (e.key !== "Tab" || !panelRef.current) return;
52
+ const nodes = focusables(panelRef.current);
53
+ const active = document.activeElement;
54
+ const atStart = nodes.length === 0 || active === nodes[0] || active === panelRef.current;
55
+ const atEnd = nodes.length === 0 || active === nodes[nodes.length - 1];
56
+ if (e.shiftKey && atStart || !e.shiftKey && atEnd) {
57
+ e.preventDefault();
58
+ onOpenChangeRef.current(false, "tab");
59
+ }
60
+ }
61
+ return createPortal(
62
+ /* @__PURE__ */ jsx(
63
+ "div",
64
+ {
65
+ ...rest,
66
+ ref: setPanelRef,
67
+ role: "dialog",
68
+ "aria-label": ariaLabel,
69
+ tabIndex: -1,
70
+ "data-side": pos?.side,
71
+ "data-state": "open",
72
+ onKeyDown,
73
+ style: floatingStyle(pos, {
74
+ ...style,
75
+ width,
76
+ maxHeight: pos?.maxHeight,
77
+ zIndex: "var(--nish-z-dropdown, 40)"
78
+ }),
79
+ className: cn(
80
+ "max-w-[calc(100vw-1rem)] overflow-y-auto overscroll-contain rounded-lg border border-th-line bg-th-elevated p-3 text-sm text-th-hi2 shadow-pop outline-none",
81
+ "animate-[nish-fade-in_120ms_ease-out]",
82
+ className
83
+ ),
84
+ children
85
+ }
86
+ ),
87
+ layerHost(anchor.current, config.portalContainer)
88
+ );
89
+ }
90
+ export {
91
+ Popover
92
+ };
@@ -5,7 +5,8 @@ import { useEffect, useId, useRef, useState } from "react";
5
5
  import { cn } from "../cn.js";
6
6
  import { useScrollEdges } from "./layout-vars.js";
7
7
  import { revealInRow } from "./nav.js";
8
- import { FloatingTip, keyboardFocused, touchTracker } from "./overlay.js";
8
+ import { keyboardFocused, touchTracker } from "./overlay-classes.js";
9
+ import { FloatingTip } from "./tooltip.js";
9
10
  import { isRtl } from "./client.js";
10
11
  import { SEGMENTED_SELECTED, SEGMENTED_SIZE, setRef } from "./forms-classes.js";
11
12
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -18,7 +18,7 @@ import {
18
18
  import { isRtl, useIsoLayoutEffect } from "./client.js";
19
19
  import { useMediaQuery } from "./hooks.js";
20
20
  import { ScrollRow } from "./nav.js";
21
- import { Tooltip } from "./overlay.js";
21
+ import { Tooltip } from "./tooltip.js";
22
22
  import { useNishStrings } from "./provider.js";
23
23
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
24
24
  function nodeAt(node, path) {
@@ -4,6 +4,8 @@ var DEFAULT_STRINGS = {
4
4
  cancel: "Cancel",
5
5
  menu: "Menu",
6
6
  back: "Back: ",
7
+ contextMenu: "Actions",
8
+ sortAnnounce: (header, dir) => dir ? `Sorted by ${header}, ${dir === "asc" ? "ascending" : "descending"}` : "Sorting cleared",
7
9
  dismiss: "Dismiss",
8
10
  moreCount: (count) => `${count} more`,
9
11
  copy: "Copy",
@@ -21,6 +23,29 @@ var DEFAULT_STRINGS = {
21
23
  noMatches: "No matches",
22
24
  clear: "Clear",
23
25
  searching: "Searching\u2026",
26
+ invalidDate: "Enter a valid date.",
27
+ chooseDate: "Choose date",
28
+ changeDate: (date) => `Change date, ${date}`,
29
+ previousMonth: "Previous month",
30
+ nextMonth: "Next month",
31
+ month: "Month",
32
+ year: "Year",
33
+ dayToken: "DD",
34
+ monthToken: "MM",
35
+ yearToken: "YYYY",
36
+ optionAdded: (l) => `Added ${l}`,
37
+ optionRemoved: (l) => `Removed ${l}`,
38
+ clearAll: "Clear all",
39
+ maxSelected: (n) => `You can pick up to ${n}`,
40
+ carouselRole: "carousel",
41
+ slideRole: "slide",
42
+ slideLabel: (n, c) => `${n} of ${c}`,
43
+ previousSlide: "Previous slide",
44
+ nextSlide: "Next slide",
45
+ goToSlide: (n) => `Go to slide ${n}`,
46
+ slidePicker: "Choose slide",
47
+ startRotation: "Start slide rotation",
48
+ stopRotation: "Stop slide rotation",
24
49
  searchPlaceholder: "Search\u2026",
25
50
  noResults: "No results",
26
51
  results: "Results",
@@ -0,0 +1,177 @@
1
+ "use client";
2
+
3
+ // src/components/tooltip.tsx
4
+ import { cloneElement, isValidElement, useCallback, useEffect, useId, useRef, useState } from "react";
5
+ import { createPortal } from "react-dom";
6
+ import { cn } from "../cn.js";
7
+ import { shared } from "../runtime.js";
8
+ import { useIsoLayoutEffect } from "./client.js";
9
+ import { useNishConfig } from "./provider.js";
10
+ import { keyboardFocused, touchTracker } from "./overlay-classes.js";
11
+ import { FOCUSABLE, layerHost, useMergedRef } from "./overlay-core.js";
12
+ import { EDGE, useAnchoredPosition, floatingStyle } from "./overlay-position.js";
13
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
14
+ var TIP_MAX_WIDTH = 320;
15
+ var TIP_GRACE_MS = 100;
16
+ var openTip = () => shared("tooltip", () => ({ close: null }));
17
+ var FOCUSABLE_HOST_TAGS = /* @__PURE__ */ new Set(["button", "a", "input", "select", "textarea", "summary"]);
18
+ function Tooltip({ tip, children, className, side = "top", as = "span", focusable, variant = "default", ref, ...rest }) {
19
+ const [triggerRef, setTriggerRef] = useMergedRef(ref);
20
+ const [open, setOpen] = useState(false);
21
+ const id = useId();
22
+ const graceTimer = useRef(0);
23
+ const only = isValidElement(children) ? children : null;
24
+ const staticInner = only !== null && typeof only.type === "string" && FOCUSABLE_HOST_TAGS.has(only.type);
25
+ const [measuredInner, setMeasuredInner] = useState(false);
26
+ useIsoLayoutEffect(() => {
27
+ const el = triggerRef.current;
28
+ const found = only !== null && !!el && el.querySelector(FOCUSABLE) !== null;
29
+ setMeasuredInner(found);
30
+ });
31
+ const inner = only !== null && (staticInner || measuredInner);
32
+ useEffect(() => {
33
+ const el = triggerRef.current;
34
+ if (!el) return;
35
+ const touch = touchTracker();
36
+ const show = () => {
37
+ window.clearTimeout(graceTimer.current);
38
+ setOpen(true);
39
+ };
40
+ const hide = () => {
41
+ window.clearTimeout(graceTimer.current);
42
+ setOpen(false);
43
+ };
44
+ const hideSoon = () => {
45
+ window.clearTimeout(graceTimer.current);
46
+ graceTimer.current = window.setTimeout(() => setOpen(false), TIP_GRACE_MS);
47
+ };
48
+ const onMouseEnter = () => {
49
+ if (!touch.recent()) show();
50
+ };
51
+ const onFocusIn = (e) => {
52
+ if (e.target === el || e.target instanceof Element && keyboardFocused(e.target)) show();
53
+ };
54
+ const onPointerDown = (e) => {
55
+ if (e.target !== el) hide();
56
+ };
57
+ el.addEventListener("pointerenter", touch.onPointer);
58
+ el.addEventListener("pointerdown", touch.onPointer);
59
+ el.addEventListener("pointerdown", onPointerDown);
60
+ el.addEventListener("mouseenter", onMouseEnter);
61
+ el.addEventListener("mouseleave", hideSoon);
62
+ el.addEventListener("focusin", onFocusIn);
63
+ el.addEventListener("focusout", hide);
64
+ return () => {
65
+ window.clearTimeout(graceTimer.current);
66
+ el.removeEventListener("pointerenter", touch.onPointer);
67
+ el.removeEventListener("pointerdown", touch.onPointer);
68
+ el.removeEventListener("pointerdown", onPointerDown);
69
+ el.removeEventListener("mouseenter", onMouseEnter);
70
+ el.removeEventListener("mouseleave", hideSoon);
71
+ el.removeEventListener("focusin", onFocusIn);
72
+ el.removeEventListener("focusout", hide);
73
+ };
74
+ }, [triggerRef]);
75
+ useEffect(() => {
76
+ if (!open) return;
77
+ const slot = openTip();
78
+ const close = () => {
79
+ window.clearTimeout(graceTimer.current);
80
+ setOpen(false);
81
+ };
82
+ if (slot.close && slot.close !== close) slot.close();
83
+ slot.close = close;
84
+ return () => {
85
+ if (slot.close === close) slot.close = null;
86
+ };
87
+ }, [open]);
88
+ useEffect(() => {
89
+ if (!open) return;
90
+ const onKey = (e) => {
91
+ if (e.key !== "Escape") return;
92
+ e.stopPropagation();
93
+ setOpen(false);
94
+ };
95
+ document.addEventListener("keydown", onKey, true);
96
+ return () => document.removeEventListener("keydown", onKey, true);
97
+ }, [open]);
98
+ const onTipPointer = useCallback((over) => {
99
+ window.clearTimeout(graceTimer.current);
100
+ if (!over) graceTimer.current = window.setTimeout(() => setOpen(false), TIP_GRACE_MS);
101
+ }, []);
102
+ const wrapperFocusable = focusable ?? !inner;
103
+ const a11y = {
104
+ tabIndex: wrapperFocusable ? 0 : void 0,
105
+ "aria-describedby": open && !inner ? id : void 0,
106
+ "data-state": open ? "open" : "closed"
107
+ };
108
+ const hint = variant === "hint" && "cursor-help underline decoration-th-hi3 decoration-dotted underline-offset-2";
109
+ let content = children;
110
+ if (inner && only) {
111
+ const existing = only.props["aria-describedby"];
112
+ const describedby = open ? [typeof existing === "string" ? existing : "", id].filter(Boolean).join(" ") : existing;
113
+ content = cloneElement(only, {
114
+ "aria-describedby": describedby || void 0
115
+ });
116
+ }
117
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
118
+ as === "tr" ? /* @__PURE__ */ jsx("tr", { ...rest, ref: setTriggerRef, className: cn(hint, className), ...a11y, children: content }) : /* @__PURE__ */ jsx(
119
+ "span",
120
+ {
121
+ ...rest,
122
+ ref: setTriggerRef,
123
+ className: cn(hint ? "inline" : "inline-flex items-center", hint, className),
124
+ ...a11y,
125
+ children: content
126
+ }
127
+ ),
128
+ open ? /* @__PURE__ */ jsx(
129
+ FloatingTip,
130
+ {
131
+ anchor: triggerRef,
132
+ id,
133
+ tip,
134
+ side,
135
+ onPointerEnter: () => onTipPointer(true),
136
+ onPointerLeave: () => onTipPointer(false)
137
+ }
138
+ ) : null
139
+ ] });
140
+ }
141
+ function FloatingTip({
142
+ anchor,
143
+ id,
144
+ tip,
145
+ side = "top",
146
+ onPointerEnter,
147
+ onPointerLeave
148
+ }) {
149
+ const config = useNishConfig();
150
+ const tipRef = useRef(null);
151
+ const pos = useAnchoredPosition(anchor, tipRef, true, side, "center");
152
+ return createPortal(
153
+ /* @__PURE__ */ jsx(
154
+ "span",
155
+ {
156
+ ref: tipRef,
157
+ id,
158
+ role: "tooltip",
159
+ "data-side": pos?.side,
160
+ "data-state": "open",
161
+ onPointerEnter,
162
+ onPointerLeave,
163
+ style: floatingStyle(pos, {
164
+ maxWidth: Math.min(TIP_MAX_WIDTH, (window.innerWidth || TIP_MAX_WIDTH) - 2 * EDGE),
165
+ zIndex: "var(--nish-z-tooltip, 100)"
166
+ }),
167
+ className: "block w-max rounded-lg border border-th-line-strong bg-th-elevated px-3 py-2 text-xs font-normal normal-case leading-snug tracking-normal text-th-hi shadow-pop",
168
+ children: tip
169
+ }
170
+ ),
171
+ layerHost(anchor.current, config.portalContainer)
172
+ );
173
+ }
174
+ export {
175
+ FloatingTip,
176
+ Tooltip
177
+ };
@@ -0,0 +1,57 @@
1
+ // src/components/tree-view-classes.ts
2
+ import { cn } from "../cn.js";
3
+ import { FORCED_MARK } from "./display-classes.js";
4
+ function hasChildren(node) {
5
+ return !!node.children && node.children.length > 0;
6
+ }
7
+ function visibleNodes(items, expanded) {
8
+ const out = [];
9
+ const walk = (nodes, level, parentId) => {
10
+ nodes.forEach((node, i) => {
11
+ out.push({ node, level, parentId, posInSet: i + 1, setSize: nodes.length });
12
+ if (hasChildren(node) && expanded.has(node.id)) walk(node.children, level + 1, node.id);
13
+ });
14
+ };
15
+ walk(items, 1, null);
16
+ return out;
17
+ }
18
+ function parentMap(items) {
19
+ const map = /* @__PURE__ */ new Map();
20
+ const walk = (nodes, parentId) => {
21
+ for (const node of nodes) {
22
+ if (!map.has(node.id)) map.set(node.id, parentId);
23
+ if (node.children) walk(node.children, node.id);
24
+ }
25
+ };
26
+ walk(items, null);
27
+ return map;
28
+ }
29
+ function duplicateIds(items) {
30
+ const seen = /* @__PURE__ */ new Set();
31
+ const dupes = [];
32
+ const walk = (nodes) => {
33
+ for (const node of nodes) {
34
+ if (seen.has(node.id)) {
35
+ if (!dupes.includes(node.id)) dupes.push(node.id);
36
+ } else seen.add(node.id);
37
+ if (node.children) walk(node.children);
38
+ }
39
+ };
40
+ walk(items);
41
+ return dupes;
42
+ }
43
+ function treeRowClass({ selected, disabled, className }) {
44
+ return cn(
45
+ "flex min-h-8 w-full cursor-pointer select-none items-center gap-1.5 rounded-md pe-2 text-start transition-colors pointer-coarse:min-h-11",
46
+ selected ? `bg-th-accent-soft font-medium text-th-accent ${FORCED_MARK}` : !disabled && "text-th-hi2 hover:bg-th-overlay hover:text-th-hi",
47
+ disabled && "cursor-default text-th-ghost forced-colors:text-[GrayText]",
48
+ className
49
+ );
50
+ }
51
+ export {
52
+ duplicateIds,
53
+ hasChildren,
54
+ parentMap,
55
+ treeRowClass,
56
+ visibleNodes
57
+ };