@manohub/ui 0.7.0 → 0.8.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 (75) hide show
  1. package/README.md +4 -4
  2. package/dist/components/button/index.d.ts +14 -8
  3. package/dist/components/capsule/index.d.ts +13 -9
  4. package/dist/components/capsule/index.js +1 -1
  5. package/dist/components/card/index.d.ts +1 -1
  6. package/dist/components/card/index.js +7 -4
  7. package/dist/components/checkbox/index.js +1 -0
  8. package/dist/components/dialog/index.d.ts +1 -1
  9. package/dist/components/form/index.d.ts +142 -62
  10. package/dist/components/form/index.js +41 -29
  11. package/dist/components/input/index.d.ts +74 -6
  12. package/dist/components/input/index.js +13 -1
  13. package/dist/components/layout/index.d.ts +43 -1
  14. package/dist/components/layout/index.js +22 -2
  15. package/dist/components/list-view/index.d.ts +1 -1
  16. package/dist/components/notice/index.d.ts +2 -2
  17. package/dist/components/notification/index.d.ts +2 -2
  18. package/dist/components/page/index.js +4 -4
  19. package/dist/components/pagination/index.d.ts +2 -2
  20. package/dist/components/pagination/index.js +1 -1
  21. package/dist/components/panel/index.js +4 -4
  22. package/dist/components/part-padding.d.ts +9 -6
  23. package/dist/components/part-padding.js +2 -1
  24. package/dist/components/query-state/index.d.ts +18 -2
  25. package/dist/components/radio/index.d.ts +1 -1
  26. package/dist/components/radio/index.js +1 -0
  27. package/dist/components/select/index.d.ts +32 -30
  28. package/dist/components/select/index.js +46 -82
  29. package/dist/components/select/select-list.d.ts +125 -0
  30. package/dist/components/select/select-list.js +95 -0
  31. package/dist/components/select/select-panel.d.ts +106 -0
  32. package/dist/components/select/select-panel.js +72 -0
  33. package/dist/components/select/select-shared.d.ts +64 -0
  34. package/dist/components/select/select-shared.js +24 -0
  35. package/dist/components/select/select-tree-filter.d.ts +61 -0
  36. package/dist/components/select/select-tree-filter.js +63 -0
  37. package/dist/components/select/select-tree.d.ts +274 -0
  38. package/dist/components/select/select-tree.js +263 -0
  39. package/dist/components/select/select-trigger.d.ts +132 -0
  40. package/dist/components/select/select-trigger.js +101 -0
  41. package/dist/components/steps/index.d.ts +232 -6
  42. package/dist/components/steps/index.js +84 -26
  43. package/dist/components/switch/index.d.ts +29 -5
  44. package/dist/components/switch/index.js +8 -2
  45. package/dist/components/tabbar/index.d.ts +184 -0
  46. package/dist/components/tabbar/index.js +161 -0
  47. package/dist/components/table/index.d.ts +99 -12
  48. package/dist/components/table/index.js +69 -16
  49. package/dist/components/tabs/index.d.ts +142 -126
  50. package/dist/components/tabs/index.js +87 -119
  51. package/dist/components/tag/index.d.ts +2 -2
  52. package/dist/components/text/index.d.ts +7 -2
  53. package/dist/components/toast/index.d.ts +8 -8
  54. package/dist/components/tree/index.d.ts +28 -2
  55. package/dist/components/tree/index.js +14 -1
  56. package/dist/index.d.ts +6 -6
  57. package/dist/index.js +6 -3
  58. package/dist/styles/components/capsule.css +4 -4
  59. package/dist/styles/components/form.css +198 -39
  60. package/dist/styles/components/input.css +53 -1
  61. package/dist/styles/components/layout.css +2 -0
  62. package/dist/styles/components/select.css +21 -0
  63. package/dist/styles/components/select.tokens.css +3 -0
  64. package/dist/styles/components/steps.css +48 -0
  65. package/dist/styles/components/{tabs.css → tabbar.css} +66 -65
  66. package/dist/styles/components/tabbar.tokens.css +30 -0
  67. package/dist/styles/components/table.css +50 -1
  68. package/dist/styles/components/table.tokens.css +3 -0
  69. package/dist/styles/index.css +3 -3
  70. package/dist/styles/operations/tabs.css +73 -0
  71. package/package.json +2 -2
  72. package/dist/components/tabset/index.d.ts +0 -109
  73. package/dist/components/tabset/index.js +0 -75
  74. package/dist/styles/components/tabs.tokens.css +0 -30
  75. package/dist/styles/operations/tabset.css +0 -57
