@hezhijie0327/zjdesign 0.1.3 → 0.1.4

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.
@@ -1,2 +1,2 @@
1
- import { _ as watchSystemTheme, a as THEME_BOOTSTRAP, c as THEME_COLOR_LIGHT, d as applyThemeStyle, f as cookieThemeStorage, g as setThemeStyle, h as readThemeStyle, i as useExitPresence, l as ThemeStorage, m as localStorageThemeStorage, n as UseThemeResult, o as THEME_COLOR_BLACK, p as createThemeController, r as useTheme, s as THEME_COLOR_DARK, t as UseThemeOptions, u as ThemeStyle, v as watchThemeDark, y as reducedMotion } from "../index-B-bZqvO6.mjs";
1
+ import { _ as watchSystemTheme, a as THEME_BOOTSTRAP, c as THEME_COLOR_LIGHT, d as applyThemeStyle, f as cookieThemeStorage, g as setThemeStyle, h as readThemeStyle, i as useExitPresence, l as ThemeStorage, m as localStorageThemeStorage, n as UseThemeResult, o as THEME_COLOR_BLACK, p as createThemeController, r as useTheme, s as THEME_COLOR_DARK, t as UseThemeOptions, u as ThemeStyle, v as watchThemeDark, y as reducedMotion } from "../index-UTcA5mi9.mjs";
2
2
  export { THEME_BOOTSTRAP, THEME_COLOR_BLACK, THEME_COLOR_DARK, THEME_COLOR_LIGHT, ThemeStorage, ThemeStyle, UseThemeOptions, UseThemeResult, applyThemeStyle, cookieThemeStorage, createThemeController, localStorageThemeStorage, readThemeStyle, reducedMotion, setThemeStyle, useExitPresence, useTheme, watchSystemTheme, watchThemeDark };
@@ -1,3 +1,3 @@
1
- import { a as THEME_COLOR_DARK, c as cookieThemeStorage, d as readThemeStyle, f as setThemeStyle, h as reducedMotion, i as THEME_COLOR_BLACK, l as createThemeController, m as watchThemeDark, n as useExitPresence, o as THEME_COLOR_LIGHT, p as watchSystemTheme, r as THEME_BOOTSTRAP, s as applyThemeStyle, t as useTheme, u as localStorageThemeStorage } from "../hooks-_Gk75q-U.mjs";
1
+ import { a as THEME_COLOR_DARK, c as cookieThemeStorage, d as readThemeStyle, f as setThemeStyle, h as reducedMotion, i as THEME_COLOR_BLACK, l as createThemeController, m as watchThemeDark, n as useExitPresence, o as THEME_COLOR_LIGHT, p as watchSystemTheme, r as THEME_BOOTSTRAP, s as applyThemeStyle, t as useTheme, u as localStorageThemeStorage } from "../hooks-5sbEaltY.mjs";
2
2
 
3
3
  export { THEME_BOOTSTRAP, THEME_COLOR_BLACK, THEME_COLOR_DARK, THEME_COLOR_LIGHT, applyThemeStyle, cookieThemeStorage, createThemeController, localStorageThemeStorage, readThemeStyle, reducedMotion, setThemeStyle, useExitPresence, useTheme, watchSystemTheme, watchThemeDark };
@@ -97,12 +97,16 @@ const defaultController = /* @__PURE__ */ createThemeController();
97
97
  const readThemeStyle = defaultController.readThemeStyle;
98
98
  const applyThemeStyle = defaultController.applyThemeStyle;
99
99
  const setThemeStyle = defaultController.setThemeStyle;
100
- /** In auto mode, follow the system light/dark switch in real time. */
100
+ /** In auto mode, follow the system light/dark switch in real time.
101
+ * Returns an unsubscribe function (call it on teardown). */
101
102
  function watchSystemTheme(storage = localStorageThemeStorage()) {
102
- window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", () => {
103
+ const mq = window.matchMedia("(prefers-color-scheme: dark)");
104
+ const onChange = () => {
103
105
  const controller = createThemeController(storage);
104
106
  if (controller.readThemeStyle() === "auto") controller.applyThemeStyle("auto");
105
- });
107
+ };
108
+ mq.addEventListener("change", onChange);
109
+ return () => mq.removeEventListener("change", onChange);
106
110
  }
