@hamster-note/components 0.2.1-beta.3 → 0.4.0-beta.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 (100) hide show
  1. package/README.md +341 -73
  2. package/dist/Icon-BuZRZcjv.js +1143 -0
  3. package/dist/button-mmBNcoG1.js +45 -0
  4. package/dist/button.js +1 -1
  5. package/dist/components/button/Button.d.ts +5 -3
  6. package/dist/components/dialog/Dialog.d.ts +3 -1
  7. package/dist/components/drawer/Drawer.d.ts +3 -1
  8. package/dist/components/icon/icon-names.d.ts +1 -15
  9. package/dist/components/menu/Menu.d.ts +11 -19
  10. package/dist/components/menu/Menu.placement.test.d.ts +1 -0
  11. package/dist/components/menu/MenuSubmenu.d.ts +13 -0
  12. package/dist/components/menu/MenuSurface.d.ts +12 -0
  13. package/dist/components/menu/menu-tree-context.d.ts +9 -0
  14. package/dist/components/popover/use-anchor-position.d.ts +16 -1
  15. package/dist/components/popover/use-anchor-position.test.d.ts +1 -0
  16. package/dist/components/theme/theme-context.d.ts +10 -0
  17. package/dist/components/theme/theme.d.ts +1 -87
  18. package/dist/{confirm-3eBmopl8.js → confirm-DKgVMWkR.js} +4 -5
  19. package/dist/confirm.js +1 -1
  20. package/dist/dialog-DI_yumUn.js +102 -0
  21. package/dist/dialog.js +1 -1
  22. package/dist/drawer-Cpe3Yf3K.js +120 -0
  23. package/dist/drawer.js +1 -1
  24. package/dist/hamster-note-components.css +1 -1
  25. package/dist/icon-u7jiIYal.js +5 -0
  26. package/dist/icon.js +2 -1
  27. package/dist/index.js +10 -9
  28. package/dist/menu-B4WwCQyw.js +179 -0
  29. package/dist/menu.js +1 -1
  30. package/dist/{popover-baLHE3lf.js → popover-D00SlGpL.js} +1 -1
  31. package/dist/popover.js +1 -1
  32. package/dist/shared/icon-names.d.ts +15 -0
  33. package/dist/shared/icons.d.ts +1216 -0
  34. package/dist/shared/theme.d.ts +87 -0
  35. package/dist/shared/tokens.d.ts +67 -0
  36. package/dist/test/fields-and-cards.test.d.ts +1 -0
  37. package/dist/test/imperative-apis.test.d.ts +1 -0
  38. package/dist/test/modals.test.d.ts +1 -0
  39. package/dist/test/primitives.test.d.ts +1 -0
  40. package/dist/test/setup.d.ts +0 -0
  41. package/dist/test/shared-data.test.d.ts +1 -0
  42. package/dist/test/theme-and-popover.test.d.ts +1 -0
  43. package/dist/{theme-C0p_hpKk.js → theme-DNK-xd31.js} +30 -22
  44. package/dist/theme-context-CdWvVVP8.js +8 -0
  45. package/dist/theme.js +1 -1
  46. package/dist/use-anchor-position-D3QBcIet.js +166 -0
  47. package/dist-native/badge.d.ts +10 -0
  48. package/dist-native/badge.js +7 -0
  49. package/dist-native/button.d.ts +16 -0
  50. package/dist-native/button.js +7 -0
  51. package/dist-native/chunk-6RD26X3W.js +78 -0
  52. package/dist-native/chunk-6SR5ZHDD.js +13 -0
  53. package/dist-native/chunk-6VYUVVCP.js +27 -0
  54. package/dist-native/chunk-7LN4VNRB.js +124 -0
  55. package/dist-native/chunk-CF76TWL4.js +85 -0
  56. package/dist-native/chunk-ENTYQ6M4.js +256 -0
  57. package/dist-native/chunk-GSG6CXIE.js +1688 -0
  58. package/dist-native/chunk-JHT74YG3.js +186 -0
  59. package/dist-native/chunk-KPDK62A5.js +106 -0
  60. package/dist-native/chunk-PLFX4RVR.js +134 -0
  61. package/dist-native/chunk-QUGLAOXA.js +49 -0
  62. package/dist-native/chunk-S2EUKEYI.js +35 -0
  63. package/dist-native/chunk-VTE5RPMO.js +38 -0
  64. package/dist-native/chunk-YJ4H3ZBQ.js +145 -0
  65. package/dist-native/chunk-ZTQATW6Y.js +127 -0
  66. package/dist-native/confirm.d.ts +24 -0
  67. package/dist-native/confirm.js +14 -0
  68. package/dist-native/dialog.d.ts +8 -0
  69. package/dist-native/dialog.js +10 -0
  70. package/dist-native/drawer.d.ts +13 -0
  71. package/dist-native/drawer.js +10 -0
  72. package/dist-native/focus-C0k0lLui.d.ts +9 -0
  73. package/dist-native/icon.d.ts +28 -0
  74. package/dist-native/icon.js +9 -0
  75. package/dist-native/index.d.ts +20 -0
  76. package/dist-native/index.js +84 -0
  77. package/dist-native/kbd.d.ts +9 -0
  78. package/dist-native/kbd.js +7 -0
  79. package/dist-native/loading.d.ts +19 -0
  80. package/dist-native/loading.js +11 -0
  81. package/dist-native/menu.d.ts +31 -0
  82. package/dist-native/menu.js +17 -0
  83. package/dist-native/modal-panel-BOpp1oRC.d.ts +23 -0
  84. package/dist-native/note-card.d.ts +13 -0
  85. package/dist-native/note-card.js +7 -0
  86. package/dist-native/popover.d.ts +34 -0
  87. package/dist-native/popover.js +8 -0
  88. package/dist-native/position-CkPoZ5AD.d.ts +3 -0
  89. package/dist-native/text-field.d.ts +13 -0
  90. package/dist-native/text-field.js +7 -0
  91. package/dist-native/theme.d.ts +120 -0
  92. package/dist-native/theme.js +16 -0
  93. package/dist-native/tokens-DHoNd-yT.d.ts +41 -0
  94. package/package.json +151 -6
  95. package/dist/button-DRz0VTkf.js +0 -18
  96. package/dist/dialog-B4xS5zlK.js +0 -53
  97. package/dist/drawer-DoeuGAHD.js +0 -60
  98. package/dist/icon-DNZLJUqH.js +0 -517
  99. package/dist/menu-Dj-Dje_l.js +0 -153
  100. package/dist/use-anchor-position-DWle8yoL.js +0 -87