@@ -8,6 +8,12 @@ export interface StepsItem {
8
8
  icon?: IconName;
9
9
  }
10
10
  export type StepsVariant = 'node' | 'bar';
11
+ /**
12
+ * 跳转验证:**能不能跳到第 `index` 步**(`current` 是当前步)。
13
+ *
14
+ * 不传即「全可跳」—— 件不猜业务规则,限制由调用方注入(如「只允许回退」= `i <= current`)。
15
+ */
16
+ export type CanJump = (index: number, current: number) => boolean;
11
17
  /**
12
18
  * 步骤条(**自绘**;节点式 + 燕尾段式 + 进度条)。
13
19
  *
@@ -23,7 +29,28 @@ export type StepsVariant = 'node' | 'bar';
23
29
  * - `variant="node"`(缺省):节点 + 同行标题 + 点线折角箭头,段长弹性 —— 步骤数少、要给每步留标题时用;
24
30
  * - `variant="bar"`:燕尾段条(定宽 140、相邻重叠 10),只有当前段是主色 —— 段数固定、像进度分段时用。
25
31
  *
26
- * 步骤条**不可点**(规范未演示跳步):要跳转请在步骤旁自己放操作,或改用别的件。
32
+ * ## 可点档(`clickable`)
33
+ *
34
+ * 规范未演示跳步 ⇒ **缺省不可点**(连手型都不给;步的标签与类名也与老版本一致,只多一个
35
+ * `aria-current="step"` —— 那是当前步的语义标注,与可不可点无关)。要跳转就显式开
36
+ * `clickable`:步渲染成**原生 `<button>`**(键盘 / 焦点 / 禁用都交浏览器)。
37
+ *
38
+ * ### 「哪几步能跳」由调用方给(`canJump`)
39
+ *
40
+ * 本件**不猜业务规则**:`canJump` 缺省 `true`(每一步都可跳),要限制就注入一条判定:
41
+ *
42
+ * ```tsx
43
+ * <Steps clickable :can-jump="(index, current) => index <= current" … />
44
+ * ```
45
+ *
46
+ * 为什么不给内置的「前进最多一步 / 只允许后退」默认:向导的「往前走」几乎总带着前置校验
47
+ * (扫过了吗 / 风险确认了吗),而**步骤条上的点击不会跑那些校验** —— 件若自己放开一步,
48
+ * 就等于给了一条绕开门禁的旁路;可若定成「一律不许前进」,那又是替业务做了决定。
49
+ * 通用件该回答的是「能不能跳」,答案让调用方给。
50
+ *
51
+ * 本件**不给 `beforeChange` / `onBeforeChange` 一类的钩子**:它认 `current`(受控件),件本就不自己
52
+ * 换步,「跳转前验证」的落点是**渲染期的 `disabled`** —— 在事件里再判一次只会得到
53
+ * 「看着可点、点了没反应」这个更差的状态。
27
54
  *
28
55
  * 进度条(`Steps.Progress`)单列,用于"跑到百分之几"这类无步骤语义的场景。
29
56
  *
@@ -53,7 +80,43 @@ export declare const Steps: import("vue").DefineComponent<import("vue").ExtractP
53
80
  type: PropType<ControlSize>;
54
81
  default: string;
55
82
  };
56
- }>, () => import("vue/jsx-runtime").JSX.Element, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
83
+ /**
84
+ * 步骤可点:点某步即切到该步(**节点与标题整块**都是点击区)。
85
+ *
86
+ * 缺省 `false` —— 规范未演示跳步,件不凭空长交互。开了之后:
87
+ * - 步渲染成**原生 `<button type="button">`** ⇒ 键盘 Tab/Enter 可达、`:focus-visible` 有焦点环。
88
+ * 不要再靠 `title` 插槽自绘可点元素:那会嵌进 `<button>` 形成嵌套交互,且拿不到键盘支持;
89
+ * - 「哪几步能跳」由 `canJump` 决定(缺省全可跳);
90
+ * - 点击发 `update:current`(可写 `v-model:current`)与 `onChange`。
91
+ *
92
+ * ⚠️ 「跳转前验证」写在**渲染期**(`disabled`),不要写成点击时的事件拦截 —— 见文件头。
93
+ */
94
+ clickable: {
95
+ type: BooleanConstructor;
96
+ default: boolean;
97
+ };
98
+ /**
99
+ * 跳转验证:**能不能跳到第 `index` 步**(第二参是当前步)。缺省全可跳。
100
+ *
101
+ * 返回 `false` 的步会被画成禁用态(置灰 + `not-allowed`)、拦掉点击、**也不进键盘序列** ——
102
+ * 判定跑在**渲染期**,不是「点了再拦」(那样只能得到「看着可点、点了没反应」)。
103
+ * 需要异步验证才能决定能不能跳时,把结果先存进状态、再据此返回。
104
+ *
105
+ * ⚠️ 它只回答「能不能跳」。若某一步是「本身不可用」(不论从哪来),也用它统一表达 ——
106
+ * 本件不另设行级 `disabled`,免得同一条规则散在两处。
107
+ */
108
+ canJump: {
109
+ type: PropType<(index: number, current: number) => boolean>;
110
+ default: undefined;
111
+ };
112
+ /** 点击换步(`clickable` 档下生效);`prevIndex` 为点击前的当前步 */
113
+ onChange: {
114
+ type: PropType<(index: number, prevIndex: number) => void>;
115
+ default: undefined;
116
+ };
117
+ }>, () => import("vue/jsx-runtime").JSX.Element, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
118
+ 'update:current': (index: number) => true;
119
+ }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
57
120
  /** 步骤表(标题 + 可选节点图标) */
