@manohub/ui 0.6.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 (169) hide show
  1. package/README.md +141 -0
  2. package/dist/components/avatar/index.d.ts +283 -0
  3. package/dist/components/avatar/index.js +167 -0
  4. package/dist/components/badge/index.d.ts +132 -0
  5. package/dist/components/badge/index.js +99 -0
  6. package/dist/components/button/index.d.ts +578 -0
  7. package/dist/components/button/index.js +191 -0
  8. package/dist/components/capsule/index.d.ts +161 -0
  9. package/dist/components/capsule/index.js +101 -0
  10. package/dist/components/card/index.d.ts +456 -0
  11. package/dist/components/card/index.js +231 -0
  12. package/dist/components/checkbox/index.d.ts +331 -0
  13. package/dist/components/checkbox/index.js +165 -0
  14. package/dist/components/code/index.d.ts +134 -0
  15. package/dist/components/code/index.js +117 -0
  16. package/dist/components/code-editor/index.d.ts +163 -0
  17. package/dist/components/code-editor/index.js +98 -0
  18. package/dist/components/collapse/index.d.ts +125 -0
  19. package/dist/components/collapse/index.js +95 -0
  20. package/dist/components/control-size.d.ts +8 -0
  21. package/dist/components/dialog/index.d.ts +224 -0
  22. package/dist/components/dialog/index.js +194 -0
  23. package/dist/components/divider/index.d.ts +64 -0
  24. package/dist/components/divider/index.js +62 -0
  25. package/dist/components/drawer/index.d.ts +226 -0
  26. package/dist/components/drawer/index.js +190 -0
  27. package/dist/components/filter/index.d.ts +391 -0
  28. package/dist/components/filter/index.js +203 -0
  29. package/dist/components/form/index.d.ts +704 -0
  30. package/dist/components/form/index.js +329 -0
  31. package/dist/components/input/index.d.ts +980 -0
  32. package/dist/components/input/index.js +334 -0
  33. package/dist/components/layout/index.d.ts +162 -0
  34. package/dist/components/layout/index.js +100 -0
  35. package/dist/components/list-view/index.d.ts +563 -0
  36. package/dist/components/list-view/index.js +221 -0
  37. package/dist/components/loading/index.d.ts +77 -0
  38. package/dist/components/loading/index.js +40 -0
  39. package/dist/components/nav/index.d.ts +293 -0
  40. package/dist/components/nav/index.js +164 -0
  41. package/dist/components/notice/index.d.ts +137 -0
  42. package/dist/components/notice/index.js +101 -0
  43. package/dist/components/notification/index.d.ts +118 -0
  44. package/dist/components/notification/index.js +99 -0
  45. package/dist/components/page/index.d.ts +276 -0
  46. package/dist/components/page/index.js +351 -0
  47. package/dist/components/page/split-resize.d.ts +42 -0
  48. package/dist/components/page/split-resize.js +36 -0
  49. package/dist/components/pagination/index.d.ts +171 -0
  50. package/dist/components/pagination/index.js +226 -0
  51. package/dist/components/panel/index.d.ts +401 -0
  52. package/dist/components/panel/index.js +193 -0
  53. package/dist/components/part-padding.d.ts +27 -0
  54. package/dist/components/part-padding.js +23 -0
  55. package/dist/components/query-state/index.d.ts +207 -0
  56. package/dist/components/query-state/index.js +181 -0
  57. package/dist/components/radio/index.d.ts +473 -0
  58. package/dist/components/radio/index.js +250 -0
  59. package/dist/components/search/index.d.ts +167 -0
  60. package/dist/components/search/index.js +105 -0
  61. package/dist/components/select/index.d.ts +252 -0
  62. package/dist/components/select/index.js +281 -0
  63. package/dist/components/skeleton/index.d.ts +88 -0
  64. package/dist/components/skeleton/index.js +56 -0
  65. package/dist/components/steps/index.d.ts +199 -0
  66. package/dist/components/steps/index.js +117 -0
  67. package/dist/components/switch/index.d.ts +150 -0
  68. package/dist/components/switch/index.js +103 -0
  69. package/dist/components/table/index.d.ts +351 -0
  70. package/dist/components/table/index.js +286 -0
  71. package/dist/components/tabs/index.d.ts +179 -0
  72. package/dist/components/tabs/index.js +153 -0
  73. package/dist/components/tabset/index.d.ts +105 -0
  74. package/dist/components/tabset/index.js +68 -0
  75. package/dist/components/tag/index.d.ts +203 -0
  76. package/dist/components/tag/index.js +144 -0
  77. package/dist/components/toast/index.d.ts +271 -0
  78. package/dist/components/toast/index.js +116 -0
  79. package/dist/components/tooltip/index.d.ts +126 -0
  80. package/dist/components/tooltip/index.js +97 -0
  81. package/dist/components/tree/index.d.ts +317 -0
  82. package/dist/components/tree/index.js +251 -0
  83. package/dist/components/upload/index.d.ts +384 -0
  84. package/dist/components/upload/index.js +172 -0
  85. package/dist/index.d.ts +63 -0
  86. package/dist/index.js +102 -0
  87. package/dist/services/base.d.ts +21 -0
  88. package/dist/services/base.js +42 -0
  89. package/dist/services/dialog.d.ts +41 -0
  90. package/dist/services/dialog.js +83 -0
  91. package/dist/services/index.d.ts +12 -0
  92. package/dist/services/loading.d.ts +21 -0
  93. package/dist/services/loading.js +41 -0
  94. package/dist/services/toast.d.ts +40 -0
  95. package/dist/services/toast.js +74 -0
  96. package/dist/styles/components/avatar.css +128 -0
  97. package/dist/styles/components/avatar.tokens.css +24 -0
  98. package/dist/styles/components/badge.css +237 -0
  99. package/dist/styles/components/button.css +454 -0
  100. package/dist/styles/components/button.tokens.css +56 -0
  101. package/dist/styles/components/capsule.css +120 -0
  102. package/dist/styles/components/capsule.tokens.css +27 -0
  103. package/dist/styles/components/card.css +192 -0
  104. package/dist/styles/components/checkbox.css +145 -0
  105. package/dist/styles/components/checkbox.tokens.css +26 -0
  106. package/dist/styles/components/code-editor.css +91 -0
  107. package/dist/styles/components/code-editor.tokens.css +24 -0
  108. package/dist/styles/components/code.css +153 -0
  109. package/dist/styles/components/code.tokens.css +29 -0
  110. package/dist/styles/components/collapse.css +62 -0
  111. package/dist/styles/components/collapse.tokens.css +20 -0
  112. package/dist/styles/components/dialog.css +106 -0
  113. package/dist/styles/components/dialog.tokens.css +24 -0
  114. package/dist/styles/components/divider.css +71 -0
  115. package/dist/styles/components/divider.tokens.css +21 -0
  116. package/dist/styles/components/drawer.css +143 -0
  117. package/dist/styles/components/drawer.tokens.css +22 -0
  118. package/dist/styles/components/filter.css +41 -0
  119. package/dist/styles/components/filter.tokens.css +14 -0
  120. package/dist/styles/components/form.css +220 -0
  121. package/dist/styles/components/form.tokens.css +15 -0
  122. package/dist/styles/components/input.css +445 -0
  123. package/dist/styles/components/input.tokens.css +41 -0
  124. package/dist/styles/components/layout.css +198 -0
  125. package/dist/styles/components/list-view.css +244 -0
  126. package/dist/styles/components/loading.css +76 -0
  127. package/dist/styles/components/loading.tokens.css +23 -0
  128. package/dist/styles/components/nav.css +48 -0
  129. package/dist/styles/components/notice.css +153 -0
  130. package/dist/styles/components/notice.tokens.css +17 -0
  131. package/dist/styles/components/notification.css +159 -0
  132. package/dist/styles/components/notification.tokens.css +37 -0
  133. package/dist/styles/components/page.css +473 -0
  134. package/dist/styles/components/pagination.css +297 -0
  135. package/dist/styles/components/pagination.tokens.css +32 -0
  136. package/dist/styles/components/panel.css +77 -0
  137. package/dist/styles/components/query-state.css +88 -0
  138. package/dist/styles/components/radio.css +271 -0
  139. package/dist/styles/components/radio.tokens.css +26 -0
  140. package/dist/styles/components/search.css +30 -0
  141. package/dist/styles/components/select.css +242 -0
  142. package/dist/styles/components/select.tokens.css +33 -0
  143. package/dist/styles/components/skeleton.css +60 -0
  144. package/dist/styles/components/skeleton.tokens.css +27 -0
  145. package/dist/styles/components/steps.css +157 -0
  146. package/dist/styles/components/steps.tokens.css +42 -0
  147. package/dist/styles/components/switch.css +165 -0
  148. package/dist/styles/components/switch.tokens.css +26 -0
  149. package/dist/styles/components/table.css +439 -0
  150. package/dist/styles/components/table.tokens.css +41 -0
  151. package/dist/styles/components/tabs.css +234 -0
  152. package/dist/styles/components/tabs.tokens.css +30 -0
  153. package/dist/styles/components/tag.css +200 -0
  154. package/dist/styles/components/tag.tokens.css +30 -0
  155. package/dist/styles/components/toast.css +150 -0
  156. package/dist/styles/components/toast.tokens.css +26 -0
  157. package/dist/styles/components/tooltip.css +89 -0
  158. package/dist/styles/components/tooltip.tokens.css +25 -0
  159. package/dist/styles/components/tree.css +139 -0
  160. package/dist/styles/components/tree.tokens.css +20 -0
  161. package/dist/styles/components/upload.css +150 -0
  162. package/dist/styles/components/upload.tokens.css +27 -0
  163. package/dist/styles/index.css +149 -0
  164. package/dist/styles/operations/collapse.css +84 -0
  165. package/dist/styles/operations/popup.css +189 -0
  166. package/dist/styles/operations/tabset.css +57 -0
  167. package/dist/utils/state-illustration.d.ts +31 -0
  168. package/dist/utils/state-illustration.js +156 -0
  169. package/package.json +62 -0
