mdui 2.0.1 → 2.0.3

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 (127) hide show
  1. package/LICENSE +21 -21
  2. package/components/avatar/index.d.ts +4 -2
  3. package/components/avatar/index.js +4 -2
  4. package/components/badge/index.d.ts +4 -2
  5. package/components/badge/index.js +4 -2
  6. package/components/bottom-app-bar/index.d.ts +9 -3
  7. package/components/bottom-app-bar/index.js +9 -9
  8. package/components/button/button-base.d.ts +5 -5
  9. package/components/button/button-base.js +22 -19
  10. package/components/button/index.d.ts +6 -1
  11. package/components/button/index.js +2 -1
  12. package/components/button-icon/index.d.ts +7 -1
  13. package/components/button-icon/index.js +3 -3
  14. package/components/card/index.d.ts +8 -4
  15. package/components/card/index.js +7 -3
  16. package/components/checkbox/index.d.ts +10 -3
  17. package/components/checkbox/index.js +13 -16
  18. package/components/checkbox/style.js +1 -1
  19. package/components/chip/index.d.ts +8 -1
  20. package/components/chip/index.js +5 -5
  21. package/components/circular-progress/index.d.ts +4 -2
  22. package/components/circular-progress/index.js +5 -4
  23. package/components/collapse/collapse-item-style.js +1 -1
  24. package/components/collapse/collapse-item.d.ts +15 -3
  25. package/components/collapse/collapse-item.js +26 -23
  26. package/components/collapse/collapse.d.ts +16 -8
  27. package/components/collapse/collapse.js +61 -38
  28. package/components/dialog/index.d.ts +12 -4
  29. package/components/dialog/index.js +36 -36
  30. package/components/divider/index.d.ts +4 -2
  31. package/components/divider/index.js +4 -2
  32. package/components/dropdown/index.d.ts +13 -7
  33. package/components/dropdown/index.js +70 -63
  34. package/components/fab/index.d.ts +7 -1
  35. package/components/fab/index.js +10 -5
  36. package/components/icon/index.d.ts +4 -2
  37. package/components/icon/index.js +4 -2
  38. package/components/layout/helper.d.ts +5 -6
  39. package/components/layout/helper.js +42 -48
  40. package/components/layout/layout-item-base.d.ts +3 -2
  41. package/components/layout/layout-item-base.js +3 -4
  42. package/components/layout/layout-item.d.ts +4 -3
  43. package/components/layout/layout-item.js +3 -3
  44. package/components/layout/layout-main.d.ts +4 -2
  45. package/components/layout/layout-main.js +4 -2
  46. package/components/layout/layout.d.ts +4 -2
  47. package/components/layout/layout.js +4 -2
  48. package/components/linear-progress/index.d.ts +4 -2
  49. package/components/linear-progress/index.js +5 -4
  50. package/components/list/list-item-style.js +1 -1
  51. package/components/list/list-item.d.ts +7 -3
  52. package/components/list/list-item.js +5 -3
  53. package/components/list/list-subheader.d.ts +4 -2
  54. package/components/list/list-subheader.js +4 -2
  55. package/components/list/list.d.ts +4 -2
  56. package/components/list/list.js +4 -2
  57. package/components/menu/menu-item.d.ts +12 -3
  58. package/components/menu/menu-item.js +53 -40
  59. package/components/menu/menu.d.ts +9 -3
  60. package/components/menu/menu.js +85 -59
  61. package/components/navigation-bar/navigation-bar-item-style.js +1 -1
  62. package/components/navigation-bar/navigation-bar-item.d.ts +13 -5
  63. package/components/navigation-bar/navigation-bar-item.js +28 -11
  64. package/components/navigation-bar/navigation-bar.d.ts +14 -7
  65. package/components/navigation-bar/navigation-bar.js +58 -49
  66. package/components/navigation-drawer/index.d.ts +13 -2
  67. package/components/navigation-drawer/index.js +69 -49
  68. package/components/navigation-drawer/style.js +1 -1
  69. package/components/navigation-rail/navigation-rail-item-style.js +1 -1
  70. package/components/navigation-rail/navigation-rail-item.d.ts +13 -5
  71. package/components/navigation-rail/navigation-rail-item.js +22 -9
  72. package/components/navigation-rail/navigation-rail.d.ts +8 -6
  73. package/components/navigation-rail/navigation-rail.js +55 -46
  74. package/components/radio/radio-group.d.ts +13 -6
  75. package/components/radio/radio-group.js +69 -59
  76. package/components/radio/radio-style.js +1 -1
  77. package/components/radio/radio.d.ts +11 -5
  78. package/components/radio/radio.js +26 -19
  79. package/components/range-slider/index.d.ts +9 -3
  80. package/components/range-slider/index.js +13 -11
  81. package/components/ripple/index.d.ts +4 -2
  82. package/components/ripple/index.js +4 -2
  83. package/components/ripple/ripple-mixin.d.ts +1 -1
  84. package/components/ripple/ripple-mixin.js +0 -1
  85. package/components/segmented-button/segmented-button-group-style.js +1 -1
  86. package/components/segmented-button/segmented-button-group.d.ts +12 -5
  87. package/components/segmented-button/segmented-button-group.js +92 -77
  88. package/components/segmented-button/segmented-button.d.ts +8 -3
  89. package/components/segmented-button/segmented-button.js +5 -4
  90. package/components/select/index.d.ts +13 -5
  91. package/components/select/index.js +30 -28
  92. package/components/slider/index.d.ts +8 -1
  93. package/components/slider/index.js +11 -18
  94. package/components/slider/slider-base-style.js +1 -1
  95. package/components/slider/slider-base.d.ts +7 -3
  96. package/components/slider/slider-base.js +28 -13
  97. package/components/snackbar/index.d.ts +9 -2
  98. package/components/snackbar/index.js +11 -10
  99. package/components/switch/index.d.ts +10 -3
  100. package/components/switch/index.js +12 -15
  101. package/components/switch/style.js +1 -1
  102. package/components/tabs/tab-panel.d.ts +4 -2
  103. package/components/tabs/tab-panel.js +4 -2
  104. package/components/tabs/tab-style.js +1 -1
  105. package/components/tabs/tab.d.ts +7 -3
  106. package/components/tabs/tab.js +12 -6
  107. package/components/tabs/tabs-style.js +1 -1
  108. package/components/tabs/tabs.d.ts +11 -7
  109. package/components/tabs/tabs.js +57 -40
  110. package/components/text-field/index.d.ts +13 -5
  111. package/components/text-field/index.js +43 -65
  112. package/components/text-field/style.js +1 -1
  113. package/components/tooltip/index.d.ts +14 -7
  114. package/components/tooltip/index.js +45 -38
  115. package/components/top-app-bar/top-app-bar-title-style.js +1 -1
  116. package/components/top-app-bar/top-app-bar-title.d.ts +4 -2
  117. package/components/top-app-bar/top-app-bar-title.js +18 -13
  118. package/components/top-app-bar/top-app-bar.d.ts +9 -3
  119. package/components/top-app-bar/top-app-bar.js +11 -10
  120. package/custom-elements.json +904 -546
  121. package/functions/getTheme.js +3 -3
  122. package/functions/snackbar.js +1 -2
  123. package/functions/utils/colorScheme.js +2 -2
  124. package/mdui.esm.js +8 -8
  125. package/mdui.global.js +8 -8
  126. package/package.json +8 -7
  127. package/web-types.zh-cn.json +1 -1
