mdui 2.0.2 → 2.0.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.
Files changed (118) hide show
  1. package/components/avatar/index.d.ts +17 -15
  2. package/components/avatar/index.js +7 -6
  3. package/components/badge/index.d.ts +11 -8
  4. package/components/badge/index.js +9 -7
  5. package/components/bottom-app-bar/index.d.ts +11 -4
  6. package/components/bottom-app-bar/index.js +8 -9
  7. package/components/button/button-base-style.js +1 -1
  8. package/components/button/button-base.d.ts +46 -47
  9. package/components/button/button-base.js +27 -25
  10. package/components/button/index.d.ts +19 -14
  11. package/components/button/index.js +12 -12
  12. package/components/button-icon/index.d.ts +15 -9
  13. package/components/button-icon/index.js +8 -9
  14. package/components/card/index.d.ts +15 -11
  15. package/components/card/index.js +10 -9
  16. package/components/checkbox/index.d.ts +30 -23
  17. package/components/checkbox/index.js +25 -25
  18. package/components/chip/index.d.ts +27 -20
  19. package/components/chip/index.js +19 -20
  20. package/components/circular-progress/index.d.ts +6 -4
  21. package/components/circular-progress/index.js +4 -3
  22. package/components/collapse/collapse-item.d.ts +17 -6
  23. package/components/collapse/collapse-item.js +7 -7
  24. package/components/collapse/collapse.d.ts +16 -11
  25. package/components/collapse/collapse.js +10 -10
  26. package/components/dialog/index.d.ts +22 -15
  27. package/components/dialog/index.js +23 -27
  28. package/components/divider/index.d.ts +7 -5
  29. package/components/divider/index.js +6 -5
  30. package/components/dropdown/index.d.ts +44 -37
  31. package/components/dropdown/index.js +50 -48
  32. package/components/fab/index.d.ts +12 -7
  33. package/components/fab/index.js +6 -6
  34. package/components/icon/index.d.ts +4 -2
  35. package/components/icon/index.js +3 -2
  36. package/components/layout/layout-item-base.d.ts +3 -2
  37. package/components/layout/layout-item-base.js +2 -2
  38. package/components/layout/layout-item.d.ts +11 -10
  39. package/components/layout/layout-item.js +6 -6
  40. package/components/layout/layout-main.d.ts +6 -4
  41. package/components/layout/layout-main.js +5 -4
  42. package/components/layout/layout.d.ts +6 -4
  43. package/components/layout/layout.js +5 -4
  44. package/components/linear-progress/index.d.ts +8 -6
  45. package/components/linear-progress/index.js +6 -5
  46. package/components/list/list-item-style.js +1 -1
  47. package/components/list/list-item.d.ts +24 -20
  48. package/components/list/list-item.js +10 -9
  49. package/components/list/list-subheader.d.ts +6 -4
  50. package/components/list/list-subheader.js +5 -4
  51. package/components/list/list.d.ts +5 -3
  52. package/components/list/list.js +4 -3
  53. package/components/menu/menu-item.d.ts +15 -7
  54. package/components/menu/menu-item.js +11 -15
  55. package/components/menu/menu.d.ts +20 -20
  56. package/components/menu/menu.js +13 -13
  57. package/components/navigation-bar/navigation-bar-item.d.ts +12 -8
  58. package/components/navigation-bar/navigation-bar-item.js +7 -6
  59. package/components/navigation-bar/navigation-bar.d.ts +17 -9
  60. package/components/navigation-bar/navigation-bar.js +15 -13
  61. package/components/navigation-drawer/index.d.ts +27 -21
  62. package/components/navigation-drawer/index.js +51 -38
  63. package/components/navigation-drawer/style.js +1 -1
  64. package/components/navigation-rail/navigation-rail-item.d.ts +13 -9
  65. package/components/navigation-rail/navigation-rail-item.js +7 -6
  66. package/components/navigation-rail/navigation-rail.d.ts +14 -12
  67. package/components/navigation-rail/navigation-rail.js +13 -12
  68. package/components/radio/radio-group.d.ts +20 -15
  69. package/components/radio/radio-group.js +21 -24
  70. package/components/radio/radio.d.ts +11 -6
  71. package/components/radio/radio.js +7 -7
  72. package/components/range-slider/index.d.ts +13 -8
  73. package/components/range-slider/index.js +10 -7
  74. package/components/ripple/index.d.ts +4 -2
  75. package/components/ripple/index.js +3 -2
  76. package/components/ripple/ripple-mixin.d.ts +1 -1
  77. package/components/ripple/ripple-mixin.js +0 -1
  78. package/components/segmented-button/segmented-button-group-style.js +1 -1
  79. package/components/segmented-button/segmented-button-group.d.ts +23 -22
  80. package/components/segmented-button/segmented-button-group.js +20 -23
  81. package/components/segmented-button/segmented-button.d.ts +9 -4
  82. package/components/segmented-button/segmented-button.js +3 -3
  83. package/components/select/index.d.ts +42 -35
  84. package/components/select/index.js +24 -25
  85. package/components/slider/index.d.ts +9 -2
  86. package/components/slider/index.js +5 -10
  87. package/components/slider/slider-base.d.ts +22 -18
  88. package/components/slider/slider-base.js +40 -21
  89. package/components/snackbar/index.d.ts +30 -23
  90. package/components/snackbar/index.js +25 -25
  91. package/components/switch/index.d.ts +24 -17
  92. package/components/switch/index.js +18 -18
  93. package/components/tabs/tab-panel.d.ts +7 -5
  94. package/components/tabs/tab-panel.js +5 -4
  95. package/components/tabs/tab.d.ts +13 -9
  96. package/components/tabs/tab.js +8 -7
  97. package/components/tabs/tabs.d.ts +24 -21
  98. package/components/tabs/tabs.js +24 -21
  99. package/components/text-field/index.d.ts +62 -54
  100. package/components/text-field/index.js +37 -37
  101. package/components/tooltip/index.d.ts +40 -33
  102. package/components/tooltip/index.js +45 -43
  103. package/components/top-app-bar/top-app-bar-title.d.ts +8 -6
  104. package/components/top-app-bar/top-app-bar-title.js +7 -6
  105. package/components/top-app-bar/top-app-bar.d.ts +12 -6
  106. package/components/top-app-bar/top-app-bar.js +9 -10
  107. package/css-data.en.json +2826 -0
  108. package/css-data.zh-cn.json +374 -367
  109. package/custom-elements.json +3844 -3824
  110. package/html-data.en.json +6551 -0
  111. package/html-data.zh-cn.json +1621 -1636
  112. package/jsx.en.d.ts +3303 -0
  113. package/jsx.zh-cn.d.ts +3351 -0
  114. package/mdui.esm.js +9 -9
  115. package/mdui.global.js +9 -9
  116. package/package.json +7 -5
  117. package/web-types.en.json +11718 -0
  118. package/web-types.zh-cn.json +3613 -3623