58
121
  steps: {
59
122
  type: PropType<StepsItem[]>;
@@ -73,15 +136,55 @@ export declare const Steps: import("vue").DefineComponent<import("vue").ExtractP
73
136
  type: PropType<ControlSize>;
74
137
  default: string;
75
138
  };
76
- }>> & Readonly<{}>, {
139
+ /**
140
+ * 步骤可点:点某步即切到该步(**节点与标题整块**都是点击区)。
141
+ *
142
+ * 缺省 `false` —— 规范未演示跳步,件不凭空长交互。开了之后:
143
+ * - 步渲染成**原生 `<button type="button">`** ⇒ 键盘 Tab/Enter 可达、`:focus-visible` 有焦点环。
144
+ * 不要再靠 `title` 插槽自绘可点元素:那会嵌进 `<button>` 形成嵌套交互,且拿不到键盘支持;
145
+ * - 「哪几步能跳」由 `canJump` 决定(缺省全可跳);
146
+ * - 点击发 `update:current`(可写 `v-model:current`)与 `onChange`。
147
+ *
148
+ * ⚠️ 「跳转前验证」写在**渲染期**(`disabled`),不要写成点击时的事件拦截 —— 见文件头。
149
+ */
150
+ clickable: {
151
+ type: BooleanConstructor;
152
+ default: boolean;
153
+ };
154
+ /**
155
+ * 跳转验证:**能不能跳到第 `index` 步**(第二参是当前步)。缺省全可跳。
156
+ *
157
+ * 返回 `false` 的步会被画成禁用态(置灰 + `not-allowed`)、拦掉点击、**也不进键盘序列** ——
158
+ * 判定跑在**渲染期**,不是「点了再拦」(那样只能得到「看着可点、点了没反应」)。
159
+ * 需要异步验证才能决定能不能跳时,把结果先存进状态、再据此返回。
160
+ *
161
+ * ⚠️ 它只回答「能不能跳」。若某一步是「本身不可用」(不论从哪来),也用它统一表达 ——
162
+ * 本件不另设行级 `disabled`,免得同一条规则散在两处。
163
+ */
164
+ canJump: {
165
+ type: PropType<(index: number, current: number) => boolean>;
166
+ default: undefined;
167
+ };
168
+ /** 点击换步(`clickable` 档下生效);`prevIndex` 为点击前的当前步 */
169
+ onChange: {
170
+ type: PropType<(index: number, prevIndex: number) => void>;
171
+ default: undefined;
172
+ };
173
+ }>> & Readonly<{
174
+ "onUpdate:current"?: ((index: number) => any) | undefined;
175
+ }>, {
77
176
  size: ControlSize;
177
+ onChange: (index: number, prevIndex: number) => void;
78
178
  variant: StepsVariant;
79
179
  current: number;
80
180
  steps: StepsItem[];
181
+ clickable: boolean;
182
+ canJump: (index: number, current: number) => boolean;
81
183
  }, SlotsType<{
82
184
  title?: (context: {
83
185
  item: StepsItem;
84
186
  index: number;
187
+ disabled: boolean;
85
188
  }) => VNodeChild;
86
189
  }>, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
