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,12 +1,9 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { html } from 'lit';
3
- import { customElement, property, state } from 'lit/decorators.js';
4
- import { $ } from '@mdui/jq/$.js';
5
- import '@mdui/jq/methods/find.js';
6
- import '@mdui/jq/methods/get.js';
3
+ import { customElement, property, queryAssignedElements, state, } from 'lit/decorators.js';
4
+ import { DefinedController } from '@mdui/shared/controllers/defined.js';
7
5
  import { watch } from '@mdui/shared/decorators/watch.js';
8
6
  import { booleanConverter } from '@mdui/shared/helpers/decorator.js';
9
- import { emit } from '@mdui/shared/helpers/event.js';
10
7
  import { componentStyle } from '@mdui/shared/lit-styles/component-style.js';
11
8
  import { ScrollBehaviorMixin } from '@mdui/shared/mixins/scrollBehavior.js';
12
9
  import { LayoutItemBase } from '../layout/layout-item-base.js';
@@ -33,7 +30,7 @@ import { navigationBarStyle } from './navigation-bar-style.js';
33
30
  * @cssprop --shape-corner - 组件的圆角大小。可以指定一个具体的像素值;但更推荐[引用设计令牌](/docs/2/styles/design-tokens#shape-corner)
34
31
  * @cssprop --z-index - 组件的 CSS 的 `z-index` 值
35
32
  */
36
- export let NavigationBar = class NavigationBar extends ScrollBehaviorMixin(LayoutItemBase) {
33
+ let NavigationBar = class NavigationBar extends ScrollBehaviorMixin(LayoutItemBase) {
37
34
  constructor() {
38
35
  super(...arguments);
39
36
  /**
@@ -51,8 +48,11 @@ export let NavigationBar = class NavigationBar extends ScrollBehaviorMixin(Layou
51
48
  this.labelVisibility = 'auto';
52
49
  // 因为 navigation-bar-item 的 value 可能会重复,所以在每个 navigation-bar-item 元素上都添加了一个唯一的 key,通过 activeKey 来记录激活状态的 key
53
50
  this.activeKey = 0;
54
- // 是否已完成初始 value 的设置。首次设置初始值时,不触发 change 事件
55
- this.hasSetDefaultValue = false;
51
+ // 是否是初始状态,初始状态不触发 change 事件,没有动画
52
+ this.isInitial = true;
53
+ this.definedController = new DefinedController(this, {
54
+ relatedElements: ['mdui-navigation-bar-item'],
55
+ });
56
56
  }
57
57
  get scrollPaddingPosition() {
58
58
  return 'bottom';
@@ -60,46 +60,31 @@ export let NavigationBar = class NavigationBar extends ScrollBehaviorMixin(Layou
60
60
  get layoutPlacement() {
61
61
  return 'bottom';
62
62
  }
63
- // 所有的子项元素
64
- get items() {
65
- return $(this)
66
- .find('mdui-navigation-bar-item')
67
- .get();
68
- }
69
- onActiveKeyChange() {
63
+ async onActiveKeyChange() {
64
+ await this.definedController.whenDefined();
70
65
  // 根据 activeKey 读取对应 navigation-bar-item 的值
71
66
  const item = this.items.find((item) => item.key === this.activeKey);
72
- this.value = item === null || item === void 0 ? void 0 : item.value;
73
- if (this.hasSetDefaultValue) {
74
- emit(this, 'change');
75
- }
76
- else {
77
- this.hasSetDefaultValue = true;
67
+ this.value = item?.value;
68
+ if (!this.isInitial) {
69
+ this.emit('change');
78
70
  }
79
71
  }
80
- onValueChange() {
81
- var _a;
72
+ async onValueChange() {
73
+ this.isInitial = !this.hasUpdated;
74
+ await this.definedController.whenDefined();
82
75
  const item = this.items.find((item) => item.value === this.value);
83
- this.activeKey = (_a = item === null || item === void 0 ? void 0 : item.key) !== null && _a !== void 0 ? _a : 0;
84
- this.updateActive();
76
+ this.activeKey = item?.key ?? 0;
77
+ this.updateItems();
85
78
  }
86
- onLabelVisibilityChange() {
87
- const items = this.items;
88
- // 为 navigation-bar-item 设置 labelVisibility 属性
89
- const labelVisibility = this.labelVisibility === 'auto'
90
- ? items.length <= 3
91
- ? 'labeled'
92
- : 'selected'
93
- : this.labelVisibility;
94
- items.forEach((item) => {
95
- item.labelVisibility = labelVisibility;
96
- });
79
+ async onLabelVisibilityChange() {
80
+ await this.definedController.whenDefined();
81
+ this.updateItems();
97
82
  }
98
- connectedCallback() {
99
- super.connectedCallback();
83
+ firstUpdated(_changedProperties) {
84
+ super.firstUpdated(_changedProperties);
100
85
  this.addEventListener('transitionend', (event) => {
101
86
  if (event.target === this) {
102
- emit(this, this.hide ? 'hidden' : 'shown');
87
+ this.emit(this.hide ? 'hidden' : 'shown');
103
88
  }
104
89
  });
105
90
  }
@@ -113,15 +98,15 @@ export let NavigationBar = class NavigationBar extends ScrollBehaviorMixin(Layou
113
98
  runScrollThreshold(isScrollingUp) {
114
99
  // 向下滚动
115
100
  if (!isScrollingUp && !this.hide) {
116
- const requestHide = emit(this, 'hide');
117
- if (!requestHide.defaultPrevented) {
101
+ const eventProceeded = this.emit('hide', { cancelable: true });
102
+ if (eventProceeded) {
118
103
  this.hide = true;
119
104
  }
120
105
  }
121
106
  // 向上滚动
122
107
  if (isScrollingUp && this.hide) {
123
- const requestShow = emit(this, 'show');
124
- if (!requestShow.defaultPrevented) {
108
+ const eventProceeded = this.emit('show', { cancelable: true });
109
+ if (eventProceeded) {
125
110
  this.hide = false;
126
111
  }
127
112
  }
@@ -133,14 +118,31 @@ export let NavigationBar = class NavigationBar extends ScrollBehaviorMixin(Layou
133
118
  }
134
119
  const target = event.target;
135
120
  const item = target.closest('mdui-navigation-bar-item');
121
+ if (!item) {
122
+ return;
123
+ }
136
124
  this.activeKey = item.key;
137
- this.updateActive();
125
+ this.isInitial = false;
126
+ this.updateItems();
138
127
  }
139
- updateActive() {
140
- this.items.forEach((item) => (item.active = this.activeKey === item.key));
128
+ // 更新 <mdui-navigation-bar-item> 的状态
129
+ updateItems() {
130
+ const items = this.items;
131
+ // <mdui-navigation-bar-item> 的 labelVisibility 不含 auto
132
+ const labelVisibility = this.labelVisibility === 'auto'
133
+ ? items.length <= 3
134
+ ? 'labeled'
135
+ : 'selected'
136
+ : this.labelVisibility;
137
+ items.forEach((item) => {
138
+ item.active = this.activeKey === item.key;
139
+ item.labelVisibility = labelVisibility;
140
+ item.isInitial = this.isInitial;
141
+ });
141
142
  }
142
- onSlotChange() {
143
- this.onLabelVisibilityChange();
143
+ async onSlotChange() {
144
+ await this.definedController.whenDefined();
145
+ this.updateItems();
144
146
  }
145
147
  };
146
148
  NavigationBar.styles = [
@@ -167,7 +169,13 @@ __decorate([
167
169
  state()
168
170
  ], NavigationBar.prototype, "activeKey", void 0);
169
171
  __decorate([
170
- watch('activeKey')
172
+ queryAssignedElements({
173
+ selector: 'mdui-navigation-bar-item',
174
+ flatten: true,
175
+ })
176
+ ], NavigationBar.prototype, "items", void 0);
177
+ __decorate([
178
+ watch('activeKey', true)
171
179
  ], NavigationBar.prototype, "onActiveKeyChange", null);
172
180
  __decorate([
173
181
  watch('value')
@@ -178,3 +186,4 @@ __decorate([
178
186
  NavigationBar = __decorate([
179
187
  customElement('mdui-navigation-bar')
180
188
  ], NavigationBar);
189
+ export { NavigationBar };
@@ -2,7 +2,7 @@ import '@mdui/jq/methods/css.js';
2
2
  import '@mdui/jq/methods/innerWidth.js';
3
3
  import { LayoutItemBase } from '../layout/layout-item-base.js';
4
4
  import type { LayoutPlacement } from '../layout/helper.js';
5
- import type { CSSResultGroup, TemplateResult } from 'lit';
5
+ import type { CSSResultGroup, PropertyValues, TemplateResult } from 'lit';
6
6
  /**
7
7
  * 在手机端,`modal` 始终为 `true`;大于手机端时,`modal` 属性才开始生效
8
8
  *
@@ -26,7 +26,7 @@ import type { CSSResultGroup, TemplateResult } from 'lit';
26
26
  * @cssprop --shape-corner - 组件的圆角大小。可以指定一个具体的像素值;但更推荐[引用设计令牌](/docs/2/styles/design-tokens#shape-corner)
27
27
  * @cssprop --z-index - 组件的 CSS 的 `z-index` 值
28
28
  */
29
- export declare class NavigationDrawer extends LayoutItemBase {
29
+ export declare class NavigationDrawer extends LayoutItemBase<NavigationDrawerEventMap> {
30
30
  static styles: CSSResultGroup;
31
31
  /**
32
32
  * 是否打开抽屉导航
@@ -66,16 +66,27 @@ export declare class NavigationDrawer extends LayoutItemBase {
66
66
  private modalHelper;
67
67
  private readonly overlayRef;
68
68
  private readonly panelRef;
69
+ private readonly definedController;
69
70
  protected get layoutPlacement(): LayoutPlacement;
70
71
  private get lockTarget();
71
72
  private get isModal();
72
73
  private onContainedChange;
73
74
  private onPlacementChange;
75
+ private onMobileChange;
74
76
  private onOpenChange;
75
77
  connectedCallback(): void;
76
78
  disconnectedCallback(): void;
79
+ protected firstUpdated(_changedProperties: PropertyValues): void;
77
80
  protected render(): TemplateResult;
78
81
  private onOverlayClick;
82
+ private getLockTargetAnimate;
83
+ }
84
+ export interface NavigationDrawerEventMap {
85
+ open: CustomEvent<void>;
86
+ opened: CustomEvent<void>;
87
+ close: CustomEvent<void>;
88
+ closed: CustomEvent<void>;
89
+ 'overlay-click': CustomEvent<void>;
79
90
  }
80
91
  declare global {
81
92
  interface HTMLElementTagNameMap {
@@ -6,12 +6,12 @@ import { when } from 'lit/directives/when.js';
6
6
  import { $ } from '@mdui/jq/$.js';
7
7
  import '@mdui/jq/methods/css.js';
8
8
  import '@mdui/jq/methods/innerWidth.js';
9
- import { isNull } from '@mdui/jq/shared/helper.js';
9
+ import { isFunction, isNull } from '@mdui/jq/shared/helper.js';
10
+ import { DefinedController } from '@mdui/shared/controllers/defined.js';
10
11
  import { watch } from '@mdui/shared/decorators/watch.js';
11
12
  import { animateTo, stopAnimations } from '@mdui/shared/helpers/animate.js';
12
13
  import { breakpoint } from '@mdui/shared/helpers/breakpoint.js';
13
14
  import { booleanConverter } from '@mdui/shared/helpers/decorator.js';
14
- import { emit } from '@mdui/shared/helpers/event.js';
15
15
  import { Modal } from '@mdui/shared/helpers/modal.js';
16
16
  import { getDuration, getEasing } from '@mdui/shared/helpers/motion.js';
17
17
  import { observeResize } from '@mdui/shared/helpers/observeResize.js';
@@ -42,7 +42,7 @@ import { style } from './style.js';
42
42
  * @cssprop --shape-corner - 组件的圆角大小。可以指定一个具体的像素值;但更推荐[引用设计令牌](/docs/2/styles/design-tokens#shape-corner)
43
43
  * @cssprop --z-index - 组件的 CSS 的 `z-index` 值
44
44
  */
45
- export let NavigationDrawer = class NavigationDrawer extends LayoutItemBase {
45
+ let NavigationDrawer = class NavigationDrawer extends LayoutItemBase {
46
46
  constructor() {
47
47
  super(...arguments);
48
48
  /**
@@ -81,6 +81,9 @@ export let NavigationDrawer = class NavigationDrawer extends LayoutItemBase {
81
81
  this.mobile = false;
82
82
  this.overlayRef = createRef();
83
83
  this.panelRef = createRef();
84
+ this.definedController = new DefinedController(this, {
85
+ needDomReady: true,
86
+ });
84
87
  }
85
88
  get layoutPlacement() {
86
89
  return this.placement;
@@ -94,11 +97,9 @@ export let NavigationDrawer = class NavigationDrawer extends LayoutItemBase {
94
97
  return this.mobile || this.modal;
95
98
  }
96
99
  // contained 变更后,修改监听尺寸变化的元素。为 true 时,监听父元素;为 false 时,监听 body
97
- onContainedChange() {
98
- var _a;
99
- if (this.hasUpdated) {
100
- (_a = this.observeResize) === null || _a === void 0 ? void 0 : _a.unobserve();
101
- }
100
+ async onContainedChange() {
101
+ await this.definedController.whenDefined();
102
+ this.observeResize?.unobserve();
102
103
  this.observeResize = observeResize(this.contained ? this.parentElement : document.body, () => {
103
104
  const target = this.contained ? this.parentElement : undefined;
104
105
  this.mobile = breakpoint(target).down('md');
@@ -115,11 +116,24 @@ export let NavigationDrawer = class NavigationDrawer extends LayoutItemBase {
115
116
  this.layoutManager.updateLayout(this);
116
117
  }
117
118
  }
119
+ async onMobileChange() {
120
+ if (!this.open || this.isParentLayout || this.contained) {
121
+ return;
122
+ }
123
+ await this.definedController.whenDefined();
124
+ if (this.isModal) {
125
+ lockScreen(this, this.lockTarget);
126
+ await this.getLockTargetAnimate(false, 0);
127
+ }
128
+ else {
129
+ unlockScreen(this, this.lockTarget);
130
+ await this.getLockTargetAnimate(true, 0);
131
+ }
132
+ }
118
133
  async onOpenChange() {
119
134
  let panel = this.panelRef.value;
120
135
  let overlay = this.overlayRef.value;
121
136
  const isRight = this.placement === 'right';
122
- const paddingPropName = isRight ? 'paddingRight' : 'paddingLeft';
123
137
  const easingLinear = getEasing(this, 'linear');
124
138
  const easingEmphasized = getEasing(this, 'emphasized');
125
139
  // 在当前 drawer 位于 layout 中时,设置所有 layout-item 和 layout-main 元素的 transition 样式
@@ -147,16 +161,19 @@ export let NavigationDrawer = class NavigationDrawer extends LayoutItemBase {
147
161
  overlay = this.overlayRef.value;
148
162
  }
149
163
  if (hasUpdated) {
150
- const requestOpen = emit(this, 'open', { cancelable: true });
151
- if (requestOpen.defaultPrevented) {
164
+ const eventProceeded = this.emit('open', { cancelable: true });
165
+ if (!eventProceeded) {
152
166
  return;
153
167
  }
154
168
  }
169
+ await this.definedController.whenDefined();
155
170
  this.style.display = 'block';
156
171
  this.originalTrigger = document.activeElement;
157
172
  if (this.isModal) {
158
173
  this.modalHelper.activate();
159
- lockScreen(this, this.lockTarget);
174
+ if (!this.contained) {
175
+ lockScreen(this, this.lockTarget);
176
+ }
160
177
  }
161
178
  await stopOldAnimations();
162
179
  // 设置聚焦
@@ -180,14 +197,7 @@ export let NavigationDrawer = class NavigationDrawer extends LayoutItemBase {
180
197
  }
181
198
  // 不位于 layout 中,父元素 padding 变化的动画
182
199
  else if (!this.isParentLayout) {
183
- animations.push(animateTo(this.lockTarget, [
184
- { [paddingPropName]: 0 },
185
- { [paddingPropName]: $(panel).innerWidth() + 'px' },
186
- ], {
187
- duration: hasUpdated ? duration : 0,
188
- easing: easingEmphasized,
189
- fill: 'forwards',
190
- }));
200
+ animations.push(this.getLockTargetAnimate(true, hasUpdated ? duration : 0));
191
201
  }
192
202
  // 若位于 layout 中,则 layout-main 的 padding 变化需要有和 drawer 相同的动画
193
203
  // 但首次渲染不执行动画
@@ -208,16 +218,16 @@ export let NavigationDrawer = class NavigationDrawer extends LayoutItemBase {
208
218
  setLayoutTransition(null);
209
219
  }
210
220
  if (hasUpdated) {
211
- emit(this, 'opened');
221
+ this.emit('opened');
212
222
  }
213
- return;
214
223
  }
215
- // 关闭
216
- if (!this.open && this.hasUpdated) {
217
- const requestClose = emit(this, 'close', { cancelable: true });
218
- if (requestClose.defaultPrevented) {
224
+ else if (this.hasUpdated) {
225
+ // 关闭
226
+ const eventProceeded = this.emit('close', { cancelable: true });
227
+ if (!eventProceeded) {
219
228
  return;
220
229
  }
230
+ await this.definedController.whenDefined();
221
231
  if (this.isModal) {
222
232
  this.modalHelper.deactivate();
223
233
  }
@@ -233,14 +243,7 @@ export let NavigationDrawer = class NavigationDrawer extends LayoutItemBase {
233
243
  }
234
244
  // 不位于 layout 中,父元素 padding 变化的动画
235
245
  else if (!this.isParentLayout) {
236
- animations.push(animateTo(this.lockTarget, [
237
- { [paddingPropName]: $(panel).innerWidth() + 'px' },
238
- { [paddingPropName]: 0 },
239
- ], {
240
- duration,
241
- easing: easingEmphasized,
242
- fill: 'forwards',
243
- }));
246
+ animations.push(this.getLockTargetAnimate(false, duration));
244
247
  }
245
248
  // 若位于 layout 中,则 layout-main 的 padding 变化需要有和 drawer 相同的动画
246
249
  if (this.isParentLayout) {
@@ -260,21 +263,28 @@ export let NavigationDrawer = class NavigationDrawer extends LayoutItemBase {
260
263
  setLayoutTransition(null);
261
264
  }
262
265
  this.style.display = 'none';
263
- if (this.isModal) {
266
+ if (this.isModal && !this.contained) {
264
267
  unlockScreen(this, this.lockTarget);
265
268
  }
266
269
  // 抽屉导航关闭后,恢复焦点到原有的元素上
267
270
  const trigger = this.originalTrigger;
268
- if (typeof (trigger === null || trigger === void 0 ? void 0 : trigger.focus) === 'function') {
271
+ if (isFunction(trigger?.focus)) {
269
272
  setTimeout(() => trigger.focus());
270
273
  }
271
- emit(this, 'closed');
272
- return;
274
+ this.emit('closed');
273
275
  }
274
276
  }
275
277
  connectedCallback() {
276
278
  super.connectedCallback();
277
279
  this.modalHelper = new Modal(this);
280
+ }
281
+ disconnectedCallback() {
282
+ super.disconnectedCallback();
283
+ unlockScreen(this, this.lockTarget);
284
+ this.observeResize?.unobserve();
285
+ }
286
+ firstUpdated(_changedProperties) {
287
+ super.firstUpdated(_changedProperties);
278
288
  this.addEventListener('keydown', (event) => {
279
289
  if (this.open &&
280
290
  this.closeOnEsc &&
@@ -285,21 +295,26 @@ export let NavigationDrawer = class NavigationDrawer extends LayoutItemBase {
285
295
  }
286
296
  });
287
297
  }
288
- disconnectedCallback() {
289
- var _a;
290
- super.disconnectedCallback();
291
- unlockScreen(this, this.lockTarget);
292
- (_a = this.observeResize) === null || _a === void 0 ? void 0 : _a.unobserve();
293
- }
294
298
  render() {
295
299
  return html `${when(this.isModal, () => html `<div ${ref(this.overlayRef)} part="overlay" class="overlay" @click="${this.onOverlayClick}"></div>`)}<slot ${ref(this.panelRef)} part="panel" class="panel" tabindex="0"></slot>`;
296
300
  }
297
301
  onOverlayClick() {
298
- emit(this, 'overlay-click');
299
- if (!this.closeOnOverlayClick) {
300
- return;
302
+ this.emit('overlay-click');
303
+ if (this.closeOnOverlayClick) {
304
+ this.open = false;
301
305
  }
302
- this.open = false;
306
+ }
307
+ getLockTargetAnimate(open, duration) {
308
+ const paddingName = this.placement === 'right' ? 'paddingRight' : 'paddingLeft';
309
+ const panelWidth = $(this.panelRef.value).innerWidth() + 'px';
310
+ return animateTo(this.lockTarget, [
311
+ { [paddingName]: open ? 0 : panelWidth },
312
+ { [paddingName]: open ? panelWidth : 0 },
313
+ ], {
314
+ duration,
315
+ easing: getEasing(this, 'emphasized'),
316
+ fill: 'forwards',
317
+ });
303
318
  }
304
319
  };
305
320
  NavigationDrawer.styles = [componentStyle, style];
@@ -355,11 +370,16 @@ __decorate([
355
370
  watch('contained')
356
371
  ], NavigationDrawer.prototype, "onContainedChange", null);
357
372
  __decorate([
358
- watch('placement')
373
+ watch('placement', true)
359
374
  ], NavigationDrawer.prototype, "onPlacementChange", null);
375
+ __decorate([
376
+ watch('mobile', true),
377
+ watch('modal', true)
378
+ ], NavigationDrawer.prototype, "onMobileChange", null);
360
379
  __decorate([
361
380
  watch('open')
362
381
  ], NavigationDrawer.prototype, "onOpenChange", null);
363
382
  NavigationDrawer = __decorate([
364
383
  customElement('mdui-navigation-drawer')
365
384
  ], NavigationDrawer);
385
+ export { NavigationDrawer };
@@ -1,2 +1,2 @@
1
1
  import { css } from 'lit';
2
- export const style = css `:host{--shape-corner:var(--mdui-shape-corner-large);--z-index:2200;display:none;position:fixed;top:0;bottom:0;left:0;z-index:1;width:22.5rem}:host([placement=right]){left:initial;right:0}:host([mobile]),:host([modal]){top:0!important;right:0;bottom:0!important;width:initial;z-index:var(--z-index)}:host([placement=right][mobile]),:host([placement=right][modal]){left:0}:host([contained]){position:absolute}.overlay{position:absolute;inset:0;z-index:inherit;background-color:rgba(var(--mdui-color-scrim),.4)}.panel{display:block;position:absolute;top:0;bottom:0;left:0;width:100%;overflow:auto;z-index:inherit;background-color:rgb(var(--mdui-color-surface));box-shadow:var(--mdui-elevation-level0)}:host([mobile]) .panel,:host([modal]) .panel{border-radius:0 var(--shape-corner) var(--shape-corner) 0;width:22.5rem;background-color:rgb(var(--mdui-color-surface-container-low));box-shadow:var(--mdui-elevation-level1)}:host([placement=right]) .panel{left:initial;right:0}:host([placement=right][mobile]) .panel,:host([placement=right][modal]) .panel{border-radius:var(--shape-corner) 0 0 var(--shape-corner)}`;
2
+ export const style = css `:host{--shape-corner:var(--mdui-shape-corner-large);--z-index:2200;display:none;position:fixed;top:0;bottom:0;left:0;z-index:1;width:22.5rem}:host([placement=right]){left:initial;right:0}:host([mobile]),:host([modal]){top:0!important;right:0;bottom:0!important;width:initial;z-index:var(--z-index)}:host([placement=right][mobile]),:host([placement=right][modal]){left:0}:host([contained]){position:absolute}.overlay{position:absolute;inset:0;z-index:inherit;background-color:rgba(var(--mdui-color-scrim),.4)}.panel{display:block;position:absolute;top:0;bottom:0;left:0;width:100%;overflow:auto;z-index:inherit;background-color:rgb(var(--mdui-color-surface));box-shadow:var(--mdui-elevation-level0)}:host([mobile]) .panel,:host([modal]) .panel{border-radius:0 var(--shape-corner) var(--shape-corner) 0;max-width:80%;width:22.5rem;background-color:rgb(var(--mdui-color-surface-container-low));box-shadow:var(--mdui-elevation-level1)}:host([placement=right]) .panel{left:initial;right:0}:host([placement=right][mobile]) .panel,:host([placement=right][modal]) .panel{border-radius:var(--shape-corner) 0 0 var(--shape-corner)}`;
@@ -1,2 +1,2 @@
1
1
  import { css } from 'lit';
2
- export const navigationRailItemStyle = css `:host{--shape-corner-indicator:var(--mdui-shape-corner-full);position:relative;z-index:0;width:100%;--mdui-comp-ripple-state-layer-color:var(--mdui-color-on-surface-variant)}.container{display:flex;flex-direction:column;align-items:center;justify-content:center;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);height:3.5rem}mdui-ripple{z-index:1;width:3.5rem;height:2rem;border-radius:var(--mdui-shape-corner-full)}.container:not(.has-label)+mdui-ripple{height:3.5rem}.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 var(--mdui-motion-duration-short4) var(--mdui-motion-easing-standard);height:2rem;width:2rem}::slotted([slot=badge]){position:absolute;transform:translate(50%,-50%)}:host([placement=right]) ::slotted([slot=badge]){transform:translate(-50%,-50%)}::slotted([slot=badge][variant=small]){transform:translate(.5625rem,-.5625rem)}:host([placement=right]) ::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-icon]),::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([active]){--mdui-comp-ripple-state-layer-color:var(--mdui-color-on-surface)}:host([active]) .indicator{width:3.5rem;background-color:rgb(var(--mdui-color-secondary-container))}:host([active]) :not(.has-label) .indicator{height:3.5rem}: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 navigationRailItemStyle = css `:host{--shape-corner-indicator:var(--mdui-shape-corner-full);position:relative;z-index:0;width:100%;--mdui-comp-ripple-state-layer-color:var(--mdui-color-on-surface-variant)}.container{display:flex;flex-direction:column;align-items:center;justify-content:center;text-decoration:none;cursor:pointer;-webkit-user-select:none;user-select:none;-webkit-tap-highlight-color:transparent;height:3.5rem}.container:not(.initial){transition:padding var(--mdui-motion-duration-short4) var(--mdui-motion-easing-standard)}mdui-ripple{z-index:1;width:3.5rem;height:2rem;border-radius:var(--mdui-shape-corner-full)}.container:not(.has-label)+mdui-ripple{height:3.5rem}.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),height var(--mdui-motion-duration-short4) var(--mdui-motion-easing-standard)}::slotted([slot=badge]){position:absolute;transform:translate(50%,-50%)}.placement-right::slotted([slot=badge]){transform:translate(-50%,-50%)}::slotted([slot=badge][variant=small]){transform:translate(.5625rem,-.5625rem)}.placement-right::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-icon]),::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([active]){--mdui-comp-ripple-state-layer-color:var(--mdui-color-on-surface)}:host([active]) .indicator{width:3.5rem;background-color:rgb(var(--mdui-color-secondary-container))}:host([active]) :not(.has-label) .indicator{height:3.5rem}: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 NavigationRailItem_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 NavigationRailItem_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-rail>` 组件配合使用
8
8
  *
@@ -31,7 +31,7 @@ declare const NavigationRailItem_base: import("@open-wc/dedupe-mixin").Construct
31
31
  *
32
32
  * @cssprop --shape-corner-indicator - 指示器的圆角大小。可以指定一个具体的像素值;但更推荐[引用设计令牌](/docs/2/styles/design-tokens#shape-corner)
33
33
  */
34
- export declare class NavigationRailItem extends NavigationRailItem_base {
34
+ export declare class NavigationRailItem extends NavigationRailItem_base<NavigationRailItemEventMap> {
35
35
  static styles: CSSResultGroup;
36
36
  /**
37
37
  * 未激活状态的 Material Icons 图标名。也可以通过 `slot="icon"` 设置
@@ -46,11 +46,15 @@ export declare class NavigationRailItem extends NavigationRailItem_base {
46
46
  */
47
47
  value?: string;
48
48
  /**
49
- * 是否为激活状态,由 `navigation-rail` 组件控制该参数
49
+ * 是否为激活状态,由 `<mdui-navigation-rail>` 组件控制该参数
50
50
  */
51
51
  protected active: boolean;
52
52
  /**
53
- * 导航栏的位置,由 `navigation-rail` 组件控制该参数
53
+ * 是否是初始状态,不显示动画。由 `<mdui-navigation-rail>` 组件控制该参数
54
+ */
55
+ protected isInitial: boolean;
56
+ /**
57
+ * 导航栏的位置,由 `<mdui-navigation-rail>` 组件控制该参数
54
58
  */
55
59
  protected placement: 'left' | 'right';
56
60
  private disabled;
@@ -64,6 +68,10 @@ export declare class NavigationRailItem extends NavigationRailItem_base {
64
68
  protected render(): TemplateResult;
65
69
  private renderInner;
66
70
  }
71
+ export interface NavigationRailItemEventMap {
72
+ focus: FocusEvent;
73
+ blur: FocusEvent;
74
+ }
67
75
  declare global {
68
76
  interface HTMLElementTagNameMap {
69
77
  'mdui-navigation-rail-item': NavigationRailItem;
@@ -1,8 +1,10 @@
1
1
  import { __decorate } from "tslib";
2
- import { html, LitElement, nothing } from 'lit';
2
+ import { html, nothing } from 'lit';
3
3
  import { customElement, property, state } from 'lit/decorators.js';
4
+ import { classMap } from 'lit/directives/class-map.js';
4
5
  import { createRef, ref } from 'lit/directives/ref.js';
5
6
  import cc from 'classcat';
7
+ import { MduiElement } from '@mdui/shared/base/mdui-element.js';
6
8
  import { HasSlotController } from '@mdui/shared/controllers/has-slot.js';
7
9
  import { booleanConverter } from '@mdui/shared/helpers/decorator.js';
8
10
  import { nothingTemplate } from '@mdui/shared/helpers/template.js';
@@ -41,20 +43,24 @@ import { navigationRailItemStyle } from './navigation-rail-item-style.js';
41
43
  *
42
44
  * @cssprop --shape-corner-indicator - 指示器的圆角大小。可以指定一个具体的像素值;但更推荐[引用设计令牌](/docs/2/styles/design-tokens#shape-corner)
43
45
  */
44
- export let NavigationRailItem = class NavigationRailItem extends AnchorMixin(RippleMixin(FocusableMixin(LitElement))) {
46
+ let NavigationRailItem = class NavigationRailItem extends AnchorMixin(RippleMixin(FocusableMixin(MduiElement))) {
45
47
  constructor() {
46
48
  super(...arguments);
47
49
  /**
48
- * 是否为激活状态,由 `navigation-rail` 组件控制该参数
50
+ * 是否为激活状态,由 `<mdui-navigation-rail>` 组件控制该参数
49
51
  */
50
52
  this.active = false;
51
53
  /**
52
- * 导航栏的位置,由 `navigation-rail` 组件控制该参数
54
+ * 是否是初始状态,不显示动画。由 `<mdui-navigation-rail>` 组件控制该参数
55
+ */
56
+ this.isInitial = true;
57
+ /**
58
+ * 导航栏的位置,由 `<mdui-navigation-rail>` 组件控制该参数
53
59
  */
54
60
  this.placement = 'left';
55
61
  // 是否禁用该元素,该组件没有禁用状态
56
62
  this.disabled = false;
57
- // 每一个 `navigation-rail-item` 元素都添加一个唯一的 key
63
+ // 每一个 `<mdui-navigation-rail-item>` 元素都添加一个唯一的 key
58
64
  this.key = uniqueId();
59
65
  this.rippleRef = createRef();
60
66
  this.hasSlotController = new HasSlotController(this, '[default]', 'active-icon');
@@ -66,8 +72,7 @@ export let NavigationRailItem = class NavigationRailItem extends AnchorMixin(Rip
66
72
  return this.disabled;
67
73
  }
68
74
  get focusElement() {
69
- var _a;
70
- return this.href ? (_a = this.renderRoot) === null || _a === void 0 ? void 0 : _a.querySelector('._a') : this;
75
+ return this.href ? this.renderRoot?.querySelector('._a') : this;
71
76
  }
72
77
  get focusDisabled() {
73
78
  return this.disabled;
@@ -78,6 +83,7 @@ export let NavigationRailItem = class NavigationRailItem extends AnchorMixin(Rip
78
83
  container: true,
79
84
  'has-label': hasDefaultSlot,
80
85
  'has-active-icon': this.activeIcon || this.hasSlotController.test('active-icon'),
86
+ initial: this.isInitial,
81
87
  });
82
88
  return html `${this.href
83
89
  ? this.renderAnchor({
@@ -88,7 +94,10 @@ export let NavigationRailItem = class NavigationRailItem extends AnchorMixin(Rip
88
94
  : html `<div part="container" class="${className}">${this.renderInner(hasDefaultSlot)}</div>`}<mdui-ripple .noRipple="${!this.active || this.noRipple}" ${ref(this.rippleRef)}></mdui-ripple>`;
89
95
  }
90
96
  renderInner(hasDefaultSlot) {
91
- return html `<div part="indicator" class="indicator"><slot name="badge" part="badge" class="badge"></slot><slot name="active-icon" part="active-icon" class="active-icon">${this.activeIcon
97
+ return html `<div part="indicator" class="indicator"><slot name="badge" part="badge" class="${classMap({
98
+ badge: true,
99
+ 'placement-right': this.placement === 'right',
100
+ })}"></slot><slot name="active-icon" part="active-icon" class="active-icon">${this.activeIcon
92
101
  ? html `<mdui-icon name="${this.activeIcon}"></mdui-icon>`
93
102
  : nothingTemplate}</slot><slot name="icon" part="icon" class="icon">${this.icon
94
103
  ? html `<mdui-icon name="${this.icon}"></mdui-icon>`
@@ -118,7 +127,10 @@ __decorate([
118
127
  })
119
128
  ], NavigationRailItem.prototype, "active", void 0);
120
129
  __decorate([
121
- property({ reflect: true })
130
+ state()
131
+ ], NavigationRailItem.prototype, "isInitial", void 0);
132
+ __decorate([
133
+ state()
122
134
  ], NavigationRailItem.prototype, "placement", void 0);
123
135
  __decorate([
124
136
  state()
@@ -126,3 +138,4 @@ __decorate([
126
138
  NavigationRailItem = __decorate([
127
139
  customElement('mdui-navigation-rail-item')
128
140
  ], NavigationRailItem);
141
+ export { NavigationRailItem };