@@ -0,0 +1,45 @@
1
+ /* empty css */
2
+ import { jsx as e } from "react/jsx-runtime";
3
+ //#region src/shared/tokens.ts
4
+ var t = {
5
+ small: {
6
+ height: 30,
7
+ padding: 11,
8
+ fontSize: 12
9
+ },
10
+ medium: {
11
+ height: 36,
12
+ padding: 14,
13
+ fontSize: 13
14
+ },
15
+ large: {
16
+ height: 42,
17
+ padding: 18,
18
+ fontSize: 14
19
+ }
20
+ };
21
+ //#endregion
22
+ //#region src/components/button/Button.tsx
23
+ function n({ children: n, className: r, ghost: i = !1, size: a = "medium", type: o = "button", style: s, variant: c = "secondary", ...l }) {
24
+ let u = c === "ghost" ? "secondary" : c, d = i || c === "ghost", f = [
25
+ "hn-button",
26
+ `hn-button--${u}`,
27
+ d && "hn-button--ghost",
28
+ `hn-button--${a}`,
29
+ r
30
+ ].filter(Boolean).join(" "), p = t[a], m = {
31
+ "--hn-button-min-height": `${String(p.height)}px`,
32
+ "--hn-button-padding": `${String(p.padding)}px`,
33
+ "--hn-button-font-size": `${String(p.fontSize)}px`,
34
+ ...s
35
+ };
36
+ return /* @__PURE__ */ e("button", {
37
+ className: f,
38
+ type: o,
39
+ ...l,
40
+ style: m,
41
+ children: n
42
+ });
43
+ }
44
+ //#endregion
45
+ export { n as t };
package/dist/button.js CHANGED
@@ -1,2 +1,2 @@
1
- import { t as e } from "./button-DRz0VTkf.js";
1
+ import { t as e } from "./button-mmBNcoG1.js";
2
2
  export { e as Button };
@@ -1,9 +1,11 @@
1
+ import { BUTTON_SIZES } from '../../shared/tokens';
1
2
  import { ButtonHTMLAttributes, ReactNode } from 'react';
2
- export type ButtonVariant = 'primary' | 'secondary' | 'ghost';
3
- export type ButtonSize = 'small' | 'medium' | 'large';
3
+ export type ButtonVariant = 'primary' | 'secondary' | 'ghost' | 'danger' | 'warning' | 'success' | 'info';
4
+ export type ButtonSize = keyof typeof BUTTON_SIZES;
4
5
  export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
5
6
  readonly children: ReactNode;
7
+ readonly ghost?: boolean;
6
8
  readonly variant?: ButtonVariant;
7
9
  readonly size?: ButtonSize;
8
10
  }
9
- export declare function Button({ children, className, size, type, variant, ...props }: ButtonProps): import("react").JSX.Element;
11
+ export declare function Button({ children, className, ghost, size, type, style, variant, ...props }: ButtonProps): import("react").JSX.Element;
@@ -6,6 +6,8 @@ export interface DialogProps extends HTMLAttributes<HTMLDivElement> {
6
6
  readonly description?: string | undefined;
7
7
  readonly closeOnEsc?: boolean | undefined;
8
8
  readonly closeOnBackdrop?: boolean | undefined;
9
+ readonly showCloseButton?: boolean | undefined;
10
+ readonly showFullscreenButton?: boolean | undefined;
9
11
  readonly ref?: Ref<HTMLDivElement>;
10
12
  }