87
190
  export declare const StepsCompound: {
@@ -105,15 +208,57 @@ export declare const StepsCompound: {
105
208
  type: PropType<ControlSize>;
106
209
  default: string;
107
210
  };
108
- }>> & Readonly<{}>, () => import("vue/jsx-runtime").JSX.Element, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, import("vue").PublicProps, {
211
+ /**
212
+ * 步骤可点:点某步即切到该步(**节点与标题整块**都是点击区)。
213
+ *
214
+ * 缺省 `false` —— 规范未演示跳步,件不凭空长交互。开了之后:
215
+ * - 步渲染成**原生 `<button type="button">`** ⇒ 键盘 Tab/Enter 可达、`:focus-visible` 有焦点环。
216
+ * 不要再靠 `title` 插槽自绘可点元素:那会嵌进 `<button>` 形成嵌套交互,且拿不到键盘支持;
217
+ * - 「哪几步能跳」由 `canJump` 决定(缺省全可跳);
218
+ * - 点击发 `update:current`(可写 `v-model:current`)与 `onChange`。
219
+ *
220
+ * ⚠️ 「跳转前验证」写在**渲染期**(`disabled`),不要写成点击时的事件拦截 —— 见文件头。
221
+ */
222
+ clickable: {
223
+ type: BooleanConstructor;
224
+ default: boolean;
225
+ };
226
+ /**
227
+ * 跳转验证:**能不能跳到第 `index` 步**(第二参是当前步)。缺省全可跳。
228
+ *
229
+ * 返回 `false` 的步会被画成禁用态(置灰 + `not-allowed`)、拦掉点击、**也不进键盘序列** ——
230
+ * 判定跑在**渲染期**,不是「点了再拦」(那样只能得到「看着可点、点了没反应」)。
231
+ * 需要异步验证才能决定能不能跳时,把结果先存进状态、再据此返回。
232
+ *
233
+ * ⚠️ 它只回答「能不能跳」。若某一步是「本身不可用」(不论从哪来),也用它统一表达 ——
234
+ * 本件不另设行级 `disabled`,免得同一条规则散在两处。
235
+ */
236
+ canJump: {
237
+ type: PropType<(index: number, current: number) => boolean>;
238
+ default: undefined;
239
+ };
240
+ /** 点击换步(`clickable` 档下生效);`prevIndex` 为点击前的当前步 */
241
+ onChange: {
242
+ type: PropType<(index: number, prevIndex: number) => void>;
243
+ default: undefined;
244
+ };
245
+ }>> & Readonly<{
246
+ "onUpdate:current"?: ((index: number) => any) | undefined;
247
+ }>, () => import("vue/jsx-runtime").JSX.Element, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
248
+ 'update:current': (index: number) => true;
249
+ }, import("vue").PublicProps, {
109
250
  size: ControlSize;
251
+ onChange: (index: number, prevIndex: number) => void;
110
252
  variant: StepsVariant;
111
253
  current: number;
112
254
  steps: StepsItem[];
255
+ clickable: boolean;
256
+ canJump: (index: number, current: number) => boolean;
113
257
  }, true, {}, SlotsType<{
114
258
  title?: (context: {
115
259
  item: StepsItem;
116
260
  index: number;
261
+ disabled: boolean;
117
262
  }) => VNodeChild;
118
263
  }>, import("vue").GlobalComponents, import("vue").GlobalDirectives, string, {}, any, import("vue").ComponentProvideOptions, {
119
264
  P: {};
@@ -142,11 +287,50 @@ export declare const StepsCompound: {
142
287
  type: PropType<ControlSize>;
143
288
  default: string;
144
289
  };
145
- }>> & Readonly<{}>, () => import("vue/jsx-runtime").JSX.Element, {}, {}, {}, {
290
+ /**
291
+ * 步骤可点:点某步即切到该步(**节点与标题整块**都是点击区)。
292
+ *
293
+ * 缺省 `false` —— 规范未演示跳步,件不凭空长交互。开了之后:
294
+ * - 步渲染成**原生 `<button type="button">`** ⇒ 键盘 Tab/Enter 可达、`:focus-visible` 有焦点环。
295
+ * 不要再靠 `title` 插槽自绘可点元素:那会嵌进 `<button>` 形成嵌套交互,且拿不到键盘支持;
296
+ * - 「哪几步能跳」由 `canJump` 决定(缺省全可跳);
297
+ * - 点击发 `update:current`(可写 `v-model:current`)与 `onChange`。
298
+ *
299
+ * ⚠️ 「跳转前验证」写在**渲染期**(`disabled`),不要写成点击时的事件拦截 —— 见文件头。
300
+ */
301
+ clickable: {
302
+ type: BooleanConstructor;
303
+ default: boolean;
304
+ };
305
+ /**
306
+ * 跳转验证:**能不能跳到第 `index` 步**(第二参是当前步)。缺省全可跳。
307
+ *
308
+ * 返回 `false` 的步会被画成禁用态(置灰 + `not-allowed`)、拦掉点击、**也不进键盘序列** ——
309
+ * 判定跑在**渲染期**,不是「点了再拦」(那样只能得到「看着可点、点了没反应」)。
310
+ * 需要异步验证才能决定能不能跳时,把结果先存进状态、再据此返回。
311
+ *
312
+ * ⚠️ 它只回答「能不能跳」。若某一步是「本身不可用」(不论从哪来),也用它统一表达 ——
313
+ * 本件不另设行级 `disabled`,免得同一条规则散在两处。
314
+ */
315
+ canJump: {
316
+ type: PropType<(index: number, current: number) => boolean>;
317
+ default: undefined;
318
+ };
319
+ /** 点击换步(`clickable` 档下生效);`prevIndex` 为点击前的当前步 */
320
+ onChange: {
321
+ type: PropType<(index: number, prevIndex: number) => void>;
322
+ default: undefined;
323
+ };
324
+ }>> & Readonly<{
325
+ "onUpdate:current"?: ((index: number) => any) | undefined;
326
+ }>, () => import("vue/jsx-runtime").JSX.Element, {}, {}, {}, {
146
327
  size: ControlSize;
328
+ onChange: (index: number, prevIndex: number) => void;
147
329
  variant: StepsVariant;
148
330
  current: number;
149
331
  steps: StepsItem[];
332
+ clickable: boolean;
333
+ canJump: (index: number, current: number) => boolean;
150
334
  }>;