@@ -1,5 +1,5 @@
1
1
  import { __decorate } from "tslib";
2
- import { html, LitElement } from 'lit';
2
+ import { html } from 'lit';
3
3
  import { customElement, property, queryAssignedElements, state, } from 'lit/decorators.js';
4
4
  import { $ } from '@mdui/jq/$.js';
5
5
  import '@mdui/jq/methods/add.js';
@@ -9,11 +9,13 @@ import '@mdui/jq/methods/get.js';
9
9
  import '@mdui/jq/methods/is.js';
10
10
  import '@mdui/jq/methods/parent.js';
11
11
  import '@mdui/jq/methods/parents.js';
12
- import { isString } from '@mdui/jq/shared/helper.js';
12
+ import { isString, isUndefined } from '@mdui/jq/shared/helper.js';
13
+ import { MduiElement } from '@mdui/shared/base/mdui-element.js';
14
+ import { DefinedController } from '@mdui/shared/controllers/defined.js';
13
15
  import { watch } from '@mdui/shared/decorators/watch.js';
16
+ import { arraysEqualIgnoreOrder } from '@mdui/shared/helpers/array.js';
14
17
  import { booleanConverter } from '@mdui/shared/helpers/decorator.js';
15
18
  import { delay } from '@mdui/shared/helpers/delay.js';
16
- import { emit } from '@mdui/shared/helpers/event.js';
17
19
  import { componentStyle } from '@mdui/shared/lit-styles/component-style.js';
18
20
  import { menuStyle } from './menu-style.js';
19
21
  /**
@@ -39,7 +41,7 @@ import { menuStyle } from './menu-style.js';
39
41
  *
40
42
  * @cssprop --shape-corner - 组件的圆角大小。可以指定一个具体的像素值;但更推荐[引用设计令牌](/docs/2/styles/design-tokens#shape-corner)
41
43
  */