107
111
  /** Subscribe to the dark state (html.dark is the single source of truth; both in-site
108
112
  * toggles and system-follow flip it). Returns an unsubscribe function. Heavy theme
@@ -40,8 +40,9 @@ declare function createThemeController(storage?: ThemeStorage): {
40
40
  declare const readThemeStyle: () => ThemeStyle;
41
41
  declare const applyThemeStyle: (style: ThemeStyle) => void;
42
42
  declare const setThemeStyle: (style: ThemeStyle) => void;
43
- /** In auto mode, follow the system light/dark switch in real time. */
44
- declare function watchSystemTheme(storage?: ThemeStorage): void;
43
+ /** In auto mode, follow the system light/dark switch in real time.
44
+ * Returns an unsubscribe function (call it on teardown). */
45
+ declare function watchSystemTheme(storage?: ThemeStorage): () => void;
45
46
  /** Subscribe to the dark state (html.dark is the single source of truth; both in-site
46
47
  * toggles and system-follow flip it). Returns an unsubscribe function. Heavy theme
47
48
  * dependencies (giscus iframe / mermaid re-render) hook in here — do not attach your own
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { _ as watchSystemTheme, a as THEME_BOOTSTRAP, c as THEME_COLOR_LIGHT, d as applyThemeStyle, f as cookieThemeStorage, g as setThemeStyle, h as readThemeStyle, i as useExitPresence, l as ThemeStorage, m as localStorageThemeStorage, n as UseThemeResult, o as THEME_COLOR_BLACK, p as createThemeController, r as useTheme, s as THEME_COLOR_DARK, t as UseThemeOptions, u as ThemeStyle, v as watchThemeDark, y as reducedMotion } from "./index-B-bZqvO6.mjs";
2
- import * as react1 from "react";
1
+ import { _ as watchSystemTheme, a as THEME_BOOTSTRAP, c as THEME_COLOR_LIGHT, d as applyThemeStyle, f as cookieThemeStorage, g as setThemeStyle, h as readThemeStyle, i as useExitPresence, l as ThemeStorage, m as localStorageThemeStorage, n as UseThemeResult, o as THEME_COLOR_BLACK, p as createThemeController, r as useTheme, s as THEME_COLOR_DARK, t as UseThemeOptions, u as ThemeStyle, v as watchThemeDark, y as reducedMotion } from "./index-UTcA5mi9.mjs";
2
+ import * as react3 from "react";
3
3
  import { ButtonHTMLAttributes, ReactNode, RefObject } from "react";
4
4
 
5
5
  //#region src/components/Button/Button.d.ts
@@ -9,7 +9,7 @@ interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
9
9
  }
10
10
  /** Pill button in the family language (BTN_PRIMARY / BTN_OUTLINE / BTN_GHOST
11
11
  * fragments + the danger state). */
12
- declare const Button: react1.ForwardRefExoticComponent<ButtonProps & react1.RefAttributes<HTMLButtonElement>>;
12
+ declare const Button: react3.ForwardRefExoticComponent<ButtonProps & react3.RefAttributes<HTMLButtonElement>>;
13
13
  //#endregion
14
14
  //#region src/components/Collapse/Collapse.d.ts
15
15
  /**
@@ -42,7 +42,7 @@ declare function Collapse({
42
42
  className?: string;
43
43
  id?: string;
44
44
  children: ReactNode;
45
- }): react1.JSX.Element | null;
45
+ }): react3.JSX.Element | null;
46
46
  //#endregion
47
47
  //#region src/components/IconButton/IconButton.d.ts
48
48
  interface IconButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
@@ -51,7 +51,7 @@ interface IconButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
51
51
  active?: boolean;
52
52
  }
53
53
  /** Round icon button (ICON_BTN fragment); `active` lights the accent. */
54
- declare const IconButton: react1.ForwardRefExoticComponent<IconButtonProps & react1.RefAttributes<HTMLButtonElement>>;
54
+ declare const IconButton: react3.ForwardRefExoticComponent<IconButtonProps & react3.RefAttributes<HTMLButtonElement>>;
55
55
  //#endregion