@@ -1,15 +1,15 @@
1
- import { LitElement } from 'lit';
1
+ import { MduiElement } from '@mdui/shared/base/mdui-element.js';
2
2
  import type { CSSResultGroup, TemplateResult } from 'lit';
3
3
  import type { Ref } from 'lit/directives/ref.js';
4
- declare const SliderBase_base: import("@open-wc/dedupe-mixin").Constructor<import("../ripple/ripple-mixin.js").RippleMixinInterface> & import("@open-wc/dedupe-mixin").Constructor<import("@mdui/shared/mixins/focusable.js").FocusableMixinInterface> & typeof LitElement;
5
- export declare class SliderBase extends SliderBase_base {
4
+ declare const SliderBase_base: import("@open-wc/dedupe-mixin").Constructor<import("../ripple/ripple-mixin.js").RippleMixinInterface> & import("@open-wc/dedupe-mixin").Constructor<import("@mdui/shared/mixins/focusable.js").FocusableMixinInterface> & typeof MduiElement;
5
+ export declare class SliderBase<E> extends SliderBase_base<E> {
6
6
  static styles: CSSResultGroup;
7
7
  /**
8
- * 最小允许值,默认为 `0`
8
+ * 滑块的最小值,默认为 `0`
9
9
  */
10
10
  min: number;
11
11
  /**
12
- * 最大允许值,默认为 `100`
12
+ * 滑块的最大值,默认为 `100`
13
13
  */
14
14
  max: number;
15
15
  /**
@@ -21,21 +21,21 @@ export declare class SliderBase extends SliderBase_base {
21
21
  */
22
22
  tickmarks: boolean;
23
23
  /**
24
- * 是否不显示文本提示
24
+ * 是否隐藏文本提示
25
25
  */
26
26
  nolabel: boolean;
27
27
  /**
28
- * 是否禁用
28
+ * 是否被禁用
29
29
  */
30
30
  disabled: boolean;
31
31
  /**
32
- * 关联的 `form` 元素。此属性值必须为同一页面中的一个 `<form>` 元素的 `id` 属性。
32
+ * 关联的 `<form>` 元素。此属性值应为同一页面中的一个 `<form>` 元素的 `id`。
33
33
  *
34
- * 如果此属性未指定,则元素必须是 `form` 元素的后代。利用此属性,你可以将元素放置在页面中的任何位置,而不仅仅是作为 `form` 元素的后代。
34
+ * 如果未指定此属性,则该元素必须是 `<form>` 元素的子元素。通过此属性,你可以将元素放置在页面的任何位置,而不仅仅是 `<form>` 元素的子元素。
35
35
  */
36
36
  form?: string;
37
37
  /**
38
- * 滑块名称,将与表单数据一起提交
38
+ * 滑块的名称,该名称将与表单数据一起提交
39
39
  */
40
40
  name: string;
41
41
  /**
@@ -48,37 +48,41 @@ export declare class SliderBase extends SliderBase_base {
48
48
  protected readonly inputRef: Ref<HTMLInputElement>;
49
49
  protected readonly trackActiveRef: Ref<HTMLElement>;
50
50
  /**
51
- * 表单验证状态对象
51
+ * 表单验证状态对象,具体参见 [`ValidityState`](https://developer.mozilla.org/zh-CN/docs/Web/API/ValidityState)
52
52
  */
53
53
  get validity(): ValidityState;
54
54
  /**
55
- * 表单验证的错误提示信息
55
+ * 如果表单验证未通过,此属性将包含提示信息。如果验证通过,此属性将为空字符串
56
56
  */
57
57
  get validationMessage(): string;
58
58
  protected get rippleDisabled(): boolean;
59
59
  protected get focusElement(): HTMLElement;
60
60
  protected get focusDisabled(): boolean;
61
61
  /**
62
- * 用于自定义标签的显示格式
62
+ * 用于自定义标签的显示格式的函数。函数参数为滑块的当前值,返回值为期望显示的文本。
63
63
  */
64
64
  labelFormatter: (value: number) => string;
65
65
  private onDisabledChange;
66
66
  /**
67
- * 检查表单字段是否验证通过。若未通过则返回 `false`,并触发 `invalid` 事件;若验证通过,则返回 `true`
67
+ * 检查表单字段是否通过验证。如果未通过,返回 `false` 并触发 `invalid` 事件;如果通过,返回 `true`
68
68
  */
69
69
  checkValidity(): boolean;
70
70
  /**
71
- * 检查表单字段是否验证通过。若未通过则返回 `false`,并触发 `invalid` 事件;若验证通过,则返回 `true`。
71
+ * 检查表单字段是否通过验证。如果未通过,返回 `false` 并触发 `invalid` 事件;如果通过,返回 `true`。
72
72
  *
73
- * 验证未通过时,还将在组件上显示未通过的提示。
73
+ * 如果验证未通过,还会在组件上显示验证失败的提示。
74
74
  */
75
75
  reportValidity(): boolean;
76
76
  /**
77
- * 设置自定义的错误提示文本。只要文本不为空,则表示字段验证未通过
77
+ * 设置自定义的错误提示文本。只要这个文本不为空,就表示字段未通过验证
78
78
  *
79
- * @param message 自定义的提示文本
79
+ * @param message 自定义的错误提示文本
80
80
  */
81
81
  setCustomValidity(message: string): void;
82
+ /**
83
+ * value 不在 min、max 或 step 的限制范围内时,修正 value 的值
84
+ */
85
+ protected fixValue(value: number): number;
82
86
  /**
83
87
  * 获取候选值组成的数组
84
88
  */
@@ -1,25 +1,25 @@
1
1
  import { __decorate } from "tslib";
2
- import { html, LitElement } from 'lit';
2
+ import { html } from 'lit';
3
3
  import { property, state } from 'lit/decorators.js';
4
4
  import { classMap } from 'lit/directives/class-map.js';
5
5
  import { createRef } from 'lit/directives/ref.js';
6
6
  import { when } from 'lit/directives/when.js';
7
+ import { MduiElement } from '@mdui/shared/base/mdui-element.js';
7
8
  import { watch } from '@mdui/shared/decorators/watch.js';
8
9
  import { booleanConverter } from '@mdui/shared/helpers/decorator.js';
9
- import { emit } from '@mdui/shared/helpers/event.js';
10
10
  import { componentStyle } from '@mdui/shared/lit-styles/component-style.js';
11
11
  import { FocusableMixin } from '@mdui/shared/mixins/focusable.js';
12
12
  import { RippleMixin } from '../ripple/ripple-mixin.js';
13
13
  import { sliderBaseStyle } from './slider-base-style.js';
14
- export class SliderBase extends RippleMixin(FocusableMixin(LitElement)) {
14
+ export class SliderBase extends RippleMixin(FocusableMixin(MduiElement)) {
15
15
  constructor() {
16
16
  super(...arguments);
17
17
  /**
18
- * 最小允许值,默认为 `0`
18
+ * 滑块的最小值,默认为 `0`
19
19
  */
20
20
  this.min = 0;
21
21
  /**
22
- * 最大允许值,默认为 `100`
22
+ * 滑块的最大值,默认为 `100`
23
23
  */
24
24
  this.max = 100;
25
25
  /**
@@ -31,15 +31,15 @@ export class SliderBase extends RippleMixin(FocusableMixin(LitElement)) {
31
31
  */
32
32
  this.tickmarks = false;
33
33
  /**
34
- * 是否不显示文本提示
34
+ * 是否隐藏文本提示
35
35
  */
36
36
  this.nolabel = false;
37
37
  /**
38
- * 是否禁用
38
+ * 是否被禁用
39
39
  */
40
40
  this.disabled = false;
41
41
  /**
42
- * 滑块名称,将与表单数据一起提交
42
+ * 滑块的名称,该名称将与表单数据一起提交
43
43
  */
44
44
  this.name = '';
45
45
  /**
@@ -53,18 +53,18 @@ export class SliderBase extends RippleMixin(FocusableMixin(LitElement)) {
53
53
  this.inputRef = createRef();
54
54
  this.trackActiveRef = createRef();
55
55
  /**
56
- * 用于自定义标签的显示格式
56
+ * 用于自定义标签的显示格式的函数。函数参数为滑块的当前值,返回值为期望显示的文本。
57
57
  */
58
58
  this.labelFormatter = (value) => value.toString();
59
59
  }
60
60
  /**
61
- * 表单验证状态对象
61
+ * 表单验证状态对象,具体参见 [`ValidityState`](https://developer.mozilla.org/zh-CN/docs/Web/API/ValidityState)
62
62
  */
63
63
  get validity() {
64
64
  return this.inputRef.value.validity;
65
65
  }
66
66
  /**
67
- * 表单验证的错误提示信息
67
+ * 如果表单验证未通过,此属性将包含提示信息。如果验证通过,此属性将为空字符串
68
68
  */
69
69
  get validationMessage() {
70
70
  return this.inputRef.value.validationMessage;
@@ -82,12 +82,13 @@ export class SliderBase extends RippleMixin(FocusableMixin(LitElement)) {
82
82
  this.invalid = !this.inputRef.value.checkValidity();
83
83
  }
84
84
  /**
85
- * 检查表单字段是否验证通过。若未通过则返回 `false`,并触发 `invalid` 事件;若验证通过,则返回 `true`
85
+ * 检查表单字段是否通过验证。如果未通过,返回 `false` 并触发 `invalid` 事件;如果通过,返回 `true`
86
86
  */
87
87
  checkValidity() {
88
88
  const valid = this.inputRef.value.checkValidity();
89
89
  if (!valid) {
90
- emit(this, 'invalid', {
90
+ // @ts-ignore
91
+ this.emit('invalid', {
91
92
  bubbles: false,
92
93
  cancelable: true,
93
94
  composed: false,
@@ -96,20 +97,21 @@ export class SliderBase extends RippleMixin(FocusableMixin(LitElement)) {
96
97
  return valid;
97
98
  }
98
99
  /**
99
- * 检查表单字段是否验证通过。若未通过则返回 `false`,并触发 `invalid` 事件;若验证通过,则返回 `true`。
100
+ * 检查表单字段是否通过验证。如果未通过,返回 `false` 并触发 `invalid` 事件;如果通过,返回 `true`。
100
101
  *
101
- * 验证未通过时,还将在组件上显示未通过的提示。
102
+ * 如果验证未通过,还会在组件上显示验证失败的提示。
102
103
  */
103
104
  reportValidity() {
104
105
  this.invalid = !this.inputRef.value.reportValidity();
105
106
  if (this.invalid) {
106
- const requestInvalid = emit(this, 'invalid', {
107
+ // @ts-ignore
108
+ const eventProceeded = this.emit('invalid', {
107
109
  bubbles: false,
108
110
  cancelable: true,
109
111
  composed: false,
110
112
  });
111
- // 调用了 preventDefault() 时,隐藏默认的表单错误提示
112
- if (requestInvalid.defaultPrevented) {
113
+ if (!eventProceeded) {
114
+ // 调用了 preventDefault() 时,隐藏默认的表单错误提示
113
115
  this.blur();
114
116
  this.focus();
115
117
  }
@@ -117,14 +119,30 @@ export class SliderBase extends RippleMixin(FocusableMixin(LitElement)) {
117
119
  return !this.invalid;
118
120
  }
119
121
  /**
120
- * 设置自定义的错误提示文本。只要文本不为空,则表示字段验证未通过
122
+ * 设置自定义的错误提示文本。只要这个文本不为空,就表示字段未通过验证
121
123
  *
122
- * @param message 自定义的提示文本
124
+ * @param message 自定义的错误提示文本
123
125
  */
124
126
  setCustomValidity(message) {
125
127
  this.inputRef.value.setCustomValidity(message);
126
128
  this.invalid = !this.inputRef.value.checkValidity();
127
129
  }
130
+ /**
131
+ * value 不在 min、max 或 step 的限制范围内时,修正 value 的值
132
+ */
133
+ fixValue(value) {
134
+ const { min, max, step } = this;
135
+ // 确保 value 在 min 和 max 范围内
136
+ value = Math.min(Math.max(value, min), max);
137
+ // 计算最接近 value 的 step 值
138
+ const steps = Math.round((value - min) / step);
139
+ let fixedValue = min + steps * step;
140
+ // 如果修正后的值超出最大值,则减去一个 step
141
+ if (fixedValue > max) {
142
+ fixedValue -= step;
143
+ }
144
+ return fixedValue;
145
+ }
128
146
  /**
129
147
  * 获取候选值组成的数组
130
148
  */
@@ -138,7 +156,8 @@ export class SliderBase extends RippleMixin(FocusableMixin(LitElement)) {
138
156
  return when(!this.nolabel, () => html `<div part="label" class="label ${classMap({ 'label-visible': this.labelVisible })}">${this.labelFormatter(value)}</div>`);
139
157
  }
140
158
  onChange() {
141
- emit(this, 'change');
159
+ // @ts-ignore
160
+ this.emit('change');
142
161
  }
143
162
  }
144
163
  SliderBase.styles = [
@@ -1,4 +1,4 @@
1
- import { LitElement } from 'lit';
1
+ import { MduiElement } from '@mdui/shared/base/mdui-element.js';
2
2
  import '@mdui/shared/icons/clear.js';
3
3
  import '../button-icon.js';
4
4
  import '../button.js';
@@ -17,42 +17,42 @@ import type { CSSResultGroup, TemplateResult } from 'lit';
17
17
  * @event closed - Snackbar 隐藏动画完成时,事件被触发
18
18
  * @event action-click - 点击操作按钮时触发
19
19
  *
20
- * @slot - Snackbar 中的消息文本内容
20
+ * @slot - Snackbar 的消息文本内容
21
21
  * @slot action - 右侧的操作按钮
22
- * @slot close-button - 右侧的关闭按钮。必须设置 `closeable` 属性为 `true` 才会显示该按钮
23
- * @slot close-icon - 右侧的关闭按钮中的图标
22
+ * @slot close-button - 右侧的关闭按钮。必须设置 `closeable` 属性为 `true` 才会显示
23
+ * @slot close-icon - 关闭按钮中的图标
24
24
  *
25
25
  * @csspart message - 消息文本
26
26
  * @csspart action - 操作按钮
27
27
  * @csspart close-button - 关闭按钮
28
28
  * @csspart close-icon - 关闭按钮中的图标
29
29
  *
30
- * @cssprop --shape-corner - 组件的圆角大小。可以指定一个具体的像素值;但更推荐[引用设计令牌](/docs/2/styles/design-tokens#shape-corner)
31
- * @cssprop --z-index - 组件的 CSS `z-index` 值
30
+ * @cssprop --shape-corner - 组件的圆角大小。可以指定一个具体的像素值;但更推荐引用[设计令牌](/docs/2/styles/design-tokens#shape-corner)
31
+ * @cssprop --z-index - 组件的 CSS `z-index` 值
32
32
  */
33
- export declare class Snackbar extends LitElement {
33
+ export declare class Snackbar extends MduiElement<SnackbarEventMap> {
34
34
  static styles: CSSResultGroup;
35
35
  /**
36
36
  * 是否显示 Snackbar
37
37
  */
38
38
  open: boolean;
39
39
  /**
40
- * Snackbar 出现的位置。默认为 `bottom`。可选值为:
40
+ * Snackbar 的显示位置。默认为 `bottom`。可选值包括:
41
41
  *
42
- * * `top`:位于顶部,居中对齐
43
- * * `top-start`:位于顶部,左对齐
44
- * * `top-end`:位于顶部,右对齐
45
- * * `bottom`:位于底部,居中对齐
46
- * * `bottom-start`:位于底部,左对齐
47
- * * `bottom-end`:位于底部,右对齐
42
+ * * `top`:顶部居中
43
+ * * `top-start`:顶部左对齐
44
+ * * `top-end`:顶部右对齐
45
+ * * `bottom`:底部居中
46
+ * * `bottom-start`:底部左对齐
47
+ * * `bottom-end`:底部右对齐
48
48
  */
49
- placement: /*位于顶部,居中对齐*/ 'top' | /*位于顶部,左对齐*/ 'top-start' | /*位于顶部,右对齐*/ 'top-end' | /*位于底部,居中对齐*/ 'bottom' | /*位于底部,左对齐*/ 'bottom-start' | /*位于底部,右对齐*/ 'bottom-end';
49
+ placement: /*顶部居中*/ 'top' | /*顶部左对齐*/ 'top-start' | /*顶部右对齐*/ 'top-end' | /*底部居中*/ 'bottom' | /*底部左对齐*/ 'bottom-start' | /*底部右对齐*/ 'bottom-end';
50
50
  /**
51
51
  * 操作按钮的文本。也可以通过 `slot="action"` 设置操作按钮
52
52
  */
53
53
  action?: string;
54
54
  /**
55
- * 操作按钮是否为 loading 状态
55
+ * 操作按钮是否处于加载中状态
56
56
  */
57
57
  actionLoading: boolean;
58
58
  /**
@@ -60,22 +60,22 @@ export declare class Snackbar extends LitElement {
60
60
  */
61
61
  closeable: boolean;
62
62
  /**
63
- * 关闭按钮中的 Material Icons 图标名。也可以通过 `slot="close-icon"` 设置
63
+ * 关闭按钮的 Material Icons 图标名。也可以通过 `slot="close-icon"` 设置
64
64
  */
65
65
  closeIcon?: string;
66
66
  /**
67
- * 消息文本最多显示几行。默认不限制行数。可选值为:
67
+ * 消息文本的最大显示行数。默认不限制。可选值包括:
68
68
  *
69
- * * `1`:消息文本最多显示一行
70
- * * `2`:消息文本最多显示两行
69
+ * * `1`:最多显示一行
70
+ * * `2`:最多显示两行
71
71
  */
72
- messageLine?: /*消息文本最多显示一行*/ 1 | /*消息文本最多显示两行*/ 2;
72
+ messageLine?: /*最多显示一行*/ 1 | /*最多显示两行*/ 2;
73
73
  /**
74
- * 在多长时间后自动关闭(单位为毫秒)。设置为 `0` 时,不自动关闭。默认为 5 秒后自动关闭。
74
+ * 自动关闭的延迟时间(单位:毫秒)。设置为 `0` 则不自动关闭。默认为 5000 毫秒
75
75
  */
76
76
  autoCloseDelay: number;
77
77
  /**
78
- * 点击或触摸 Snackbar 以外的区域时是否关闭 Snackbar
78
+ * 点击或触摸 Snackbar 以外的区域时,是否关闭 Snackbar
79
79
  */
80
80
  closeOnOutsideClick: boolean;
81
81
  private closeTimeout;
@@ -91,6 +91,13 @@ export declare class Snackbar extends LitElement {
91
91
  private onActionClick;
92
92
  private onCloseClick;
93
93
  }
94
+ export interface SnackbarEventMap {
95
+ open: CustomEvent<void>;
96
+ opened: CustomEvent<void>;
97
+ close: CustomEvent<void>;
98
+ closed: CustomEvent<void>;
99
+ 'action-click': CustomEvent<void>;
100
+ }
94
101
  declare global {
95
102
  interface HTMLElementTagNameMap {
96
103
  'mdui-snackbar': Snackbar;
@@ -1,12 +1,12 @@
1
1
  import { __decorate } from "tslib";
2
- import { html, LitElement } from 'lit';
2
+ import { html } from 'lit';
3
3
  import { customElement, property } from 'lit/decorators.js';
4
4
  import { when } from 'lit/directives/when.js';
5
+ import { MduiElement } from '@mdui/shared/base/mdui-element.js';
5
6
  import { watch } from '@mdui/shared/decorators/watch.js';
6
7
  import { animateTo, stopAnimations } from '@mdui/shared/helpers/animate.js';
7
8
  import { breakpoint } from '@mdui/shared/helpers/breakpoint.js';
8
9
  import { booleanConverter } from '@mdui/shared/helpers/decorator.js';
9
- import { emit } from '@mdui/shared/helpers/event.js';
10
10
  import { getDuration, getEasing } from '@mdui/shared/helpers/motion.js';
11
11
  import { nothingTemplate } from '@mdui/shared/helpers/template.js';
12
12
  import '@mdui/shared/icons/clear.js';
@@ -28,20 +28,20 @@ import { style } from './style.js';
28
28
  * @event closed - Snackbar 隐藏动画完成时,事件被触发
29
29
  * @event action-click - 点击操作按钮时触发
30
30
  *
31
- * @slot - Snackbar 中的消息文本内容
31
+ * @slot - Snackbar 的消息文本内容
32
32
  * @slot action - 右侧的操作按钮
33
- * @slot close-button - 右侧的关闭按钮。必须设置 `closeable` 属性为 `true` 才会显示该按钮
34
- * @slot close-icon - 右侧的关闭按钮中的图标
33
+ * @slot close-button - 右侧的关闭按钮。必须设置 `closeable` 属性为 `true` 才会显示
34
+ * @slot close-icon - 关闭按钮中的图标
35
35
  *
36
36
  * @csspart message - 消息文本
37
37
  * @csspart action - 操作按钮
38
38
  * @csspart close-button - 关闭按钮
39
39
  * @csspart close-icon - 关闭按钮中的图标
40
40
  *
41
- * @cssprop --shape-corner - 组件的圆角大小。可以指定一个具体的像素值;但更推荐[引用设计令牌](/docs/2/styles/design-tokens#shape-corner)
42
- * @cssprop --z-index - 组件的 CSS `z-index` 值
41
+ * @cssprop --shape-corner - 组件的圆角大小。可以指定一个具体的像素值;但更推荐引用[设计令牌](/docs/2/styles/design-tokens#shape-corner)
42
+ * @cssprop --z-index - 组件的 CSS `z-index` 值
43
43
  */
44
- let Snackbar = class Snackbar extends LitElement {
44
+ let Snackbar = class Snackbar extends MduiElement {
45
45
  constructor() {
46
46
  super();
47
47
  /**
@@ -49,18 +49,18 @@ let Snackbar = class Snackbar extends LitElement {
49
49
  */
50
50
  this.open = false;
51
51
  /**
52
- * Snackbar 出现的位置。默认为 `bottom`。可选值为:
52
+ * Snackbar 的显示位置。默认为 `bottom`。可选值包括:
53
53
  *
54
- * * `top`:位于顶部,居中对齐
55
- * * `top-start`:位于顶部,左对齐
56
- * * `top-end`:位于顶部,右对齐
57
- * * `bottom`:位于底部,居中对齐
58
- * * `bottom-start`:位于底部,左对齐
59
- * * `bottom-end`:位于底部,右对齐
54
+ * * `top`:顶部居中
55
+ * * `top-start`:顶部左对齐
56
+ * * `top-end`:顶部右对齐
57
+ * * `bottom`:底部居中
58
+ * * `bottom-start`:底部左对齐
59
+ * * `bottom-end`:底部右对齐
60
60
  */
61
61
  this.placement = 'bottom';
62
62
  /**
63
- * 操作按钮是否为 loading 状态
63
+ * 操作按钮是否处于加载中状态
64
64
  */
65
65
  this.actionLoading = false;
66
66
  /**
@@ -68,11 +68,11 @@ let Snackbar = class Snackbar extends LitElement {
68
68
  */
69
69
  this.closeable = false;
70
70
  /**
71
- * 在多长时间后自动关闭(单位为毫秒)。设置为 `0` 时,不自动关闭。默认为 5 秒后自动关闭。
71
+ * 自动关闭的延迟时间(单位:毫秒)。设置为 `0` 则不自动关闭。默认为 5000 毫秒
72
72
  */
73
73
  this.autoCloseDelay = 5000;
74
74
  /**
75
- * 点击或触摸 Snackbar 以外的区域时是否关闭 Snackbar
75
+ * 点击或触摸 Snackbar 以外的区域时,是否关闭 Snackbar
76
76
  */
77
77
  this.closeOnOutsideClick = false;
78
78
  this.onDocumentClick = this.onDocumentClick.bind(this);
@@ -97,8 +97,8 @@ let Snackbar = class Snackbar extends LitElement {
97
97
  await this.updateComplete;
98
98
  }
99
99
  if (hasUpdated) {
100
- const requestOpen = emit(this, 'open', { cancelable: true });
101
- if (requestOpen.defaultPrevented) {
100
+ const eventProceeded = this.emit('open', { cancelable: true });
101
+ if (!eventProceeded) {
102
102
  return;
103
103
  }
104
104
  }
@@ -155,14 +155,14 @@ let Snackbar = class Snackbar extends LitElement {
155
155
  })),
156
156
  ]);
157
157
  if (hasUpdated) {
158
- emit(this, 'opened');
158
+ this.emit('opened');
159
159
  }
160
160
  return;
161
161
  }
162
162
  // 关闭
163
163
  if (!this.open && this.hasUpdated) {
164
- const requestClose = emit(this, 'close', { cancelable: true });
165
- if (requestClose.defaultPrevented) {
164
+ const eventProceeded = this.emit('close', { cancelable: true });
165
+ if (!eventProceeded) {
166
166
  return;
167
167
  }
168
168
  window.clearTimeout(this.closeTimeout);
@@ -191,7 +191,7 @@ let Snackbar = class Snackbar extends LitElement {
191
191
  ...children.map((child) => animateTo(child, [{ opacity: 1 }, { opacity: 0, offset: 0.75 }, { opacity: 0 }], { duration, easing: easingLinear })),
192
192
  ]);
193
193
  this.style.display = 'none';
194
- emit(this, 'closed');
194
+ this.emit('closed');
195
195
  return;
196
196
  }
197
197
  }
@@ -224,7 +224,7 @@ let Snackbar = class Snackbar extends LitElement {
224
224
  }
225
225
  onActionClick(event) {
226
226
  event.stopPropagation();
227
- emit(this, 'action-click');
227
+ this.emit('action-click');
228
228
  }
229
229
  onCloseClick() {
230
230
  this.open = false;
@@ -1,10 +1,10 @@
1
- import { LitElement } from 'lit';
1
+ import { MduiElement } from '@mdui/shared/base/mdui-element.js';
2
2
  import '@mdui/shared/icons/check.js';
3
3
  import '../icon.js';
4
4
  import type { Ripple } from '../ripple/index.js';
5
5
  import type { FormControl } from '@mdui/jq/shared/form.js';
6
6
  import type { CSSResultGroup, TemplateResult } from 'lit';
7
- declare const Switch_base: import("@open-wc/dedupe-mixin").Constructor<import("../ripple/ripple-mixin.js").RippleMixinInterface> & import("@open-wc/dedupe-mixin").Constructor<import("@mdui/shared/mixins/focusable.js").FocusableMixinInterface> & typeof LitElement;
7
+ declare const Switch_base: import("@open-wc/dedupe-mixin").Constructor<import("../ripple/ripple-mixin.js").RippleMixinInterface> & import("@open-wc/dedupe-mixin").Constructor<import("@mdui/shared/mixins/focusable.js").FocusableMixinInterface> & typeof MduiElement;
8
8
  /**
9
9
  * @summary 开关切换组件
10
10
  *
@@ -26,10 +26,10 @@ declare const Switch_base: import("@open-wc/dedupe-mixin").Constructor<import(".
26
26
  * @csspart unchecked-icon - 未选中状态的图标
27
27
  * @csspart checked-icon 选中状态的图标
28
28
  *
29
- * @cssprop --shape-corner - 组件的轨道的圆角大小。可以指定一个具体的像素值;但更推荐[引用设计令牌](/docs/2/styles/design-tokens#shape-corner)
30
- * @cssprop --shape-corner-thumb - 组件的图标容器的圆角大小。可以指定一个具体的像素值;但更推荐[引用设计令牌](/docs/2/styles/design-tokens#shape-corner)
29
+ * @cssprop --shape-corner - 组件轨道的圆角大小。可以指定一个具体的像素值;但更推荐引用[设计令牌](/docs/2/styles/design-tokens#shape-corner)
30
+ * @cssprop --shape-corner-thumb - 组件图标容器的圆角大小。可以指定一个具体的像素值;但更推荐引用[设计令牌](/docs/2/styles/design-tokens#shape-corner)
31
31
  */
32
- export declare class Switch extends Switch_base implements FormControl {
32
+ export declare class Switch extends Switch_base<SwitchEventMap> implements FormControl {
33
33
  static styles: CSSResultGroup;
34
34
  /**
35
35
  * 是否为禁用状态
@@ -40,7 +40,7 @@ export declare class Switch extends Switch_base implements FormControl {
40
40
  */
41
41
  checked: boolean;
42
42
  /**
43
- * 默认选中状态。在重置表单时,将重置为该默认状态。该属性只能通过 JavaScript 属性设置
43
+ * 默认选中状态。在重置表单时,将重置为此状态。此属性只能通过 JavaScript 属性设置
44
44
  */
45
45
  defaultChecked: boolean;
46
46
  /**
@@ -50,17 +50,17 @@ export declare class Switch extends Switch_base implements FormControl {
50
50
  /**
51
51
  * 选中状态的 Material Icons 图标名。也可以通过 `slot="checked-icon"` 设置
52
52
  *
53
- * 默认为 check 图标,可传入空字符串移除默认图标
53
+ * 默认为 `check` 图标,可传入空字符串移除默认图标
54
54
  */
55
55
  checkedIcon?: string;
56
56
  /**
57
- * 提交表单时,是否必须选中该开关
57
+ * 提交表单时,是否必须选中此开关
58
58
  */
59
59
  required: boolean;
60
60
  /**
61
- * 关联的 `form` 元素。此属性值必须为同一页面中的一个 `<form>` 元素的 `id` 属性。
61
+ * 关联的 `<form>` 元素。此属性值应为同一页面中的一个 `<form>` 元素的 `id`。
62
62
  *
63
- * 如果此属性未指定,则元素必须是 `form` 元素的后代。利用此属性,你可以将元素放置在页面中的任何位置,而不仅仅是作为 `form` 元素的后代。
63
+ * 如果未指定此属性,则该元素必须是 `<form>` 元素的子元素。通过此属性,你可以将元素放置在页面的任何位置,而不仅仅是 `<form>` 元素的子元素。
64
64
  */
65
65
  form?: string;
66
66
  /**
@@ -80,11 +80,11 @@ export declare class Switch extends Switch_base implements FormControl {
80
80
  private readonly formController;
81
81
  private readonly hasSlotController;
82
82
  /**
83
- * 表单验证状态对象
83
+ * 表单验证状态对象,具体参见 [`ValidityState`](https://developer.mozilla.org/zh-CN/docs/Web/API/ValidityState)
84
84
  */
85
85
  get validity(): ValidityState;
86
86
  /**
87
- * 表单验证的错误提示信息
87
+ * 如果表单验证未通过,此属性将包含提示信息。如果验证通过,此属性将为空字符串
88
88
  */
89
89
  get validationMessage(): string;
90
90
  protected get rippleElement(): Ripple;
@@ -94,19 +94,19 @@ export declare class Switch extends Switch_base implements FormControl {
94
94
  private onDisabledChange;
95
95
  private onCheckedChange;
96
96
  /**
97
- * 检查表单字段是否验证通过。若未通过则返回 `false`,并触发 `invalid` 事件;若验证通过,则返回 `true`
97
+ * 检查表单字段是否通过验证。如果未通过,返回 `false` 并触发 `invalid` 事件;如果通过,返回 `true`
98
98
  */
99
99
  checkValidity(): boolean;
100
100
  /**
101
- * 检查表单字段是否验证通过。若未通过则返回 `false`,并触发 `invalid` 事件;若验证通过,则返回 `true`。
101
+ * 检查表单字段是否通过验证。如果未通过,返回 `false` 并触发 `invalid` 事件;如果通过,返回 `true`。
102
102
  *
103
- * 验证未通过时,还将在组件上显示未通过的提示。
103
+ * 如果验证未通过,还会在组件上显示验证失败的提示。
104
104
  */
105
105
  reportValidity(): boolean;
106
106
  /**
107
- * 设置自定义的错误提示文本。只要文本不为空,则表示字段验证未通过
107
+ * 设置自定义的错误提示文本。只要这个文本不为空,就表示字段未通过验证
108
108
  *
109
- * @param message 自定义的提示文本
109
+ * @param message 自定义的错误提示文本
110
110
  */
111
111
  setCustomValidity(message: string): void;
112
112
  protected render(): TemplateResult;
@@ -115,6 +115,13 @@ export declare class Switch extends Switch_base implements FormControl {
115
115
  */
116
116
  private onChange;
117
117
  }
118
+ export interface SwitchEventMap {
119
+ focus: FocusEvent;
120
+ blur: FocusEvent;
121
+ change: CustomEvent<void>;
122
+ input: Event;
123
+ invalid: CustomEvent<void>;
124
+ }
118
125
  declare global {
119
126
  interface HTMLElementTagNameMap {
120
127
  'mdui-switch': Switch;