42
- export let Menu = class Menu extends LitElement {
44
+ let Menu = class Menu extends MduiElement {
43
45
  constructor() {
44
46
  super(...arguments);
45
47
  /**
@@ -65,10 +67,13 @@ export let Menu = class Menu extends LitElement {
65
67
  this.submenuCloseDelay = 200;
66
68
  // 因为 menu-item 的 value 可能会重复,所有在每一个 menu-item 元素上都加了一个唯一的 key 属性,通过 selectedKeys 来记录选中状态的 key
67
69
  this.selectedKeys = [];
68
- // 是否已完成初始 value 的设置。首次设置初始值时,不触发 change 事件
69
- this.hasSetDefaultValue = false;
70
+ // 是否是初始状态,初始状态不触发 change 事件
71
+ this.isInitial = true;
70
72
  // 最后一次获得焦点的 menu-item 元素。为嵌套菜单时,把不同层级的 menu-item 放到对应索引位的位置
71
73
  this.lastActiveItems = [];
74
+ this.definedController = new DefinedController(this, {
75
+ relatedElements: ['mdui-menu-item'],
76
+ });
72
77
  }
73
78
  // 菜单项元素(包含子菜单中的菜单项)
74
79
  get items() {
@@ -110,7 +115,8 @@ export let Menu = class Menu extends LitElement {
110
115
  : 0;
111
116
  this.lastActiveItems[index] = item;
112
117
  }
113
- onSlotChange() {
118
+ async onSlotChange() {
119
+ await this.definedController.whenDefined();
114
120
  this.items.forEach((item) => {
115
121
  item.dense = this.dense;
116
122
  item.selects = this.selects;
@@ -119,43 +125,32 @@ export let Menu = class Menu extends LitElement {
119
125
  item.submenuCloseDelay = this.submenuCloseDelay;
120
126
  });
121
127
  }
122
- onSelectsChange() {
123
- if (!this.isSelectable && this.selectedKeys.length) {
124
- this.selectedKeys = [];
125
- this.onSelectedKeysChange();
126
- this.onValueChange();
128
+ async onSelectsChange() {
129
+ if (!this.isSelectable) {
130
+ // 不可选中,清空选中值
131
+ this.setSelectedKeys([]);
127
132
  }
128
- if (this.isSingle && this.selectedKeys.length > 1) {
129
- this.selectedKeys = this.selectedKeys.slice(0, 1);
130
- this.onSelectedKeysChange();
131
- this.onValueChange();
133
+ else if (this.isSingle) {
134
+ // 单选,只保留第一个选中的值
135
+ this.setSelectedKeys(this.selectedKeys.slice(0, 1));
132
136
  }
137
+ await this.onSelectedKeysChange();
133
138
  }
134
- onSelectedKeysChange(oldSelectedKeys) {
135
- // 根据 selectedKeys 读取出对应 menu-item 的 value。页面首次渲染时,values 始终为空数组
139
+ async onSelectedKeysChange() {
140
+ await this.definedController.whenDefined();
141
+ // 根据 selectedKeys 读取出对应 menu-item 的 value
136
142
  const values = this.itemsEnabled
137
143
  .filter((item) => this.selectedKeys.includes(item.key))
138
144
  .map((item) => item.value);
139
- // 如果是多选,且每一项值都不变,则视为未变更,不触发 change 事件
140
- if (this.isMultiple &&
141
- oldSelectedKeys &&
142
- oldSelectedKeys.length === this.selectedKeys.length &&
143
- oldSelectedKeys.every((v, i) => v === this.selectedKeys[i])) {
144
- this.hasSetDefaultValue = true;
145
- return;
146
- }
147
- this.value = this.isMultiple ? values : values[0] || undefined;
148
- if (this.hasSetDefaultValue) {
149
- emit(this, 'change');
150
- }
151
- else {
152
- this.hasSetDefaultValue = true;
145
+ const value = this.isMultiple ? values : values[0] || undefined;
146
+ this.setValue(value);
147
+ if (!this.isInitial) {
148
+ this.emit('change');
153
149
  }
154
150
  }
155
151
  async onValueChange() {
156
- if (!this.hasUpdated) {
157
- await this.updateComplete;
158
- }
152
+ this.isInitial = !this.hasUpdated;
153
+ await this.definedController.whenDefined();
159
154
  // 根据 value 找出对应的 menu-item,并把这些 menu-item 的 key 赋值给 selectedKeys
160
155
  if (!this.isSelectable) {
161
156
  this.updateSelected();
@@ -168,16 +163,16 @@ export let Menu = class Menu extends LitElement {
168
163
  ? [this.value]
169
164
  : this.value).filter((i) => i);
170
165
  if (!values.length) {
171
- this.selectedKeys = [];
166
+ this.setSelectedKeys([]);
172
167
  }
173
168
  else if (this.isSingle) {
174
169
  const firstItem = this.itemsEnabled.find((item) => item.value === values[0]);
175
- this.selectedKeys = firstItem ? [firstItem.key] : [];
170
+ this.setSelectedKeys(firstItem ? [firstItem.key] : []);
176
171
  }
177
172
  else if (this.isMultiple) {
178
- this.selectedKeys = this.itemsEnabled
173
+ this.setSelectedKeys(this.itemsEnabled
179
174
  .filter((item) => values.includes(item.value))
180
- .map((item) => item.key);
175
+ .map((item) => item.key));
181
176
  }
182
177
  this.updateSelected();
183
178
  this.updateFocusable();
@@ -200,8 +195,10 @@ export let Menu = class Menu extends LitElement {
200
195
  }
201
196
  firstUpdated(changedProperties) {
202
197
  super.firstUpdated(changedProperties);
203
- this.updateFocusable();
204
- this.lastActiveItem = this.items.find((item) => item.focusable);
198
+ this.definedController.whenDefined().then(() => {
199
+ this.updateFocusable();
200
+ this.lastActiveItem = this.items.find((item) => item.focusable);
201
+ });
205
202
  // 子菜单打开时,把焦点放到新的子菜单上
206
203
  this.addEventListener('submenu-open', (e) => {
207
204
  const $parentItem = $(e.target);
@@ -231,6 +228,19 @@ export let Menu = class Menu extends LitElement {
231
228
  render() {
232
229
  return html `<slot @slotchange="${this.onSlotChange}" @click="${this.onClick}" @keydown="${this.onKeyDown}"></slot>`;
233
230
  }
231
+ setSelectedKeys(selectedKeys) {
232
+ if (!arraysEqualIgnoreOrder(this.selectedKeys, selectedKeys)) {
233
+ this.selectedKeys = selectedKeys;
234
+ }
235
+ }
236
+ setValue(value) {
237
+ if (this.isSingle || isUndefined(this.value) || isUndefined(value)) {
238
+ this.value = value;
239
+ }
240
+ else if (!arraysEqualIgnoreOrder(this.value, value)) {
241
+ this.value = value;
242
+ }
243
+ }
234
244
  // 获取和指定菜单项同级的所有菜单项
235
245
  getSiblingsItems(item, onlyEnabled = false) {
236
246
  return $(item)
@@ -242,23 +252,29 @@ export let Menu = class Menu extends LitElement {
242
252
  updateFocusable() {
243
253
  // 焦点优先放在之前焦点所在的元素上
244
254
  if (this.lastActiveItem) {
245
- this.items.forEach((item) => (item.focusable = item.key === this.lastActiveItem.key));
255
+ this.items.forEach((item) => {
256
+ item.focusable = item.key === this.lastActiveItem.key;
257
+ });
246
258
  return;
247
259
  }
248
260
  // 没有选中任何一项,焦点放在第一个 menu-item 上
249
261
  if (!this.selectedKeys.length) {
250
- this.itemsEnabled.forEach((item, index) => (item.focusable = !index));
262
+ this.itemsEnabled.forEach((item, index) => {
263
+ item.focusable = !index;
264
+ });
251
265
  return;
252
266
  }
253
267
  // 如果是单选,焦点放在当前选中的元素上
254
268
  if (this.isSingle) {
255
- this.items.forEach((item) => (item.focusable = this.selectedKeys.includes(item.key)));
269
+ this.items.forEach((item) => {
270
+ item.focusable = this.selectedKeys.includes(item.key);
271
+ });
256
272
  return;
257
273
  }
258
274
  // 是多选,且原焦点不在 selectedKeys 上,焦点放在第一个选中的 menu-item 上
259
275
  if (this.isMultiple) {
260
276
  const focusableItem = this.items.find((item) => item.focusable);
261
- if (!(focusableItem === null || focusableItem === void 0 ? void 0 : focusableItem.key) ||
277
+ if (!focusableItem?.key ||
262
278
  !this.selectedKeys.includes(focusableItem.key)) {
263
279
  this.itemsEnabled
264
280
  .filter((item) => this.selectedKeys.includes(item.key))
@@ -268,7 +284,9 @@ export let Menu = class Menu extends LitElement {
268
284
  }
269
285
  updateSelected() {
270
286
  // 选中 menu-item
271
- this.items.forEach((item) => (item.selected = this.selectedKeys.includes(item.key)));
287
+ this.items.forEach((item) => {
288
+ item.selected = this.selectedKeys.includes(item.key);
289
+ });
272
290
  }
273
291
  // 切换一个菜单项的选中状态
274
292
  selectOne(item) {
@@ -281,28 +299,32 @@ export let Menu = class Menu extends LitElement {
281
299
  else {
282
300
  selectedKeys.push(item.key);
283
301
  }
284
- this.selectedKeys = selectedKeys;
302
+ this.setSelectedKeys(selectedKeys);
285
303
  }
286
304
  if (this.isSingle) {
287
305
  if (this.selectedKeys.includes(item.key)) {
288
- this.selectedKeys = [];
306
+ this.setSelectedKeys([]);
289
307
  }
290
308
  else {
291
- this.selectedKeys = [item.key];
309
+ this.setSelectedKeys([item.key]);
292
310
  }
293
311
  }
312
+ this.isInitial = false;
294
313
  this.updateSelected();
295
314
  }
296
315
  // 使一个 menu-item 可聚焦
297
- focusableOne(item) {
316
+ async focusableOne(item) {
298
317
  this.items.forEach((_item) => (_item.focusable = _item.key === item.key));
318
+ await delay(); // 等待 focusableMixin 更新完成
299
319
  }
300
320
  // 聚焦一个 menu-item
301
- async focusOne(item, options) {
302
- await delay(); // 等待 focusableMixin 更新完成
321
+ focusOne(item, options) {
303
322
  item.focus(options);
304
323
  }
305
- onClick(event) {
324
+ async onClick(event) {
325
+ if (!this.definedController.isDefined()) {
326
+ return;
327
+ }
306
328
  if (this.isSubmenu) {
307
329
  return;
308
330
  }
@@ -312,17 +334,20 @@ export let Menu = class Menu extends LitElement {
312
334
  }
313
335
  const target = event.target;
314
336
  const item = target.closest('mdui-menu-item');
315
- if (item === null || item === void 0 ? void 0 : item.disabled) {
337
+ if (!item || item.disabled) {
316
338
  return;
317
339
  }
318
340
  this.lastActiveItem = item;
319
341
  if (this.isSelectable && item.value) {
320
342
  this.selectOne(item);
321
343
  }
322
- this.focusableOne(item);
344
+ await this.focusableOne(item);
323
345
  this.focusOne(item);
324
346
  }
325
- onKeyDown(event) {
347
+ async onKeyDown(event) {
348
+ if (!this.definedController.isDefined()) {
349
+ return;
350
+ }
326
351
  if (this.isSubmenu) {
327
352
  return;
328
353
  }
@@ -337,7 +362,7 @@ export let Menu = class Menu extends LitElement {
337
362
  event.preventDefault();
338
363
  if (this.isSelectable && item.value) {
339
364
  this.selectOne(item);
340
- this.focusableOne(item);
365
+ await this.focusableOne(item);
341
366
  this.focusOne(item);
342
367
  }
343
368
  }
@@ -367,7 +392,7 @@ export let Menu = class Menu extends LitElement {
367
392
  index = 0;
368
393
  }
369
394
  this.lastActiveItem = items[index];
370
- this.focusableOne(items[index]);
395
+ await this.focusableOne(items[index]);
371
396
  this.focusOne(items[index]);
372
397
  return;
373
398
  }
@@ -412,7 +437,7 @@ __decorate([
412
437
  watch('submenuCloseDelay')
413
438
  ], Menu.prototype, "onSlotChange", null);
414
439
  __decorate([
415
- watch('selects')
440
+ watch('selects', true)
416
441
  ], Menu.prototype, "onSelectsChange", null);
417
442
  __decorate([
418
443
  watch('selectedKeys', true)
@@ -423,3 +448,4 @@ __decorate([
423
448
  Menu = __decorate([
424
449
  customElement('mdui-menu')
425
450
  ], Menu);
451
+ export { Menu };
@@ -1,2 +1,2 @@
1
1
  import { css } from 'lit';
2
- export const navigationBarItemStyle = css `:host{--shape-corner-indicator:var(--mdui-shape-corner-full);position:relative;z-index:0;flex:1;overflow:hidden;min-width:3rem;--mdui-comp-ripple-state-layer-color:var(--mdui-color-on-surface-variant)}.container{display:flex;flex-direction:column;align-items:center;justify-content:center;height:100%;text-decoration:none;cursor:pointer;-webkit-user-select:none;user-select:none;-webkit-tap-highlight-color:transparent;transition:padding var(--mdui-motion-duration-short4) var(--mdui-motion-easing-standard);padding-top:.75rem;padding-bottom:.75rem}mdui-ripple{z-index:1;left:50%;transform:translateX(-50%);transition:margin-top var(--mdui-motion-duration-short4) var(--mdui-motion-easing-standard);width:4rem;height:2rem;margin-top:.75rem;border-radius:var(--mdui-shape-corner-full)}.indicator{position:relative;display:flex;align-items:center;justify-content:center;background-color:transparent;border-radius:var(--shape-corner-indicator);transition:background-color var(--mdui-motion-duration-short1) var(--mdui-motion-easing-standard),width var(--mdui-motion-duration-short4) var(--mdui-motion-easing-standard);height:2rem;width:2rem}::slotted([slot=badge]){position:absolute;transform:translate(50%,-50%)}::slotted([slot=badge][variant=small]){transform:translate(.5625rem,-.5625rem)}.active-icon,.icon{color:rgb(var(--mdui-color-on-surface-variant));font-size:1.5rem}.active-icon mdui-icon,.icon mdui-icon,::slotted([slot=active]),::slotted([slot=icon]){font-size:inherit}.icon{display:flex}.active-icon{display:none}.label{display:flex;align-items:center;transition:opacity var(--mdui-motion-duration-short4) var(--mdui-motion-easing-linear);height:1rem;color:rgb(var(--mdui-color-on-surface-variant));margin-top:.25rem;margin-bottom:.25rem;font-size:var(--mdui-typescale-label-medium-size);font-weight:var(--mdui-typescale-label-medium-weight);letter-spacing:var(--mdui-typescale-label-medium-tracking);line-height:var(--mdui-typescale-label-medium-line-height)}:host([label-visibility=selected]:not([active])) mdui-ripple,:host([label-visibility=unlabeled]) mdui-ripple{margin-top:1.5rem}:host([label-visibility=selected]:not([active])) .container,:host([label-visibility=unlabeled]) .container{padding-top:1.5rem;padding-bottom:0}:host([label-visibility=selected]:not([active])) .label,:host([label-visibility=unlabeled]) .label{opacity:0}:host([active]){--mdui-comp-ripple-state-layer-color:var(--mdui-color-on-surface)}:host([active]) .indicator{width:4rem;background-color:rgb(var(--mdui-color-secondary-container))}:host([active]) .active-icon,:host([active]) .icon{color:rgb(var(--mdui-color-on-secondary-container))}:host([active]) .has-active-icon .active-icon{display:flex}:host([active]) .has-active-icon .icon{display:none}:host([active]) .label{color:rgb(var(--mdui-color-on-surface))}`;
2
+ export const navigationBarItemStyle = css `:host{--shape-corner-indicator:var(--mdui-shape-corner-full);position:relative;z-index:0;flex:1;overflow:hidden;min-width:3rem;--mdui-comp-ripple-state-layer-color:var(--mdui-color-on-surface-variant)}.container{display:flex;flex-direction:column;align-items:center;justify-content:center;height:100%;text-decoration:none;cursor:pointer;-webkit-user-select:none;user-select:none;-webkit-tap-highlight-color:transparent;padding-top:.75rem;padding-bottom:.75rem}.container:not(.initial){transition:padding var(--mdui-motion-duration-short4) var(--mdui-motion-easing-standard)}mdui-ripple{z-index:1;left:50%;transform:translateX(-50%);width:4rem;height:2rem;margin-top:.75rem;border-radius:var(--mdui-shape-corner-full)}mdui-ripple:not(.initial){transition:margin-top var(--mdui-motion-duration-short4) var(--mdui-motion-easing-standard)}.indicator{position:relative;display:flex;align-items:center;justify-content:center;background-color:transparent;border-radius:var(--shape-corner-indicator);height:2rem;width:2rem}:not(.initial) .indicator{transition:background-color var(--mdui-motion-duration-short1) var(--mdui-motion-easing-standard),width var(--mdui-motion-duration-short4) var(--mdui-motion-easing-standard)}::slotted([slot=badge]){position:absolute;transform:translate(50%,-50%)}::slotted([slot=badge][variant=small]){transform:translate(.5625rem,-.5625rem)}.active-icon,.icon{color:rgb(var(--mdui-color-on-surface-variant));font-size:1.5rem}.active-icon mdui-icon,.icon mdui-icon,::slotted([slot=active]),::slotted([slot=icon]){font-size:inherit}.icon{display:flex}.active-icon{display:none}.label{display:flex;align-items:center;height:1rem;color:rgb(var(--mdui-color-on-surface-variant));margin-top:.25rem;margin-bottom:.25rem;font-size:var(--mdui-typescale-label-medium-size);font-weight:var(--mdui-typescale-label-medium-weight);letter-spacing:var(--mdui-typescale-label-medium-tracking);line-height:var(--mdui-typescale-label-medium-line-height)}:not(.initial) .label{transition:opacity var(--mdui-motion-duration-short4) var(--mdui-motion-easing-linear)}:host(:not([active])) mdui-ripple.label-visibility-selected,mdui-ripple.label-visibility-unlabeled{margin-top:1.5rem}.container.label-visibility-unlabeled,:host(:not([active])) .container.label-visibility-selected{padding-top:1.5rem;padding-bottom:0}.container.label-visibility-unlabeled .label,:host(:not([active])) .container.label-visibility-selected .label{opacity:0}:host([active]){--mdui-comp-ripple-state-layer-color:var(--mdui-color-on-surface)}:host([active]) .indicator{width:4rem;background-color:rgb(var(--mdui-color-secondary-container))}:host([active]) .active-icon,:host([active]) .icon{color:rgb(var(--mdui-color-on-secondary-container))}:host([active]) .has-active-icon .active-icon{display:flex}:host([active]) .has-active-icon .icon{display:none}:host([active]) .label{color:rgb(var(--mdui-color-on-surface))}`;
@@ -1,8 +1,8 @@
1
- import { LitElement } from 'lit';
1
+ import { MduiElement } from '@mdui/shared/base/mdui-element.js';
2
2
  import '../icon.js';
3
3
  import type { Ripple } from '../ripple/index.js';
4
4
  import type { CSSResultGroup, TemplateResult } from 'lit';
5
- declare const NavigationBarItem_base: import("@open-wc/dedupe-mixin").Constructor<import("@mdui/shared/mixins/anchor.js").AnchorMixinInterface> & 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
+ declare const NavigationBarItem_base: import("@open-wc/dedupe-mixin").Constructor<import("@mdui/shared/mixins/anchor.js").AnchorMixinInterface> & 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;
6
6
  /**
7
7
  * @summary 底部导航栏项组件。需与 `<mdui-navigation-bar>` 组件配合使用
8
8
  *
@@ -31,7 +31,7 @@ declare const NavigationBarItem_base: import("@open-wc/dedupe-mixin").Constructo
31
31
  *
32
32
  * @cssprop --shape-corner-indicator - 指示器的圆角大小。可以指定一个具体的像素值;但更推荐[引用设计令牌](/docs/2/styles/design-tokens#shape-corner)
33
33
  */
34
- export declare class NavigationBarItem extends NavigationBarItem_base {
34
+ export declare class NavigationBarItem extends NavigationBarItem_base<NavigationBarItemEventMap> {
35
35
  static styles: CSSResultGroup;
36
36
  /**
37
37
  * 未激活状态的 Material Icons 图标名。也可以通过 `slot="icon"` 设置
@@ -46,11 +46,15 @@ export declare class NavigationBarItem extends NavigationBarItem_base {
46
46
  */
47
47
  value?: string;
48
48
  /**
49
- * 文本的可视状态,由 `navigation-bar` 调用
49
+ * 文本的可视状态,由 `<mdui-navigation-bar>` 组件控制该参数
50
50
  */
51
51
  protected labelVisibility?: 'selected' | 'labeled' | 'unlabeled';
52
52
  /**
53
- * 是否为激活状态,由 `navigation-bar` 组件控制该参数
53
+ * 是否是初始状态,不显示动画。由 `<mdui-navigation-bar>` 组件控制该参数
54
+ */
55
+ protected isInitial: boolean;
56
+ /**
57
+ * 是否为激活状态,由 `<mdui-navigation-bar>` 组件控制该参数
54
58
  */
55
59
  protected active: boolean;
56
60
  private disabled;
@@ -64,6 +68,10 @@ export declare class NavigationBarItem extends NavigationBarItem_base {
64
68
  protected render(): TemplateResult;
65
69
  private renderInner;
66
70
  }
71
+ export interface NavigationBarItemEventMap {
72
+ focus: FocusEvent;
73
+ blur: FocusEvent;
74
+ }
67
75
  declare global {
68
76
  interface HTMLElementTagNameMap {
69
77
  'mdui-navigation-bar-item': NavigationBarItem;
@@ -1,8 +1,9 @@
1
1
  import { __decorate } from "tslib";
2
- import { html, LitElement } from 'lit';
2
+ import { html } from 'lit';
3
3
  import { customElement, property, state } from 'lit/decorators.js';
4
4
  import { createRef, ref } from 'lit/directives/ref.js';
5
5
  import cc from 'classcat';
6
+ import { MduiElement } from '@mdui/shared/base/mdui-element.js';
6
7
  import { HasSlotController } from '@mdui/shared/controllers/has-slot.js';
7
8
  import { booleanConverter } from '@mdui/shared/helpers/decorator.js';
8
9
  import { nothingTemplate } from '@mdui/shared/helpers/template.js';
@@ -41,16 +42,20 @@ import { navigationBarItemStyle } from './navigation-bar-item-style.js';
41
42
  *
42
43
  * @cssprop --shape-corner-indicator - 指示器的圆角大小。可以指定一个具体的像素值;但更推荐[引用设计令牌](/docs/2/styles/design-tokens#shape-corner)
43
44
  */
44
- export let NavigationBarItem = class NavigationBarItem extends AnchorMixin(RippleMixin(FocusableMixin(LitElement))) {
45
+ let NavigationBarItem = class NavigationBarItem extends AnchorMixin(RippleMixin(FocusableMixin(MduiElement))) {
45
46
  constructor() {
46
47
  super(...arguments);
47
48
  /**
48
- * 是否为激活状态,由 `navigation-bar` 组件控制该参数
49
+ * 是否是初始状态,不显示动画。由 `<mdui-navigation-bar>` 组件控制该参数
50
+ */
51
+ this.isInitial = true;
52
+ /**
53
+ * 是否为激活状态,由 `<mdui-navigation-bar>` 组件控制该参数
49
54
  */
50
55
  this.active = false;
51
56
  // 是否禁用该元素,该组件没有禁用状态
52
57
  this.disabled = false;
53
- // 每一个 `navigation-bar-item` 元素都添加一个唯一的 key
58
+ // 每一个 `<navigation-bar-item>` 元素都添加一个唯一的 key
54
59
  this.key = uniqueId();
55
60
  this.rippleRef = createRef();
56
61
  this.hasSlotController = new HasSlotController(this, 'active-icon');
@@ -62,18 +67,26 @@ export let NavigationBarItem = class NavigationBarItem extends AnchorMixin(Rippl
62
67
  return this.disabled;
63
68
  }
64
69
  get focusElement() {
65
- var _a;
66
- return this.href ? (_a = this.renderRoot) === null || _a === void 0 ? void 0 : _a.querySelector('._a') : this;
70
+ return this.href ? this.renderRoot?.querySelector('._a') : this;
67
71
  }
68
72
  get focusDisabled() {
69
73
  return this.disabled;
70
74
  }
71
75
  render() {
72
- const className = cc({
73
- container: true,
74
- 'has-active-icon': this.activeIcon || this.hasSlotController.test('active-icon'),
76
+ const labelVisibilityClassName = cc({
77
+ 'label-visibility-selected': this.labelVisibility === 'selected',
78
+ 'label-visibility-labeled': this.labelVisibility === 'labeled',
79
+ 'label-visibility-unlabeled': this.labelVisibility === 'unlabeled',
80
+ initial: this.isInitial,
75
81
  });
76
- return html `<mdui-ripple .noRipple="${!this.active || this.noRipple}" ${ref(this.rippleRef)}></mdui-ripple>${this.href
82
+ const className = cc([
83
+ {
84
+ container: true,
85
+ 'has-active-icon': this.activeIcon || this.hasSlotController.test('active-icon'),
86
+ },
87
+ labelVisibilityClassName,
88
+ ]);
89
+ return html `<mdui-ripple .noRipple="${!this.active || this.noRipple}" class="${labelVisibilityClassName}" ${ref(this.rippleRef)}></mdui-ripple>${this.href
77
90
  ? this.renderAnchor({
78
91
  part: 'container',
79
92
  className,
@@ -103,8 +116,11 @@ __decorate([
103
116
  property({ reflect: true })
104
117
  ], NavigationBarItem.prototype, "value", void 0);
105
118
  __decorate([
106
- property({ reflect: true, attribute: 'label-visibility' })
119
+ state()
107
120
  ], NavigationBarItem.prototype, "labelVisibility", void 0);
121
+ __decorate([
122
+ state()
123
+ ], NavigationBarItem.prototype, "isInitial", void 0);
108
124
  __decorate([
109
125
  property({
110
126
  type: Boolean,
@@ -118,3 +134,4 @@ __decorate([
118
134
  NavigationBarItem = __decorate([
119
135
  customElement('mdui-navigation-bar-item')
120
136
  ], NavigationBarItem);
137
+ export { NavigationBarItem };
@@ -1,5 +1,4 @@
1
- import '@mdui/jq/methods/find.js';
2
- import '@mdui/jq/methods/get.js';
1
+ import { PropertyValues } from 'lit';
3
2
  import { LayoutItemBase } from '../layout/layout-item-base.js';
4
3
  import type { LayoutPlacement } from '../layout/helper.js';
5
4
  import type { ScrollPaddingPosition } from '@mdui/shared/mixins/scrollBehavior.js';
@@ -27,7 +26,7 @@ declare const NavigationBar_base: import("@open-wc/dedupe-mixin").Constructor<im
27
26
  * @cssprop --shape-corner - 组件的圆角大小。可以指定一个具体的像素值;但更推荐[引用设计令牌](/docs/2/styles/design-tokens#shape-corner)
28
27
  * @cssprop --z-index - 组件的 CSS 的 `z-index` 值
29
28
  */
30
- export declare class NavigationBar extends NavigationBar_base {
29
+ export declare class NavigationBar extends NavigationBar_base<NavigationBarEventMap> {
31
30
  static styles: CSSResultGroup;
32
31
  /**
33
32
  * 是否隐藏
@@ -52,14 +51,15 @@ export declare class NavigationBar extends NavigationBar_base {
52
51
  */
53
52
  scrollBehavior?: 'hide';
54
53
  private activeKey;
55
- private hasSetDefaultValue;
54
+ private readonly items;
55
+ private isInitial;
56
+ private definedController;
56
57
  protected get scrollPaddingPosition(): ScrollPaddingPosition;
57
58
  protected get layoutPlacement(): LayoutPlacement;
58
- private get items();
59
59
  private onActiveKeyChange;
60
60
  private onValueChange;
61
61
  private onLabelVisibilityChange;
62
- connectedCallback(): void;
62
+ protected firstUpdated(_changedProperties: PropertyValues): void;
63
63
  protected render(): TemplateResult;
64
64
  /**
65
65
  * 滚动行为
@@ -67,9 +67,16 @@ export declare class NavigationBar extends NavigationBar_base {
67
67
  */
68
68
  protected runScrollThreshold(isScrollingUp: boolean): void;
69
69
  private onClick;
70
- private updateActive;
70
+ private updateItems;
71
71
  private onSlotChange;
72
72
  }
73
+ export interface NavigationBarEventMap {
74
+ change: CustomEvent<void>;
75
+ show: CustomEvent<void>;
76
+ shown: CustomEvent<void>;
77
+ hide: CustomEvent<void>;
78
+ hidden: CustomEvent<void>;
79
+ }
73
80
  declare global {
74
81
  interface HTMLElementTagNameMap {
75
82
  'mdui-navigation-bar': NavigationBar;