151
335
  __isFragment?: never;
152
336
  __isTeleport?: never;
@@ -171,15 +355,57 @@ export declare const StepsCompound: {
171
355
  type: PropType<ControlSize>;
172
356
  default: string;
173
357
  };
174
- }>> & Readonly<{}>, () => import("vue/jsx-runtime").JSX.Element, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, {
358
+ /**
359
+ * 步骤可点:点某步即切到该步(**节点与标题整块**都是点击区)。
360
+ *
361
+ * 缺省 `false` —— 规范未演示跳步,件不凭空长交互。开了之后:
362
+ * - 步渲染成**原生 `<button type="button">`** ⇒ 键盘 Tab/Enter 可达、`:focus-visible` 有焦点环。
363
+ * 不要再靠 `title` 插槽自绘可点元素:那会嵌进 `<button>` 形成嵌套交互,且拿不到键盘支持;
364
+ * - 「哪几步能跳」由 `canJump` 决定(缺省全可跳);
365
+ * - 点击发 `update:current`(可写 `v-model:current`)与 `onChange`。
366
+ *
367
+ * ⚠️ 「跳转前验证」写在**渲染期**(`disabled`),不要写成点击时的事件拦截 —— 见文件头。
368
+ */
369
+ clickable: {
370
+ type: BooleanConstructor;
371
+ default: boolean;
372
+ };
373
+ /**
374
+ * 跳转验证:**能不能跳到第 `index` 步**(第二参是当前步)。缺省全可跳。
375
+ *
376
+ * 返回 `false` 的步会被画成禁用态(置灰 + `not-allowed`)、拦掉点击、**也不进键盘序列** ——
377
+ * 判定跑在**渲染期**,不是「点了再拦」(那样只能得到「看着可点、点了没反应」)。
378
+ * 需要异步验证才能决定能不能跳时,把结果先存进状态、再据此返回。
379
+ *
380
+ * ⚠️ 它只回答「能不能跳」。若某一步是「本身不可用」(不论从哪来),也用它统一表达 ——
381
+ * 本件不另设行级 `disabled`,免得同一条规则散在两处。
382
+ */
383
+ canJump: {
384
+ type: PropType<(index: number, current: number) => boolean>;
385
+ default: undefined;
386
+ };
387
+ /** 点击换步(`clickable` 档下生效);`prevIndex` 为点击前的当前步 */
388
+ onChange: {
389
+ type: PropType<(index: number, prevIndex: number) => void>;
390
+ default: undefined;
391
+ };
392
+ }>> & Readonly<{
393
+ "onUpdate:current"?: ((index: number) => any) | undefined;
394
+ }>, () => import("vue/jsx-runtime").JSX.Element, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
395
+ 'update:current': (index: number) => true;
396
+ }, string, {
175
397
  size: ControlSize;
398
+ onChange: (index: number, prevIndex: number) => void;
176
399
  variant: StepsVariant;
177
400
  current: number;
178
401
  steps: StepsItem[];
402
+ clickable: boolean;
403
+ canJump: (index: number, current: number) => boolean;
179
404
  }, {}, string, SlotsType<{
180
405
  title?: (context: {
181
406
  item: StepsItem;
182
407
  index: number;
408
+ disabled: boolean;
183
409
  }) => VNodeChild;
184
410
  }>, import("vue").GlobalComponents, import("vue").GlobalDirectives, string, import("vue").ComponentProvideOptions> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & {
185
411
  Progress: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
@@ -1,4 +1,4 @@
1
- import { defineComponent, createVNode, Fragment } from "vue";
1
+ import { defineComponent, computed, createVNode, mergeProps, Fragment } from "vue";
2
2
  import { Icon } from "@manohub/icon";
3
3
  const Steps = /* @__PURE__ */ defineComponent({
4
4
  name: "Steps",
@@ -22,27 +22,81 @@ const Steps = /* @__PURE__ */ defineComponent({
22
22
  size: {
23
23
  type: String,
24
24
  default: "md"
25
+ },
26
+ /**
27
+ * 步骤可点:点某步即切到该步(**节点与标题整块**都是点击区)。
28
+ *
29
+ * 缺省 `false` —— 规范未演示跳步,件不凭空长交互。开了之后:
30
+ * - 步渲染成**原生 `<button type="button">`** ⇒ 键盘 Tab/Enter 可达、`:focus-visible` 有焦点环。
31
+ * 不要再靠 `title` 插槽自绘可点元素:那会嵌进 `<button>` 形成嵌套交互,且拿不到键盘支持;
32
+ * - 「哪几步能跳」由 `canJump` 决定(缺省全可跳);
33
+ * - 点击发 `update:current`(可写 `v-model:current`)与 `onChange`。
34
+ *
35
+ * ⚠️ 「跳转前验证」写在**渲染期**(`disabled`),不要写成点击时的事件拦截 —— 见文件头。
36
+ */
37
+ clickable: {
38
+ type: Boolean,
39
+ default: false
40
+ },
41
+ /**
42
+ * 跳转验证:**能不能跳到第 `index` 步**(第二参是当前步)。缺省全可跳。
43
+ *
44
+ * 返回 `false` 的步会被画成禁用态(置灰 + `not-allowed`)、拦掉点击、**也不进键盘序列** ——
45
+ * 判定跑在**渲染期**,不是「点了再拦」(那样只能得到「看着可点、点了没反应」)。
46
+ * 需要异步验证才能决定能不能跳时,把结果先存进状态、再据此返回。
47
+ *
48
+ * ⚠️ 它只回答「能不能跳」。若某一步是「本身不可用」(不论从哪来),也用它统一表达 ——
49
+ * 本件不另设行级 `disabled`,免得同一条规则散在两处。
50
+ */
51
+ canJump: {
52
+ type: Function,
53
+ default: void 0
54
+ },
55
+ /** 点击换步(`clickable` 档下生效);`prevIndex` 为点击前的当前步 */
56
+ onChange: {
57
+ type: Function,
58
+ default: void 0
25
59
  }
26
60
  },
61
+ emits: {
62
+ "update:current": (index) => true
63
+ },
27
64
  slots: Object,
28
65
  setup(props, {
29
66
  slots,
30
- attrs
67
+ attrs,
68
+ emit
31
69
  }) {
70
+ const jumpable = computed(() => props.steps.map((_, index) => props.canJump?.(index, props.current) ?? true));
71
+ const selectStep = (index) => {
72
+ if (!jumpable.value[index]) return;
73
+ emit("update:current", index);
74
+ props.onChange?.(index, props.current);
75
+ };
76
+ const stepAction = (index) => props.clickable ? {
77
+ type: "button",
78
+ disabled: !jumpable.value[index],
79
+ onClick: () => selectStep(index)
80
+ } : {};
32
81
  return () => {
82
+ const PartTag = props.clickable ? "button" : props.variant === "bar" ? "span" : "div";
33
83
  const root = ["mh-steps", props.size === "md" ? "" : `mh-steps--${props.size}`, attrs.class].filter(Boolean).join(" ");
34
84
  const style = attrs.style;
35
85
  if (props.variant === "bar") {
36
86
  return createVNode("div", {
37
87
  "class": ["mh-steps__bar", attrs.class].filter(Boolean).join(" "),
38
88
  "style": style
39
- }, [props.steps.map((step, index) => createVNode("span", {
89
+ }, [props.steps.map((step, index) => createVNode(PartTag, mergeProps({
40
90
  "key": `${step.title}-${index}`,
41
- "class": ["mh-steps__seg", index === props.current ? "mh-steps__seg--active" : ""].filter(Boolean).join(" ")
42
- }, [createVNode("span", null, [index + 1]), slots.title ? slots.title({
43
- item: step,
44
- index
45
- }) : step.title]))]);
91
+ "class": ["mh-steps__seg", index === props.current ? "mh-steps__seg--active" : "", props.clickable ? "mh-steps__seg--clickable" : "", props.clickable && !jumpable.value[index] ? "mh-steps__seg--disabled" : ""].filter(Boolean).join(" "),
92
+ "aria-current": index === props.current ? "step" : void 0
93
+ }, stepAction(index)), {
94
+ default: () => [createVNode("span", null, [index + 1]), slots.title ? slots.title({
95
+ item: step,
96
+ index,
97
+ disabled: !jumpable.value[index]
98
+ }) : step.title]
99
+ }))]);
46
100
  }
47
101
  return createVNode("div", {
48
102
  "class": root,
@@ -57,24 +111,28 @@ const Steps = /* @__PURE__ */ defineComponent({
57
111
  // 连线在「步 index-1 之后」:当前步之后那一段才转蓝
58
112
  index - 1 === props.current ? "mh-steps__connector--active" : ""
59
113
  ].filter(Boolean).join(" ")
60
- }, null) : null, createVNode("div", {
61
- "class": ["mh-steps__step", state].filter(Boolean).join(" ")
62
- }, [createVNode("span", {
63
- "class": "mh-steps__node"
64
- }, [index < props.current ? createVNode(Icon, {
65
- "name": "check",
66
- "class": "mh-steps__node-icon",
67
- "size": 16
68
- }, null) : step.icon ? createVNode(Icon, {
69
- "name": step.icon,
70
- "class": "mh-steps__node-icon",
71
- "size": 16
72
- }, null) : index + 1]), createVNode("span", {
73
- "class": "mh-steps__title"
74
- }, [slots.title ? slots.title({
75
- item: step,
76
- index
77
- }) : step.title])])]);
114
+ }, null) : null, createVNode(PartTag, mergeProps({
115
+ "class": ["mh-steps__step", state, props.clickable ? "mh-steps__step--clickable" : "", props.clickable && !jumpable.value[index] ? "mh-steps__step--disabled" : ""].filter(Boolean).join(" "),
116
+ "aria-current": index === props.current ? "step" : void 0
117
+ }, stepAction(index)), {
118
+ default: () => [createVNode("span", {
119
+ "class": "mh-steps__node"
120
+ }, [index < props.current ? createVNode(Icon, {
121
+ "name": "check",
122
+ "class": "mh-steps__node-icon",
123
+ "size": 16
124
+ }, null) : step.icon ? createVNode(Icon, {
125
+ "name": step.icon,
126
+ "class": "mh-steps__node-icon",
127
+ "size": 16
128
+ }, null) : index + 1]), createVNode("span", {
129
+ "class": "mh-steps__title"
130
+ }, [slots.title ? slots.title({
131
+ item: step,
132
+ index,
133
+ disabled: !jumpable.value[index]
134
+ }) : step.title])]
135
+ })]);
78
136
  })]);