11
- export declare function Dialog({ children, className, title, description, open, onClose, closeOnEsc, closeOnBackdrop, ref, style, ...props }: DialogProps): import('react').ReactPortal | null;
13
+ export declare function Dialog({ children, className, title, description, open, onClose, closeOnEsc, closeOnBackdrop, showCloseButton, showFullscreenButton, ref, style, ...props }: DialogProps): import('react').ReactPortal | null;
@@ -9,6 +9,8 @@ export interface DrawerProps extends HTMLAttributes<HTMLDivElement> {
9
9
  readonly size?: number | undefined;
10
10
  readonly closeOnEsc?: boolean | undefined;
11
11
  readonly closeOnBackdrop?: boolean | undefined;
12
+ readonly showCloseButton?: boolean | undefined;
13
+ readonly showFullscreenButton?: boolean | undefined;
12
14
  readonly ref?: Ref<HTMLDivElement>;
13
15
  }
14
- export declare function Drawer({ children, className, title, description, open, onClose, placement, size, closeOnEsc, closeOnBackdrop, ref, style, ...props }: DrawerProps): import('react').ReactPortal | null;
16
+ export declare function Drawer({ children, className, title, description, open, onClose, placement, size, closeOnEsc, closeOnBackdrop, showCloseButton, showFullscreenButton, ref, style, ...props }: DrawerProps): import('react').ReactPortal | null;
@@ -1,15 +1 @@
1
- /**
2
- * Icon 名称数组 + 派生类型
3
- * ───────────────────────────────────────────────────────────────────────────
4
- * 把名称数组从 Icon.tsx 拆出来的原因:
5
- * `react-refresh/only-export-components` 要求一个文件要么只导出组件,要么把
6
- * 非组件导出拆到独立文件。Icon.tsx 同时导出 Icon 组件和 ICON_NAMES 常量会
7
- * 触发该规则,故把名称数组 + 类型派生放到这里。
8
- *
9
- * 设计:单一数据源。IconName 类型从 ICON_NAMES 数组派生,避免数组与联合
10
- * 类型之间出现漂移。新增图标只需在数组里追加一个字面量。
11
- */
12
- /** 55 个图标名称字面量数组(运行时枚举与 demo 遍历用) */
13
- export declare const ICON_NAMES: readonly ["file", "save", "study", "switch", "mouse", "line", "curve", "polygon", "lasso", "rectangle", "ellipse", "pen", "eraser", "magnet", "locate", "delete", "add", "copy", "paste", "info", "touch", "edit", "keyboard", "type", "handle", "card", "minimap", "font-size", "drag", "search", "close", "check", "chevron-down", "chevron-up", "chevron-left", "chevron-right", "arrow-up", "arrow-down", "arrow-left", "arrow-right", "settings", "user", "home", "star", "bookmark", "link", "image", "calendar", "clock", "bell", "download", "upload", "share", "undo", "redo", "zoom-in", "zoom-out", "menu", "more", "filter", "sort"];
14
- /** 55 个图标的名称联合类型(从 ICON_NAMES 派生,单一数据源) */
15
- export type IconName = (typeof ICON_NAMES)[number];
1
+ export { ICON_NAMES, type IconName } from '../../shared/icon-names';
@@ -1,15 +1,14 @@
1
- import { ButtonHTMLAttributes, HTMLAttributes, ReactNode, Ref } from 'react';
2
- import { FloatingPlacement } from '../popover/use-anchor-position';
1
+ import { ButtonHTMLAttributes, HTMLAttributes, ReactNode } from 'react';
2
+ import { MenuSurfaceProps } from './MenuSurface';
3
+ import { MenuPlacement } from './menu-tree-context';
4
+ export type { MenuSubmenuProps } from './MenuSubmenu';
5
+ export { MenuSubmenu } from './MenuSubmenu';
6
+ export type { MenuPlacement } from './menu-tree-context';
3
7
  export type MenuItemTone = 'default' | 'danger';
