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.
- package/LICENSE +21 -21
- package/components/avatar/index.d.ts +4 -2
- package/components/avatar/index.js +4 -2
- package/components/badge/index.d.ts +4 -2
- package/components/badge/index.js +4 -2
- package/components/bottom-app-bar/index.d.ts +9 -3
- package/components/bottom-app-bar/index.js +9 -9
- package/components/button/button-base.d.ts +5 -5
- package/components/button/button-base.js +22 -19
- package/components/button/index.d.ts +6 -1
- package/components/button/index.js +2 -1
- package/components/button-icon/index.d.ts +7 -1
- package/components/button-icon/index.js +3 -3
- package/components/card/index.d.ts +8 -4
- package/components/card/index.js +7 -3
- package/components/checkbox/index.d.ts +10 -3
- package/components/checkbox/index.js +13 -16
- package/components/checkbox/style.js +1 -1
- package/components/chip/index.d.ts +8 -1
- package/components/chip/index.js +5 -5
- package/components/circular-progress/index.d.ts +4 -2
- package/components/circular-progress/index.js +5 -4
- package/components/collapse/collapse-item-style.js +1 -1
- package/components/collapse/collapse-item.d.ts +15 -3
- package/components/collapse/collapse-item.js +26 -23
- package/components/collapse/collapse.d.ts +16 -8
- package/components/collapse/collapse.js +61 -38
- package/components/dialog/index.d.ts +12 -4
- package/components/dialog/index.js +36 -36
- package/components/divider/index.d.ts +4 -2
- package/components/divider/index.js +4 -2
- package/components/dropdown/index.d.ts +13 -7
- package/components/dropdown/index.js +70 -63
- package/components/fab/index.d.ts +7 -1
- package/components/fab/index.js +10 -5
- package/components/icon/index.d.ts +4 -2
- package/components/icon/index.js +4 -2
- package/components/layout/helper.d.ts +5 -6
- package/components/layout/helper.js +42 -48
- package/components/layout/layout-item-base.d.ts +3 -2
- package/components/layout/layout-item-base.js +3 -4
- package/components/layout/layout-item.d.ts +4 -3
- package/components/layout/layout-item.js +3 -3
- package/components/layout/layout-main.d.ts +4 -2
- package/components/layout/layout-main.js +4 -2
- package/components/layout/layout.d.ts +4 -2
- package/components/layout/layout.js +4 -2
- package/components/linear-progress/index.d.ts +4 -2
- package/components/linear-progress/index.js +5 -4
- package/components/list/list-item-style.js +1 -1
- package/components/list/list-item.d.ts +7 -3
- package/components/list/list-item.js +5 -3
- package/components/list/list-subheader.d.ts +4 -2
- package/components/list/list-subheader.js +4 -2
- package/components/list/list.d.ts +4 -2
- package/components/list/list.js +4 -2
- package/components/menu/menu-item.d.ts +12 -3
- package/components/menu/menu-item.js +53 -40
- package/components/menu/menu.d.ts +9 -3
- package/components/menu/menu.js +85 -59
- package/components/navigation-bar/navigation-bar-item-style.js +1 -1
- package/components/navigation-bar/navigation-bar-item.d.ts +13 -5
- package/components/navigation-bar/navigation-bar-item.js +28 -11
- package/components/navigation-bar/navigation-bar.d.ts +14 -7
- package/components/navigation-bar/navigation-bar.js +58 -49
- package/components/navigation-drawer/index.d.ts +13 -2
- package/components/navigation-drawer/index.js +69 -49
- package/components/navigation-drawer/style.js +1 -1
- package/components/navigation-rail/navigation-rail-item-style.js +1 -1
- package/components/navigation-rail/navigation-rail-item.d.ts +13 -5
- package/components/navigation-rail/navigation-rail-item.js +22 -9
- package/components/navigation-rail/navigation-rail.d.ts +8 -6
- package/components/navigation-rail/navigation-rail.js +55 -46
- package/components/radio/radio-group.d.ts +13 -6
- package/components/radio/radio-group.js +69 -59
- package/components/radio/radio-style.js +1 -1
- package/components/radio/radio.d.ts +11 -5
- package/components/radio/radio.js +26 -19
- package/components/range-slider/index.d.ts +9 -3
- package/components/range-slider/index.js +13 -11
- package/components/ripple/index.d.ts +4 -2
- package/components/ripple/index.js +4 -2
- package/components/ripple/ripple-mixin.d.ts +1 -1
- package/components/ripple/ripple-mixin.js +0 -1
- package/components/segmented-button/segmented-button-group-style.js +1 -1
- package/components/segmented-button/segmented-button-group.d.ts +12 -5
- package/components/segmented-button/segmented-button-group.js +92 -77
- package/components/segmented-button/segmented-button.d.ts +8 -3
- package/components/segmented-button/segmented-button.js +5 -4
- package/components/select/index.d.ts +13 -5
- package/components/select/index.js +30 -28
- package/components/slider/index.d.ts +8 -1
- package/components/slider/index.js +11 -18
- package/components/slider/slider-base-style.js +1 -1
- package/components/slider/slider-base.d.ts +7 -3
- package/components/slider/slider-base.js +28 -13
- package/components/snackbar/index.d.ts +9 -2
- package/components/snackbar/index.js +11 -10
- package/components/switch/index.d.ts +10 -3
- package/components/switch/index.js +12 -15
- package/components/switch/style.js +1 -1
- package/components/tabs/tab-panel.d.ts +4 -2
- package/components/tabs/tab-panel.js +4 -2
- package/components/tabs/tab-style.js +1 -1
- package/components/tabs/tab.d.ts +7 -3
- package/components/tabs/tab.js +12 -6
- package/components/tabs/tabs-style.js +1 -1
- package/components/tabs/tabs.d.ts +11 -7
- package/components/tabs/tabs.js +57 -40
- package/components/text-field/index.d.ts +13 -5
- package/components/text-field/index.js +43 -65
- package/components/text-field/style.js +1 -1
- package/components/tooltip/index.d.ts +14 -7
- package/components/tooltip/index.js +45 -38
- package/components/top-app-bar/top-app-bar-title-style.js +1 -1
- package/components/top-app-bar/top-app-bar-title.d.ts +4 -2
- package/components/top-app-bar/top-app-bar-title.js +18 -13
- package/components/top-app-bar/top-app-bar.d.ts +9 -3
- package/components/top-app-bar/top-app-bar.js +11 -10
- package/custom-elements.json +904 -546
- package/functions/getTheme.js +3 -3
- package/functions/snackbar.js +1 -2
- package/functions/utils/colorScheme.js +2 -2
- package/mdui.esm.js +8 -8
- package/mdui.global.js +8 -8
- package/package.json +8 -7
- package/web-types.zh-cn.json +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { LitElement } from 'lit';
|
|
2
1
|
import '@mdui/jq/methods/css.js';
|
|
3
2
|
import '@mdui/jq/methods/filter.js';
|
|
4
3
|
import '@mdui/jq/methods/height.js';
|
|
5
4
|
import '@mdui/jq/methods/prop.js';
|
|
6
5
|
import '@mdui/jq/methods/width.js';
|
|
6
|
+
import { MduiElement } from '@mdui/shared/base/mdui-element.js';
|
|
7
7
|
import type { CSSResultGroup, TemplateResult, PropertyValues } from 'lit';
|
|
8
8
|
/**
|
|
9
9
|
* @summary 工具提示组件
|
|
@@ -33,7 +33,7 @@ import type { CSSResultGroup, TemplateResult, PropertyValues } from 'lit';
|
|
|
33
33
|
* @cssprop --shape-corner-rich - variant="rich" 时,组件的圆角大小。可以指定一个具体的像素值;但更推荐[引用设计令牌](/docs/2/styles/design-tokens#shape-corner)
|
|
34
34
|
* @cssprop --z-index - 组件的 CSS 的 `z-index` 值
|
|
35
35
|
*/
|
|
36
|
-
export declare class Tooltip extends
|
|
36
|
+
export declare class Tooltip extends MduiElement<TooltipEventMap> {
|
|
37
37
|
static styles: CSSResultGroup;
|
|
38
38
|
/**
|
|
39
39
|
* tooltip 的形状。默认为 `plain`。可选值为:
|
|
@@ -98,12 +98,17 @@ export declare class Tooltip extends LitElement {
|
|
|
98
98
|
*/
|
|
99
99
|
open: boolean;
|
|
100
100
|
private observeResize?;
|
|
101
|
-
private
|
|
101
|
+
private overflowAncestors?;
|
|
102
102
|
private hoverTimeout;
|
|
103
103
|
private readonly popupRef;
|
|
104
104
|
private readonly hasSlotController;
|
|
105
105
|
private readonly hoverController;
|
|
106
|
+
private readonly definedController;
|
|
106
107
|
constructor();
|
|
108
|
+
/**
|
|
109
|
+
* 获取第一个非 <style> 和 content slot 的子元素,作为 tooltip 的目标元素
|
|
110
|
+
*/
|
|
111
|
+
private get target();
|
|
107
112
|
private onPositionChange;
|
|
108
113
|
private onOpenChange;
|
|
109
114
|
connectedCallback(): void;
|
|
@@ -115,10 +120,6 @@ export declare class Tooltip extends LitElement {
|
|
|
115
120
|
* 请求关闭 tooltip。鼠标未悬浮在 tooltip 上时,直接关闭;否则等鼠标移走再关闭
|
|
116
121
|
*/
|
|
117
122
|
private requestClose;
|
|
118
|
-
/**
|
|
119
|
-
* 获取第一个非 <style> 和 content slot 的子元素,作为 tooltip 的目标元素
|
|
120
|
-
*/
|
|
121
|
-
private getTarget;
|
|
122
123
|
private hasTrigger;
|
|
123
124
|
private onFocus;
|
|
124
125
|
private onBlur;
|
|
@@ -133,6 +134,12 @@ export declare class Tooltip extends LitElement {
|
|
|
133
134
|
private onWindowScroll;
|
|
134
135
|
private updatePositioner;
|
|
135
136
|
}
|
|
137
|
+
export interface TooltipEventMap {
|
|
138
|
+
open: CustomEvent<void>;
|
|
139
|
+
opened: CustomEvent<void>;
|
|
140
|
+
close: CustomEvent<void>;
|
|
141
|
+
closed: CustomEvent<void>;
|
|
142
|
+
}
|
|
136
143
|
declare global {
|
|
137
144
|
interface HTMLElementTagNameMap {
|
|
138
145
|
'mdui-tooltip': Tooltip;
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
|
-
import { html
|
|
2
|
+
import { html } from 'lit';
|
|
3
3
|
import { customElement, property } from 'lit/decorators.js';
|
|
4
4
|
import { createRef, ref } from 'lit/directives/ref.js';
|
|
5
5
|
import { when } from 'lit/directives/when.js';
|
|
6
|
+
import { getOverflowAncestors } from '@floating-ui/utils/dom';
|
|
6
7
|
import { $ } from '@mdui/jq/$.js';
|
|
7
8
|
import '@mdui/jq/methods/css.js';
|
|
8
9
|
import '@mdui/jq/methods/filter.js';
|
|
9
10
|
import '@mdui/jq/methods/height.js';
|
|
10
11
|
import '@mdui/jq/methods/prop.js';
|
|
11
12
|
import '@mdui/jq/methods/width.js';
|
|
13
|
+
import { MduiElement } from '@mdui/shared/base/mdui-element.js';
|
|
14
|
+
import { DefinedController } from '@mdui/shared/controllers/defined.js';
|
|
12
15
|
import { HasSlotController } from '@mdui/shared/controllers/has-slot.js';
|
|
13
16
|
import { HoverController } from '@mdui/shared/controllers/hover.js';
|
|
14
17
|
import { watch } from '@mdui/shared/decorators/watch.js';
|
|
15
18
|
import { animateTo, stopAnimations } from '@mdui/shared/helpers/animate.js';
|
|
16
19
|
import { booleanConverter } from '@mdui/shared/helpers/decorator.js';
|
|
17
|
-
import { emit } from '@mdui/shared/helpers/event.js';
|
|
18
20
|
import { getDuration, getEasing } from '@mdui/shared/helpers/motion.js';
|
|
19
21
|
import { observeResize } from '@mdui/shared/helpers/observeResize.js';
|
|
20
22
|
import { componentStyle } from '@mdui/shared/lit-styles/component-style.js';
|
|
@@ -47,7 +49,7 @@ import { style } from './style.js';
|
|
|
47
49
|
* @cssprop --shape-corner-rich - variant="rich" 时,组件的圆角大小。可以指定一个具体的像素值;但更推荐[引用设计令牌](/docs/2/styles/design-tokens#shape-corner)
|
|
48
50
|
* @cssprop --z-index - 组件的 CSS 的 `z-index` 值
|
|
49
51
|
*/
|
|
50
|
-
|
|
52
|
+
let Tooltip = class Tooltip extends MduiElement {
|
|
51
53
|
constructor() {
|
|
52
54
|
super();
|
|
53
55
|
/**
|
|
@@ -107,6 +109,9 @@ export let Tooltip = class Tooltip extends LitElement {
|
|
|
107
109
|
this.popupRef = createRef();
|
|
108
110
|
this.hasSlotController = new HasSlotController(this, 'headline', 'action');
|
|
109
111
|
this.hoverController = new HoverController(this, this.popupRef);
|
|
112
|
+
this.definedController = new DefinedController(this, {
|
|
113
|
+
needDomReady: true,
|
|
114
|
+
});
|
|
110
115
|
this.onDocumentClick = this.onDocumentClick.bind(this);
|
|
111
116
|
this.onWindowScroll = this.onWindowScroll.bind(this);
|
|
112
117
|
this.onFocus = this.onFocus.bind(this);
|
|
@@ -116,8 +121,16 @@ export let Tooltip = class Tooltip extends LitElement {
|
|
|
116
121
|
this.onMouseEnter = this.onMouseEnter.bind(this);
|
|
117
122
|
this.onMouseLeave = this.onMouseLeave.bind(this);
|
|
118
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* 获取第一个非 <style> 和 content slot 的子元素,作为 tooltip 的目标元素
|
|
126
|
+
*/
|
|
127
|
+
get target() {
|
|
128
|
+
return [...this.children].find((el) => el.tagName.toLowerCase() !== 'style' &&
|
|
129
|
+
el.getAttribute('slot') !== 'content');
|
|
130
|
+
}
|
|
119
131
|
async onPositionChange() {
|
|
120
132
|
if (this.open) {
|
|
133
|
+
await this.definedController.whenDefined();
|
|
121
134
|
this.updatePositioner();
|
|
122
135
|
}
|
|
123
136
|
}
|
|
@@ -128,6 +141,7 @@ export let Tooltip = class Tooltip extends LitElement {
|
|
|
128
141
|
// 打开
|
|
129
142
|
// 要区分是否首次渲染,首次渲染时不触发事件,不执行动画;非首次渲染,触发事件,执行动画
|
|
130
143
|
if (this.open) {
|
|
144
|
+
await this.definedController.whenDefined();
|
|
131
145
|
// 先关闭页面中所有其他相同 variant 的 tooltip
|
|
132
146
|
$(`mdui-tooltip[variant="${this.variant}"]`)
|
|
133
147
|
.filter((_, element) => element !== this)
|
|
@@ -136,10 +150,8 @@ export let Tooltip = class Tooltip extends LitElement {
|
|
|
136
150
|
await this.updateComplete;
|
|
137
151
|
}
|
|
138
152
|
if (hasUpdated) {
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
});
|
|
142
|
-
if (requestOpen.defaultPrevented) {
|
|
153
|
+
const eventProceeded = this.emit('open', { cancelable: true });
|
|
154
|
+
if (!eventProceeded) {
|
|
143
155
|
return;
|
|
144
156
|
}
|
|
145
157
|
}
|
|
@@ -151,52 +163,53 @@ export let Tooltip = class Tooltip extends LitElement {
|
|
|
151
163
|
easing,
|
|
152
164
|
});
|
|
153
165
|
if (hasUpdated) {
|
|
154
|
-
emit(
|
|
166
|
+
this.emit('opened');
|
|
155
167
|
}
|
|
156
168
|
return;
|
|
157
169
|
}
|
|
158
170
|
// 关闭
|
|
159
171
|
if (!this.open && hasUpdated) {
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
});
|
|
163
|
-
if (requestClose.defaultPrevented) {
|
|
172
|
+
const eventProceeded = this.emit('close', { cancelable: true });
|
|
173
|
+
if (!eventProceeded) {
|
|
164
174
|
return;
|
|
165
175
|
}
|
|
166
176
|
await stopAnimations(this.popupRef.value);
|
|
167
177
|
await animateTo(this.popupRef.value, [{ transform: 'scale(1)' }, { transform: 'scale(0)' }], { duration, easing });
|
|
168
178
|
this.popupRef.value.hidden = true;
|
|
169
|
-
emit(
|
|
170
|
-
return;
|
|
179
|
+
this.emit('closed');
|
|
171
180
|
}
|
|
172
181
|
}
|
|
173
182
|
connectedCallback() {
|
|
174
183
|
super.connectedCallback();
|
|
175
184
|
document.addEventListener('pointerdown', this.onDocumentClick);
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
this.observeResize = observeResize(this.target, () => {
|
|
180
|
-
this.updatePositioner();
|
|
181
|
-
});
|
|
185
|
+
this.overflowAncestors = getOverflowAncestors(this.target);
|
|
186
|
+
this.overflowAncestors.forEach((ancestor) => {
|
|
187
|
+
ancestor.addEventListener('scroll', this.onWindowScroll);
|
|
182
188
|
});
|
|
183
189
|
}
|
|
184
190
|
disconnectedCallback() {
|
|
185
|
-
var _a;
|
|
186
191
|
super.disconnectedCallback();
|
|
187
192
|
document.removeEventListener('pointerdown', this.onDocumentClick);
|
|
188
|
-
|
|
189
|
-
|
|
193
|
+
this.overflowAncestors?.forEach((ancestor) => {
|
|
194
|
+
ancestor.removeEventListener('scroll', this.onWindowScroll);
|
|
195
|
+
});
|
|
196
|
+
this.observeResize?.unobserve();
|
|
190
197
|
}
|
|
191
198
|
firstUpdated(changedProperties) {
|
|
192
199
|
super.firstUpdated(changedProperties);
|
|
193
|
-
this.
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
+
this.definedController.whenDefined().then(() => {
|
|
201
|
+
const target = this.target;
|
|
202
|
+
target.addEventListener('focus', this.onFocus);
|
|
203
|
+
target.addEventListener('blur', this.onBlur);
|
|
204
|
+
target.addEventListener('pointerdown', this.onClick);
|
|
205
|
+
target.addEventListener('keydown', this.onKeydown);
|
|
206
|
+
target.addEventListener('mouseenter', this.onMouseEnter);
|
|
207
|
+
target.addEventListener('mouseleave', this.onMouseLeave);
|
|
208
|
+
// trigger 尺寸变化时,重新调整 tooltip 的位置
|
|
209
|
+
this.observeResize = observeResize(target, () => {
|
|
210
|
+
this.updatePositioner();
|
|
211
|
+
});
|
|
212
|
+
});
|
|
200
213
|
}
|
|
201
214
|
render() {
|
|
202
215
|
const hasHeadline = this.isRich() &&
|
|
@@ -210,7 +223,7 @@ export let Tooltip = class Tooltip extends LitElement {
|
|
|
210
223
|
/**
|
|
211
224
|
* 请求关闭 tooltip。鼠标未悬浮在 tooltip 上时,直接关闭;否则等鼠标移走再关闭
|
|
212
225
|
*/
|
|
213
|
-
|
|
226
|
+
requestClose() {
|
|
214
227
|
if (!this.hoverController.isHover) {
|
|
215
228
|
this.open = false;
|
|
216
229
|
return;
|
|
@@ -228,13 +241,6 @@ export let Tooltip = class Tooltip extends LitElement {
|
|
|
228
241
|
}
|
|
229
242
|
}, true);
|
|
230
243
|
}
|
|
231
|
-
/**
|
|
232
|
-
* 获取第一个非 <style> 和 content slot 的子元素,作为 tooltip 的目标元素
|
|
233
|
-
*/
|
|
234
|
-
getTarget() {
|
|
235
|
-
return [...this.children].find((el) => el.tagName.toLowerCase() !== 'style' &&
|
|
236
|
-
el.getAttribute('slot') !== 'content');
|
|
237
|
-
}
|
|
238
244
|
hasTrigger(trigger) {
|
|
239
245
|
const triggers = this.trigger.split(' ');
|
|
240
246
|
return triggers.includes(trigger);
|
|
@@ -495,3 +501,4 @@ __decorate([
|
|
|
495
501
|
Tooltip = __decorate([
|
|
496
502
|
customElement('mdui-tooltip')
|
|
497
503
|
], Tooltip);
|
|
504
|
+
export { Tooltip };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { css } from 'lit';
|
|
2
|
-
export const topAppBarTitleStyle = css `:host{display:block;width:100%;flex-shrink:initial!important;overflow:hidden;color:rgb(var(--mdui-color-on-surface));font-size:var(--mdui-typescale-title-large-size);font-weight:var(--mdui-typescale-title-large-weight);letter-spacing:var(--mdui-typescale-title-large-tracking);line-height:var(--mdui-typescale-title-large-line-height);line-height:2.5rem}.label{display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;opacity:1;transition:opacity var(--mdui-motion-duration-short2) var(--mdui-motion-easing-linear)}
|
|
2
|
+
export const topAppBarTitleStyle = css `:host{display:block;width:100%;flex-shrink:initial!important;overflow:hidden;color:rgb(var(--mdui-color-on-surface));font-size:var(--mdui-typescale-title-large-size);font-weight:var(--mdui-typescale-title-large-weight);letter-spacing:var(--mdui-typescale-title-large-tracking);line-height:var(--mdui-typescale-title-large-line-height);line-height:2.5rem}.label{display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;opacity:1;transition:opacity var(--mdui-motion-duration-short2) var(--mdui-motion-easing-linear)}.label.variant-center-aligned{text-align:center}.label.variant-large:not(.shrink),.label.variant-medium:not(.shrink){opacity:0}.label.variant-large.shrink,.label.variant-medium.shrink{transition-delay:var(--mdui-motion-duration-short2)}.label-large{display:none;position:absolute;width:100%;left:0;margin-right:0;padding:0 1rem;transition:opacity var(--mdui-motion-duration-short2) var(--mdui-motion-easing-linear)}.label-large.variant-large,.label-large.variant-medium{display:block}.label-large.variant-medium{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;bottom:.75rem;font-size:var(--mdui-typescale-headline-small-size);font-weight:var(--mdui-typescale-headline-small-weight);letter-spacing:var(--mdui-typescale-headline-small-tracking);line-height:var(--mdui-typescale-headline-small-line-height)}.label-large.variant-large{display:-webkit-box;overflow:hidden;white-space:normal;-webkit-box-orient:vertical;-webkit-line-clamp:2;bottom:1.25rem;font-size:var(--mdui-typescale-headline-medium-size);font-weight:var(--mdui-typescale-headline-medium-weight);letter-spacing:var(--mdui-typescale-headline-medium-tracking);line-height:var(--mdui-typescale-headline-medium-line-height)}.label-large.variant-large:not(.shrink),.label-large.variant-medium:not(.shrink){opacity:1;transition-delay:var(--mdui-motion-duration-short2)}.label-large.variant-large.shrink,.label-large.variant-medium.shrink{opacity:0;z-index:-1}`;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MduiElement } from '@mdui/shared/base/mdui-element.js';
|
|
2
2
|
import type { CSSResultGroup, TemplateResult } from 'lit';
|
|
3
3
|
/**
|
|
4
4
|
* @summary 顶部应用栏标题组件。需与 `<mdui-top-app-bar>` 组件配合使用
|
|
@@ -18,7 +18,7 @@ import type { CSSResultGroup, TemplateResult } from 'lit';
|
|
|
18
18
|
* @csspart label 文本内容
|
|
19
19
|
* @csspart label-large 展开状态的文本内容
|
|
20
20
|
*/
|
|
21
|
-
export declare class TopAppBarTitle extends
|
|
21
|
+
export declare class TopAppBarTitle extends MduiElement<TopAppBarTitleEventMap> {
|
|
22
22
|
static styles: CSSResultGroup;
|
|
23
23
|
/**
|
|
24
24
|
* 顶部应用栏形状。由 mdui-top-app-bar 组件控制该参数
|
|
@@ -39,6 +39,8 @@ export declare class TopAppBarTitle extends LitElement {
|
|
|
39
39
|
*/
|
|
40
40
|
private onSlotChange;
|
|
41
41
|
}
|
|
42
|
+
export interface TopAppBarTitleEventMap {
|
|
43
|
+
}
|
|
42
44
|
declare global {
|
|
43
45
|
interface HTMLElementTagNameMap {
|
|
44
46
|
'mdui-top-app-bar-title': TopAppBarTitle;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
|
-
import { html
|
|
3
|
-
import { customElement,
|
|
2
|
+
import { html } from 'lit';
|
|
3
|
+
import { customElement, state } from 'lit/decorators.js';
|
|
4
|
+
import { classMap } from 'lit/directives/class-map.js';
|
|
4
5
|
import { createRef, ref } from 'lit/directives/ref.js';
|
|
6
|
+
import { MduiElement } from '@mdui/shared/base/mdui-element.js';
|
|
5
7
|
import { HasSlotController } from '@mdui/shared/controllers/has-slot.js';
|
|
6
|
-
import { booleanConverter } from '@mdui/shared/helpers/decorator.js';
|
|
7
8
|
import { getInnerHtmlFromSlot } from '@mdui/shared/helpers/slot.js';
|
|
8
9
|
import { componentStyle } from '@mdui/shared/lit-styles/component-style.js';
|
|
9
10
|
import { topAppBarTitleStyle } from './top-app-bar-title-style.js';
|
|
@@ -25,7 +26,7 @@ import { topAppBarTitleStyle } from './top-app-bar-title-style.js';
|
|
|
25
26
|
* @csspart label 文本内容
|
|
26
27
|
* @csspart label-large 展开状态的文本内容
|
|
27
28
|
*/
|
|
28
|
-
|
|
29
|
+
let TopAppBarTitle = class TopAppBarTitle extends MduiElement {
|
|
29
30
|
constructor() {
|
|
30
31
|
super(...arguments);
|
|
31
32
|
/**
|
|
@@ -42,9 +43,16 @@ export let TopAppBarTitle = class TopAppBarTitle extends LitElement {
|
|
|
42
43
|
}
|
|
43
44
|
render() {
|
|
44
45
|
const hasLabelLargeSlot = this.hasSlotController.test('label-large');
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
:
|
|
46
|
+
const className = classMap({
|
|
47
|
+
shrink: this.shrink,
|
|
48
|
+
'variant-center-aligned': this.variant === 'center-aligned',
|
|
49
|
+
'variant-small': this.variant === 'small',
|
|
50
|
+
'variant-medium': this.variant === 'medium',
|
|
51
|
+
'variant-large': this.variant === 'large',
|
|
52
|
+
});
|
|
53
|
+
return html `<slot part="label" class="label ${className}" ${ref(this.defaultSlotRef)} @slotchange="${() => this.onSlotChange(hasLabelLargeSlot)}"></slot>${hasLabelLargeSlot
|
|
54
|
+
? html `<slot name="label-large" part="label-large" class="label-large ${className}"></slot>`
|
|
55
|
+
: html `<div ${ref(this.labelLargeRef)} part="label-large" class="label-large ${className}"></div>`}`;
|
|
48
56
|
}
|
|
49
57
|
/**
|
|
50
58
|
* default slot 变化时,同步到 label-large 中
|
|
@@ -62,15 +70,12 @@ TopAppBarTitle.styles = [
|
|
|
62
70
|
topAppBarTitleStyle,
|
|
63
71
|
];
|
|
64
72
|
__decorate([
|
|
65
|
-
|
|
73
|
+
state()
|
|
66
74
|
], TopAppBarTitle.prototype, "variant", void 0);
|
|
67
75
|
__decorate([
|
|
68
|
-
|
|
69
|
-
type: Boolean,
|
|
70
|
-
reflect: true,
|
|
71
|
-
converter: booleanConverter,
|
|
72
|
-
})
|
|
76
|
+
state()
|
|
73
77
|
], TopAppBarTitle.prototype, "shrink", void 0);
|
|
74
78
|
TopAppBarTitle = __decorate([
|
|
75
79
|
customElement('mdui-top-app-bar-title')
|
|
76
80
|
], TopAppBarTitle);
|
|
81
|
+
export { TopAppBarTitle };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { LayoutItemBase } from '../layout/layout-item-base.js';
|
|
2
2
|
import type { LayoutPlacement } from '../layout/helper.js';
|
|
3
3
|
import type { ScrollPaddingPosition } from '@mdui/shared/mixins/scrollBehavior.js';
|
|
4
|
-
import type { CSSResultGroup, TemplateResult } from 'lit';
|
|
4
|
+
import type { CSSResultGroup, PropertyValues, TemplateResult } from 'lit';
|
|
5
5
|
declare const TopAppBar_base: import("@open-wc/dedupe-mixin").Constructor<import("@mdui/shared/mixins/scrollBehavior.js").ScrollBehaviorMixinInterface> & typeof LayoutItemBase;
|
|
6
6
|
/**
|
|
7
7
|
* @summary 顶部应用栏组件
|
|
@@ -25,7 +25,7 @@ declare const TopAppBar_base: import("@open-wc/dedupe-mixin").Constructor<import
|
|
|
25
25
|
* @cssprop --shape-corner - 组件的圆角大小。可以指定一个具体的像素值;但更推荐[引用设计令牌](/docs/2/styles/design-tokens#shape-corner)
|
|
26
26
|
* @cssprop --z-index - 组件的 CSS 的 `z-index` 值
|
|
27
27
|
*/
|
|
28
|
-
export declare class TopAppBar extends TopAppBar_base {
|
|
28
|
+
export declare class TopAppBar extends TopAppBar_base<TopAppBarEventMap> {
|
|
29
29
|
static styles: CSSResultGroup;
|
|
30
30
|
/**
|
|
31
31
|
* 顶部应用栏形状。默认为 `small`。可选值为:
|
|
@@ -61,11 +61,17 @@ export declare class TopAppBar extends TopAppBar_base {
|
|
|
61
61
|
protected get layoutPlacement(): LayoutPlacement;
|
|
62
62
|
private onVariantChange;
|
|
63
63
|
private onShrinkChange;
|
|
64
|
-
|
|
64
|
+
protected firstUpdated(_changedProperties: PropertyValues): void;
|
|
65
65
|
protected render(): TemplateResult;
|
|
66
66
|
protected runScrollNoThreshold(isScrollingUp: boolean, scrollTop: number): void;
|
|
67
67
|
protected runScrollThreshold(isScrollingUp: boolean, scrollTop: number): void;
|
|
68
68
|
}
|
|
69
|
+
export interface TopAppBarEventMap {
|
|
70
|
+
show: CustomEvent<void>;
|
|
71
|
+
shown: CustomEvent<void>;
|
|
72
|
+
hide: CustomEvent<void>;
|
|
73
|
+
hidden: CustomEvent<void>;
|
|
74
|
+
}
|
|
69
75
|
declare global {
|
|
70
76
|
interface HTMLElementTagNameMap {
|
|
71
77
|
'mdui-top-app-bar': TopAppBar;
|
|
@@ -3,7 +3,6 @@ import { html } from 'lit';
|
|
|
3
3
|
import { customElement, property, queryAssignedElements, } from 'lit/decorators.js';
|
|
4
4
|
import { watch } from '@mdui/shared/decorators/watch.js';
|
|
5
5
|
import { booleanConverter } from '@mdui/shared/helpers/decorator.js';
|
|
6
|
-
import { emit } from '@mdui/shared/helpers/event.js';
|
|
7
6
|
import { componentStyle } from '@mdui/shared/lit-styles/component-style.js';
|
|
8
7
|
import { ScrollBehaviorMixin } from '@mdui/shared/mixins/scrollBehavior.js';
|
|
9
8
|
import { LayoutItemBase } from '../layout/layout-item-base.js';
|
|
@@ -30,7 +29,7 @@ import { topAppBarStyle } from './top-app-bar-style.js';
|
|
|
30
29
|
* @cssprop --shape-corner - 组件的圆角大小。可以指定一个具体的像素值;但更推荐[引用设计令牌](/docs/2/styles/design-tokens#shape-corner)
|
|
31
30
|
* @cssprop --z-index - 组件的 CSS 的 `z-index` 值
|
|
32
31
|
*/
|
|
33
|
-
|
|
32
|
+
let TopAppBar = class TopAppBar extends ScrollBehaviorMixin(LayoutItemBase) {
|
|
34
33
|
constructor() {
|
|
35
34
|
super(...arguments);
|
|
36
35
|
/**
|
|
@@ -64,7 +63,8 @@ export let TopAppBar = class TopAppBar extends ScrollBehaviorMixin(LayoutItemBas
|
|
|
64
63
|
async onVariantChange() {
|
|
65
64
|
if (this.hasUpdated) {
|
|
66
65
|
// variant 变更时,重新为 scrollTargetContainer 元素添加 padding-top。避免 top-app-bar 覆盖内容
|
|
67
|
-
this.addEventListener('transitionend', () => {
|
|
66
|
+
this.addEventListener('transitionend', async () => {
|
|
67
|
+
await this.scrollBehaviorDefinedController.whenDefined();
|
|
68
68
|
this.updateContainerPadding();
|
|
69
69
|
}, { once: true });
|
|
70
70
|
}
|
|
@@ -83,11 +83,11 @@ export let TopAppBar = class TopAppBar extends ScrollBehaviorMixin(LayoutItemBas
|
|
|
83
83
|
titleElement.shrink = this.shrink;
|
|
84
84
|
});
|
|
85
85
|
}
|
|
86
|
-
|
|
87
|
-
super.
|
|
86
|
+
firstUpdated(_changedProperties) {
|
|
87
|
+
super.firstUpdated(_changedProperties);
|
|
88
88
|
this.addEventListener('transitionend', (e) => {
|
|
89
89
|
if (e.target === this) {
|
|
90
|
-
emit(this
|
|
90
|
+
this.emit(this.hide ? 'hidden' : 'shown');
|
|
91
91
|
}
|
|
92
92
|
});
|
|
93
93
|
}
|
|
@@ -118,15 +118,15 @@ export let TopAppBar = class TopAppBar extends ScrollBehaviorMixin(LayoutItemBas
|
|
|
118
118
|
if (this.hasScrollBehavior('hide')) {
|
|
119
119
|
// 向下滚动
|
|
120
120
|
if (!isScrollingUp && !this.hide) {
|
|
121
|
-
const
|
|
122
|
-
if (
|
|
121
|
+
const eventProceeded = this.emit('hide', { cancelable: true });
|
|
122
|
+
if (eventProceeded) {
|
|
123
123
|
this.hide = true;
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
// 向上滚动
|
|
127
127
|
if (isScrollingUp && this.hide) {
|
|
128
|
-
const
|
|
129
|
-
if (
|
|
128
|
+
const eventProceeded = this.emit('show', { cancelable: true });
|
|
129
|
+
if (eventProceeded) {
|
|
130
130
|
this.hide = false;
|
|
131
131
|
}
|
|
132
132
|
}
|
|
@@ -176,3 +176,4 @@ __decorate([
|
|
|
176
176
|
TopAppBar = __decorate([
|
|
177
177
|
customElement('mdui-top-app-bar')
|
|
178
178
|
], TopAppBar);
|
|
179
|
+
export { TopAppBar };
|