79
137
  };
80
138
  }
@@ -13,8 +13,22 @@ import type { ControlSize } from '../control-size';
13
13
  * - 选中态三源等价:原生 `:checked` / 组件下发 `data-state` / 静态档 `.is-checked`;
14
14
  * - `labelPosition` 用 flex `order` 翻转,**不改 DOM 顺序** —— 否则那条 `~` 兄弟规则立刻失效。
15
15
  *
16
+ * ## 与 `Form.Item` 的关系(**同一个词别写两遍**)
17
+ *
18
+ * `label` 是**控件自己的文案** —— 它长在根 `<label>` 里,**点它也切换开关**;
19
+ * 而 `Form.Item` 的 `label` 是**字段名**(点它只是聚焦控件)。两者不是一回事。
20
+ *
21
+ * 所以放进表单行时**不要再传一次**:字段名归 `Form.Item`,开关只放控件本身。
22
+ *
23
+ * - 正确:`<Form.Item label="启用"><Switch v-model={on} /></Form.Item>`
24
+ * - 错误:`<Form.Item label="启用"><Switch v-model={on} label="启用" /></Form.Item>`
25
+ * —— 同一行会显示成「启用 启用 (开关)」,同一个词出现两遍。
26
+ *
27
+ * 只有**没有表单行**的场合(表格行内 / 工具栏 / 设置面板)才需要 `label` 自己带文字;
28
+ * 那种场景若要把文字放到开关右侧,给 `labelPosition="right"`。
29
+ *
16
30
  * @example