56
56
  //#region src/components/CopyButton/CopyButton.d.ts
57
57
  interface CopyButtonProps extends Omit<IconButtonProps, "label" | "children" | "onClick"> {
@@ -69,7 +69,7 @@ declare function CopyButton({
69
69
  label,
70
70
  feedbackMs,
71
71
  ...props
72
- }: CopyButtonProps): react1.JSX.Element;
72
+ }: CopyButtonProps): react3.JSX.Element;
73
73
  //#endregion
74
74
  //#region src/components/Dropdown/Dropdown.d.ts
75
75
  interface DropdownOption {
@@ -90,7 +90,9 @@ interface DropdownProps {
90
90
  }
91
91
  /** Custom select wearing the family skin: hairline trigger button + CARD
92
92
  * popover list (LIST_ROW rows, accent check on the selected option).
93
- * Replaces every native <select> — the OS dropdown sheet breaks the style. */
93
+ * Replaces every native <select> — the OS dropdown sheet breaks the style.
94
+ * Keyboard: ArrowDown/Up opens and moves through options, Home/End jump,
95
+ * Enter picks, Esc closes back to the trigger (APG listbox pattern). */
94
96
  declare function Dropdown({
95
97
  label,
96
98
  value,
@@ -101,7 +103,7 @@ declare function Dropdown({
101
103
  menuClassName,
102
104
  disabled,
103
105
  id
104
- }: DropdownProps): react1.JSX.Element;
106
+ }: DropdownProps): react3.JSX.Element;
105
107
  //#endregion
106
108
  //#region src/components/Kbd/Kbd.d.ts
107
109
  /** Mono chip for keys / states (MONO_CHIP fragment with tighter padding). */
@@ -111,7 +113,7 @@ declare function Kbd({
111
113
  }: {
112
114
  children: ReactNode;
113
115
  className?: string;
114
- }): react1.JSX.Element;
116
+ }): react3.JSX.Element;
115
117
  /** Single-line panel row label (text-sm) — the standard row label inside
116
118
  * toolbar panels. Never wraps: narrow rows scale via column layout instead. */
117
119
  declare const ROW_LABEL = "shrink-0 whitespace-nowrap text-sm text-ink";
@@ -136,7 +138,7 @@ declare function Modal({
136
138
  label,
137
139
  className,
138
140
  children
139
- }: ModalProps): react1.ReactPortal | null;
141
+ }: ModalProps): react3.ReactPortal | null;
140
142
  //#endregion
141
143
  //#region src/components/Popover/Popover.d.ts
142
144
  interface PopoverProps {
@@ -160,7 +162,7 @@ declare function Popover({
160
162
  className,
161
163
  children,
162
164
  anchorRef
163
- }: PopoverProps): react1.JSX.Element | null;
165
+ }: PopoverProps): react3.JSX.Element | null;
164
166
  //#endregion
165
167
  //#region src/components/ProgressBar/ProgressBar.d.ts
166
168
  /** Top-of-page loading bar: 2px accent strip riding the `progress` keyframes
@@ -170,7 +172,7 @@ declare function ProgressBar({
170
172
  className
171
173
  }: {
172
174
  className?: string;
173
- }): react1.JSX.Element;
175
+ }): react3.JSX.Element;
174
176
  //#endregion
175
177
  //#region src/components/Segmented/Segmented.d.ts
176
178
  interface SegmentedProps<T extends string | number> {
@@ -190,7 +192,7 @@ declare function Segmented<T extends string | number>({
190
192
  onChange,
191
193
  label,
192
194
  className
193
- }: SegmentedProps<T>): react1.JSX.Element;
195
+ }: SegmentedProps<T>): react3.JSX.Element;
194
196
  //#endregion
195
197
  //#region src/components/Slider/Slider.d.ts
196
198
  interface SliderProps {
@@ -215,7 +217,7 @@ declare function Slider({
215
217
  label,
216
218
  display,
217
219
  className
218
- }: SliderProps): react1.JSX.Element;
220
+ }: SliderProps): react3.JSX.Element;
219
221
  //#endregion
220
222
  //#region src/components/Switch/Switch.d.ts
221
223
  interface SwitchProps {
@@ -232,12 +234,12 @@ declare function Switch({
232
234
  label,
233
235
  className,
234
236
  disabled
235
- }: SwitchProps): react1.JSX.Element;
237
+ }: SwitchProps): react3.JSX.Element;
236
238
  //#endregion
237
239
  //#region src/components/Toast/Toaster.d.ts
238
240
  /** Toast stack: bottom-center paper cards, fade-up in, auto-removed after 3 s.
239
241
  * Mount once near the app root. */
