nish-ui 1.9.0 → 2.0.1

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 (152) hide show
  1. package/README.md +218 -58
  2. package/dist/base-tailwind.css +1757 -0
  3. package/dist/base.css +1590 -1445
  4. package/dist/chart.d.ts +4 -1
  5. package/dist/chart.js +122 -49
  6. package/dist/elements-all.d.ts +8 -0
  7. package/dist/elements-all.js +178 -0
  8. package/dist/elements-charts.d.ts +71 -0
  9. package/dist/elements-charts.js +56 -57
  10. package/dist/elements-data.d.ts +71 -0
  11. package/dist/elements-data.js +5 -6
  12. package/dist/elements-forms.d.ts +71 -0
  13. package/dist/elements-forms.js +24 -25
  14. package/dist/elements.d.ts +71 -0
  15. package/dist/elements.js +4 -5
  16. package/dist/esm/chart-values.js +58 -0
  17. package/dist/esm/chart.js +10 -0
  18. package/dist/esm/cn.js +19 -0
  19. package/dist/esm/combobox-filter.js +13 -0
  20. package/dist/esm/components/accordion.js +166 -0
  21. package/dist/esm/components/app-shell.js +198 -0
  22. package/dist/esm/components/avatar-classes.js +28 -0
  23. package/dist/esm/components/avatar.js +113 -0
  24. package/dist/esm/components/breadcrumbs.js +154 -0
  25. package/dist/esm/components/canvas/follow-caption.js +32 -0
  26. package/dist/esm/components/canvas/follow.js +119 -0
  27. package/dist/esm/components/canvas/icons.js +70 -0
  28. package/dist/esm/components/canvas/index.js +10 -0
  29. package/dist/esm/components/canvas/layout.js +258 -0
  30. package/dist/esm/components/canvas/legend.js +93 -0
  31. package/dist/esm/components/canvas/minimap.js +127 -0
  32. package/dist/esm/components/canvas/node.js +87 -0
  33. package/dist/esm/components/canvas/route.js +262 -0
  34. package/dist/esm/components/canvas/system-canvas.js +837 -0
  35. package/dist/esm/components/canvas/types.js +10 -0
  36. package/dist/esm/components/canvas/view.js +47 -0
  37. package/dist/esm/components/chart-hooks.js +19 -0
  38. package/dist/esm/components/charts.js +467 -0
  39. package/dist/esm/components/client.js +24 -0
  40. package/dist/esm/components/combobox.js +343 -0
  41. package/dist/esm/components/command.js +403 -0
  42. package/dist/esm/components/data-classes.js +159 -0
  43. package/dist/esm/components/data.js +517 -0
  44. package/dist/esm/components/display-classes.js +130 -0
  45. package/dist/esm/components/display.js +755 -0
  46. package/dist/esm/components/error-boundary.js +64 -0
  47. package/dist/esm/components/feedback.js +136 -0
  48. package/dist/esm/components/file-dropzone.js +184 -0
  49. package/dist/esm/components/filters.js +108 -0
  50. package/dist/esm/components/flow.js +746 -0
  51. package/dist/esm/components/forms-classes.js +43 -0
  52. package/dist/esm/components/forms.js +581 -0
  53. package/dist/esm/components/hooks-classes.js +9 -0
  54. package/dist/esm/components/hooks.js +236 -0
  55. package/dist/esm/components/icons.js +96 -0
  56. package/dist/esm/components/inbox-classes.js +29 -0
  57. package/dist/esm/components/inbox.js +257 -0
  58. package/dist/esm/components/latest.js +13 -0
  59. package/dist/esm/components/layout-vars.js +96 -0
  60. package/dist/esm/components/layout.js +272 -0
  61. package/dist/esm/components/media.js +143 -0
  62. package/dist/esm/components/nav.js +614 -0
  63. package/dist/esm/components/overlay-classes.js +66 -0
  64. package/dist/esm/components/overlay.js +1461 -0
  65. package/dist/esm/components/pagination-classes.js +29 -0
  66. package/dist/esm/components/pagination.js +154 -0
  67. package/dist/esm/components/portal.js +16 -0
  68. package/dist/esm/components/primitives-classes.js +198 -0
  69. package/dist/esm/components/primitives.js +268 -0
  70. package/dist/esm/components/progress.js +77 -0
  71. package/dist/esm/components/provider.js +32 -0
  72. package/dist/esm/components/radio-group.js +186 -0
  73. package/dist/esm/components/resource-classes.js +133 -0
  74. package/dist/esm/components/resource.js +209 -0
  75. package/dist/esm/components/segmented.js +178 -0
  76. package/dist/esm/components/separator.js +38 -0
  77. package/dist/esm/components/service-tokens.js +221 -0
  78. package/dist/esm/components/settings.js +301 -0
  79. package/dist/esm/components/slider.js +262 -0
  80. package/dist/esm/components/split-classes.js +8 -0
  81. package/dist/esm/components/split.js +411 -0
  82. package/dist/esm/components/strings.js +119 -0
  83. package/dist/esm/components/table.js +144 -0
  84. package/dist/esm/components/tabs-classes.js +21 -0
  85. package/dist/esm/components/tabs.js +201 -0
  86. package/dist/esm/components/tag-input.js +257 -0
  87. package/dist/esm/components/theme-toggle.js +177 -0
  88. package/dist/esm/components/toast.js +361 -0
  89. package/dist/esm/components/url-state.js +118 -0
  90. package/dist/esm/components/visually-hidden.js +20 -0
  91. package/dist/esm/format.js +320 -0
  92. package/dist/esm/inbox-client.js +2 -0
  93. package/dist/esm/inbox-types.js +2 -0
  94. package/dist/esm/index.js +320 -0
  95. package/dist/esm/runtime.js +37 -0
  96. package/dist/esm/server/inbox/client.js +297 -0
  97. package/dist/esm/server/inbox/types.js +24 -0
  98. package/dist/esm/sparkline-path.js +59 -0
  99. package/dist/esm/split-layout.js +419 -0
  100. package/dist/esm/system-canvas.js +2 -0
  101. package/dist/esm/theme.js +804 -0
  102. package/dist/esm/tokens.mjs +425 -0
  103. package/dist/esm/url.js +20 -0
  104. package/dist/files.json +5 -1
  105. package/dist/fonts/LICENSE-Inter.txt +93 -0
  106. package/dist/format.d.ts +32 -18
  107. package/dist/format.js +227 -82
  108. package/dist/inbox-client.js +3 -1
  109. package/dist/index.d.ts +1686 -667
  110. package/dist/nish-components.css +4649 -4506
  111. package/dist/nish-components.min.css +1 -0
  112. package/dist/nish.css +1603 -1450
  113. package/dist/nish.min.css +1 -0
  114. package/dist/node/eslint.js +29 -14
  115. package/dist/node/th-check.js +29 -14
  116. package/dist/node/vite.d.ts +12 -0
  117. package/dist/node/vite.js +12 -2
  118. package/dist/server/hono.d.ts +15 -6
  119. package/dist/server/hono.js +30 -25
  120. package/dist/server/index.d.ts +3 -10
  121. package/dist/server/index.js +71 -38
  122. package/dist/{spa-DuVB5O7S.d.ts → spa-BLlMc0eI.d.ts} +38 -5
  123. package/dist/system-canvas-BLuWd69H.d.ts +183 -0
  124. package/dist/system-canvas.d.ts +2 -168
  125. package/dist/tailwind-core.css +114 -0
  126. package/dist/tailwind.css +3 -7
  127. package/dist/theme-init.js +23 -9
  128. package/dist/theme-init.sha256 +1 -0
  129. package/dist/theme.d.ts +243 -4
  130. package/dist/theme.global.js +356 -89
  131. package/dist/theme.js +337 -67
  132. package/dist/tokens.css +14 -6
  133. package/dist/tokens.dtcg.json +1513 -0
  134. package/dist/tokens.js +29 -14
  135. package/dist/tokens.json +512 -0
  136. package/package.json +51 -13
  137. package/dist/chart.js.map +0 -1
  138. package/dist/elements-charts.js.map +0 -1
  139. package/dist/elements-data.js.map +0 -1
  140. package/dist/elements-forms.js.map +0 -1
  141. package/dist/elements.js.map +0 -1
  142. package/dist/format.js.map +0 -1
  143. package/dist/inbox-client.js.map +0 -1
  144. package/dist/index.js +0 -10260
  145. package/dist/index.js.map +0 -1
  146. package/dist/server/hono.js.map +0 -1
  147. package/dist/server/index.js.map +0 -1
  148. package/dist/split-layout.js.map +0 -1
  149. package/dist/system-canvas.js +0 -2204
  150. package/dist/system-canvas.js.map +0 -1
  151. package/dist/theme.global.js.map +0 -1
  152. package/dist/theme.js.map +0 -1