17
- * <Switch modelValue={on} label="启用" onChange={(v) => (on = v)} />
31
+ * <Switch modelValue={on} onChange={(v) => (on = v)} />
18
32
  *
19
33
  * @example 轨道内文案 + 尺寸 + 加载
20
34
  * <Switch v-model={auto} checkedText="开" uncheckedText="关" size="lg" loading={saving} />
@@ -25,7 +39,12 @@ export declare const Switch: import("vue").DefineComponent<import("vue").Extract
25
39
  type: BooleanConstructor;
26
40
  default: boolean;
27
41
  };
28
- /** 开关文字(复杂内容走默认插槽) */
42
+ /**
43
+ * 开关**自己的文案**(点它也切换;复杂内容走默认插槽)。
44
+ *
45
+ * ⚠️ 放进 `Form.Item` 时**不要传** —— 字段名由 `Form.Item` 的 `label` 给,
46
+ * 两处写同一个词会显示成「启用 启用 (开关)」。独立使用(表格行内 / 工具栏 / 设置面板)才用它。
47
+ */
29
48
  label: {
30
49
  type: StringConstructor;
31
50
  default: undefined;
@@ -44,7 +63,7 @@ export declare const Switch: import("vue").DefineComponent<import("vue").Extract
44
63
  type: BooleanConstructor;
45
64
  default: boolean;
46
65
  };
