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.
- package/README.md +218 -58
- package/dist/base-tailwind.css +1757 -0
- package/dist/base.css +1590 -1445
- package/dist/chart.d.ts +4 -1
- package/dist/chart.js +122 -49
- package/dist/elements-all.d.ts +8 -0
- package/dist/elements-all.js +178 -0
- package/dist/elements-charts.d.ts +71 -0
- package/dist/elements-charts.js +56 -57
- package/dist/elements-data.d.ts +71 -0
- package/dist/elements-data.js +5 -6
- package/dist/elements-forms.d.ts +71 -0
- package/dist/elements-forms.js +24 -25
- package/dist/elements.d.ts +71 -0
- package/dist/elements.js +4 -5
- package/dist/esm/chart-values.js +58 -0
- package/dist/esm/chart.js +10 -0
- package/dist/esm/cn.js +19 -0
- package/dist/esm/combobox-filter.js +13 -0
- package/dist/esm/components/accordion.js +166 -0
- package/dist/esm/components/app-shell.js +198 -0
- package/dist/esm/components/avatar-classes.js +28 -0
- package/dist/esm/components/avatar.js +113 -0
- package/dist/esm/components/breadcrumbs.js +154 -0
- package/dist/esm/components/canvas/follow-caption.js +32 -0
- package/dist/esm/components/canvas/follow.js +119 -0
- package/dist/esm/components/canvas/icons.js +70 -0
- package/dist/esm/components/canvas/index.js +10 -0
- package/dist/esm/components/canvas/layout.js +258 -0
- package/dist/esm/components/canvas/legend.js +93 -0
- package/dist/esm/components/canvas/minimap.js +127 -0
- package/dist/esm/components/canvas/node.js +87 -0
- package/dist/esm/components/canvas/route.js +262 -0
- package/dist/esm/components/canvas/system-canvas.js +837 -0
- package/dist/esm/components/canvas/types.js +10 -0
- package/dist/esm/components/canvas/view.js +47 -0
- package/dist/esm/components/chart-hooks.js +19 -0
- package/dist/esm/components/charts.js +467 -0
- package/dist/esm/components/client.js +24 -0
- package/dist/esm/components/combobox.js +343 -0
- package/dist/esm/components/command.js +403 -0
- package/dist/esm/components/data-classes.js +159 -0
- package/dist/esm/components/data.js +517 -0
- package/dist/esm/components/display-classes.js +130 -0
- package/dist/esm/components/display.js +755 -0
- package/dist/esm/components/error-boundary.js +64 -0
- package/dist/esm/components/feedback.js +136 -0
- package/dist/esm/components/file-dropzone.js +184 -0
- package/dist/esm/components/filters.js +108 -0
- package/dist/esm/components/flow.js +746 -0
- package/dist/esm/components/forms-classes.js +43 -0
- package/dist/esm/components/forms.js +581 -0
- package/dist/esm/components/hooks-classes.js +9 -0
- package/dist/esm/components/hooks.js +236 -0
- package/dist/esm/components/icons.js +96 -0
- package/dist/esm/components/inbox-classes.js +29 -0
- package/dist/esm/components/inbox.js +257 -0
- package/dist/esm/components/latest.js +13 -0
- package/dist/esm/components/layout-vars.js +96 -0
- package/dist/esm/components/layout.js +272 -0
- package/dist/esm/components/media.js +143 -0
- package/dist/esm/components/nav.js +614 -0
- package/dist/esm/components/overlay-classes.js +66 -0
- package/dist/esm/components/overlay.js +1461 -0
- package/dist/esm/components/pagination-classes.js +29 -0
- package/dist/esm/components/pagination.js +154 -0
- package/dist/esm/components/portal.js +16 -0
- package/dist/esm/components/primitives-classes.js +198 -0
- package/dist/esm/components/primitives.js +268 -0
- package/dist/esm/components/progress.js +77 -0
- package/dist/esm/components/provider.js +32 -0
- package/dist/esm/components/radio-group.js +186 -0
- package/dist/esm/components/resource-classes.js +133 -0
- package/dist/esm/components/resource.js +209 -0
- package/dist/esm/components/segmented.js +178 -0
- package/dist/esm/components/separator.js +38 -0
- package/dist/esm/components/service-tokens.js +221 -0
- package/dist/esm/components/settings.js +301 -0
- package/dist/esm/components/slider.js +262 -0
- package/dist/esm/components/split-classes.js +8 -0
- package/dist/esm/components/split.js +411 -0
- package/dist/esm/components/strings.js +119 -0
- package/dist/esm/components/table.js +144 -0
- package/dist/esm/components/tabs-classes.js +21 -0
- package/dist/esm/components/tabs.js +201 -0
- package/dist/esm/components/tag-input.js +257 -0
- package/dist/esm/components/theme-toggle.js +177 -0
- package/dist/esm/components/toast.js +361 -0
- package/dist/esm/components/url-state.js +118 -0
- package/dist/esm/components/visually-hidden.js +20 -0
- package/dist/esm/format.js +320 -0
- package/dist/esm/inbox-client.js +2 -0
- package/dist/esm/inbox-types.js +2 -0
- package/dist/esm/index.js +320 -0
- package/dist/esm/runtime.js +37 -0
- package/dist/esm/server/inbox/client.js +297 -0
- package/dist/esm/server/inbox/types.js +24 -0
- package/dist/esm/sparkline-path.js +59 -0
- package/dist/esm/split-layout.js +419 -0
- package/dist/esm/system-canvas.js +2 -0
- package/dist/esm/theme.js +804 -0
- package/dist/esm/tokens.mjs +425 -0
- package/dist/esm/url.js +20 -0
- package/dist/files.json +5 -1
- package/dist/fonts/LICENSE-Inter.txt +93 -0
- package/dist/format.d.ts +32 -18
- package/dist/format.js +227 -82
- package/dist/inbox-client.js +3 -1
- package/dist/index.d.ts +1686 -667
- package/dist/nish-components.css +4649 -4506
- package/dist/nish-components.min.css +1 -0
- package/dist/nish.css +1603 -1450
- package/dist/nish.min.css +1 -0
- package/dist/node/eslint.js +29 -14
- package/dist/node/th-check.js +29 -14
- package/dist/node/vite.d.ts +12 -0
- package/dist/node/vite.js +12 -2
- package/dist/server/hono.d.ts +15 -6
- package/dist/server/hono.js +30 -25
- package/dist/server/index.d.ts +3 -10
- package/dist/server/index.js +71 -38
- package/dist/{spa-DuVB5O7S.d.ts → spa-BLlMc0eI.d.ts} +38 -5
- package/dist/system-canvas-BLuWd69H.d.ts +183 -0
- package/dist/system-canvas.d.ts +2 -168
- package/dist/tailwind-core.css +114 -0
- package/dist/tailwind.css +3 -7
- package/dist/theme-init.js +23 -9
- package/dist/theme-init.sha256 +1 -0
- package/dist/theme.d.ts +243 -4
- package/dist/theme.global.js +356 -89
- package/dist/theme.js +337 -67
- package/dist/tokens.css +14 -6
- package/dist/tokens.dtcg.json +1513 -0
- package/dist/tokens.js +29 -14
- package/dist/tokens.json +512 -0
- package/package.json +51 -13
- package/dist/chart.js.map +0 -1
- package/dist/elements-charts.js.map +0 -1
- package/dist/elements-data.js.map +0 -1
- package/dist/elements-forms.js.map +0 -1
- package/dist/elements.js.map +0 -1
- package/dist/format.js.map +0 -1
- package/dist/inbox-client.js.map +0 -1
- package/dist/index.js +0 -10260
- package/dist/index.js.map +0 -1
- package/dist/server/hono.js.map +0 -1
- package/dist/server/index.js.map +0 -1
- package/dist/split-layout.js.map +0 -1
- package/dist/system-canvas.js +0 -2204
- package/dist/system-canvas.js.map +0 -1
- package/dist/theme.global.js.map +0 -1
- package/dist/theme.js.map +0 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// src/components/pagination-classes.ts
|
|
2
|
+
function range(from, to) {
|
|
3
|
+
const out = [];
|
|
4
|
+
for (let i = from; i <= to; i++) out.push(i);
|
|
5
|
+
return out;
|
|
6
|
+
}
|
|
7
|
+
function paginationRange(page, pageCount, siblings = 1, boundaries = 1) {
|
|
8
|
+
const total = Math.max(0, Math.floor(pageCount));
|
|
9
|
+
const sib = Math.max(0, Math.floor(siblings));
|
|
10
|
+
const bnd = Math.max(0, Math.floor(boundaries));
|
|
11
|
+
if (total === 0) return [];
|
|
12
|
+
const slots = sib * 2 + 3 + bnd * 2;
|
|
13
|
+
if (total <= slots) return range(1, total);
|
|
14
|
+
const current = Math.min(Math.max(1, page), total);
|
|
15
|
+
const left = Math.max(current - sib, bnd + 1);
|
|
16
|
+
const right = Math.min(current + sib, total - bnd);
|
|
17
|
+
const dotsLeft = left > bnd + 2;
|
|
18
|
+
const dotsRight = right < total - bnd - 1;
|
|
19
|
+
if (!dotsLeft && dotsRight) {
|
|
20
|
+
return [...range(1, sib * 2 + bnd + 2), "dots-end", ...range(total - bnd + 1, total)];
|
|
21
|
+
}
|
|
22
|
+
if (dotsLeft && !dotsRight) {
|
|
23
|
+
return [...range(1, bnd), "dots-start", ...range(total - (sib * 2 + bnd + 2) + 1, total)];
|
|
24
|
+
}
|
|
25
|
+
return [...range(1, bnd), "dots-start", ...range(left, right), "dots-end", ...range(total - bnd + 1, total)];
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
paginationRange
|
|
29
|
+
};
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/components/pagination.tsx
|
|
4
|
+
import { useCallback, useRef, useState } from "react";
|
|
5
|
+
import { cn } from "../cn.js";
|
|
6
|
+
import { useIsoLayoutEffect } from "./client.js";
|
|
7
|
+
import { useNishStrings } from "./provider.js";
|
|
8
|
+
import { paginationRange } from "./pagination-classes.js";
|
|
9
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
var SIZE = { sm: "h-8 min-w-8 text-xs", md: "h-9 min-w-9 text-sm" };
|
|
11
|
+
function controlClass(size, current, disabled) {
|
|
12
|
+
return cn(
|
|
13
|
+
"inline-flex shrink-0 select-none items-center justify-center rounded-lg px-2 font-medium tabular-nums transition-colors duration-150",
|
|
14
|
+
"pointer-coarse:min-h-11 pointer-coarse:min-w-11",
|
|
15
|
+
SIZE[size],
|
|
16
|
+
current ? "bg-th-accent text-th-on-accent forced-color-adjust-none forced-colors:bg-[Highlight] forced-colors:text-[HighlightText]" : "text-th-hi2 hover:bg-th-elevated hover:text-th-hi",
|
|
17
|
+
disabled && "pointer-events-none cursor-not-allowed text-th-ghost"
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
function Chevron({ dir }) {
|
|
21
|
+
return /* @__PURE__ */ jsx(
|
|
22
|
+
"svg",
|
|
23
|
+
{
|
|
24
|
+
width: 16,
|
|
25
|
+
height: 16,
|
|
26
|
+
viewBox: "0 0 24 24",
|
|
27
|
+
fill: "none",
|
|
28
|
+
stroke: "currentColor",
|
|
29
|
+
strokeWidth: 2,
|
|
30
|
+
strokeLinecap: "round",
|
|
31
|
+
strokeLinejoin: "round",
|
|
32
|
+
"aria-hidden": "true",
|
|
33
|
+
focusable: "false",
|
|
34
|
+
className: "rtl:-scale-x-100",
|
|
35
|
+
children: /* @__PURE__ */ jsx("path", { d: dir === "prev" ? "m15 18-6-6 6-6" : "m9 18 6-6-6-6" })
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
function clampPage(p, count) {
|
|
40
|
+
const n = Number.isFinite(p) ? Math.floor(p) : 1;
|
|
41
|
+
return Math.min(Math.max(1, n), Math.max(1, count));
|
|
42
|
+
}
|
|
43
|
+
function Pagination({
|
|
44
|
+
page: pageProp,
|
|
45
|
+
defaultPage = 1,
|
|
46
|
+
onPageChange,
|
|
47
|
+
pageCount,
|
|
48
|
+
siblings = 1,
|
|
49
|
+
boundaries = 1,
|
|
50
|
+
size = "md",
|
|
51
|
+
renderLink,
|
|
52
|
+
compact: compactProp,
|
|
53
|
+
disabled = false,
|
|
54
|
+
label,
|
|
55
|
+
previousLabel,
|
|
56
|
+
nextLabel,
|
|
57
|
+
pageLabel,
|
|
58
|
+
compactLabel,
|
|
59
|
+
className,
|
|
60
|
+
ref,
|
|
61
|
+
...rest
|
|
62
|
+
}) {
|
|
63
|
+
const strings = useNishStrings();
|
|
64
|
+
const [pageState, setPageState] = useState(defaultPage);
|
|
65
|
+
const navRef = useRef(null);
|
|
66
|
+
const [narrow, setNarrow] = useState(false);
|
|
67
|
+
const count = Math.max(0, Math.floor(pageCount));
|
|
68
|
+
const page = clampPage(pageProp ?? pageState, count);
|
|
69
|
+
const empty = count < 1;
|
|
70
|
+
const setRefs = useCallback(
|
|
71
|
+
(node) => {
|
|
72
|
+
navRef.current = node;
|
|
73
|
+
if (typeof ref === "function") ref(node);
|
|
74
|
+
else if (ref) ref.current = node;
|
|
75
|
+
},
|
|
76
|
+
[ref]
|
|
77
|
+
);
|
|
78
|
+
useIsoLayoutEffect(() => {
|
|
79
|
+
const el = navRef.current;
|
|
80
|
+
if (compactProp !== void 0 || !el || typeof ResizeObserver === "undefined") return;
|
|
81
|
+
const measure = (w) => setNarrow(w > 0 && w < 400);
|
|
82
|
+
measure(el.getBoundingClientRect().width);
|
|
83
|
+
const ro = new ResizeObserver((entries) => {
|
|
84
|
+
const w = entries[0]?.contentRect.width;
|
|
85
|
+
if (w !== void 0) measure(w);
|
|
86
|
+
});
|
|
87
|
+
ro.observe(el);
|
|
88
|
+
return () => ro.disconnect();
|
|
89
|
+
}, [compactProp, empty]);
|
|
90
|
+
if (empty) return null;
|
|
91
|
+
const compact = compactProp ?? narrow;
|
|
92
|
+
function go(next2) {
|
|
93
|
+
if (disabled) return;
|
|
94
|
+
const target = clampPage(next2, count);
|
|
95
|
+
if (pageProp === void 0) setPageState(target);
|
|
96
|
+
if (target !== page) onPageChange?.(target);
|
|
97
|
+
}
|
|
98
|
+
const pageName = pageLabel ?? strings.pageLabel;
|
|
99
|
+
const prevName = previousLabel ?? strings.previousPage;
|
|
100
|
+
const nextName = nextLabel ?? strings.nextPage;
|
|
101
|
+
function control(target, name, current, off, children, key) {
|
|
102
|
+
const cls = controlClass(size, current, off);
|
|
103
|
+
const state = current ? "active" : "inactive";
|
|
104
|
+
if (renderLink && !off) {
|
|
105
|
+
const props = {
|
|
106
|
+
className: cls,
|
|
107
|
+
"aria-label": name,
|
|
108
|
+
"aria-current": current ? "page" : void 0,
|
|
109
|
+
"data-state": state,
|
|
110
|
+
children,
|
|
111
|
+
onClick: () => go(target)
|
|
112
|
+
};
|
|
113
|
+
return /* @__PURE__ */ jsx("li", { children: renderLink(target, props) }, key);
|
|
114
|
+
}
|
|
115
|
+
return /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(
|
|
116
|
+
"button",
|
|
117
|
+
{
|
|
118
|
+
type: "button",
|
|
119
|
+
className: cls,
|
|
120
|
+
"aria-label": name,
|
|
121
|
+
"aria-current": current ? "page" : void 0,
|
|
122
|
+
"data-state": state,
|
|
123
|
+
disabled: off,
|
|
124
|
+
"data-disabled": off ? "" : void 0,
|
|
125
|
+
onClick: () => go(target),
|
|
126
|
+
children
|
|
127
|
+
}
|
|
128
|
+
) }, key);
|
|
129
|
+
}
|
|
130
|
+
const prev = control(page - 1, prevName, false, page <= 1 || disabled, /* @__PURE__ */ jsx(Chevron, { dir: "prev" }), "prev");
|
|
131
|
+
const next = control(page + 1, nextName, false, page >= count || disabled, /* @__PURE__ */ jsx(Chevron, { dir: "next" }), "next");
|
|
132
|
+
return /* @__PURE__ */ jsx(
|
|
133
|
+
"nav",
|
|
134
|
+
{
|
|
135
|
+
"aria-label": label ?? strings.paginationLabel,
|
|
136
|
+
"data-state": compact ? "compact" : "full",
|
|
137
|
+
"data-disabled": disabled ? "" : void 0,
|
|
138
|
+
...rest,
|
|
139
|
+
ref: setRefs,
|
|
140
|
+
className: cn("w-full min-w-0", className),
|
|
141
|
+
children: /* @__PURE__ */ jsxs("ul", { className: cn("flex flex-wrap items-center gap-1", compact && "justify-between"), children: [
|
|
142
|
+
prev,
|
|
143
|
+
compact ? /* @__PURE__ */ jsx("li", { className: "px-2 text-sm tabular-nums text-th-hi2", children: (compactLabel ?? ((p, c) => `${strings.pageLabel(p)} of ${c}`))(page, count) }) : paginationRange(page, count, siblings, boundaries).map(
|
|
144
|
+
(slot) => typeof slot === "number" ? control(slot, pageName(slot), slot === page, disabled, slot, `p${slot}`) : /* @__PURE__ */ jsx("li", { "aria-hidden": "true", className: cn("inline-flex items-center justify-center text-th-hi3", "min-w-6", SIZE[size].split(" ")[0]), children: "\u2026" }, slot)
|
|
145
|
+
),
|
|
146
|
+
next
|
|
147
|
+
] })
|
|
148
|
+
}
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
export {
|
|
152
|
+
Pagination,
|
|
153
|
+
paginationRange
|
|
154
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/components/portal.tsx
|
|
4
|
+
import { createPortal } from "react-dom";
|
|
5
|
+
import { useIsClient } from "./client.js";
|
|
6
|
+
import { useNishConfig } from "./provider.js";
|
|
7
|
+
function Portal({ children, container }) {
|
|
8
|
+
const isClient = useIsClient();
|
|
9
|
+
const config = useNishConfig();
|
|
10
|
+
if (!isClient) return null;
|
|
11
|
+
const target = container ?? config.portalContainer ?? document.body;
|
|
12
|
+
return createPortal(children, target);
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
Portal
|
|
16
|
+
};
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
// src/components/primitives-classes.ts
|
|
2
|
+
import { cn } from "../cn.js";
|
|
3
|
+
var BUTTON_VARIANT = {
|
|
4
|
+
primary: "bg-th-accent text-th-on-accent hover:bg-th-accent/90 active:bg-th-accent/80",
|
|
5
|
+
secondary: "border border-th-line-strong bg-th-surface text-th-hi hover:bg-th-elevated",
|
|
6
|
+
ghost: "text-th-hi2 hover:bg-th-elevated hover:text-th-hi",
|
|
7
|
+
danger: "bg-th-loss text-th-on-loss hover:bg-th-loss/90 active:bg-th-loss/80",
|
|
8
|
+
soft: "bg-th-accent-soft text-th-accent hover:bg-th-accent/20 active:bg-th-accent/25",
|
|
9
|
+
subtle: "bg-th-elevated text-th-hi hover:bg-th-overlay",
|
|
10
|
+
link: "h-auto p-0 font-medium text-th-accent underline-offset-2 hover:underline"
|
|
11
|
+
};
|
|
12
|
+
var BUTTON_SIZE = {
|
|
13
|
+
xs: "h-6 gap-1 px-2 text-2xs pointer-coarse:min-h-11",
|
|
14
|
+
sm: "h-7 gap-1.5 px-2.5 text-xs pointer-coarse:min-h-11",
|
|
15
|
+
md: "h-9 gap-2 px-3.5 text-sm pointer-coarse:min-h-11",
|
|
16
|
+
lg: "h-11 gap-2 px-5 text-base"
|
|
17
|
+
};
|
|
18
|
+
var LINK_SIZE = {
|
|
19
|
+
xs: "gap-1 text-2xs",
|
|
20
|
+
sm: "gap-1 text-xs",
|
|
21
|
+
md: "gap-1.5 text-sm",
|
|
22
|
+
lg: "gap-2 text-base"
|
|
23
|
+
};
|
|
24
|
+
var BUTTON_BASE = "inline-flex shrink-0 select-none items-center justify-center whitespace-nowrap rounded-lg font-medium transition-[color,background-color,border-color,transform] duration-150";
|
|
25
|
+
var BUTTON_FORCED = "forced-colors:border forced-colors:border-[ButtonText]";
|
|
26
|
+
var PRESS = "pointer-coarse:not-disabled:active:scale-[0.97]";
|
|
27
|
+
var LINK_HIT = "pointer-coarse:relative pointer-coarse:after:absolute pointer-coarse:after:-inset-x-2 pointer-coarse:after:-inset-y-3 pointer-coarse:after:content-['']";
|
|
28
|
+
var BUTTON_DISABLED = "disabled:pointer-events-none disabled:border disabled:border-th-line disabled:bg-th-elevated disabled:text-th-ghost disabled:shadow-none forced-colors:disabled:border-[GrayText] forced-colors:disabled:text-[GrayText]";
|
|
29
|
+
var LINK_DISABLED = "disabled:pointer-events-none disabled:text-th-ghost disabled:no-underline forced-colors:disabled:text-[GrayText]";
|
|
30
|
+
function buttonClass({ variant = "secondary", size = "md", inline = false, className } = {}) {
|
|
31
|
+
return cn(
|
|
32
|
+
BUTTON_BASE,
|
|
33
|
+
variant === "link" ? LINK_SIZE[size] : [BUTTON_SIZE[size], BUTTON_FORCED],
|
|
34
|
+
variant === "link" ? !inline && LINK_HIT : PRESS,
|
|
35
|
+
BUTTON_VARIANT[variant],
|
|
36
|
+
className
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
function linkClass({ tone = "accent", inline = false, className } = {}) {
|
|
40
|
+
return cn(
|
|
41
|
+
"font-medium underline-offset-2 transition-colors duration-150 hover:underline",
|
|
42
|
+
tone === "accent" ? "text-th-accent" : "text-th-hi3 hover:text-th-hi",
|
|
43
|
+
!inline && LINK_HIT,
|
|
44
|
+
className
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
function revealClass(className) {
|
|
48
|
+
return cn(
|
|
49
|
+
"opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100 focus-visible:opacity-100 pointer-coarse:opacity-100",
|
|
50
|
+
className
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
var ICON_SIZE = {
|
|
54
|
+
"2xs": "relative size-5 rounded pointer-fine:after:absolute pointer-fine:after:-inset-0.5 pointer-fine:after:content-['']",
|
|
55
|
+
xs: "size-6 rounded-md",
|
|
56
|
+
sm: "size-7 rounded-lg",
|
|
57
|
+
md: "size-9 rounded-lg"
|
|
58
|
+
};
|
|
59
|
+
var ICON_VARIANT = {
|
|
60
|
+
ghost: { idle: "text-th-hi3 hover:bg-th-elevated hover:text-th-hi", active: "bg-th-elevated text-th-hi" },
|
|
61
|
+
subtle: { idle: "bg-th-elevated text-th-hi hover:bg-th-overlay", active: "bg-th-overlay text-th-hi" },
|
|
62
|
+
soft: { idle: "bg-th-accent-soft text-th-accent hover:bg-th-accent/20", active: "bg-th-accent/25 text-th-accent" }
|
|
63
|
+
};
|
|
64
|
+
var ICON_DANGER = "hover:bg-th-loss-soft hover:text-th-loss active:bg-th-loss-soft active:text-th-loss";
|
|
65
|
+
function iconButtonClass({
|
|
66
|
+
size = "md",
|
|
67
|
+
variant = "ghost",
|
|
68
|
+
tone = "neutral",
|
|
69
|
+
active = false,
|
|
70
|
+
className
|
|
71
|
+
} = {}) {
|
|
72
|
+
return cn(
|
|
73
|
+
"inline-flex shrink-0 items-center justify-center transition-[color,background-color,border-color,transform] duration-150",
|
|
74
|
+
PRESS,
|
|
75
|
+
"disabled:pointer-events-none disabled:bg-transparent disabled:text-th-ghost forced-colors:disabled:text-[GrayText]",
|
|
76
|
+
"pointer-coarse:min-h-11 pointer-coarse:min-w-11",
|
|
77
|
+
// A pressed toggle is shown by fill only, which forced colors drops: outline it.
|
|
78
|
+
active && "forced-colors:outline forced-colors:outline-2 forced-colors:-outline-offset-2 forced-colors:outline-[Highlight]",
|
|
79
|
+
ICON_SIZE[size],
|
|
80
|
+
ICON_VARIANT[variant].idle,
|
|
81
|
+
active && ICON_VARIANT[variant].active,
|
|
82
|
+
tone === "danger" && ICON_DANGER,
|
|
83
|
+
active && tone === "danger" && "bg-th-loss-soft text-th-loss",
|
|
84
|
+
className
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
var CARD_PADDING = {
|
|
88
|
+
none: "",
|
|
89
|
+
sm: "p-3",
|
|
90
|
+
md: "p-4 sm:p-5",
|
|
91
|
+
lg: "p-6"
|
|
92
|
+
};
|
|
93
|
+
var resolvePadding = (padding, padded) => padding ?? (padded === false ? "none" : "md");
|
|
94
|
+
function cardClass({ padding, padded, interactive = false, variant = "surface", className } = {}) {
|
|
95
|
+
const inset = variant === "inset";
|
|
96
|
+
return cn(
|
|
97
|
+
// The inset card has a transparent border; forced colors still draws its edge.
|
|
98
|
+
inset ? "rounded-lg border border-transparent bg-th-elevated forced-colors:border-[CanvasText]" : "rounded-xl border border-th-line bg-th-surface shadow-card",
|
|
99
|
+
CARD_PADDING[resolvePadding(padding, padded)],
|
|
100
|
+
interactive && (inset ? "transition-colors duration-150 hover:bg-th-overlay" : "transition-colors duration-150 hover:border-th-line-strong hover:bg-th-elevated/60"),
|
|
101
|
+
className
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
var BADGE_TONE = {
|
|
105
|
+
neutral: "border-th-line bg-th-elevated text-th-hi2",
|
|
106
|
+
accent: "border-th-accent/30 bg-th-accent-soft text-th-accent",
|
|
107
|
+
ok: "border-th-ok/30 bg-th-ok-soft text-th-ok",
|
|
108
|
+
loss: "border-th-loss/30 bg-th-loss-soft text-th-loss",
|
|
109
|
+
warn: "border-th-warn/30 bg-th-warn-soft text-th-warn",
|
|
110
|
+
info: "border-th-info/30 bg-th-info-soft text-th-info",
|
|
111
|
+
// A label on a solid accent fill (inside a primary Button or an accent link).
|
|
112
|
+
"on-accent": "border-transparent bg-th-on-accent/20 text-th-on-accent"
|
|
113
|
+
};
|
|
114
|
+
var BADGE_HUE = {
|
|
115
|
+
emerald: "border-th-emerald/30 bg-th-emerald-soft text-th-hi",
|
|
116
|
+
indigo: "border-th-indigo/30 bg-th-indigo-soft text-th-hi",
|
|
117
|
+
amber: "border-th-amber/30 bg-th-amber-soft text-th-hi",
|
|
118
|
+
lime: "border-th-lime/30 bg-th-lime-soft text-th-hi",
|
|
119
|
+
rose: "border-th-rose/30 bg-th-rose-soft text-th-hi",
|
|
120
|
+
sky: "border-th-sky/30 bg-th-sky-soft text-th-hi",
|
|
121
|
+
violet: "border-th-violet/30 bg-th-violet-soft text-th-hi",
|
|
122
|
+
teal: "border-th-teal/30 bg-th-teal-soft text-th-hi"
|
|
123
|
+
};
|
|
124
|
+
var DOT_TONE = {
|
|
125
|
+
neutral: "bg-th-ghost",
|
|
126
|
+
accent: "bg-th-accent",
|
|
127
|
+
ok: "bg-th-ok-fill",
|
|
128
|
+
loss: "bg-th-loss-fill",
|
|
129
|
+
warn: "bg-th-warn-fill",
|
|
130
|
+
info: "bg-th-info-fill",
|
|
131
|
+
"on-accent": "bg-th-on-accent"
|
|
132
|
+
};
|
|
133
|
+
var DOT_HUE = {
|
|
134
|
+
emerald: "bg-th-emerald",
|
|
135
|
+
indigo: "bg-th-indigo",
|
|
136
|
+
amber: "bg-th-amber",
|
|
137
|
+
lime: "bg-th-lime",
|
|
138
|
+
rose: "bg-th-rose",
|
|
139
|
+
sky: "bg-th-sky",
|
|
140
|
+
violet: "bg-th-violet",
|
|
141
|
+
teal: "bg-th-teal"
|
|
142
|
+
};
|
|
143
|
+
function badgeClass({ tone = "neutral", hue, size = "sm", variant = "pill", className } = {}) {
|
|
144
|
+
return cn(
|
|
145
|
+
"inline-flex items-center gap-1 whitespace-nowrap rounded-full border font-medium",
|
|
146
|
+
size === "xs" ? "px-1.5 py-0 text-3xs leading-4" : "px-2 py-0.5 text-xs leading-4",
|
|
147
|
+
hue ? BADGE_HUE[hue] : BADGE_TONE[tone],
|
|
148
|
+
// A tag has no border color of its own; forced colors still draws its edge.
|
|
149
|
+
variant === "tag" && "rounded-sm border-transparent font-semibold uppercase tracking-wide forced-colors:border-[CanvasText]",
|
|
150
|
+
className
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
var FIELD = "w-full min-w-0 rounded-lg border border-th-line-control bg-th-elevated text-th-hi placeholder:text-th-hi3 transition-colors duration-150 hover:border-th-hi3/60 focus:border-th-accent focus:outline-none focus:ring-2 focus:ring-th-accent/25 forced-colors:focus:outline-solid forced-colors:focus:outline-2 forced-colors:focus:outline-[Highlight] disabled:cursor-not-allowed disabled:opacity-50 forced-colors:disabled:border-[GrayText] forced-colors:disabled:text-[GrayText] aria-[invalid=true]:border-th-loss";
|
|
154
|
+
var FIELD_SIZE = {
|
|
155
|
+
xs: { box: "h-7 pointer-coarse:min-h-11", pad: "ps-2 pe-2", text: "text-2xs pointer-coarse:text-base" },
|
|
156
|
+
sm: { box: "h-8 pointer-coarse:min-h-11", pad: "ps-2.5 pe-2.5", text: "text-xs pointer-coarse:text-base" },
|
|
157
|
+
md: { box: "h-9 pointer-coarse:min-h-11", pad: "ps-3 pe-3", text: "text-sm pointer-coarse:text-base" }
|
|
158
|
+
};
|
|
159
|
+
var FIELD_INVALID = "border-th-loss hover:border-th-loss";
|
|
160
|
+
function fieldClass({ size = "md", invalid = false, className } = {}) {
|
|
161
|
+
const s = FIELD_SIZE[size];
|
|
162
|
+
return cn(FIELD, s.box, s.pad, s.text, invalid && FIELD_INVALID, className);
|
|
163
|
+
}
|
|
164
|
+
var SELECT_SIZE = {
|
|
165
|
+
xs: { pad: "ps-2 pe-6", chevron: "end-1.5", icon: 12 },
|
|
166
|
+
sm: { pad: "ps-2.5 pe-7", chevron: "end-2", icon: 13 },
|
|
167
|
+
md: { pad: "ps-3 pe-8", chevron: "end-2.5", icon: 14 }
|
|
168
|
+
};
|
|
169
|
+
export {
|
|
170
|
+
BADGE_HUE,
|
|
171
|
+
BADGE_TONE,
|
|
172
|
+
BUTTON_BASE,
|
|
173
|
+
BUTTON_DISABLED,
|
|
174
|
+
BUTTON_SIZE,
|
|
175
|
+
BUTTON_VARIANT,
|
|
176
|
+
CARD_PADDING,
|
|
177
|
+
DOT_HUE,
|
|
178
|
+
DOT_TONE,
|
|
179
|
+
FIELD,
|
|
180
|
+
FIELD_INVALID,
|
|
181
|
+
FIELD_SIZE,
|
|
182
|
+
ICON_DANGER,
|
|
183
|
+
ICON_SIZE,
|
|
184
|
+
ICON_VARIANT,
|
|
185
|
+
LINK_DISABLED,
|
|
186
|
+
LINK_HIT,
|
|
187
|
+
LINK_SIZE,
|
|
188
|
+
PRESS,
|
|
189
|
+
SELECT_SIZE,
|
|
190
|
+
badgeClass,
|
|
191
|
+
buttonClass,
|
|
192
|
+
cardClass,
|
|
193
|
+
fieldClass,
|
|
194
|
+
iconButtonClass,
|
|
195
|
+
linkClass,
|
|
196
|
+
resolvePadding,
|
|
197
|
+
revealClass
|
|
198
|
+
};
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/components/primitives.tsx
|
|
4
|
+
import {
|
|
5
|
+
useId
|
|
6
|
+
} from "react";
|
|
7
|
+
import { cn } from "../cn.js";
|
|
8
|
+
import { ChevronDownIcon, LoaderIcon } from "./icons.js";
|
|
9
|
+
import {
|
|
10
|
+
BUTTON_DISABLED,
|
|
11
|
+
DOT_HUE,
|
|
12
|
+
DOT_TONE,
|
|
13
|
+
LINK_DISABLED,
|
|
14
|
+
SELECT_SIZE,
|
|
15
|
+
badgeClass,
|
|
16
|
+
buttonClass,
|
|
17
|
+
cardClass,
|
|
18
|
+
fieldClass,
|
|
19
|
+
iconButtonClass,
|
|
20
|
+
resolvePadding
|
|
21
|
+
} from "./primitives-classes.js";
|
|
22
|
+
import {
|
|
23
|
+
FIELD,
|
|
24
|
+
badgeClass as badgeClass2,
|
|
25
|
+
buttonClass as buttonClass2,
|
|
26
|
+
cardClass as cardClass2,
|
|
27
|
+
fieldClass as fieldClass2,
|
|
28
|
+
iconButtonClass as iconButtonClass2,
|
|
29
|
+
linkClass,
|
|
30
|
+
revealClass
|
|
31
|
+
} from "./primitives-classes.js";
|
|
32
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
33
|
+
var warned = /* @__PURE__ */ new Set();
|
|
34
|
+
function warnOnce(message) {
|
|
35
|
+
if (globalThis.process?.env?.NODE_ENV === "production" || warned.has(message)) return;
|
|
36
|
+
warned.add(message);
|
|
37
|
+
console.warn(`nish-ui: ${message}`);
|
|
38
|
+
}
|
|
39
|
+
function Button({
|
|
40
|
+
variant = "secondary",
|
|
41
|
+
size = "md",
|
|
42
|
+
inline = false,
|
|
43
|
+
loading = false,
|
|
44
|
+
icon,
|
|
45
|
+
className,
|
|
46
|
+
children,
|
|
47
|
+
disabled,
|
|
48
|
+
type = "button",
|
|
49
|
+
ref,
|
|
50
|
+
...rest
|
|
51
|
+
}) {
|
|
52
|
+
const off = !!disabled || loading;
|
|
53
|
+
return /* @__PURE__ */ jsxs(
|
|
54
|
+
"button",
|
|
55
|
+
{
|
|
56
|
+
ref,
|
|
57
|
+
type,
|
|
58
|
+
disabled: off,
|
|
59
|
+
"aria-busy": loading || void 0,
|
|
60
|
+
"data-disabled": off ? "" : void 0,
|
|
61
|
+
className: buttonClass({
|
|
62
|
+
variant,
|
|
63
|
+
size,
|
|
64
|
+
inline,
|
|
65
|
+
className: cn(variant === "link" ? LINK_DISABLED : BUTTON_DISABLED, className)
|
|
66
|
+
}),
|
|
67
|
+
...rest,
|
|
68
|
+
children: [
|
|
69
|
+
loading ? /* @__PURE__ */ jsx(
|
|
70
|
+
LoaderIcon,
|
|
71
|
+
{
|
|
72
|
+
size: size === "xs" || size === "sm" ? 12 : 14,
|
|
73
|
+
className: "animate-spin motion-reduce:animate-pulse",
|
|
74
|
+
"data-nish-spin": ""
|
|
75
|
+
}
|
|
76
|
+
) : icon,
|
|
77
|
+
children
|
|
78
|
+
]
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
function IconButton({
|
|
83
|
+
label,
|
|
84
|
+
size = "md",
|
|
85
|
+
active,
|
|
86
|
+
variant = "ghost",
|
|
87
|
+
tone = "neutral",
|
|
88
|
+
className,
|
|
89
|
+
children,
|
|
90
|
+
type = "button",
|
|
91
|
+
disabled,
|
|
92
|
+
ref,
|
|
93
|
+
...rest
|
|
94
|
+
}) {
|
|
95
|
+
if (!label && !rest["aria-label"] && !rest["aria-labelledby"]) {
|
|
96
|
+
warnOnce("<IconButton> has no `label`. An icon-only button needs an accessible name.");
|
|
97
|
+
}
|
|
98
|
+
const pressed = active === true;
|
|
99
|
+
return /* @__PURE__ */ jsx(
|
|
100
|
+
"button",
|
|
101
|
+
{
|
|
102
|
+
ref,
|
|
103
|
+
type,
|
|
104
|
+
disabled,
|
|
105
|
+
"aria-label": label,
|
|
106
|
+
title: label,
|
|
107
|
+
"aria-pressed": pressed || void 0,
|
|
108
|
+
"data-state": active === void 0 ? void 0 : pressed ? "active" : "inactive",
|
|
109
|
+
"data-disabled": disabled ? "" : void 0,
|
|
110
|
+
className: iconButtonClass({ size, variant, tone, active: pressed, className }),
|
|
111
|
+
...rest,
|
|
112
|
+
children
|
|
113
|
+
}
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
function CardHeader({
|
|
117
|
+
title,
|
|
118
|
+
description,
|
|
119
|
+
action,
|
|
120
|
+
icon,
|
|
121
|
+
as: Heading = "h2",
|
|
122
|
+
divided = false,
|
|
123
|
+
titleId,
|
|
124
|
+
className,
|
|
125
|
+
ref,
|
|
126
|
+
...rest
|
|
127
|
+
}) {
|
|
128
|
+
return /* @__PURE__ */ jsxs(
|
|
129
|
+
"div",
|
|
130
|
+
{
|
|
131
|
+
ref,
|
|
132
|
+
className: cn(
|
|
133
|
+
"flex flex-wrap items-center justify-between gap-x-3 gap-y-2",
|
|
134
|
+
divided && "border-b border-th-line px-4 py-3",
|
|
135
|
+
className
|
|
136
|
+
),
|
|
137
|
+
...rest,
|
|
138
|
+
children: [
|
|
139
|
+
/* @__PURE__ */ jsxs("div", { className: "flex min-w-0 items-start gap-2", children: [
|
|
140
|
+
icon ? /* @__PURE__ */ jsx("span", { className: "mt-0.5 inline-flex shrink-0 text-th-hi3", "aria-hidden": "true", children: icon }) : null,
|
|
141
|
+
/* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
|
|
142
|
+
/* @__PURE__ */ jsx(Heading, { id: titleId, className: "text-sm font-semibold text-th-hi", children: title }),
|
|
143
|
+
description ? /* @__PURE__ */ jsx("p", { className: "mt-0.5 text-xs text-th-hi3", children: description }) : null
|
|
144
|
+
] })
|
|
145
|
+
] }),
|
|
146
|
+
action ? /* @__PURE__ */ jsx("div", { className: "flex shrink-0 flex-wrap items-center gap-2", children: action }) : null
|
|
147
|
+
]
|
|
148
|
+
}
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
function Card({
|
|
152
|
+
as = "div",
|
|
153
|
+
padding,
|
|
154
|
+
padded,
|
|
155
|
+
interactive = false,
|
|
156
|
+
variant = "surface",
|
|
157
|
+
title,
|
|
158
|
+
description,
|
|
159
|
+
action,
|
|
160
|
+
className,
|
|
161
|
+
children,
|
|
162
|
+
ref,
|
|
163
|
+
...rest
|
|
164
|
+
}) {
|
|
165
|
+
const Tag = as;
|
|
166
|
+
const pad = resolvePadding(padding, padded);
|
|
167
|
+
const headingId = useId();
|
|
168
|
+
const region = title != null && (as === "section" || as === "article" || as === "aside");
|
|
169
|
+
return /* @__PURE__ */ jsxs(
|
|
170
|
+
Tag,
|
|
171
|
+
{
|
|
172
|
+
ref,
|
|
173
|
+
"aria-labelledby": region && !rest["aria-label"] && !rest["aria-labelledby"] ? headingId : void 0,
|
|
174
|
+
className: cardClass({ padding: pad, interactive, variant, className }),
|
|
175
|
+
...rest,
|
|
176
|
+
children: [
|
|
177
|
+
title != null ? /* @__PURE__ */ jsx(
|
|
178
|
+
CardHeader,
|
|
179
|
+
{
|
|
180
|
+
title,
|
|
181
|
+
description,
|
|
182
|
+
action,
|
|
183
|
+
titleId: headingId,
|
|
184
|
+
divided: pad === "none",
|
|
185
|
+
className: pad === "none" ? void 0 : "mb-3"
|
|
186
|
+
}
|
|
187
|
+
) : null,
|
|
188
|
+
children
|
|
189
|
+
]
|
|
190
|
+
}
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
function Badge({
|
|
194
|
+
tone = "neutral",
|
|
195
|
+
hue,
|
|
196
|
+
size = "sm",
|
|
197
|
+
variant = "pill",
|
|
198
|
+
dot = false,
|
|
199
|
+
className,
|
|
200
|
+
children,
|
|
201
|
+
ref,
|
|
202
|
+
...rest
|
|
203
|
+
}) {
|
|
204
|
+
return /* @__PURE__ */ jsxs("span", { ref, className: badgeClass({ tone, hue, size, variant, className }), ...rest, children: [
|
|
205
|
+
dot ? /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: cn("inline-block size-1.5 shrink-0 rounded-full", hue ? DOT_HUE[hue] : DOT_TONE[tone]) }) : null,
|
|
206
|
+
children
|
|
207
|
+
] });
|
|
208
|
+
}
|
|
209
|
+
function Input({ invalid, size = "md", leading, trailing, wrapperClassName, className, ref, ...rest }) {
|
|
210
|
+
const input = /* @__PURE__ */ jsx(
|
|
211
|
+
"input",
|
|
212
|
+
{
|
|
213
|
+
ref,
|
|
214
|
+
"aria-invalid": invalid || void 0,
|
|
215
|
+
className: fieldClass({ size, className: cn(leading != null && "ps-8", trailing != null && "pe-8", className) }),
|
|
216
|
+
...rest
|
|
217
|
+
}
|
|
218
|
+
);
|
|
219
|
+
if (leading == null && trailing == null) return input;
|
|
220
|
+
return /* @__PURE__ */ jsxs("span", { className: cn("relative inline-flex w-full min-w-0 items-center", wrapperClassName), children: [
|
|
221
|
+
leading != null ? /* @__PURE__ */ jsx("span", { className: "pointer-events-none absolute inset-y-0 start-0 flex w-8 items-center justify-center text-sm text-th-hi2", children: leading }) : null,
|
|
222
|
+
input,
|
|
223
|
+
trailing != null ? /* @__PURE__ */ jsx("span", { className: "absolute inset-y-0 end-0 flex min-w-8 items-center justify-center pe-0.5 text-sm text-th-hi2", children: trailing }) : null
|
|
224
|
+
] });
|
|
225
|
+
}
|
|
226
|
+
function Select({ invalid, size = "md", selectClassName, className, children, ref, ...rest }) {
|
|
227
|
+
const s = SELECT_SIZE[size];
|
|
228
|
+
return /* @__PURE__ */ jsxs("span", { className: cn("relative inline-flex w-full min-w-0", className), children: [
|
|
229
|
+
/* @__PURE__ */ jsx(
|
|
230
|
+
"select",
|
|
231
|
+
{
|
|
232
|
+
ref,
|
|
233
|
+
"aria-invalid": invalid || void 0,
|
|
234
|
+
className: fieldClass({ size, className: cn("appearance-none", s.pad, selectClassName) }),
|
|
235
|
+
...rest,
|
|
236
|
+
children
|
|
237
|
+
}
|
|
238
|
+
),
|
|
239
|
+
/* @__PURE__ */ jsx(
|
|
240
|
+
ChevronDownIcon,
|
|
241
|
+
{
|
|
242
|
+
size: s.icon,
|
|
243
|
+
className: cn("pointer-events-none absolute top-1/2 -translate-y-1/2 text-th-hi3", s.chevron)
|
|
244
|
+
}
|
|
245
|
+
)
|
|
246
|
+
] });
|
|
247
|
+
}
|
|
248
|
+
function Label({ className, ref, ...rest }) {
|
|
249
|
+
return /* @__PURE__ */ jsx("span", { ref, className: cn("text-xs font-medium uppercase tracking-wider text-th-hi3", className), ...rest });
|
|
250
|
+
}
|
|
251
|
+
export {
|
|
252
|
+
Badge,
|
|
253
|
+
Button,
|
|
254
|
+
Card,
|
|
255
|
+
CardHeader,
|
|
256
|
+
FIELD,
|
|
257
|
+
IconButton,
|
|
258
|
+
Input,
|
|
259
|
+
Label,
|
|
260
|
+
Select,
|
|
261
|
+
badgeClass2 as badgeClass,
|
|
262
|
+
buttonClass2 as buttonClass,
|
|
263
|
+
cardClass2 as cardClass,
|
|
264
|
+
fieldClass2 as fieldClass,
|
|
265
|
+
iconButtonClass2 as iconButtonClass,
|
|
266
|
+
linkClass,
|
|
267
|
+
revealClass
|
|
268
|
+
};
|