4
- export type MenuPlacement = FloatingPlacement;
5
- export interface MenuProps extends HTMLAttributes<HTMLDivElement> {
6
- readonly children: ReactNode;
7
- readonly anchor?: HTMLElement | null;
8
- readonly placement?: MenuPlacement;
9
- readonly anchorOffset?: number;
10
- readonly anchorCrossOffset?: number;
11
- readonly viewportMargin?: number;
12
- readonly ref?: Ref<HTMLDivElement>;
8
+ export interface MenuProps extends MenuSurfaceProps {
9
+ readonly submenuPlacement?: MenuPlacement;
10
+ readonly submenuOffset?: number;
11
+ readonly submenuViewportMargin?: number;
13
12
  }
14
13
  export interface MenuItemProps extends ButtonHTMLAttributes<HTMLButtonElement> {
15
14
  readonly children: ReactNode;
@@ -20,14 +19,7 @@ export type MenuSeparatorProps = Omit<HTMLAttributes<HTMLHRElement>, 'children'>
20
19
  export interface MenuLabelProps extends HTMLAttributes<HTMLDivElement> {
21
20
  readonly children: ReactNode;
22
21
  }
23
- export interface MenuSubmenuProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
24
- readonly label: ReactNode;
25
- readonly children: ReactNode;
26
- readonly 'aria-label'?: string;
27
- readonly disabled?: boolean;
28
- }
29
- export declare function Menu({ children, className, anchor, placement, anchorOffset, anchorCrossOffset, viewportMargin, ref, style, ...props }: MenuProps): import("react").JSX.Element;
22
+ export declare function Menu({ submenuOffset, submenuPlacement, submenuViewportMargin, ...props }: MenuProps): import("react").JSX.Element;
30
23
  export declare function MenuItem({ children, className, shortcut, tone, type, ...props }: MenuItemProps): import("react").JSX.Element;
31
24
  export declare function MenuSeparator({ className, ...props }: MenuSeparatorProps): import("react").JSX.Element;
32
25
  export declare function MenuLabel({ children, className, ...props }: MenuLabelProps): import("react").JSX.Element;
33
- export declare function MenuSubmenu({ label, children, className, disabled, 'aria-label': ariaLabel, ...props }: MenuSubmenuProps): import("react").JSX.Element;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ import { HTMLAttributes, ReactNode } from 'react';
2
+ import { MenuPlacement } from './menu-tree-context';
3
+ export interface MenuSubmenuProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
4
+ readonly label: ReactNode;
5
+ readonly children: ReactNode;
6
+ readonly 'aria-label'?: string;
7
+ readonly disabled?: boolean;
8
+ readonly panelTheme?: 'light' | 'dark';
9
+ readonly placement?: MenuPlacement;
10
+ readonly offset?: number;
11
+ readonly viewportMargin?: number;
12
+ }
13
+ export declare function MenuSubmenu({ label, children, className, disabled, offset, panelTheme, placement, viewportMargin, 'aria-label': ariaLabel, ...props }: MenuSubmenuProps): import("react").JSX.Element;
@@ -0,0 +1,12 @@
1
+ import { HTMLAttributes, ReactNode, Ref } from 'react';
2
+ import { MenuPlacement } from './menu-tree-context';
3
+ export interface MenuSurfaceProps extends HTMLAttributes<HTMLDivElement> {
4
+ readonly children: ReactNode;
5
+ readonly anchor?: HTMLElement | null;
6
+ readonly placement?: MenuPlacement;
7
+ readonly anchorOffset?: number;
8
+ readonly anchorCrossOffset?: number;
9
+ readonly viewportMargin?: number;
10
+ readonly ref?: Ref<HTMLDivElement>;
11
+ }
12
+ export declare function MenuSurface({ children, className, anchor, placement, anchorOffset, anchorCrossOffset, viewportMargin, ref, style, ...props }: MenuSurfaceProps): import("react").JSX.Element;
@@ -0,0 +1,9 @@
1
+ import { FloatingPlacement } from '../popover/use-anchor-position';
2
+ export type MenuPlacement = FloatingPlacement;
3
+ export interface MenuTreeConfig {
4
+ readonly submenuOffset: number;
5
+ readonly submenuPlacement: MenuPlacement;
6
+ readonly submenuViewportMargin: number;
7
+ }
8
+ export declare const DEFAULT_MENU_TREE_CONFIG: MenuTreeConfig;
9
+ export declare const MenuTreeContext: import('react').Context<MenuTreeConfig>;
@@ -1,5 +1,5 @@
1
1
  import { CSSProperties, RefObject } from 'react';