47
- /** 文字相对开关的位置(缺省在左;表单里常放右) */
66
+ /** 文字相对开关的位置(缺省在左)—— 表单行内一般不传 `label`,这条主要服务独立使用的场景 */
48
67
  labelPosition: {
49
68
  type: PropType<"left" | "right">;
50
69
  default: string;
@@ -82,7 +101,12 @@ export declare const Switch: import("vue").DefineComponent<import("vue").Extract
82
101
  type: BooleanConstructor;
83
102
  default: boolean;
84
103
  };
85
- /** 开关文字(复杂内容走默认插槽) */
104
+ /**
105
+ * 开关**自己的文案**(点它也切换;复杂内容走默认插槽)。
106
+ *
107
+ * ⚠️ 放进 `Form.Item` 时**不要传** —— 字段名由 `Form.Item` 的 `label` 给,
108
+ * 两处写同一个词会显示成「启用 启用 (开关)」。独立使用(表格行内 / 工具栏 / 设置面板)才用它。
109
+ */
86
110
  label: {
87
111
  type: StringConstructor;
88
112
  default: undefined;
@@ -101,7 +125,7 @@ export declare const Switch: import("vue").DefineComponent<import("vue").Extract
101
125
  type: BooleanConstructor;
102
126
  default: boolean;
103
127
  };
104
- /** 文字相对开关的位置(缺省在左;表单里常放右) */
128
+ /** 文字相对开关的位置(缺省在左)—— 表单行内一般不传 `label`,这条主要服务独立使用的场景 */
105
129
  labelPosition: {
106
130
  type: PropType<"left" | "right">;
107
131
  default: string;
@@ -8,7 +8,12 @@ const Switch = /* @__PURE__ */ defineComponent({
8
8
  type: Boolean,
9
9
  default: false
10
10
  },
11
- /** 开关文字(复杂内容走默认插槽) */
11
+ /**
12
+ * 开关**自己的文案**(点它也切换;复杂内容走默认插槽)。
13
+ *
14
+ * ⚠️ 放进 `Form.Item` 时**不要传** —— 字段名由 `Form.Item` 的 `label` 给,
15
+ * 两处写同一个词会显示成「启用 启用 (开关)」。独立使用(表格行内 / 工具栏 / 设置面板)才用它。
16
+ */
12
17
  label: {
13
18
  type: String,
14
19
  default: void 0
@@ -27,7 +32,7 @@ const Switch = /* @__PURE__ */ defineComponent({
27
32
  type: Boolean,
28
33
  default: false
29
34
  },
30
- /** 文字相对开关的位置(缺省在左;表单里常放右) */
35
+ /** 文字相对开关的位置(缺省在左)—— 表单行内一般不传 `label`,这条主要服务独立使用的场景 */
31
36
  labelPosition: {
32
37
  type: String,
33
38
  default: "left"
@@ -76,6 +81,7 @@ const Switch = /* @__PURE__ */ defineComponent({
76
81
  };
77
82
  return () => createVNode("label", {
78
83
  "class": ["mh-switch", resolvedSize.value === "md" ? "" : `mh-switch--${resolvedSize.value}`, props.form ? "mh-switch--form" : "", hasTrackText.value ? "mh-switch--with-text" : "", props.labelPosition === "right" ? "mh-switch--label-right" : "", props.loading ? "is-loading" : "", props.disabled ? "is-disabled" : "", props.modelValue ? "is-checked" : "", attrs.class].filter(Boolean).join(" "),
84
+ "data-inline-control": "true",
79
85
  "style": attrs.style
80
86
  }, [createVNode("input", {
81
87
  "class": "mh-switch__input",