@@ -0,0 +1,27 @@
1
+ /**
2
+ * skeleton —— 单件令牌(**基础值**)。
3
+ *
4
+ * 本件自己的几何 / 尺寸 / 色彩槽位;只服务本件,故不随主题进 `@manohub/theme`。
5
+ *
6
+ * ## 抽出说明
7
+ * 本文件从面文件里抽出(原先混写在 `skeleton.css` 顶部):这些是**基础值**,锚在
8
+ * `[data-manohub-ui]` —— 跨包唯一作用域锚,由入口层无条件写在应用容器上,因此**任何落在
9
+ * 容器里的分件都取得到值**,不再依赖「声明在某个组件根类上」这条脆弱假设
10
+ * (历史症状:跨件消费的 `--ui-*-group-*` 取不到值,组内间距变 0)。
11
+ *
12
+ * ⚠️ `.mh-<件>--<档>` 这类**档位改写**留在面文件的修饰符块里 —— 它们靠「同一元素上两个
13
+ * 选择器改写同一个令牌」生效,搬到本文件会让档位失效。
14
+ * ⚠️ 新增组件要登记两处:本文件 + `src/styles/index.css`(见其文件头「五处齐备」)。
15
+ */
16
+ [data-manohub-ui] {
17
+ /* 单件令牌(只服务本件) */
18
+ --ui-skeleton-bg: var(--ui-base-200); /* Ne10 底 */
19
+ --ui-skeleton-highlight: var(--ui-base-100); /* Ne12 扫过高光 */
20
+ --ui-skeleton-radius: var(--ui-radius-control);
21
+ /* 与通用行高档一致(36)。⚠️ 原注释写「规范:30 对齐表格行高」是**误导**:30 是表格行高
22
+ (设计实测),而本令牌是通用行高档。表格骨架若要贴合 30,请在消费侧覆盖本令牌,
23
+ 不要改 `--ui-row-height`(它还供 Collapse 头行使用)。 */
24
+ --ui-skeleton-height: var(--ui-row-height);
25
+ --ui-skeleton-gap: var(--ui-space-3); /* 行间距 10 */
26
+ --ui-skeleton-animation: mh-skeleton-shimmer 1.6s ease-in-out infinite;
27
+ }
@@ -0,0 +1,157 @@
1
+ /**
2
+ * Steps —— 步骤条(横向节点式 + 条形燕尾段式 + 进度条)。
3
+ *
4
+ * 出处:`@aihub/theme` 的 `playground/components/steps.css` 与 `src/components/steps.css`
5
+ * (节点 30 圆、字号 14、节点与标题**同行**、标题间距 12;连线是 2px **点线** + 末端 6px 方盒转 45°
6
+ * 的 `>` 折角箭头、最小长 58.383、弹性撑开;段 140×30、相邻**重叠 10**、整条 inline-flex 收宽;
7
+ * 进度条高 9)。
8
+ *
9
+ * **当前步之后那一段才转蓝**(已完成步之后仍是灰线)—— 这是规范实测的取向,别做成"已完成段全蓝"。
10
+ *
11
+ * 状态来源是**单一来源**(组件下发的 `--done` / `--current` / `--active`):步骤序号不是原生元素能表达的状态,
12
+ * 故这里没有「三源等价」可言 —— 与勾选/开关那类不同,别照抄那份写法。
13
+ *
14
+ * 连线用**独立空元素**(`.mh-steps__connector`)而不是 `.mh-steps__step + ::after`:折角箭头要撑开弹性余量,
15
+ * 且 N 个节点配 N-1 条线,独立元素才能让两端节点各自保持自己的标题宽度。
16
+ */
17
+
18
+ /* 几何只挂在 node 档根件上:令牌在同名 `.tokens.css`(锚 `[data-manohub-ui]`),几何若跟着挂会给 bar / 进度条多套一层 flex */
19
+ .mh-steps {
20
+ display: flex;
21
+ align-items: center;
22
+ }
23
+
24
+ /* ===== 横向节点式 ===== */
25
+ .mh-steps__step {
26
+ display: flex;
27
+ align-items: center;
28
+ gap: var(--ui-steps-title-gap);
29
+ flex: none;
30
+ }
31
+ .mh-steps__node {
32
+ display: flex;
33
+ align-items: center;
34
+ justify-content: center;
35
+ flex: none;
36
+ width: var(--ui-steps-node-size);
37
+ height: var(--ui-steps-node-size);
38
+ border-radius: var(--ui-radius-full);
39
+ background: var(--ui-steps-node-undone);
40
+ color: var(--ui-steps-node-text);
41
+ font-size: var(--ui-font-caption);
42
+ line-height: 1;
43
+ }
44
+ .mh-steps__node-icon {
45
+ width: var(--ui-steps-node-icon-size);
46
+ height: var(--ui-steps-node-icon-size);
47
+ }
48
+ .mh-steps__step--done .mh-steps__node,
49
+ .mh-steps__step--current .mh-steps__node {
50
+ background: var(--ui-steps-node-bg);
51
+ }
52
+ .mh-steps__title {
53
+ font-size: var(--ui-font-body); /* 规范字号档 md(14) */
54
+ line-height: var(--ui-line-body);
55
+ color: var(--ui-base-content);
56
+ white-space: nowrap;
57
+ }
58
+
59
+ /* 连线:本体是 ::before 的点线,箭头是 ::after 的方盒去左下两边后转 45°(不是实心三角) */
60
+ .mh-steps__connector {
61
+ display: flex;
62
+ align-items: center;
63
+ flex: 1;
64
+ min-width: var(--ui-steps-connector-length);
65
+ margin: 0 var(--ui-space-3);
66
+ color: var(--ui-steps-connector-line);
67
+ }
68
+ .mh-steps__connector::before {
69
+ content: '';
70
+ flex: 1;
71
+ height: 0;
72
+ border-top: var(--ui-steps-connector-width) dotted currentColor;
73
+ }
74
+ .mh-steps__connector::after {
75
+ content: '';
76
+ flex: none;
77
+ width: var(--ui-steps-connector-arrow);
78
+ height: var(--ui-steps-connector-arrow);
79
+ border-top: var(--ui-steps-connector-width) solid currentColor;
80
+ border-right: var(--ui-steps-connector-width) solid currentColor;
81
+ transform: rotate(45deg);
82
+ }
83
+ .mh-steps__connector--active {
84
+ color: var(--ui-steps-connector-line-active);
85
+ }
86
+
87
+ /* ===== 条形燕尾段式 ===== */
88
+ .mh-steps__bar {
89
+ display: inline-flex; /* 整条宽度收在段总宽上(块级 flex 会撑满整行) */
90
+ align-items: center;
91
+ }
92
+ .mh-steps__seg {
93
+ display: flex;
94
+ align-items: center;
95
+ gap: var(--ui-space-1);
96
+ width: var(--ui-steps-seg-width);
97
+ height: var(--ui-steps-seg-height);
98
+ /* 让开左尖 + 相邻段重叠:段是裁形,靠重叠咬合而不是留缝 */
99
+ padding-left: calc(var(--ui-steps-seg-overlap) + var(--ui-space-1));
100
+ margin-left: calc(var(--ui-steps-seg-overlap) * -1);
101
+ font-size: var(--ui-font-caption);
102
+ color: var(--ui-base-content);
103
+ background: var(--ui-steps-seg-bg);
104
+ clip-path: polygon(
105
+ 0 50%,
106
+ var(--ui-steps-seg-overlap) 0,
107
+ calc(100% - var(--ui-steps-seg-overlap)) 0,
108
+ 100% 50%,
109
+ calc(100% - var(--ui-steps-seg-overlap)) 100%,
110
+ var(--ui-steps-seg-overlap) 100%
111
+ );
112
+ }
113
+ .mh-steps__seg:first-child {
114
+ margin-left: 0;
115
+ clip-path: polygon(
116
+ 0 0,
117
+ calc(100% - var(--ui-steps-seg-overlap)) 0,
118
+ 100% 50%,
119
+ calc(100% - var(--ui-steps-seg-overlap)) 100%,
120
+ 0 100%
121
+ );
122
+ }
123
+ .mh-steps__seg:last-child {
124
+ clip-path: polygon(0 50%, var(--ui-steps-seg-overlap) 0, 100% 0, 100% 100%, var(--ui-steps-seg-overlap) 100%);
125
+ }
126
+ .mh-steps__seg--active {
127
+ position: relative;
128
+ z-index: 1; /* 压住左右相邻段 */
129
+ background: var(--ui-steps-seg-bg-active);
130
+ color: var(--ui-steps-seg-text-active);
131
+ /* 段是裁形,光晕只能用 drop-shadow 跟随形状(box-shadow 会露方角) */
132
+ filter: drop-shadow(0 4px 5px color-mix(in srgb, var(--ui-primary) 30%, transparent));
133
+ }
134
+
135
+ /* ===== 进度条(规范只有令牌、无标记示例;与对话框的进程条共用) ===== */
136
+ .mh-steps__progress {
137
+ height: var(--ui-steps-progress-height);
138
+ border-radius: var(--ui-radius-full);
139
+ background: var(--ui-steps-node-undone);
140
+ overflow: hidden;
141
+ }
142
+ .mh-steps__progress-fill {
143
+ display: block;
144
+ height: 100%;
145
+ border-radius: var(--ui-radius-full);
146
+ background: var(--ui-primary);
147
+ }
148
+
149
+ /* ===== 尺寸档(只覆盖令牌,几何规则只有一份) ===== */
150
+ .mh-steps--sm {
151
+ --ui-steps-node-size: calc(var(--ui-steps-node-size-base) * 0.8);
152
+ font-size: var(--ui-font-caption);
153
+ }
154
+ .mh-steps--lg {
155
+ --ui-steps-node-size: calc(var(--ui-steps-node-size-base) * 1.15);
156
+ font-size: var(--ui-font-heading);
157
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * steps —— 单件令牌(**基础值**)。
3
+ *
4
+ * 本件自己的几何 / 尺寸 / 色彩槽位;只服务本件,故不随主题进 `@manohub/theme`。
5
+ *
6
+ * ## 抽出说明
7
+ * 本文件从面文件里抽出(原先混写在 `steps.css` 顶部):这些是**基础值**,锚在
8
+ * `[data-manohub-ui]` —— 跨包唯一作用域锚,由入口层无条件写在应用容器上,因此**任何落在
9
+ * 容器里的分件都取得到值**,不再依赖「声明在某个组件根类上」这条脆弱假设
10
+ * (历史症状:跨件消费的 `--ui-*-group-*` 取不到值,组内间距变 0)。
11
+ *
12
+ * ⚠️ `.mh-<件>--<档>` 这类**档位改写**留在面文件的修饰符块里 —— 它们靠「同一元素上两个
13
+ * 选择器改写同一个令牌」生效,搬到本文件会让档位失效。
14
+ * ⚠️ 新增组件要登记两处:本文件 + `src/styles/index.css`(见其文件头「五处齐备」)。
15
+ */
16
+ [data-manohub-ui] {
17
+ /* bar 档与独立进度条都是**自己的根节点**(无 `.mh-steps` 祖先)—— 靠容器锚取到值 */
18
+ /* 单件令牌 */
19
+ /* 基准尺寸与「当前档尺寸」分开:尺寸档要用基准做 calc,直接自引用会构成环形引用
20
+ (自定义属性引用自身 → 整条在计算值阶段作废 → 连子节点都继承不到) */
21
+ --ui-steps-node-size-base: 30px;
22
+ --ui-steps-node-size: var(--ui-steps-node-size-base);
23
+ --ui-steps-node-undone: var(--ui-base-300); /* 规范 Ne05 未开始底(节点内也是白字,不是灰字) */
24
+ --ui-steps-node-text: var(--ui-base-100); /* 反白字:序号 / 勾 / 图标 */
25
+ --ui-steps-node-icon-size: 16px;
26
+ --ui-steps-node-bg: var(--ui-primary); /* 规范是近乎平色的主色渐变(#2a83ff→#2a87ff),本仓取主色平色 */
27
+ --ui-steps-connector-length: 58.383px; /* 规范实测最小段长(其余由 flex 撑开) */
28
+ --ui-steps-connector-width: 2px;
29
+ --ui-steps-connector-arrow: 6px;
30
+ /* 连接线沿用 base-400:设计稿里**只有三个向导页**画了连接线(`#cdd2de`),而向导页已判定为旧稿;
31
+ 四个品牌页没有步骤条样张 → 按「未覆盖槽位沿用现值并注明」处理,不做推测性改动。 */
32
+ --ui-steps-connector-line: var(--ui-base-400);
33
+ --ui-steps-connector-line-active: var(--ui-primary); /* 规范 #4999fe */
34
+ --ui-steps-title-gap: var(--ui-space-3); /* 节点与标题间距 12 */
35
+ --ui-steps-seg-width: 140px;
36
+ --ui-steps-seg-height: 30px;
37
+ --ui-steps-seg-overlap: 10px; /* 相邻段重叠(燕尾尖咬合) */
38
+ --ui-steps-seg-bg: var(--ui-base-200); /* 规范 #e9edf7 */
39
+ --ui-steps-seg-bg-active: var(--ui-primary);
40
+ --ui-steps-seg-text-active: var(--ui-base-100);
41
+ --ui-steps-progress-height: 9px; /* 规范令牌;供进度条形态用 */
42
+ }
@@ -0,0 +1,165 @@
1
+ /**
2
+ * Switch —— 开关(两档尺寸:表格档 36×18 / 表单档 50×24)。
3
+ *
4
+ * 出处:`@aihub/theme` 的 `playground/components/switch.css` 与 `src/components/switch.css`
5
+ * (轨道 36×18、滑块 14、内距 2;表单档 50×24、滑块 18、内距 3;未选中底 Ne04、选中主色;
6
+ * 文字与轨道间距 10;禁用整体降透明 0.5)。
7
+ *
8
+ * **结构固定**:`input` →(可选)`__label` → `__track > __knob` —— 轨道用**通用兄弟** `~` 命中,
9
+ * 因为文字可以夹在开关与轨道之间(规范的结构如此),用相邻兄弟 `+` 会漏。
10
+ *
11
+ * 状态三源等价:原生 `input:checked`(零 JS)/ 组件下发 `[data-state='checked']` / 静态档 `.is-checked`。
12
+ *
13
+ * **焦点环画在可见轨道上**(隐身开关没有可见焦点),外扩 2px —— 轨道自身无边框,内缩会吃掉滑块。
14
+ */
15
+ .mh-switch {
16
+ display: inline-flex;
17
+ align-items: center;
18
+ gap: var(--ui-switch-label-gap);
19
+ cursor: pointer;
20
+ }
21
+ /* 隐身开关(1px 盒 + clip-path + appearance:none,与 checkbox / radio 同配方):
22
+ 不用 display:none / visibility:hidden —— 那会把键盘与读屏一起关掉。 */
23
+ .mh-switch__input {
24
+ position: absolute;
25
+ width: 1px;
26
+ height: 1px;
27
+ margin: -1px;
28
+ padding: 0;
29
+ border: 0;
30
+ overflow: hidden;
31
+ white-space: nowrap;
32
+ clip-path: inset(50%);
33
+ appearance: none;
34
+ pointer-events: none;
35
+ }
36
+ .mh-switch__label {
37
+ font-size: var(--ui-font-caption);
38
+ line-height: var(--ui-line-caption);
39
+ color: var(--ui-base-content);
40
+ }
41
+ .mh-switch__track {
42
+ position: relative;
43
+ flex: none;
44
+ width: var(--ui-switch-track-w);
45
+ height: var(--ui-switch-track-h);
46
+ border-radius: var(--ui-radius-full);
47
+ background: var(--ui-switch-off-bg);
48
+ transition: background-color 0.15s ease;
49
+ }
50
+ .mh-switch__knob {
51
+ position: absolute;
52
+ top: var(--ui-switch-inset);
53
+ left: var(--ui-switch-inset);
54
+ width: var(--ui-switch-knob);
55
+ height: var(--ui-switch-knob);
56
+ border-radius: var(--ui-radius-full);
57
+ background: var(--ui-base-100);
58
+ box-shadow: var(--ui-shadow-card);
59
+ transition: transform 0.15s ease;
60
+ }
61
+
62
+ /* 选中:三源等价(滑动量 = 轨道宽 − 滑块 − 2×内距,不写死数值) */
63
+ .mh-switch.is-checked .mh-switch__track,
64
+ .mh-switch[data-state='checked'] .mh-switch__track,
65
+ .mh-switch > .mh-switch__input:checked ~ .mh-switch__track {
66
+ background: var(--ui-switch-on-bg);
67
+ }
68
+ .mh-switch.is-checked .mh-switch__knob,
69
+ .mh-switch[data-state='checked'] .mh-switch__knob,
70
+ .mh-switch > .mh-switch__input:checked ~ .mh-switch__track .mh-switch__knob {
71
+ transform: translateX(
72
+ calc(var(--ui-switch-track-w) - var(--ui-switch-knob) - 2 * var(--ui-switch-inset))
73
+ );
74
+ }
75
+
76
+ /* 键盘焦点环画在轨道上(外扩 2px) */
77
+ .mh-switch > .mh-switch__input:focus-visible ~ .mh-switch__track {
78
+ outline: 2px solid var(--ui-primary);
79
+ outline-offset: 2px;
80
+ }
81
+
82
+ /* 禁用:整行不可点 + 整体降透明(原生 disabled 与静态档同款) */
83
+ .mh-switch.is-disabled,
84
+ .mh-switch:has(.mh-switch__input:disabled) {
85
+ opacity: var(--ui-switch-disabled-opacity);
86
+ cursor: not-allowed;
87
+ }
88
+
89
+ /* ===== 尺寸档:sm 28×14 / lg 50×24(只覆盖令牌,不重写几何) ===== */
90
+ .mh-switch--sm {
91
+ --ui-switch-track-w: 28px;
92
+ --ui-switch-track-h: 14px;
93
+ --ui-switch-knob: 10px;
94
+ --ui-switch-inset: 2px;
95
+ }
96
+ .mh-switch--form,
97
+ .mh-switch--lg {
98
+ --ui-switch-track-w: 50px;
99
+ --ui-switch-track-h: 24px;
100
+ --ui-switch-knob: 18px;
101
+ --ui-switch-inset: 3px;
102
+ }
103
+
104
+ /* ===== 文字位置:用 flex `order` 翻转,不做 DOM 重排 =====
105
+ * 换 DOM 顺序会让上面那条 `input:checked ~ track` 兄弟规则立刻失效。 */
106
+ .mh-switch--label-right > .mh-switch__label {
107
+ order: 1;
108
+ }
109
+
110
+ /* ===== 轨道内文案(iOS 式:选中时靠左让出滑块,未选中时靠右) ===== */
111
+ .mh-switch--with-text {
112
+ --ui-switch-track-w: 46px;
113
+ }
114
+ .mh-switch--sm.mh-switch--with-text {
115
+ --ui-switch-track-w: 38px;
116
+ }
117
+ .mh-switch--lg.mh-switch--with-text {
118
+ --ui-switch-track-w: 56px;
119
+ }
120
+ .mh-switch__track-text {
121
+ position: absolute;
122
+ top: 0;
123
+ bottom: 0;
124
+ display: flex;
125
+ align-items: center;
126
+ font-size: 11px;
127
+ line-height: 1;
128
+ color: var(--ui-base-100);
129
+ white-space: nowrap;
130
+ pointer-events: none;
131
+ }
132
+ .mh-switch.is-checked .mh-switch__track-text,
133
+ .mh-switch[data-state='checked'] .mh-switch__track-text,
134
+ .mh-switch > .mh-switch__input:checked ~ .mh-switch__track .mh-switch__track-text {
135
+ left: calc(var(--ui-switch-inset) + 2px);
136
+ right: calc(var(--ui-switch-knob) + 2 * var(--ui-switch-inset));
137
+ justify-content: flex-start;
138
+ }
139
+ .mh-switch:not(.is-checked) .mh-switch__track-text {
140
+ left: calc(var(--ui-switch-knob) + 2 * var(--ui-switch-inset));
141
+ right: calc(var(--ui-switch-inset) + 2px);
142
+ justify-content: flex-end;
143
+ }
144
+
145
+ /* ===== 加载:轨道内转圈(同时置原生 disabled,真正吞掉点击) ===== */
146
+ .mh-switch__spinner {
147
+ position: absolute;
148
+ top: 50%;
149
+ left: 50%;
150
+ width: 10px;
151
+ height: 10px;
152
+ margin: -5px 0 0 -5px;
153
+ border: 1.5px solid var(--ui-base-100);
154
+ border-top-color: transparent;
155
+ border-radius: var(--ui-radius-full);
156
+ animation: mh-switch-spin 0.8s linear infinite;
157
+ }
158
+ @keyframes mh-switch-spin {
159
+ to {
160
+ transform: rotate(360deg);
161
+ }
162
+ }
163
+ .mh-switch.is-loading {
164
+ cursor: progress;
165
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * switch —— 单件令牌(**基础值**)。
3
+ *
4
+ * 本件自己的几何 / 尺寸 / 色彩槽位;只服务本件,故不随主题进 `@manohub/theme`。
5
+ *
6
+ * ## 抽出说明
7
+ * 本文件从面文件里抽出(原先混写在 `switch.css` 顶部):这些是**基础值**,锚在
8
+ * `[data-manohub-ui]` —— 跨包唯一作用域锚,由入口层无条件写在应用容器上,因此**任何落在
9
+ * 容器里的分件都取得到值**,不再依赖「声明在某个组件根类上」这条脆弱假设
10
+ * (历史症状:跨件消费的 `--ui-*-group-*` 取不到值,组内间距变 0)。
11
+ *
12
+ * ⚠️ `.mh-<件>--<档>` 这类**档位改写**留在面文件的修饰符块里 —— 它们靠「同一元素上两个
13
+ * 选择器改写同一个令牌」生效,搬到本文件会让档位失效。
14
+ * ⚠️ 新增组件要登记两处:本文件 + `src/styles/index.css`(见其文件头「五处齐备」)。
15
+ */
16
+ [data-manohub-ui] {
17
+ /* 单件令牌 */
18
+ --ui-switch-track-w: 36px; /* 规范表格档 */
19
+ --ui-switch-track-h: 18px;
20
+ --ui-switch-knob: 14px;
21
+ --ui-switch-inset: 2px;
22
+ --ui-switch-label-gap: 10px; /* 规范实测 */
23
+ --ui-switch-off-bg: var(--ui-base-400); /* Ne04 */
24
+ --ui-switch-on-bg: var(--ui-primary);
25
+ --ui-switch-disabled-opacity: 0.5; /* 规范禁用透明度 */
26
+ }