2
- export type FloatingPlacement = 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end' | 'left-start' | 'right-start';
2
+ export type FloatingPlacement = 'top-start' | 'top' | 'top-end' | 'bottom-start' | 'bottom' | 'bottom-end' | 'left-start' | 'left' | 'left-end' | 'right-start' | 'right' | 'right-end';
3
3
  export interface UseAnchorPositionOptions {
4
4
  readonly anchor: HTMLElement | null;
5
5
  readonly placement?: FloatingPlacement;
@@ -11,4 +11,19 @@ export interface UseAnchorPositionResult {
11
11
  readonly floatingRef: RefObject<HTMLDivElement | null>;
12
12
  readonly style: CSSProperties;
13
13
  }
14
+ export interface ComputeFloatingPositionOptions {
15
+ readonly anchorRect: DOMRect;
16
+ readonly crossOffset: number;
17
+ readonly floatingHeight: number;
18
+ readonly floatingWidth: number;
19
+ readonly offset: number;
20
+ readonly placement: FloatingPlacement;
21
+ readonly viewportHeight: number;
22
+ readonly viewportMargin: number;
23
+ readonly viewportWidth: number;
24
+ }
25
+ export declare function computeFloatingPosition({ anchorRect, crossOffset, floatingHeight, floatingWidth, offset, placement, viewportHeight, viewportMargin, viewportWidth, }: ComputeFloatingPositionOptions): {
26
+ readonly left: number;
27
+ readonly top: number;
28
+ };
14
29
  export declare function useAnchorPosition({ anchor, placement, offset, crossOffset, viewportMargin, }: UseAnchorPositionOptions): UseAnchorPositionResult;
@@ -0,0 +1,10 @@
1
+ import { CSSProperties } from 'react';
2
+ import { ThemeMode } from './theme';
3
+ export type ThemeStyle = CSSProperties & Partial<Record<'--hn-color-accent' | '--hn-color-accent-hover' | '--hn-focus-ring', string>>;
4
+ export interface ThemeScope {
5
+ readonly accent: string;
6
+ readonly mode: ThemeMode;
7
+ readonly style: ThemeStyle;
8
+ }
9
+ export declare const ThemeContext: import('react').Context<ThemeScope | null>;
10
+ export declare function useThemeScope(): ThemeScope | null;
@@ -1,87 +1 @@
1
- /**
2
- * 主题色配置(accent 主色)。
3
- *
4
- * 设计哲学:组件库所有组件只引用全局 token(见 tokens.css 的 :root),
5
- * 主题切换通过在包裹层重定义同名 token、经 CSS 级联让子树自动继承
6
- * (Popover 的 dark/light 即是这一范式)。本文件是 accent 主题色的
7
- * 唯一数据源:ThemeProvider 读取这里的预设值,内联下发到包裹 div 的
8
- * style 上,子树所有组件经 var(--hn-color-accent) 等拿到新色值。
9
- *
10
- * 预设色刻意避开既有语义色(danger #fb7185 / success #4ade80 /
11
- * warning #fbbf24),避免主题色与语义色产生视觉冲突。
12
- */
13
- /**
14
- * 预设主题色表。
15
- *
16
- * 每个预设包含三个字段,分别对应 tokens.css 中被 accent 影响的三个 token:
17
- * - accent:主色,映射到 --hn-color-accent
18
- * - accentHover:hover 态色,映射到 --hn-color-accent-hover
19
- * - focusRingColor:焦点环颜色(不含 box-shadow 前缀,仅颜色部分),
20
- * ThemeProvider 会拼成 `0 0 0 3px ${focusRingColor}` 写入 --hn-focus-ring
21
- *
22
- * `violet` 与 tokens.css 的默认值完全一致,作为 ThemeProvider 的默认预设,
23
- * 保证不传 accent 时视觉与未包裹 ThemeProvider 时完全等价(零 Breaking Change)。
24
- */
25
- export declare const THEME_ACCENTS: {
26
- readonly violet: {
27
- readonly accent: "#7c83ff";
28
- readonly accentHover: "#9197ff";
29
- readonly focusRingColor: "rgb(145 151 255 / 42%)";
30
- };
31
- readonly blue: {
32
- readonly accent: "#60a5fa";
33
- readonly accentHover: "#7db6fb";
34
- readonly focusRingColor: "rgb(96 165 250 / 42%)";
35
- };
36
- readonly teal: {
37
- readonly accent: "#2dd4bf";
38
- readonly accentHover: "#4fdcc9";
39
- readonly focusRingColor: "rgb(45 212 191 / 42%)";
40
- };
41
- readonly orange: {
42
- readonly accent: "#fb923c";
43
- readonly accentHover: "#fca45c";
44
- readonly focusRingColor: "rgb(251 146 60 / 42%)";
45
- };
46
- readonly pink: {
47
- readonly accent: "#f472b6";
48
- readonly accentHover: "#f68cc4";
49
- readonly focusRingColor: "rgb(244 114 182 / 42%)";
50
- };
51
- };
52
- /**
53
- * 预设主题色名:`violet` | `blue` | `teal` | `orange` | `pink`。
54
- */
55
- export type ThemeAccentPreset = keyof typeof THEME_ACCENTS;
56
- /**
57
- * 主题色入参类型。
58
- *
59
- * 用 `ThemeAccentPreset | (string & {})` 的交叉技巧保留两个能力:
60
- * 1. 传入预设名时获得自动补全(IDE 列出五个预设);
61
- * 2. 传入任意 CSS 颜色字符串时仍类型合法(`(string & {})` 让 TS 不会
62
- * 把 string 收窄成字面量联合,避免「自定义颜色」用法被类型拒绝)。
63
- */
64
- export type ThemeAccent = ThemeAccentPreset | (string & {});
65
- /**
66
- * 判断字符串是否是预设主题色名。
67
- *
68
- * 用于 Demo 或使用方在拿到一个 accent 字符串时区分「预设」与「自定义」
69
- * 两种来源:预设走 ThemeProvider 内联下发的精确派生值,自定义走
70
- * theme.css 中 `[data-accent='custom']` 的 color-mix 派生。
71
- */
72
- export declare function isThemeAccentPreset(value: string): value is ThemeAccentPreset;
73
- /**
74
- * 明暗模式。
75
- *
76
- * 与 accent 主题色正交:accent 重定义 `--hn-color-accent` 等 accent 三件套,
77
- * mode 重定义 `--hn-color-surface` / `--hn-color-text` / `--hn-color-border`
78
- * 等全套表面与文字 token。两个轴独立组合,例如可以同时「浅色背景 + 蓝色 accent」。
79
- *
80
- * - `dark`(默认):与 tokens.css 的 :root 默认值一致,不传时视觉无变化;
81
- * - `light`:重定义全套表面/文字/边框 token 为浅色配色。
82
- *
83
- * 实际的 token 覆盖值定义在 theme.css 的 `.hn-theme[data-mode='light']` 与
84
- * `.hn-theme[data-mode='dark']` 规则中,ThemeProvider 只负责把 mode 写到
85
- * 根 div 的 `data-mode` 属性上,CSS 级联完成其余工作。
86
- */
87
- export type ThemeMode = 'dark' | 'light';
1
+ export { THEME_ACCENTS, isThemeAccentPreset, type ThemeAccentPreset, type ThemeAccent, type ThemeMode, } from '../../shared/theme';
@@ -1,6 +1,6 @@
1
1
  /* empty css */
2
- import { t as e } from "./button-DRz0VTkf.js";
3
- import { t } from "./dialog-B4xS5zlK.js";
2
+ import { t as e } from "./button-mmBNcoG1.js";
3
+ import { t } from "./dialog-DI_yumUn.js";
4
4
  import { jsx as n, jsxs as r } from "react/jsx-runtime";
5
5
  import { createContext as i, createElement as a, useCallback as o, useContext as s, useMemo as c, useState as l } from "react";
6
6
  import { createRoot as u } from "react-dom/client";
@@ -19,12 +19,11 @@ function f({ open: i, title: a, description: o, confirmText: s = "确认", cance
19
19
  title: a,
20
20
  children: /* @__PURE__ */ r("div", {
21
21
  className: "hn-confirm__footer",
22
- "data-tone": l,
23
22
  children: [/* @__PURE__ */ n(e, {
24
23
  disabled: u,
24
+ ghost: !0,
25
25
  onClick: h,
26
26
  type: "button",
27
- variant: "ghost",
28
27
  children: c
29
28
  }), /* @__PURE__ */ n(e, {
30
29
  disabled: u,
@@ -32,7 +31,7 @@ function f({ open: i, title: a, description: o, confirmText: s = "确认", cance
32
31
  d();
33
32
  },
34
33
  type: "button",
35
- variant: "primary",
34
+ variant: l === "danger" ? "danger" : "primary",
36
35
  children: u ? "处理中…" : s
37
36
  })]
38
37
  })
package/dist/confirm.js CHANGED
@@ -1,2 +1,2 @@
1
- import { i as e, n as t, r as n, t as r } from "./confirm-3eBmopl8.js";
1
+ import { i as e, n as t, r as n, t as r } from "./confirm-DKgVMWkR.js";
2
2
  export { t as Confirm, n as ConfirmProvider, r as confirm, r as confirmDialog, e as useConfirm };
@@ -0,0 +1,102 @@
1
+ /* empty css */
2
+ import { t as e } from "./Icon-BuZRZcjv.js";
3
+ import { n as t } from "./theme-context-CdWvVVP8.js";
4
+ import { t as n } from "./use-modal-K9L8aPS0.js";
5
+ import { Fragment as r, jsx as i, jsxs as a } from "react/jsx-runtime";
6
+ import { useState as o } from "react";
7
+ import { createPortal as s } from "react-dom";
8
+ //#region src/components/dialog/Dialog.tsx
9
+ function c({ children: c, className: l, title: u, description: d, open: f, onClose: p, closeOnEsc: m = !0, closeOnBackdrop: h = !0, showCloseButton: g = !1, showFullscreenButton: _ = !1, ref: v, style: y, ...b }) {
10
+ let [x, S] = o({
11
+ fullscreen: !1,
12
+ open: f
13
+ });
14
+ x.open !== f && S({
15
+ fullscreen: !f && x.fullscreen,
16
+ open: f
17
+ });
18
+ let C = x.fullscreen, w = t(), { dataState: T, mounted: E, backdropRef: D, panelRef: O, titleId: k, descriptionId: A, handlePanelKeyDown: j, handleBackdropPointerDown: M } = n({
19
+ open: f,
20
+ onClose: p,
21
+ closeOnEsc: m,
22
+ closeOnBackdrop: h
23
+ });
24
+ if (!E || typeof document > "u") return null;
25
+ let N = [
26
+ "hn-dialog__panel",
27
+ C ? "hn-dialog__panel--fullscreen" : "",
28
+ l
29
+ ].filter(Boolean).join(" "), P = u === void 0 ? void 0 : k, F = d === void 0 ? void 0 : A, I = (e) => {
30
+ O.current = e, typeof v == "function" ? v(e) : v != null && (v.current = e);
31
+ }, L = /* @__PURE__ */ a(r, { children: [/* @__PURE__ */ i("div", {
32
+ className: "hn-dialog__backdrop",
33
+ "data-state": T,
34
+ onPointerDown: M,
35
+ ref: D
36
+ }), /* @__PURE__ */ a("div", {
37
+ ...b,
38
+ "aria-describedby": F,
39
+ "aria-labelledby": P,
40
+ "aria-modal": "true",
41
+ className: N,
42
+ "data-state": T,
43
+ onKeyDown: j,
44
+ ref: I,
45
+ role: "dialog",
46
+ style: y,
47
+ tabIndex: -1,
48
+ children: [
49
+ g || _ ? /* @__PURE__ */ a("div", {
50
+ className: "hn-dialog__actions",
51
+ children: [_ ? /* @__PURE__ */ i("button", {
52
+ "aria-label": C ? "退出全屏" : "全屏显示",
53
+ "aria-pressed": C,
54
+ className: "hn-dialog__icon-button",
55
+ onClick: () => {
56
+ S((e) => ({
57
+ ...e,
58
+ fullscreen: !e.fullscreen
59
+ }));
60
+ },
61
+ type: "button",
62
+ children: /* @__PURE__ */ i(e, {
63
+ "aria-hidden": "true",
64
+ name: C ? "fullscreen-exit" : "fullscreen"
65
+ })
66
+ }) : null, g ? /* @__PURE__ */ i("button", {
67
+ "aria-label": "关闭对话框",
68
+ className: "hn-dialog__icon-button",
69
+ onClick: p,
70
+ type: "button",
71
+ children: /* @__PURE__ */ i(e, {
72
+ "aria-hidden": "true",
73
+ name: "close"
74
+ })
75
+ }) : null]
76
+ }) : null,
77
+ u === void 0 ? null : /* @__PURE__ */ i("h2", {
78
+ className: "hn-dialog__title",
79
+ id: k,
80
+ children: u
81
+ }),
82
+ d === void 0 ? null : /* @__PURE__ */ i("p", {
83
+ className: "hn-dialog__description",
84
+ id: A,
85
+ children: d
86
+ }),
87
+ /* @__PURE__ */ i("div", {
88
+ className: "hn-dialog__content",
89
+ children: c
90
+ })
91
+ ]
92
+ })] });
93
+ return s(w === null ? L : /* @__PURE__ */ i("div", {
94
+ className: "hn-theme",
95
+ "data-accent": w.accent,
96
+ "data-mode": w.mode,
97
+ style: w.style,
98
+ children: L
99
+ }), document.body);
100
+ }
101
+ //#endregion
102
+ export { c as t };
package/dist/dialog.js CHANGED
@@ -1,2 +1,2 @@
1
- import { t as e } from "./dialog-B4xS5zlK.js";
1
+ import { t as e } from "./dialog-DI_yumUn.js";
2
2
  export { e as Dialog };
@@ -0,0 +1,120 @@
1
+ /* empty css */
2
+ import { t as e } from "./Icon-BuZRZcjv.js";
3
+ import { n as t } from "./theme-context-CdWvVVP8.js";
4
+ import { t as n } from "./use-modal-K9L8aPS0.js";
5
+ import { Fragment as r, jsx as i, jsxs as a } from "react/jsx-runtime";
6
+ import { useRef as o, useState as s } from "react";
7
+ import { createPortal as c } from "react-dom";
8
+ //#region src/components/drawer/Drawer.tsx
9
+ function l({ children: l, className: u, title: d, description: f, open: p, onClose: m, placement: h = "right", size: g, closeOnEsc: _ = !0, closeOnBackdrop: v = !0, showCloseButton: y = !1, showFullscreenButton: b = !1, ref: x, style: S, ...C }) {
10
+ let [w, T] = s({
11
+ fullscreen: !1,
12
+ open: p
13
+ });
14
+ w.open !== p && T({
15
+ fullscreen: !p && w.fullscreen,
16
+ open: p
17
+ });
18
+ let E = w.fullscreen, D = h === "bottom" ? E ? "arrow-down" : "arrow-up" : E ? "fullscreen-exit" : "fullscreen", O = o(null), k = t(), { dataState: A, mounted: j, backdropRef: M, panelRef: N, titleId: P, descriptionId: F, handlePanelKeyDown: I, handleBackdropPointerDown: L } = n({
19
+ open: p,
20
+ onClose: m,
21
+ closeOnEsc: _,
22
+ closeOnBackdrop: v
23
+ });
24
+ if (!j || typeof document > "u") return null;
25
+ let R = [
26
+ "hn-drawer__panel",
27
+ `hn-drawer__panel--${h}`,
28
+ E ? "hn-drawer__panel--fullscreen" : "",
29
+ u
30
+ ].filter(Boolean).join(" "), z = {
31
+ ...g === void 0 ? {} : { "--hn-drawer-size": `${String(g)}px` },
32
+ ...S
33
+ }, B = d === void 0 ? void 0 : P, V = f === void 0 ? void 0 : F, H = (e) => {
34
+ e.target instanceof Element && e.target.closest("button") !== null || (O.current = e.clientY, e.currentTarget.setPointerCapture(e.pointerId));
35
+ }, U = (e) => {
36
+ let t = O.current;
37
+ if (O.current = null, e.currentTarget.hasPointerCapture(e.pointerId) && e.currentTarget.releasePointerCapture(e.pointerId), t === null) return;
38
+ let n = e.clientY - t;
39
+ n <= -56 ? T((e) => ({
40
+ ...e,
41
+ fullscreen: !0
42
+ })) : n >= 56 && T((e) => ({
43
+ ...e,
44
+ fullscreen: !1
45
+ }));
46
+ }, W = (e) => {
47
+ N.current = e, typeof x == "function" ? x(e) : x != null && (x.current = e);
48
+ }, G = /* @__PURE__ */ a(r, { children: [/* @__PURE__ */ i("div", {
49
+ className: "hn-drawer__backdrop",
50
+ "data-state": A,
51
+ onPointerDown: L,
52
+ ref: M
53
+ }), /* @__PURE__ */ a("div", {
54
+ ...C,
55
+ "aria-describedby": V,
56
+ "aria-labelledby": B,
57
+ "aria-modal": "true",
58
+ className: R,
59
+ "data-state": A,
60
+ onKeyDown: I,
61
+ ref: W,
62
+ role: "dialog",
63
+ style: z,
64
+ tabIndex: -1,
65
+ children: [d !== void 0 || f !== void 0 || y || b ? /* @__PURE__ */ a("header", {
66
+ className: "hn-drawer__header",
67
+ onPointerCancel: U,
68
+ onPointerDown: H,
69
+ onPointerUp: U,
70
+ children: [/* @__PURE__ */ a("div", {
71
+ className: "hn-drawer__heading",
72
+ children: [b ? /* @__PURE__ */ i("button", {
73
+ "aria-label": E ? "退出全屏" : "全屏显示",
74
+ "aria-pressed": E,
75
+ className: "hn-drawer__icon-button",
76
+ onClick: () => {
77
+ T((e) => ({
78
+ ...e,
79
+ fullscreen: !e.fullscreen
80
+ }));
81
+ },
82
+ type: "button",
83
+ children: /* @__PURE__ */ i(e, {
84
+ "aria-hidden": "true",
85
+ name: D
86
+ })
87
+ }) : null, /* @__PURE__ */ a("div", { children: [d === void 0 ? null : /* @__PURE__ */ i("h2", {
88
+ className: "hn-drawer__title",
89
+ id: P,
90
+ children: d
91
+ }), f === void 0 ? null : /* @__PURE__ */ i("p", {
92
+ className: "hn-drawer__description",
93
+ id: F,
94
+ children: f
95
+ })] })]
96
+ }), y ? /* @__PURE__ */ i("button", {
97
+ "aria-label": "关闭抽屉",
98
+ className: "hn-drawer__icon-button",
99
+ onClick: m,
100
+ type: "button",
101
+ children: /* @__PURE__ */ i(e, {
102
+ "aria-hidden": "true",
103
+ name: "close"
104
+ })
105
+ }) : null]
106
+ }) : null, /* @__PURE__ */ i("div", {
107
+ className: "hn-drawer__content",
108
+ children: l
109
+ })]
110
+ })] });
111
+ return c(k === null ? G : /* @__PURE__ */ i("div", {
112
+ className: "hn-theme",
113
+ "data-accent": k.accent,
114
+ "data-mode": k.mode,
115
+ style: k.style,
116
+ children: G
117
+ }), document.body);
118
+ }
119
+ //#endregion
120
+ export { l as t };
package/dist/drawer.js CHANGED
@@ -1,2 +1,2 @@
1
- import { t as e } from "./drawer-DoeuGAHD.js";
1
+ import { t as e } from "./drawer-Cpe3Yf3K.js";
2
2
  export { e as Drawer };