240
- declare function Toaster(): react1.JSX.Element | null;
242
+ declare function Toaster(): react3.JSX.Element | null;
241
243
  //#endregion
242
244
  //#region src/components/Toast/types.d.ts
243
245
  interface ToastItem {
@@ -248,7 +250,6 @@ interface ToastItem {
248
250
  //#endregion
249
251
  //#region src/components/Toast/toast.d.ts
250
252
  type Listener = (toasts: ToastItem[]) => void;
251
- /** Push a toast; `tone` picks the border/text treatment ("ok" default). */
252
253
  declare function toast(text: string, tone?: ToastItem["tone"]): void;
253
254
  declare function subscribeToasts(listener: Listener): () => void;
254
255
  declare function getToasts(): ToastItem[];
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { A as SEGMENT, M as SEGMENT_ITEM_OFF, N as SEGMENT_ITEM_ON, V as cn, _ as META, a as BTN_PRIMARY, b as MODAL_SCRIM, h as LIST_ROW, i as BTN_OUTLINE, o as CARD, p as ICON_BTN, r as BTN_GHOST, x as MONO_CHIP } from "./styles-DhIa1Tm9.mjs";
2
- import { a as THEME_COLOR_DARK, c as cookieThemeStorage, d as readThemeStyle, f as setThemeStyle, h as reducedMotion, i as THEME_COLOR_BLACK, l as createThemeController, m as watchThemeDark, n as useExitPresence, o as THEME_COLOR_LIGHT, p as watchSystemTheme, r as THEME_BOOTSTRAP, s as applyThemeStyle, t as useTheme, u as localStorageThemeStorage } from "./hooks-_Gk75q-U.mjs";
2
+ import { a as THEME_COLOR_DARK, c as cookieThemeStorage, d as readThemeStyle, f as setThemeStyle, h as reducedMotion, i as THEME_COLOR_BLACK, l as createThemeController, m as watchThemeDark, n as useExitPresence, o as THEME_COLOR_LIGHT, p as watchSystemTheme, r as THEME_BOOTSTRAP, s as applyThemeStyle, t as useTheme, u as localStorageThemeStorage } from "./hooks-5sbEaltY.mjs";
3
3
  import { forwardRef, useEffect, useRef, useState, useSyncExternalStore } from "react";
4
4
  import { jsx, jsxs } from "react/jsx-runtime";
5
5
  import { Check, ChevronDown, Copy } from "lucide-react";
@@ -171,11 +171,36 @@ function Popover({ open, onClose, side = "bottom", align = "center", className,
171
171
  //#region src/components/Dropdown/Dropdown.tsx
172
172
  /** Custom select wearing the family skin: hairline trigger button + CARD
173
173
  * popover list (LIST_ROW rows, accent check on the selected option).
174
- * Replaces every native <select> — the OS dropdown sheet breaks the style. */
174
+ * Replaces every native <select> — the OS dropdown sheet breaks the style.
175
+ * Keyboard: ArrowDown/Up opens and moves through options, Home/End jump,
176
+ * Enter picks, Esc closes back to the trigger (APG listbox pattern). */
175
177
  function Dropdown({ label, value, options, onChange, onOpen, className, menuClassName, disabled, id }) {
176
178
  const [open, setOpen] = useState(false);
177
179
  const buttonRef = useRef(null);
180
+ const listRef = useRef(null);
178
181
  const current = options.find((option) => option.value === value);
182
+ useEffect(() => {
183
+ if (!open) return;
184
+ (listRef.current?.querySelector("[aria-selected=\"true\"]") ?? listRef.current?.querySelector("button"))?.focus();
185
+ }, [open]);
186
+ const openMenu = () => {
187
+ if (!open) onOpen?.();
188
+ setOpen(true);
189
+ };
190
+ const moveFocus = (event) => {
191
+ const buttons = [...listRef.current?.querySelectorAll("button[role=option]") ?? []];
192
+ if (buttons.length === 0) return;
193
+ const activeIdx = buttons.indexOf(document.activeElement);
194
+ let next = activeIdx;
195
+ if (event.key === "ArrowDown") next = Math.min(activeIdx + 1, buttons.length - 1);
196
+ else if (event.key === "ArrowUp") next = Math.max(activeIdx - 1, 0);
197
+ else if (event.key === "Home") next = 0;
198
+ else if (event.key === "End") next = buttons.length - 1;
199
+ else return;
200
+ event.preventDefault();
201
+ event.stopPropagation();
202
+ buttons[next]?.focus();
203
+ };
179
204
  return /* @__PURE__ */ jsxs("div", {
180
205
  className: cn("relative", className),
181
206
  children: [/* @__PURE__ */ jsxs("button", {
@@ -187,9 +212,15 @@ function Dropdown({ label, value, options, onChange, onOpen, className, menuClas
187
212
  "aria-label": label,
188
213
  title: label,
189
214
  disabled: disabled || options.length === 0,
215
+ onKeyDown: (event) => {
216
+ if (event.key === "ArrowDown" || event.key === "ArrowUp") {
217
+ event.preventDefault();
218
+ openMenu();
219
+ }
220
+ },
190
221
  onClick: () => {
191
- if (!open) onOpen?.();
192
- setOpen((o) => !o);
222
+ if (open) setOpen(false);
223
+ else openMenu();
193
224
  },
194
225
  className: "inline-flex h-9 w-full items-center justify-between gap-2 rounded-xl border border-line bg-surface px-3 text-[13px] text-ink transition-colors hover:bg-surface-2 disabled:opacity-50",
195
226
  children: [/* @__PURE__ */ jsx("span", {
@@ -207,8 +238,11 @@ function Dropdown({ label, value, options, onChange, onOpen, className, menuClas
207
238
  anchorRef: buttonRef,
208
239
  className: cn("w-full min-w-44", menuClassName),
209
240
  children: /* @__PURE__ */ jsx("div", {
241
+ ref: listRef,
210
242
  role: "listbox",
211
243
  "aria-label": label,
244
+ tabIndex: -1,
245
+ onKeyDown: moveFocus,
212
246
  className: "divide-y divide-line/70",
213
247
  children: options.map((option) => {
214
248
  const selected = option.value === value;
@@ -376,7 +410,12 @@ let nextId = 1;
376
410
  function emit() {
377
411
  for (const listener of listeners) listener(toasts);
378
412
  }
379
- /** Push a toast; `tone` picks the border/text treatment ("ok" default). */
413
+ /** Push a toast; `tone` picks the border/text treatment ("ok" default).
414
+ * Danger lingers longer — failure text that vanishes as fast as success
415
+ * text gets missed, and burst failures would otherwise replace each other
416
+ * unread. */
417
+ const OK_MS = 3e3;
418
+ const DANGER_MS = 6e3;
380
419
  function toast(text, tone = "ok") {
381
420
  const id = nextId++;
382
421
  toasts = [...toasts.slice(-3), {
@@ -388,7 +427,7 @@ function toast(text, tone = "ok") {
388
427
  window.setTimeout(() => {
389
428
  toasts = toasts.filter((item) => item.id !== id);
390
429
  emit();
391
- }, 3e3);
430
+ }, tone === "danger" ? DANGER_MS : OK_MS);
392
431
  }
393
432
  function subscribeToasts(listener) {
394
433
  listeners.add(listener);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hezhijie0327/zjdesign",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "ZJ Design — the shared design system of the ZJ product family (warm paper / ink / amber-gold). Tokens, Tailwind fragments, hooks and React components.",
5
5
  "keywords": [
6
6
  "design-system",