@@ -0,0 +1,64 @@
1
+ "use client";
2
+
3
+ // src/components/error-boundary.tsx
4
+ import { Component } from "react";
5
+ import { Button, Card } from "./primitives.js";
6
+ import { useNishStrings } from "./provider.js";
7
+ import { jsx, jsxs } from "react/jsx-runtime";
8
+ var CHUNK_MESSAGE = /Failed to fetch dynamically imported module|Importing a module script failed/;
9
+ function isChunkError(e) {
10
+ return e.name === "ChunkLoadError" || CHUNK_MESSAGE.test(e.message);
11
+ }
12
+ function changed(a = [], b = []) {
13
+ return a.length !== b.length || a.some((v, i) => !Object.is(v, b[i]));
14
+ }
15
+ function isDevelopment() {
16
+ try {
17
+ return process.env.NODE_ENV !== "production";
18
+ } catch {
19
+ return false;
20
+ }
21
+ }
22
+ var Boundary = class extends Component {
23
+ state = { error: null };
24
+ static getDerivedStateFromError(error) {
25
+ return { error: error instanceof Error ? error : new Error(String(error)) };
26
+ }
27
+ componentDidCatch(error, info) {
28
+ this.props.onError?.(error instanceof Error ? error : new Error(String(error)), { componentStack: info.componentStack });
29
+ }
30
+ componentDidUpdate(prev) {
31
+ if (this.state.error && changed(prev.resetKeys, this.props.resetKeys)) this.reset();
32
+ }
33
+ reset = () => {
34
+ this.setState({ error: null });
35
+ };
36
+ render() {
37
+ const { error } = this.state;
38
+ if (!error) return this.props.children;
39
+ if (this.props.fallback) return this.props.fallback({ error, reset: this.reset });
40
+ const s = this.props.strings;
41
+ const details = this.props.showDetails ?? isDevelopment();
42
+ const stale = isChunkError(error);
43
+ const message = error.message.length > 300 ? `${error.message.slice(0, 300)}\u2026` : error.message;
44
+ return /* @__PURE__ */ jsxs(Card, { role: "alert", className: "mx-auto my-16 max-w-md", children: [
45
+ /* @__PURE__ */ jsx("h2", { className: "text-lg font-semibold text-th-hi", children: stale ? s.errorStaleTitle : s.errorTitle }),
46
+ /* @__PURE__ */ jsx("p", { className: "mt-1 break-words text-sm text-th-hi2", children: stale ? s.errorStaleBody : details ? message || s.errorBody : s.errorBody }),
47
+ details && error.stack ? /* @__PURE__ */ jsxs("details", { className: "mt-3", children: [
48
+ /* @__PURE__ */ jsx("summary", { className: "inline-flex min-h-11 cursor-pointer items-center text-sm text-th-hi3", children: s.errorDetails }),
49
+ /* @__PURE__ */ jsx("pre", { className: "mt-2 max-h-48 overflow-auto rounded-lg bg-th-elevated p-2 font-mono text-xs text-th-hi2", children: error.stack })
50
+ ] }) : null,
51
+ /* @__PURE__ */ jsxs("div", { className: "mt-4 flex flex-wrap gap-2", children: [
52
+ stale ? null : /* @__PURE__ */ jsx(Button, { variant: "primary", onClick: this.reset, children: s.errorTryAgain }),
53
+ /* @__PURE__ */ jsx(Button, { variant: stale ? "primary" : "secondary", onClick: () => location.reload(), children: s.errorReload })
54
+ ] })
55
+ ] });
56
+ }
57
+ };
58
+ function AppErrorBoundary(props) {
59
+ const strings = useNishStrings();
60
+ return /* @__PURE__ */ jsx(Boundary, { ...props, strings });
61
+ }
62
+ export {
63
+ AppErrorBoundary
64
+ };
@@ -0,0 +1,136 @@
1
+ "use client";
2
+
3
+ // src/components/feedback.tsx
4
+ import { cn } from "../cn.js";
5
+ import { AlertTriangleIcon, LoaderIcon, RotateIcon } from "./icons.js";
6
+ import { cardClass } from "./primitives.js";
7
+ import { useNishStrings } from "./provider.js";
8
+ import { jsx, jsxs } from "react/jsx-runtime";
9
+ function Skeleton({ className, style, ref, ...rest }) {
10
+ return /* @__PURE__ */ jsx("div", { ...rest, ref, "aria-hidden": "true", className: cn("nish-skeleton rounded-md", className), style });
11
+ }
12
+ function SkeletonRows({ rows = 5, height = 56, gap = "md", label, className, rowClassName, ref, ...rest }) {
13
+ const s = useNishStrings();
14
+ return /* @__PURE__ */ jsxs("div", { ...rest, ref, role: "status", className: cn("grid", gap === "sm" ? "gap-1.5" : "gap-2.5", className), children: [
15
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: label ?? s.loading }),
16
+ Array.from({ length: rows }, (_, i) => /* @__PURE__ */ jsx(Skeleton, { className: cn("w-full rounded-xl", rowClassName), style: rowClassName && /\bh-/.test(rowClassName) ? void 0 : { height } }, i))
17
+ ] });
18
+ }
19
+ var SPINNER_SIZE = { xs: 12, sm: 14, md: 16, lg: 24 };
20
+ function Spinner({ size = "md", label, className, ref, ...rest }) {
21
+ const icon = /* @__PURE__ */ jsx(LoaderIcon, { size: SPINNER_SIZE[size], className: "animate-spin" });
22
+ if (!label) {
23
+ return /* @__PURE__ */ jsx("span", { ...rest, ref, "aria-hidden": "true", className: cn("inline-flex shrink-0 items-center", className), children: icon });
24
+ }
25
+ return /* @__PURE__ */ jsxs("span", { ...rest, ref, role: "status", className: cn("inline-flex shrink-0 items-center", className), children: [
26
+ icon,
27
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: label })
28
+ ] });
29
+ }
30
+ function SkeletonLines({ lines = 3, className, label, ref, ...rest }) {
31
+ const s = useNishStrings();
32
+ return /* @__PURE__ */ jsxs("div", { ...rest, ref, role: "status", className: cn("flex flex-col gap-2.5 p-3", className), children: [
33
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: label ?? s.loading }),
34
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-2/5" }),
35
+ Array.from({ length: lines }, (_, i) => /* @__PURE__ */ jsx(Skeleton, { className: cn("h-3", i % 2 === 0 ? "w-full" : "w-4/5") }, i))
36
+ ] });
37
+ }
38
+ function SkeletonCard({ lines = 3, media = "none", className, ref, ...rest }) {
39
+ return /* @__PURE__ */ jsxs("div", { ...rest, ref, "aria-hidden": "true", className: cn(cardClass({ padding: "md" }), "flex flex-col gap-3", className), children: [
40
+ media === "square" ? /* @__PURE__ */ jsx(Skeleton, { className: "size-24 rounded-lg" }) : null,
41
+ media === "wide" ? /* @__PURE__ */ jsx(Skeleton, { className: "aspect-video w-full rounded-lg" }) : null,
42
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-2/5" }),
43
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: Array.from({ length: lines }, (_, i) => /* @__PURE__ */ jsx(Skeleton, { className: cn("h-3", i % 2 === 0 ? "w-full" : "w-4/5") }, i)) })
44
+ ] });
45
+ }
46
+ function StatGridSkeleton({ count = 4, className, label, ref, ...rest }) {
47
+ const s = useNishStrings();
48
+ return /* @__PURE__ */ jsxs("div", { ...rest, ref, role: "status", className: cn("grid grid-cols-2 gap-3 md:grid-cols-4", className), children: [
49
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: label ?? s.loading }),
50
+ Array.from({ length: count }, (_, i) => /* @__PURE__ */ jsxs("div", { className: cn(cardClass({ padding: "sm" }), "min-w-0"), children: [
51
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-3 w-16" }),
52
+ /* @__PURE__ */ jsx(Skeleton, { className: "mt-2 h-7 w-24" }),
53
+ /* @__PURE__ */ jsx(Skeleton, { className: "mt-1.5 h-3 w-12" })
54
+ ] }, i))
55
+ ] });
56
+ }
57
+ function CardListSkeleton({ count = 3, lines = 2, className, label, ref, ...rest }) {
58
+ const s = useNishStrings();
59
+ return /* @__PURE__ */ jsxs("div", { ...rest, ref, role: "status", className: cn("grid gap-2.5", className), children: [
60
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: label ?? s.loading }),
61
+ Array.from({ length: count }, (_, i) => /* @__PURE__ */ jsx(SkeletonCard, { lines }, i))
62
+ ] });
63
+ }
64
+ function EmptyState({ icon, title, detail, action, compact = false, className, ref, ...rest }) {
65
+ return /* @__PURE__ */ jsxs(
66
+ "div",
67
+ {
68
+ ...rest,
69
+ ref,
70
+ className: cn(
71
+ "flex flex-col items-center justify-center text-center",
72
+ compact ? "h-full gap-1.5 p-4" : "gap-2 rounded-xl border border-dashed border-th-line px-6 py-12",
73
+ className
74
+ ),
75
+ children: [
76
+ icon ? /* @__PURE__ */ jsx("span", { className: "text-th-ghost [&>svg]:size-7", children: icon }) : null,
77
+ /* @__PURE__ */ jsx("p", { className: cn("font-medium text-th-hi2", compact ? "text-xs" : "text-sm"), children: title }),
78
+ detail ? /* @__PURE__ */ jsx("p", { className: "max-w-sm text-xs text-th-hi3", children: detail }) : null,
79
+ action ? /* @__PURE__ */ jsx("div", { className: "mt-2", children: action }) : null
80
+ ]
81
+ }
82
+ );
83
+ }
84
+ function ErrorState({
85
+ message,
86
+ onRetry,
87
+ retryLabel,
88
+ retrying = false,
89
+ compact = false,
90
+ className,
91
+ ref,
92
+ ...rest
93
+ }) {
94
+ const s = useNishStrings();
95
+ return /* @__PURE__ */ jsxs(
96
+ "div",
97
+ {
98
+ ...rest,
99
+ ref,
100
+ role: "alert",
101
+ className: cn(
102
+ "flex flex-col items-center justify-center text-center",
103
+ compact ? "h-full gap-2 p-4" : "gap-2 rounded-xl border border-th-loss/30 bg-th-loss-soft px-6 py-10",
104
+ className
105
+ ),
106
+ children: [
107
+ /* @__PURE__ */ jsx(AlertTriangleIcon, { size: compact ? 16 : 22, className: "shrink-0 text-th-loss" }),
108
+ /* @__PURE__ */ jsx("p", { className: cn("max-w-md text-th-hi2", compact ? "text-xs" : "text-sm"), children: message ?? s.failedToLoad }),
109
+ onRetry ? /* @__PURE__ */ jsxs(
110
+ "button",
111
+ {
112
+ type: "button",
113
+ onClick: onRetry,
114
+ disabled: retrying,
115
+ className: "mt-1 inline-flex items-center gap-1.5 rounded-full border border-th-line-strong px-3 py-1 text-xs text-th-hi2 transition-colors hover:bg-th-elevated hover:text-th-hi disabled:opacity-50 pointer-coarse:min-h-11",
116
+ children: [
117
+ retrying ? /* @__PURE__ */ jsx(LoaderIcon, { size: 12, className: "animate-spin" }) : /* @__PURE__ */ jsx(RotateIcon, { size: 12 }),
118
+ retryLabel ?? s.retry
119
+ ]
120
+ }
121
+ ) : null
122
+ ]
123
+ }
124
+ );
125
+ }
126
+ export {
127
+ CardListSkeleton,
128
+ EmptyState,
129
+ ErrorState,
130
+ Skeleton,
131
+ SkeletonCard,
132
+ SkeletonLines,
133
+ SkeletonRows,
134
+ Spinner,
135
+ StatGridSkeleton
136
+ };
@@ -0,0 +1,184 @@
1
+ "use client";
2
+
3
+ // src/components/file-dropzone.tsx
4
+ import { useRef, useState } from "react";
5
+ import { cn } from "../cn.js";
6
+ import { XIcon } from "./icons.js";
7
+ import { IconButton } from "./primitives.js";
8
+ import { useNishStrings } from "./provider.js";
9
+ import { jsx, jsxs } from "react/jsx-runtime";
10
+ function matchesAccept(file, accept) {
11
+ const tokens = (accept ?? "").split(",").map((t) => t.trim().toLowerCase()).filter(Boolean);
12
+ if (tokens.length === 0) return true;
13
+ const fileName = file.name.toLowerCase();
14
+ const type = file.type.toLowerCase();
15
+ return tokens.some((t) => {
16
+ if (t.startsWith(".")) return fileName.endsWith(t);
17
+ if (t.endsWith("/*")) return type.startsWith(t.slice(0, -1));
18
+ return type === t;
19
+ });
20
+ }
21
+ var sameFile = (a, b) => a.name === b.name && a.size === b.size && a.lastModified === b.lastModified;
22
+ function formatBytes(n) {
23
+ if (n < 1024) return `${n} B`;
24
+ if (n < 1024 * 1024) return `${(n / 1024).toFixed(n < 10 * 1024 ? 1 : 0)} KB`;
25
+ return `${(n / (1024 * 1024)).toFixed(n < 10 * 1024 * 1024 ? 1 : 0)} MB`;
26
+ }
27
+ function syncInput(input, files) {
28
+ if (!input) return;
29
+ try {
30
+ const dt = new DataTransfer();
31
+ for (const f of files) dt.items.add(f);
32
+ input.files = dt.files;
33
+ } catch {
34
+ }
35
+ }
36
+ function FileDropzone({
37
+ accept,
38
+ multiple = false,
39
+ maxSize,
40
+ maxFiles,
41
+ onFilesChange,
42
+ name,
43
+ disabled = false,
44
+ required = false,
45
+ invalid = false,
46
+ label,
47
+ className,
48
+ ref,
49
+ id,
50
+ "aria-label": ariaLabel,
51
+ "aria-labelledby": ariaLabelledBy,
52
+ "aria-describedby": ariaDescribedBy,
53
+ "aria-invalid": ariaInvalid,
54
+ ...rest
55
+ }) {
56
+ const strings = useNishStrings();
57
+ const input = useRef(null);
58
+ const depth = useRef(0);
59
+ const [files, setFiles] = useState([]);
60
+ const [dragging, setDragging] = useState(false);
61
+ const isInvalid = invalid || ariaInvalid === true || ariaInvalid === "true";
62
+ const take = (incoming) => {
63
+ const rejected = [];
64
+ const list = multiple ? [...files] : [];
65
+ const cap = multiple ? maxFiles ?? Infinity : 1;
66
+ let changed = false;
67
+ for (const file of incoming) {
68
+ if (!matchesAccept(file, accept)) rejected.push({ file, reason: "type" });
69
+ else if (maxSize !== void 0 && file.size > maxSize) rejected.push({ file, reason: "size" });
70
+ else if (multiple && list.some((f) => sameFile(f, file))) continue;
71
+ else if (list.length >= cap) rejected.push({ file, reason: "count" });
72
+ else {
73
+ list.push(file);
74
+ changed = true;
75
+ }
76
+ }
77
+ const next = !multiple && list.length === 0 ? files : list;
78
+ syncInput(input.current, next);
79
+ if (!changed && rejected.length === 0) return;
80
+ if (next !== files) setFiles(next);
81
+ onFilesChange?.(next, rejected);
82
+ };
83
+ const removeAt = (index) => {
84
+ const next = files.filter((_, i) => i !== index);
85
+ setFiles(next);
86
+ syncInput(input.current, next);
87
+ onFilesChange?.(next, []);
88
+ };
89
+ const onDragEnter = (e) => {
90
+ e.preventDefault();
91
+ depth.current += 1;
92
+ if (!disabled) setDragging(true);
93
+ };
94
+ const onDragOver = (e) => {
95
+ e.preventDefault();
96
+ if (e.dataTransfer) e.dataTransfer.dropEffect = disabled ? "none" : "copy";
97
+ };
98
+ const onDragLeave = () => {
99
+ depth.current = Math.max(0, depth.current - 1);
100
+ if (depth.current === 0) setDragging(false);
101
+ };
102
+ const onDrop = (e) => {
103
+ e.preventDefault();
104
+ depth.current = 0;
105
+ setDragging(false);
106
+ if (disabled) return;
107
+ take(Array.from(e.dataTransfer?.files ?? []));
108
+ };
109
+ return /* @__PURE__ */ jsxs(
110
+ "div",
111
+ {
112
+ ...rest,
113
+ ref,
114
+ "data-state": dragging ? "dragging" : "idle",
115
+ "data-disabled": disabled ? "" : void 0,
116
+ className: cn("group grid gap-2", className),
117
+ children: [
118
+ /* @__PURE__ */ jsxs(
119
+ "label",
120
+ {
121
+ onDragEnter,
122
+ onDragOver,
123
+ onDragLeave,
124
+ onDrop,
125
+ className: cn(
126
+ "relative flex min-h-28 cursor-pointer flex-col items-center justify-center gap-2 rounded-lg border border-dashed bg-th-elevated px-4 py-5 text-center text-sm text-th-hi2",
127
+ "transition-colors duration-150 hover:border-th-hi3 has-[:focus-visible]:ring-2 has-[:focus-visible]:ring-th-accent/40",
128
+ isInvalid ? "border-th-loss" : "border-th-line-control",
129
+ "group-data-[state=dragging]:border-th-accent group-data-[state=dragging]:bg-th-accent-soft",
130
+ "group-data-[disabled]:cursor-not-allowed group-data-[disabled]:opacity-50",
131
+ "forced-colors:border-[ButtonText] forced-colors:group-data-[state=dragging]:border-[Highlight] forced-colors:group-data-[state=dragging]:outline forced-colors:group-data-[state=dragging]:outline-2 forced-colors:group-data-[state=dragging]:outline-[Highlight]",
132
+ "forced-colors:has-[:focus-visible]:outline forced-colors:has-[:focus-visible]:outline-2 forced-colors:has-[:focus-visible]:outline-[Highlight]"
133
+ ),
134
+ children: [
135
+ /* @__PURE__ */ jsx(
136
+ "input",
137
+ {
138
+ ref: input,
139
+ id,
140
+ type: "file",
141
+ name,
142
+ accept,
143
+ multiple,
144
+ disabled,
145
+ required,
146
+ "aria-label": ariaLabel,
147
+ "aria-labelledby": ariaLabelledBy,
148
+ "aria-describedby": ariaDescribedBy,
149
+ "aria-invalid": isInvalid || void 0,
150
+ onChange: (e) => take(Array.from(e.target.files ?? [])),
151
+ className: "sr-only"
152
+ }
153
+ ),
154
+ /* @__PURE__ */ jsx("span", { children: label ?? strings.dropzoneLabel }),
155
+ /* @__PURE__ */ jsx(
156
+ "span",
157
+ {
158
+ "aria-hidden": "true",
159
+ className: "inline-flex h-8 items-center rounded-lg border border-th-line-control px-3 text-xs font-medium text-th-hi pointer-coarse:h-11 pointer-coarse:text-sm",
160
+ children: strings.browseFiles
161
+ }
162
+ )
163
+ ]
164
+ }
165
+ ),
166
+ files.length > 0 ? /* @__PURE__ */ jsx("ul", { className: "grid gap-1.5", children: files.map((file, i) => /* @__PURE__ */ jsxs(
167
+ "li",
168
+ {
169
+ className: "flex items-center gap-2 rounded-lg border border-th-line bg-th-surface py-1 pe-1 ps-3 text-sm",
170
+ children: [
171
+ /* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1 truncate text-th-hi", title: file.name, children: file.name }),
172
+ /* @__PURE__ */ jsx("span", { className: "shrink-0 text-xs tabular-nums text-th-hi3", children: formatBytes(file.size) }),
173
+ /* @__PURE__ */ jsx(IconButton, { label: strings.removeFile(file.name), size: "sm", disabled, onClick: () => removeAt(i), children: /* @__PURE__ */ jsx(XIcon, { size: 14 }) })
174
+ ]
175
+ },
176
+ `${file.name}-${file.size}-${file.lastModified}-${i}`
177
+ )) }) : null
178
+ ]
179
+ }
180
+ );
181
+ }
182
+ export {
183
+ FileDropzone
184
+ };
@@ -0,0 +1,108 @@
1
+ "use client";
2
+
3
+ // src/components/filters.tsx
4
+ import { useState } from "react";
5
+ import { cn } from "../cn.js";
6
+ import { SearchInput } from "./forms.js";
7
+ import { NARROW_QUERY, useMediaQuery } from "./hooks.js";
8
+ import { Drawer } from "./overlay.js";
9
+ import { Badge, Button } from "./primitives.js";
10
+ import { useNishStrings } from "./provider.js";
11
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
12
+ var LG_QUERY = "(max-width: 1023.98px)";
13
+ function FunnelIcon({ size = 16, ...rest }) {
14
+ return /* @__PURE__ */ jsx(
15
+ "svg",
16
+ {
17
+ width: size,
18
+ height: size,
19
+ viewBox: "0 0 24 24",
20
+ fill: "none",
21
+ stroke: "currentColor",
22
+ strokeWidth: 2,
23
+ strokeLinecap: "round",
24
+ strokeLinejoin: "round",
25
+ "aria-hidden": "true",
26
+ focusable: "false",
27
+ ...rest,
28
+ children: /* @__PURE__ */ jsx("path", { d: "M22 3H2l8 9.46V19l4 2v-8.54L22 3z" })
29
+ }
30
+ );
31
+ }
32
+ function FilterSheet({ open, onClose, title, children, onClear, activeCount, resultLabel }) {
33
+ const strings = useNishStrings();
34
+ if (!open) return null;
35
+ return /* @__PURE__ */ jsx(
36
+ Drawer,
37
+ {
38
+ side: "bottom",
39
+ size: "lg",
40
+ title: title ?? strings.filters,
41
+ onClose,
42
+ footer: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
43
+ onClear ? /* @__PURE__ */ jsx(Button, { variant: "ghost", onClick: onClear, disabled: activeCount === 0, children: strings.clear }) : null,
44
+ /* @__PURE__ */ jsx(Button, { variant: "primary", onClick: onClose, className: "ms-auto", children: resultLabel ?? strings.done })
45
+ ] }),
46
+ children: /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-4", children })
47
+ }
48
+ );
49
+ }
50
+ function FilterBar({
51
+ search,
52
+ children,
53
+ activeCount = 0,
54
+ onClear,
55
+ trailing,
56
+ sticky = false,
57
+ sheetTitle,
58
+ sheetBelow = "md",
59
+ summary,
60
+ className,
61
+ ref,
62
+ ...rest
63
+ }) {
64
+ const strings = useNishStrings();
65
+ const compact = useMediaQuery(sheetBelow === "lg" ? LG_QUERY : NARROW_QUERY);
66
+ const [open, setOpen] = useState(false);
67
+ const hasChildren = children != null && children !== false;
68
+ const searchBox = search ? /* @__PURE__ */ jsx(
69
+ SearchInput,
70
+ {
71
+ value: search.value,
72
+ onChange: (v) => search.onChange(v),
73
+ placeholder: search.placeholder,
74
+ "aria-label": search.label ?? search.placeholder ?? strings.search,
75
+ className: compact ? "min-w-[10rem] flex-1 basis-40" : "w-full max-w-xs"
76
+ }
77
+ ) : null;
78
+ return /* @__PURE__ */ jsxs(
79
+ "div",
80
+ {
81
+ ...rest,
82
+ ref,
83
+ className: cn(sticky && "sticky top-[var(--nish-header-h,0px)] z-[var(--nish-z-sticky,20)] border-b border-th-line bg-th-bg py-2", className),
84
+ children: [
85
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
86
+ searchBox,
87
+ compact ? /* @__PURE__ */ jsxs(Fragment, { children: [
88
+ hasChildren ? /* @__PURE__ */ jsxs(Button, { variant: "secondary", size: "md", icon: /* @__PURE__ */ jsx(FunnelIcon, {}), onClick: () => setOpen(true), "aria-haspopup": "dialog", "aria-expanded": open, className: "min-h-11 shrink-0", children: [
89
+ strings.filters,
90
+ activeCount > 0 ? /* @__PURE__ */ jsx(Badge, { tone: "accent", "aria-label": strings.activeCount(activeCount), children: activeCount }) : null
91
+ ] }) : null,
92
+ trailing
93
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
94
+ children,
95
+ activeCount > 0 && onClear ? /* @__PURE__ */ jsx(Button, { variant: "ghost", onClick: onClear, children: strings.clearFilters }) : null,
96
+ trailing ? /* @__PURE__ */ jsx("div", { className: "ms-auto flex items-center gap-2", children: trailing }) : null
97
+ ] })
98
+ ] }),
99
+ /* @__PURE__ */ jsx("div", { "aria-live": "polite", className: cn("text-sm text-th-hi3", summary ? "mt-2" : void 0), children: summary || null }),
100
+ compact && hasChildren ? /* @__PURE__ */ jsx(FilterSheet, { open, onClose: () => setOpen(false), title: sheetTitle ?? strings.filters, onClear, activeCount, children }) : null
101
+ ]
102
+ }
103
+ );
104
+ }
105
+ export {
106
+ FilterBar,
107
+ FilterSheet
108
+ };