mdui 2.0.1 → 2.0.2
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.
- package/LICENSE +21 -21
- package/components/avatar/index.js +2 -1
- package/components/badge/index.js +2 -1
- package/components/bottom-app-bar/index.d.ts +2 -2
- package/components/bottom-app-bar/index.js +4 -3
- package/components/button/button-base.d.ts +2 -2
- package/components/button/button-base.js +15 -14
- package/components/button/index.js +2 -1
- package/components/button-icon/index.js +2 -1
- package/components/card/index.d.ts +1 -1
- package/components/card/index.js +5 -2
- package/components/checkbox/index.js +7 -10
- package/components/checkbox/style.js +1 -1
- package/components/chip/index.js +2 -1
- package/components/circular-progress/index.js +3 -3
- package/components/collapse/collapse-item-style.js +1 -1
- package/components/collapse/collapse-item.d.ts +2 -1
- package/components/collapse/collapse-item.js +23 -20
- package/components/collapse/collapse.d.ts +6 -6
- package/components/collapse/collapse.js +57 -34
- package/components/dialog/index.d.ts +3 -2
- package/components/dialog/index.js +27 -23
- package/components/divider/index.js +2 -1
- package/components/dropdown/index.d.ts +4 -5
- package/components/dropdown/index.js +56 -51
- package/components/fab/index.d.ts +1 -0
- package/components/fab/index.js +10 -5
- package/components/icon/index.js +2 -1
- package/components/layout/helper.d.ts +5 -6
- package/components/layout/helper.js +42 -48
- package/components/layout/layout-item-base.js +1 -2
- package/components/layout/layout-item.js +3 -3
- package/components/layout/layout-main.js +2 -1
- package/components/layout/layout.js +2 -1
- package/components/linear-progress/index.js +3 -3
- package/components/list/list-item.js +3 -2
- package/components/list/list-subheader.js +2 -1
- package/components/list/list.js +2 -1
- package/components/menu/menu-item.d.ts +1 -0
- package/components/menu/menu-item.js +45 -28
- package/components/menu/menu.d.ts +4 -1
- package/components/menu/menu.js +82 -56
- package/components/navigation-bar/navigation-bar-item-style.js +1 -1
- package/components/navigation-bar/navigation-bar-item.d.ts +6 -2
- package/components/navigation-bar/navigation-bar-item.js +26 -10
- package/components/navigation-bar/navigation-bar.d.ts +6 -6
- package/components/navigation-bar/navigation-bar.js +49 -42
- package/components/navigation-drawer/index.d.ts +5 -1
- package/components/navigation-drawer/index.js +62 -41
- package/components/navigation-rail/navigation-rail-item-style.js +1 -1
- package/components/navigation-rail/navigation-rail-item.d.ts +6 -2
- package/components/navigation-rail/navigation-rail-item.js +20 -8
- package/components/navigation-rail/navigation-rail.d.ts +4 -5
- package/components/navigation-rail/navigation-rail.js +51 -44
- package/components/radio/radio-group.d.ts +6 -4
- package/components/radio/radio-group.js +61 -48
- package/components/radio/radio-style.js +1 -1
- package/components/radio/radio.d.ts +3 -2
- package/components/radio/radio.js +24 -17
- package/components/range-slider/index.js +7 -9
- package/components/ripple/index.js +2 -1
- package/components/segmented-button/segmented-button-group.d.ts +6 -3
- package/components/segmented-button/segmented-button-group.js +84 -69
- package/components/segmented-button/segmented-button.d.ts +2 -2
- package/components/segmented-button/segmented-button.js +5 -4
- package/components/select/index.d.ts +2 -2
- package/components/select/index.js +26 -24
- package/components/slider/index.js +7 -9
- package/components/slider/slider-base-style.js +1 -1
- package/components/slider/slider-base.js +1 -5
- package/components/snackbar/index.js +2 -1
- package/components/switch/index.js +6 -9
- package/components/switch/style.js +1 -1
- package/components/tabs/tab-panel.js +2 -1
- package/components/tabs/tab-style.js +1 -1
- package/components/tabs/tab.js +10 -5
- package/components/tabs/tabs-style.js +1 -1
- package/components/tabs/tabs.d.ts +6 -5
- package/components/tabs/tabs.js +52 -38
- package/components/text-field/index.d.ts +2 -2
- package/components/text-field/index.js +32 -54
- package/components/text-field/style.js +1 -1
- package/components/tooltip/index.d.ts +5 -5
- package/components/tooltip/index.js +30 -25
- package/components/top-app-bar/top-app-bar-title-style.js +1 -1
- package/components/top-app-bar/top-app-bar-title.js +16 -12
- package/components/top-app-bar/top-app-bar.d.ts +2 -2
- package/components/top-app-bar/top-app-bar.js +6 -4
- package/custom-elements.json +3421 -3126
- package/functions/getTheme.js +3 -3
- package/functions/snackbar.js +1 -2
- package/functions/utils/colorScheme.js +2 -2
- package/html-data.zh-cn.json +438 -438
- package/mdui.esm.js +8 -8
- package/mdui.global.js +8 -8
- package/package.json +7 -7
- package/web-types.zh-cn.json +770 -770
|
@@ -6,7 +6,8 @@ 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';
|
|
@@ -42,7 +43,7 @@ import { style } from './style.js';
|
|
|
42
43
|
* @cssprop --shape-corner - 组件的圆角大小。可以指定一个具体的像素值;但更推荐[引用设计令牌](/docs/2/styles/design-tokens#shape-corner)
|
|
43
44
|
* @cssprop --z-index - 组件的 CSS 的 `z-index` 值
|
|
44
45
|
*/
|
|
45
|
-
|
|
46
|
+
let NavigationDrawer = class NavigationDrawer extends LayoutItemBase {
|
|
46
47
|
constructor() {
|
|
47
48
|
super(...arguments);
|
|
48
49
|
/**
|
|
@@ -81,6 +82,9 @@ export let NavigationDrawer = class NavigationDrawer extends LayoutItemBase {
|
|
|
81
82
|
this.mobile = false;
|
|
82
83
|
this.overlayRef = createRef();
|
|
83
84
|
this.panelRef = createRef();
|
|
85
|
+
this.definedController = new DefinedController(this, {
|
|
86
|
+
needDomReady: true,
|
|
87
|
+
});
|
|
84
88
|
}
|
|
85
89
|
get layoutPlacement() {
|
|
86
90
|
return this.placement;
|
|
@@ -94,11 +98,9 @@ export let NavigationDrawer = class NavigationDrawer extends LayoutItemBase {
|
|
|
94
98
|
return this.mobile || this.modal;
|
|
95
99
|
}
|
|
96
100
|
// contained 变更后,修改监听尺寸变化的元素。为 true 时,监听父元素;为 false 时,监听 body
|
|
97
|
-
onContainedChange() {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
(_a = this.observeResize) === null || _a === void 0 ? void 0 : _a.unobserve();
|
|
101
|
-
}
|
|
101
|
+
async onContainedChange() {
|
|
102
|
+
await this.definedController.whenDefined();
|
|
103
|
+
this.observeResize?.unobserve();
|
|
102
104
|
this.observeResize = observeResize(this.contained ? this.parentElement : document.body, () => {
|
|
103
105
|
const target = this.contained ? this.parentElement : undefined;
|
|
104
106
|
this.mobile = breakpoint(target).down('md');
|
|
@@ -115,11 +117,24 @@ export let NavigationDrawer = class NavigationDrawer extends LayoutItemBase {
|
|
|
115
117
|
this.layoutManager.updateLayout(this);
|
|
116
118
|
}
|
|
117
119
|
}
|
|
120
|
+
async onMobileChange() {
|
|
121
|
+
if (!this.open || this.isParentLayout || this.contained) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
await this.definedController.whenDefined();
|
|
125
|
+
if (this.isModal) {
|
|
126
|
+
lockScreen(this, this.lockTarget);
|
|
127
|
+
await this.getLockTargetAnimate(false, 0);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
unlockScreen(this, this.lockTarget);
|
|
131
|
+
await this.getLockTargetAnimate(true, 0);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
118
134
|
async onOpenChange() {
|
|
119
135
|
let panel = this.panelRef.value;
|
|
120
136
|
let overlay = this.overlayRef.value;
|
|
121
137
|
const isRight = this.placement === 'right';
|
|
122
|
-
const paddingPropName = isRight ? 'paddingRight' : 'paddingLeft';
|
|
123
138
|
const easingLinear = getEasing(this, 'linear');
|
|
124
139
|
const easingEmphasized = getEasing(this, 'emphasized');
|
|
125
140
|
// 在当前 drawer 位于 layout 中时,设置所有 layout-item 和 layout-main 元素的 transition 样式
|
|
@@ -152,11 +167,14 @@ export let NavigationDrawer = class NavigationDrawer extends LayoutItemBase {
|
|
|
152
167
|
return;
|
|
153
168
|
}
|
|
154
169
|
}
|
|
170
|
+
await this.definedController.whenDefined();
|
|
155
171
|
this.style.display = 'block';
|
|
156
172
|
this.originalTrigger = document.activeElement;
|
|
157
173
|
if (this.isModal) {
|
|
158
174
|
this.modalHelper.activate();
|
|
159
|
-
|
|
175
|
+
if (!this.contained) {
|
|
176
|
+
lockScreen(this, this.lockTarget);
|
|
177
|
+
}
|
|
160
178
|
}
|
|
161
179
|
await stopOldAnimations();
|
|
162
180
|
// 设置聚焦
|
|
@@ -180,14 +198,7 @@ export let NavigationDrawer = class NavigationDrawer extends LayoutItemBase {
|
|
|
180
198
|
}
|
|
181
199
|
// 不位于 layout 中,父元素 padding 变化的动画
|
|
182
200
|
else if (!this.isParentLayout) {
|
|
183
|
-
animations.push(
|
|
184
|
-
{ [paddingPropName]: 0 },
|
|
185
|
-
{ [paddingPropName]: $(panel).innerWidth() + 'px' },
|
|
186
|
-
], {
|
|
187
|
-
duration: hasUpdated ? duration : 0,
|
|
188
|
-
easing: easingEmphasized,
|
|
189
|
-
fill: 'forwards',
|
|
190
|
-
}));
|
|
201
|
+
animations.push(this.getLockTargetAnimate(true, hasUpdated ? duration : 0));
|
|
191
202
|
}
|
|
192
203
|
// 若位于 layout 中,则 layout-main 的 padding 变化需要有和 drawer 相同的动画
|
|
193
204
|
// 但首次渲染不执行动画
|
|
@@ -210,14 +221,14 @@ export let NavigationDrawer = class NavigationDrawer extends LayoutItemBase {
|
|
|
210
221
|
if (hasUpdated) {
|
|
211
222
|
emit(this, 'opened');
|
|
212
223
|
}
|
|
213
|
-
return;
|
|
214
224
|
}
|
|
215
|
-
|
|
216
|
-
|
|
225
|
+
else if (this.hasUpdated) {
|
|
226
|
+
// 关闭
|
|
217
227
|
const requestClose = emit(this, 'close', { cancelable: true });
|
|
218
228
|
if (requestClose.defaultPrevented) {
|
|
219
229
|
return;
|
|
220
230
|
}
|
|
231
|
+
await this.definedController.whenDefined();
|
|
221
232
|
if (this.isModal) {
|
|
222
233
|
this.modalHelper.deactivate();
|
|
223
234
|
}
|
|
@@ -233,14 +244,7 @@ export let NavigationDrawer = class NavigationDrawer extends LayoutItemBase {
|
|
|
233
244
|
}
|
|
234
245
|
// 不位于 layout 中,父元素 padding 变化的动画
|
|
235
246
|
else if (!this.isParentLayout) {
|
|
236
|
-
animations.push(
|
|
237
|
-
{ [paddingPropName]: $(panel).innerWidth() + 'px' },
|
|
238
|
-
{ [paddingPropName]: 0 },
|
|
239
|
-
], {
|
|
240
|
-
duration,
|
|
241
|
-
easing: easingEmphasized,
|
|
242
|
-
fill: 'forwards',
|
|
243
|
-
}));
|
|
247
|
+
animations.push(this.getLockTargetAnimate(false, duration));
|
|
244
248
|
}
|
|
245
249
|
// 若位于 layout 中,则 layout-main 的 padding 变化需要有和 drawer 相同的动画
|
|
246
250
|
if (this.isParentLayout) {
|
|
@@ -260,21 +264,28 @@ export let NavigationDrawer = class NavigationDrawer extends LayoutItemBase {
|
|
|
260
264
|
setLayoutTransition(null);
|
|
261
265
|
}
|
|
262
266
|
this.style.display = 'none';
|
|
263
|
-
if (this.isModal) {
|
|
267
|
+
if (this.isModal && !this.contained) {
|
|
264
268
|
unlockScreen(this, this.lockTarget);
|
|
265
269
|
}
|
|
266
270
|
// 抽屉导航关闭后,恢复焦点到原有的元素上
|
|
267
271
|
const trigger = this.originalTrigger;
|
|
268
|
-
if (
|
|
272
|
+
if (isFunction(trigger?.focus)) {
|
|
269
273
|
setTimeout(() => trigger.focus());
|
|
270
274
|
}
|
|
271
275
|
emit(this, 'closed');
|
|
272
|
-
return;
|
|
273
276
|
}
|
|
274
277
|
}
|
|
275
278
|
connectedCallback() {
|
|
276
279
|
super.connectedCallback();
|
|
277
280
|
this.modalHelper = new Modal(this);
|
|
281
|
+
}
|
|
282
|
+
disconnectedCallback() {
|
|
283
|
+
super.disconnectedCallback();
|
|
284
|
+
unlockScreen(this, this.lockTarget);
|
|
285
|
+
this.observeResize?.unobserve();
|
|
286
|
+
}
|
|
287
|
+
firstUpdated(_changedProperties) {
|
|
288
|
+
super.firstUpdated(_changedProperties);
|
|
278
289
|
this.addEventListener('keydown', (event) => {
|
|
279
290
|
if (this.open &&
|
|
280
291
|
this.closeOnEsc &&
|
|
@@ -285,21 +296,26 @@ export let NavigationDrawer = class NavigationDrawer extends LayoutItemBase {
|
|
|
285
296
|
}
|
|
286
297
|
});
|
|
287
298
|
}
|
|
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
299
|
render() {
|
|
295
300
|
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
301
|
}
|
|
297
302
|
onOverlayClick() {
|
|
298
303
|
emit(this, 'overlay-click');
|
|
299
|
-
if (
|
|
300
|
-
|
|
304
|
+
if (this.closeOnOverlayClick) {
|
|
305
|
+
this.open = false;
|
|
301
306
|
}
|
|
302
|
-
|
|
307
|
+
}
|
|
308
|
+
getLockTargetAnimate(open, duration) {
|
|
309
|
+
const paddingName = this.placement === 'right' ? 'paddingRight' : 'paddingLeft';
|
|
310
|
+
const panelWidth = $(this.panelRef.value).innerWidth() + 'px';
|
|
311
|
+
return animateTo(this.lockTarget, [
|
|
312
|
+
{ [paddingName]: open ? 0 : panelWidth },
|
|
313
|
+
{ [paddingName]: open ? panelWidth : 0 },
|
|
314
|
+
], {
|
|
315
|
+
duration,
|
|
316
|
+
easing: getEasing(this, 'emphasized'),
|
|
317
|
+
fill: 'forwards',
|
|
318
|
+
});
|
|
303
319
|
}
|
|
304
320
|
};
|
|
305
321
|
NavigationDrawer.styles = [componentStyle, style];
|
|
@@ -355,11 +371,16 @@ __decorate([
|
|
|
355
371
|
watch('contained')
|
|
356
372
|
], NavigationDrawer.prototype, "onContainedChange", null);
|
|
357
373
|
__decorate([
|
|
358
|
-
watch('placement')
|
|
374
|
+
watch('placement', true)
|
|
359
375
|
], NavigationDrawer.prototype, "onPlacementChange", null);
|
|
376
|
+
__decorate([
|
|
377
|
+
watch('mobile', true),
|
|
378
|
+
watch('modal', true)
|
|
379
|
+
], NavigationDrawer.prototype, "onMobileChange", null);
|
|
360
380
|
__decorate([
|
|
361
381
|
watch('open')
|
|
362
382
|
], NavigationDrawer.prototype, "onOpenChange", null);
|
|
363
383
|
NavigationDrawer = __decorate([
|
|
364
384
|
customElement('mdui-navigation-drawer')
|
|
365
385
|
], NavigationDrawer);
|
|
386
|
+
export { NavigationDrawer };
|
|
@@ -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)
|
|
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))}`;
|
|
@@ -46,11 +46,15 @@ export declare class NavigationRailItem extends NavigationRailItem_base {
|
|
|
46
46
|
*/
|
|
47
47
|
value?: string;
|
|
48
48
|
/**
|
|
49
|
-
* 是否为激活状态,由
|
|
49
|
+
* 是否为激活状态,由 `<mdui-navigation-rail>` 组件控制该参数
|
|
50
50
|
*/
|
|
51
51
|
protected active: boolean;
|
|
52
52
|
/**
|
|
53
|
-
*
|
|
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;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
2
|
import { html, LitElement, 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';
|
|
6
7
|
import { HasSlotController } from '@mdui/shared/controllers/has-slot.js';
|
|
@@ -41,20 +42,24 @@ import { navigationRailItemStyle } from './navigation-rail-item-style.js';
|
|
|
41
42
|
*
|
|
42
43
|
* @cssprop --shape-corner-indicator - 指示器的圆角大小。可以指定一个具体的像素值;但更推荐[引用设计令牌](/docs/2/styles/design-tokens#shape-corner)
|
|
43
44
|
*/
|
|
44
|
-
|
|
45
|
+
let NavigationRailItem = class NavigationRailItem extends AnchorMixin(RippleMixin(FocusableMixin(LitElement))) {
|
|
45
46
|
constructor() {
|
|
46
47
|
super(...arguments);
|
|
47
48
|
/**
|
|
48
|
-
* 是否为激活状态,由
|
|
49
|
+
* 是否为激活状态,由 `<mdui-navigation-rail>` 组件控制该参数
|
|
49
50
|
*/
|
|
50
51
|
this.active = false;
|
|
51
52
|
/**
|
|
52
|
-
*
|
|
53
|
+
* 是否是初始状态,不显示动画。由 `<mdui-navigation-rail>` 组件控制该参数
|
|
54
|
+
*/
|
|
55
|
+
this.isInitial = true;
|
|
56
|
+
/**
|
|
57
|
+
* 导航栏的位置,由 `<mdui-navigation-rail>` 组件控制该参数
|
|
53
58
|
*/
|
|
54
59
|
this.placement = 'left';
|
|
55
60
|
// 是否禁用该元素,该组件没有禁用状态
|
|
56
61
|
this.disabled = false;
|
|
57
|
-
// 每一个
|
|
62
|
+
// 每一个 `<mdui-navigation-rail-item>` 元素都添加一个唯一的 key
|
|
58
63
|
this.key = uniqueId();
|
|
59
64
|
this.rippleRef = createRef();
|
|
60
65
|
this.hasSlotController = new HasSlotController(this, '[default]', 'active-icon');
|
|
@@ -66,8 +71,7 @@ export let NavigationRailItem = class NavigationRailItem extends AnchorMixin(Rip
|
|
|
66
71
|
return this.disabled;
|
|
67
72
|
}
|
|
68
73
|
get focusElement() {
|
|
69
|
-
|
|
70
|
-
return this.href ? (_a = this.renderRoot) === null || _a === void 0 ? void 0 : _a.querySelector('._a') : this;
|
|
74
|
+
return this.href ? this.renderRoot?.querySelector('._a') : this;
|
|
71
75
|
}
|
|
72
76
|
get focusDisabled() {
|
|
73
77
|
return this.disabled;
|
|
@@ -78,6 +82,7 @@ export let NavigationRailItem = class NavigationRailItem extends AnchorMixin(Rip
|
|
|
78
82
|
container: true,
|
|
79
83
|
'has-label': hasDefaultSlot,
|
|
80
84
|
'has-active-icon': this.activeIcon || this.hasSlotController.test('active-icon'),
|
|
85
|
+
initial: this.isInitial,
|
|
81
86
|
});
|
|
82
87
|
return html `${this.href
|
|
83
88
|
? this.renderAnchor({
|
|
@@ -88,7 +93,10 @@ export let NavigationRailItem = class NavigationRailItem extends AnchorMixin(Rip
|
|
|
88
93
|
: html `<div part="container" class="${className}">${this.renderInner(hasDefaultSlot)}</div>`}<mdui-ripple .noRipple="${!this.active || this.noRipple}" ${ref(this.rippleRef)}></mdui-ripple>`;
|
|
89
94
|
}
|
|
90
95
|
renderInner(hasDefaultSlot) {
|
|
91
|
-
return html `<div part="indicator" class="indicator"><slot name="badge" part="badge" class="
|
|
96
|
+
return html `<div part="indicator" class="indicator"><slot name="badge" part="badge" class="${classMap({
|
|
97
|
+
badge: true,
|
|
98
|
+
'placement-right': this.placement === 'right',
|
|
99
|
+
})}"></slot><slot name="active-icon" part="active-icon" class="active-icon">${this.activeIcon
|
|
92
100
|
? html `<mdui-icon name="${this.activeIcon}"></mdui-icon>`
|
|
93
101
|
: nothingTemplate}</slot><slot name="icon" part="icon" class="icon">${this.icon
|
|
94
102
|
? html `<mdui-icon name="${this.icon}"></mdui-icon>`
|
|
@@ -118,7 +126,10 @@ __decorate([
|
|
|
118
126
|
})
|
|
119
127
|
], NavigationRailItem.prototype, "active", void 0);
|
|
120
128
|
__decorate([
|
|
121
|
-
|
|
129
|
+
state()
|
|
130
|
+
], NavigationRailItem.prototype, "isInitial", void 0);
|
|
131
|
+
__decorate([
|
|
132
|
+
state()
|
|
122
133
|
], NavigationRailItem.prototype, "placement", void 0);
|
|
123
134
|
__decorate([
|
|
124
135
|
state()
|
|
@@ -126,3 +137,4 @@ __decorate([
|
|
|
126
137
|
NavigationRailItem = __decorate([
|
|
127
138
|
customElement('mdui-navigation-rail-item')
|
|
128
139
|
], NavigationRailItem);
|
|
140
|
+
export { NavigationRailItem };
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import '@mdui/jq/methods/css.js';
|
|
2
|
-
import '@mdui/jq/methods/find.js';
|
|
3
|
-
import '@mdui/jq/methods/get.js';
|
|
4
2
|
import '@mdui/jq/methods/innerWidth.js';
|
|
5
3
|
import { LayoutItemBase } from '../layout/layout-item-base.js';
|
|
6
4
|
import type { LayoutPlacement } from '../layout/helper.js';
|
|
@@ -62,10 +60,11 @@ export declare class NavigationRail extends LayoutItemBase {
|
|
|
62
60
|
*/
|
|
63
61
|
divider: boolean;
|
|
64
62
|
private activeKey;
|
|
63
|
+
private readonly items;
|
|
65
64
|
private readonly hasSlotController;
|
|
66
|
-
private
|
|
65
|
+
private readonly definedController;
|
|
66
|
+
private isInitial;
|
|
67
67
|
protected get layoutPlacement(): LayoutPlacement;
|
|
68
|
-
private get items();
|
|
69
68
|
private get parentTarget();
|
|
70
69
|
private get isRight();
|
|
71
70
|
private get paddingValue();
|
|
@@ -77,7 +76,7 @@ export declare class NavigationRail extends LayoutItemBase {
|
|
|
77
76
|
disconnectedCallback(): void;
|
|
78
77
|
protected render(): TemplateResult;
|
|
79
78
|
private onClick;
|
|
80
|
-
private
|
|
79
|
+
private updateItems;
|
|
81
80
|
private onSlotChange;
|
|
82
81
|
}
|
|
83
82
|
declare global {
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
2
|
import { html } from 'lit';
|
|
3
|
-
import { customElement, property, state } from 'lit/decorators.js';
|
|
3
|
+
import { customElement, property, queryAssignedElements, state, } from 'lit/decorators.js';
|
|
4
4
|
import { when } from 'lit/directives/when.js';
|
|
5
5
|
import { $ } from '@mdui/jq/$.js';
|
|
6
6
|
import '@mdui/jq/methods/css.js';
|
|
7
|
-
import '@mdui/jq/methods/find.js';
|
|
8
|
-
import '@mdui/jq/methods/get.js';
|
|
9
7
|
import '@mdui/jq/methods/innerWidth.js';
|
|
8
|
+
import { DefinedController } from '@mdui/shared/controllers/defined.js';
|
|
10
9
|
import { HasSlotController } from '@mdui/shared/controllers/has-slot.js';
|
|
11
10
|
import { watch } from '@mdui/shared/decorators/watch.js';
|
|
12
11
|
import { booleanConverter } from '@mdui/shared/helpers/decorator.js';
|
|
@@ -38,7 +37,7 @@ import { navigationRailStyle } from './navigation-rail-style.js';
|
|
|
38
37
|
* @cssprop --shape-corner - 组件的圆角大小。可以指定一个具体的像素值;但更推荐[引用设计令牌](/docs/2/styles/design-tokens#shape-corner)
|
|
39
38
|
* @cssprop --z-index - 组件的 CSS 的 `z-index` 值
|
|
40
39
|
*/
|
|
41
|
-
|
|
40
|
+
let NavigationRail = class NavigationRail extends LayoutItemBase {
|
|
42
41
|
constructor() {
|
|
43
42
|
super(...arguments);
|
|
44
43
|
/**
|
|
@@ -70,18 +69,15 @@ export let NavigationRail = class NavigationRail extends LayoutItemBase {
|
|
|
70
69
|
// 因为 navigation-rail-item 的 value 可能会重复,所以在每个 navigation-rail-item 元素上都添加了一个唯一的 key,通过 activeKey 来记录激活状态的 key
|
|
71
70
|
this.activeKey = 0;
|
|
72
71
|
this.hasSlotController = new HasSlotController(this, 'top', 'bottom');
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
this.definedController = new DefinedController(this, {
|
|
73
|
+
relatedElements: ['mdui-navigation-rail-item'],
|
|
74
|
+
});
|
|
75
|
+
// 是否是初始状态,初始状态不触发事件,不执行动画
|
|
76
|
+
this.isInitial = true;
|
|
75
77
|
}
|
|
76
78
|
get layoutPlacement() {
|
|
77
79
|
return this.placement;
|
|
78
80
|
}
|
|
79
|
-
// 所有的子项元素
|
|
80
|
-
get items() {
|
|
81
|
-
return $(this)
|
|
82
|
-
.find('mdui-navigation-rail-item')
|
|
83
|
-
.get();
|
|
84
|
-
}
|
|
85
81
|
get parentTarget() {
|
|
86
82
|
return this.contained || this.isParentLayout
|
|
87
83
|
? this.parentElement
|
|
@@ -95,28 +91,27 @@ export let NavigationRail = class NavigationRail extends LayoutItemBase {
|
|
|
95
91
|
? this.offsetWidth
|
|
96
92
|
: undefined;
|
|
97
93
|
}
|
|
98
|
-
onActiveKeyChange() {
|
|
94
|
+
async onActiveKeyChange() {
|
|
95
|
+
await this.definedController.whenDefined();
|
|
99
96
|
// 根据 activeKey 读取对应 navigation-rail-item 的值
|
|
100
97
|
const item = this.items.find((item) => item.key === this.activeKey);
|
|
101
|
-
this.value = item
|
|
102
|
-
if (this.
|
|
98
|
+
this.value = item?.value;
|
|
99
|
+
if (!this.isInitial) {
|
|
103
100
|
emit(this, 'change');
|
|
104
101
|
}
|
|
105
|
-
else {
|
|
106
|
-
this.hasSetDefaultValue = true;
|
|
107
|
-
}
|
|
108
102
|
}
|
|
109
|
-
onValueChange() {
|
|
110
|
-
|
|
103
|
+
async onValueChange() {
|
|
104
|
+
this.isInitial = !this.hasUpdated;
|
|
105
|
+
await this.definedController.whenDefined();
|
|
111
106
|
const item = this.items.find((item) => item.value === this.value);
|
|
112
|
-
this.activeKey =
|
|
113
|
-
this.
|
|
107
|
+
this.activeKey = item?.key ?? 0;
|
|
108
|
+
this.updateItems();
|
|
114
109
|
}
|
|
115
|
-
|
|
116
|
-
onContainedChange() {
|
|
110
|
+
async onContainedChange() {
|
|
117
111
|
if (this.isParentLayout) {
|
|
118
112
|
return;
|
|
119
113
|
}
|
|
114
|
+
await this.definedController.whenDefined();
|
|
120
115
|
$(document.body).css({
|
|
121
116
|
paddingLeft: this.contained || this.isRight ? null : this.paddingValue,
|
|
122
117
|
paddingRight: this.contained || !this.isRight ? null : this.paddingValue,
|
|
@@ -126,32 +121,33 @@ export let NavigationRail = class NavigationRail extends LayoutItemBase {
|
|
|
126
121
|
paddingRight: this.contained && this.isRight ? this.paddingValue : null,
|
|
127
122
|
});
|
|
128
123
|
}
|
|
129
|
-
onPlacementChange() {
|
|
130
|
-
|
|
131
|
-
|
|
124
|
+
async onPlacementChange() {
|
|
125
|
+
await this.definedController.whenDefined();
|
|
126
|
+
this.layoutManager?.updateLayout(this);
|
|
132
127
|
this.items.forEach((item) => {
|
|
133
128
|
item.placement = this.placement;
|
|
134
129
|
});
|
|
135
|
-
if (this.isParentLayout) {
|
|
136
|
-
|
|
130
|
+
if (!this.isParentLayout) {
|
|
131
|
+
$(this.parentTarget).css({
|
|
132
|
+
paddingLeft: this.isRight ? null : this.paddingValue,
|
|
133
|
+
paddingRight: this.isRight ? this.paddingValue : null,
|
|
134
|
+
});
|
|
137
135
|
}
|
|
138
|
-
$(this.parentTarget).css({
|
|
139
|
-
paddingLeft: this.isRight ? null : this.paddingValue,
|
|
140
|
-
paddingRight: this.isRight ? this.paddingValue : null,
|
|
141
|
-
});
|
|
142
136
|
}
|
|
143
137
|
connectedCallback() {
|
|
144
138
|
super.connectedCallback();
|
|
145
139
|
if (!this.isParentLayout) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
140
|
+
this.definedController.whenDefined().then(() => {
|
|
141
|
+
$(this.parentTarget).css({
|
|
142
|
+
paddingLeft: this.isRight ? null : this.paddingValue,
|
|
143
|
+
paddingRight: this.isRight ? this.paddingValue : null,
|
|
144
|
+
});
|
|
149
145
|
});
|
|
150
146
|
}
|
|
151
147
|
}
|
|
152
148
|
disconnectedCallback() {
|
|
153
149
|
super.disconnectedCallback();
|
|
154
|
-
if (!this.isParentLayout) {
|
|
150
|
+
if (!this.isParentLayout && this.definedController.isDefined()) {
|
|
155
151
|
$(this.parentTarget).css({
|
|
156
152
|
paddingLeft: this.isRight ? undefined : null,
|
|
157
153
|
paddingRight: this.isRight ? null : undefined,
|
|
@@ -171,16 +167,20 @@ export let NavigationRail = class NavigationRail extends LayoutItemBase {
|
|
|
171
167
|
const target = event.target;
|
|
172
168
|
const item = target.closest('mdui-navigation-rail-item');
|
|
173
169
|
this.activeKey = item.key;
|
|
174
|
-
this.
|
|
170
|
+
this.isInitial = false;
|
|
171
|
+
this.updateItems();
|
|
175
172
|
}
|
|
176
|
-
|
|
177
|
-
this.items.forEach((item) => (item.active = this.activeKey === item.key));
|
|
178
|
-
}
|
|
179
|
-
onSlotChange() {
|
|
173
|
+
updateItems() {
|
|
180
174
|
this.items.forEach((item) => {
|
|
175
|
+
item.active = this.activeKey === item.key;
|
|
181
176
|
item.placement = this.placement;
|
|
177
|
+
item.isInitial = this.isInitial;
|
|
182
178
|
});
|
|
183
179
|
}
|
|
180
|
+
async onSlotChange() {
|
|
181
|
+
await this.definedController.whenDefined();
|
|
182
|
+
this.updateItems();
|
|
183
|
+
}
|
|
184
184
|
};
|
|
185
185
|
NavigationRail.styles = [
|
|
186
186
|
componentStyle,
|
|
@@ -214,7 +214,13 @@ __decorate([
|
|
|
214
214
|
state()
|
|
215
215
|
], NavigationRail.prototype, "activeKey", void 0);
|
|
216
216
|
__decorate([
|
|
217
|
-
|
|
217
|
+
queryAssignedElements({
|
|
218
|
+
selector: 'mdui-navigation-rail-item',
|
|
219
|
+
flatten: true,
|
|
220
|
+
})
|
|
221
|
+
], NavigationRail.prototype, "items", void 0);
|
|
222
|
+
__decorate([
|
|
223
|
+
watch('activeKey', true)
|
|
218
224
|
], NavigationRail.prototype, "onActiveKeyChange", null);
|
|
219
225
|
__decorate([
|
|
220
226
|
watch('value')
|
|
@@ -223,8 +229,9 @@ __decorate([
|
|
|
223
229
|
watch('contained', true)
|
|
224
230
|
], NavigationRail.prototype, "onContainedChange", null);
|
|
225
231
|
__decorate([
|
|
226
|
-
watch('placement')
|
|
232
|
+
watch('placement', true)
|
|
227
233
|
], NavigationRail.prototype, "onPlacementChange", null);
|
|
228
234
|
NavigationRail = __decorate([
|
|
229
235
|
customElement('mdui-navigation-rail')
|
|
230
236
|
], NavigationRail);
|
|
237
|
+
export { NavigationRail };
|
|
@@ -52,8 +52,10 @@ export declare class RadioGroup extends LitElement implements FormControl {
|
|
|
52
52
|
* 是否验证未通过
|
|
53
53
|
*/
|
|
54
54
|
private invalid;
|
|
55
|
+
private isInitial;
|
|
55
56
|
private readonly inputRef;
|
|
56
57
|
private readonly formController;
|
|
58
|
+
private readonly definedController;
|
|
57
59
|
/**
|
|
58
60
|
* 表单验证状态对象
|
|
59
61
|
*/
|
|
@@ -62,11 +64,10 @@ export declare class RadioGroup extends LitElement implements FormControl {
|
|
|
62
64
|
* 表单验证的错误提示信息
|
|
63
65
|
*/
|
|
64
66
|
get validationMessage(): string;
|
|
65
|
-
private get
|
|
66
|
-
private get
|
|
67
|
+
private get items();
|
|
68
|
+
private get itemsEnabled();
|
|
67
69
|
private onValueChange;
|
|
68
70
|
private onInvalidChange;
|
|
69
|
-
private onDisabledChange;
|
|
70
71
|
/**
|
|
71
72
|
* 检查表单字段是否验证通过。若未通过则返回 `false`,并触发 `invalid` 事件;若验证通过,则返回 `true`
|
|
72
73
|
*/
|
|
@@ -85,7 +86,7 @@ export declare class RadioGroup extends LitElement implements FormControl {
|
|
|
85
86
|
setCustomValidity(message: string): void;
|
|
86
87
|
protected render(): TemplateResult;
|
|
87
88
|
private updateRadioFocusable;
|
|
88
|
-
private
|
|
89
|
+
private onClick;
|
|
89
90
|
/**
|
|
90
91
|
* 在内部的 `<mdui-radio>` 上按下按键时,在 `<mdui-radio>` 之间切换焦点
|
|
91
92
|
*/
|
|
@@ -95,6 +96,7 @@ export declare class RadioGroup extends LitElement implements FormControl {
|
|
|
95
96
|
* slot 中的 mdui-radio 的 checked 变更时触发的事件
|
|
96
97
|
*/
|
|
97
98
|
private onCheckedChange;
|
|
99
|
+
private updateItems;
|
|
98
100
|
}
|
|
99
101
|
declare global {
|
|
100
102
|
interface HTMLElementTagNameMap {
|