移动目录
This commit is contained in:
1
mdui_patched/components/navigation-rail/navigation-rail-item-style.d.ts
vendored
Normal file
1
mdui_patched/components/navigation-rail/navigation-rail-item-style.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export declare const navigationRailItemStyle: import("lit").CSSResult;
|
||||
@@ -0,0 +1,2 @@
|
||||
import { css } from 'lit';
|
||||
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))}`;
|
||||
80
mdui_patched/components/navigation-rail/navigation-rail-item.d.ts
vendored
Normal file
80
mdui_patched/components/navigation-rail/navigation-rail-item.d.ts
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
import { MduiElement } from '@mdui/shared/base/mdui-element.js';
|
||||
import '../icon.js';
|
||||
import type { Ripple } from '../ripple/index.js';
|
||||
import type { CSSResultGroup, TemplateResult } from 'lit';
|
||||
declare const NavigationRailItem_base: import("@lit/reactive-element/decorators/base.js").Constructor<import("@mdui/shared/mixins/anchor.js").AnchorMixinInterface> & import("@lit/reactive-element/decorators/base.js").Constructor<import("../ripple/ripple-mixin.js").RippleMixinInterface> & import("@lit/reactive-element/decorators/base.js").Constructor<import("@mdui/shared/mixins/focusable.js").FocusableMixinInterface> & typeof MduiElement;
|
||||
/**
|
||||
* @summary 侧边导航项组件。需配合 `<mdui-navigation-rail>` 组件使用
|
||||
*
|
||||
* ```html
|
||||
* <mdui-navigation-rail>
|
||||
* ..<mdui-navigation-rail-item icon="watch_later">Recent</mdui-navigation-rail-item>
|
||||
* ..<mdui-navigation-rail-item icon="image">Images</mdui-navigation-rail-item>
|
||||
* ..<mdui-navigation-rail-item icon="library_music">Library</mdui-navigation-rail-item>
|
||||
* </mdui-navigation-rail>
|
||||
* ```
|
||||
*
|
||||
* @slot - 文本内容
|
||||
* @slot icon - 图标
|
||||
* @slot active-icon - 激活状态的图标
|
||||
* @slot badge - 徽标
|
||||
*
|
||||
* @event focus - 获得焦点时触发
|
||||
* @event blur - 失去焦点时触发
|
||||
*
|
||||
* @csspart container - 导航项容器
|
||||
* @csspart indicator - 指示器
|
||||
* @csspart badge - 徽标
|
||||
* @csspart icon - 图标
|
||||
* @csspart active-icon - 激活状态的图标
|
||||
* @csspart label - 文本内容
|
||||
*
|
||||
* @cssprop --shape-corner-indicator - 指示器的圆角大小。可以指定一个具体的像素值;但更推荐引用[设计令牌](/docs/2/styles/design-tokens#shape-corner)
|
||||
*/
|
||||
export declare class NavigationRailItem extends NavigationRailItem_base<NavigationRailItemEventMap> {
|
||||
static styles: CSSResultGroup;
|
||||
/**
|
||||
* 未激活状态下的 Material Icons 图标名。也可以通过 `slot="icon"` 设置
|
||||
*/
|
||||
icon?: string;
|
||||
/**
|
||||
* 激活状态下的 Material Icons 图标名。也可以通过 `slot="active-icon"` 设置
|
||||
*/
|
||||
activeIcon?: string;
|
||||
/**
|
||||
* 导航项的值
|
||||
*/
|
||||
value?: string;
|
||||
/**
|
||||
* 是否为激活状态,由 `<mdui-navigation-rail>` 组件控制该参数
|
||||
*/
|
||||
protected active: boolean;
|
||||
/**
|
||||
* 是否是初始状态,不显示动画。由 `<mdui-navigation-rail>` 组件控制该参数
|
||||
*/
|
||||
protected isInitial: boolean;
|
||||
/**
|
||||
* 导航栏的位置,由 `<mdui-navigation-rail>` 组件控制该参数
|
||||
*/
|
||||
protected placement: 'left' | 'right';
|
||||
private disabled;
|
||||
protected readonly key: number;
|
||||
private readonly rippleRef;
|
||||
private readonly hasSlotController;
|
||||
protected get rippleElement(): Ripple;
|
||||
protected get rippleDisabled(): boolean;
|
||||
protected get focusElement(): HTMLElement | null;
|
||||
protected get focusDisabled(): boolean;
|
||||
protected render(): TemplateResult;
|
||||
private renderInner;
|
||||
}
|
||||
export interface NavigationRailItemEventMap {
|
||||
focus: FocusEvent;
|
||||
blur: FocusEvent;
|
||||
}
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
'mdui-navigation-rail-item': NavigationRailItem;
|
||||
}
|
||||
}
|
||||
export {};
|
||||
141
mdui_patched/components/navigation-rail/navigation-rail-item.js
Normal file
141
mdui_patched/components/navigation-rail/navigation-rail-item.js
Normal file
@@ -0,0 +1,141 @@
|
||||
import { __decorate } from "tslib";
|
||||
import { html, nothing } from 'lit';
|
||||
import { customElement, property, state } from 'lit/decorators.js';
|
||||
import { classMap } from 'lit/directives/class-map.js';
|
||||
import { createRef, ref } from 'lit/directives/ref.js';
|
||||
import cc from 'classcat';
|
||||
import { MduiElement } from '@mdui/shared/base/mdui-element.js';
|
||||
import { HasSlotController } from '@mdui/shared/controllers/has-slot.js';
|
||||
import { booleanConverter } from '@mdui/shared/helpers/decorator.js';
|
||||
import { nothingTemplate } from '@mdui/shared/helpers/template.js';
|
||||
import { uniqueId } from '@mdui/shared/helpers/uniqueId.js';
|
||||
import { componentStyle } from '@mdui/shared/lit-styles/component-style.js';
|
||||
import { AnchorMixin } from '@mdui/shared/mixins/anchor.js';
|
||||
import { FocusableMixin } from '@mdui/shared/mixins/focusable.js';
|
||||
import '../icon.js';
|
||||
import { RippleMixin } from '../ripple/ripple-mixin.js';
|
||||
import { navigationRailItemStyle } from './navigation-rail-item-style.js';
|
||||
/**
|
||||
* @summary 侧边导航项组件。需配合 `<mdui-navigation-rail>` 组件使用
|
||||
*
|
||||
* ```html
|
||||
* <mdui-navigation-rail>
|
||||
* ..<mdui-navigation-rail-item icon="watch_later">Recent</mdui-navigation-rail-item>
|
||||
* ..<mdui-navigation-rail-item icon="image">Images</mdui-navigation-rail-item>
|
||||
* ..<mdui-navigation-rail-item icon="library_music">Library</mdui-navigation-rail-item>
|
||||
* </mdui-navigation-rail>
|
||||
* ```
|
||||
*
|
||||
* @slot - 文本内容
|
||||
* @slot icon - 图标
|
||||
* @slot active-icon - 激活状态的图标
|
||||
* @slot badge - 徽标
|
||||
*
|
||||
* @event focus - 获得焦点时触发
|
||||
* @event blur - 失去焦点时触发
|
||||
*
|
||||
* @csspart container - 导航项容器
|
||||
* @csspart indicator - 指示器
|
||||
* @csspart badge - 徽标
|
||||
* @csspart icon - 图标
|
||||
* @csspart active-icon - 激活状态的图标
|
||||
* @csspart label - 文本内容
|
||||
*
|
||||
* @cssprop --shape-corner-indicator - 指示器的圆角大小。可以指定一个具体的像素值;但更推荐引用[设计令牌](/docs/2/styles/design-tokens#shape-corner)
|
||||
*/
|
||||
let NavigationRailItem = class NavigationRailItem extends AnchorMixin(RippleMixin(FocusableMixin(MduiElement))) {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
/**
|
||||
* 是否为激活状态,由 `<mdui-navigation-rail>` 组件控制该参数
|
||||
*/
|
||||
this.active = false;
|
||||
/**
|
||||
* 是否是初始状态,不显示动画。由 `<mdui-navigation-rail>` 组件控制该参数
|
||||
*/
|
||||
this.isInitial = true;
|
||||
/**
|
||||
* 导航栏的位置,由 `<mdui-navigation-rail>` 组件控制该参数
|
||||
*/
|
||||
this.placement = 'left';
|
||||
// 是否禁用该元素,该组件没有禁用状态
|
||||
this.disabled = false;
|
||||
// 每一个 `<mdui-navigation-rail-item>` 元素都添加一个唯一的 key
|
||||
this.key = uniqueId();
|
||||
this.rippleRef = createRef();
|
||||
this.hasSlotController = new HasSlotController(this, '[default]', 'active-icon');
|
||||
}
|
||||
get rippleElement() {
|
||||
return this.rippleRef.value;
|
||||
}
|
||||
get rippleDisabled() {
|
||||
return this.disabled;
|
||||
}
|
||||
get focusElement() {
|
||||
return this.href ? this.renderRoot?.querySelector('._a') : this;
|
||||
}
|
||||
get focusDisabled() {
|
||||
return this.disabled;
|
||||
}
|
||||
render() {
|
||||
const hasDefaultSlot = this.hasSlotController.test('[default]');
|
||||
const className = cc({
|
||||
container: true,
|
||||
'has-label': hasDefaultSlot,
|
||||
'has-active-icon': this.activeIcon || this.hasSlotController.test('active-icon'),
|
||||
initial: this.isInitial,
|
||||
});
|
||||
return html `${this.href
|
||||
? this.renderAnchor({
|
||||
part: 'container',
|
||||
className,
|
||||
content: this.renderInner(hasDefaultSlot),
|
||||
})
|
||||
: html `<div part="container" class="${className}">${this.renderInner(hasDefaultSlot)}</div>`}<mdui-ripple .noRipple="${!this.active || this.noRipple}" ${ref(this.rippleRef)}></mdui-ripple>`;
|
||||
}
|
||||
renderInner(hasDefaultSlot) {
|
||||
return html `<div part="indicator" class="indicator"><slot name="badge" part="badge" class="${classMap({
|
||||
badge: true,
|
||||
'placement-right': this.placement === 'right',
|
||||
})}"></slot><slot name="active-icon" part="active-icon" class="active-icon">${this.activeIcon
|
||||
? html `<mdui-icon name="${this.activeIcon}"></mdui-icon>`
|
||||
: nothingTemplate}</slot><slot name="icon" part="icon" class="icon">${this.icon
|
||||
? html `<mdui-icon name="${this.icon}"></mdui-icon>`
|
||||
: nothingTemplate}</slot></div>${hasDefaultSlot
|
||||
? html `<slot part="label" class="label"></slot>`
|
||||
: nothing}`;
|
||||
}
|
||||
};
|
||||
NavigationRailItem.styles = [
|
||||
componentStyle,
|
||||
navigationRailItemStyle,
|
||||
];
|
||||
__decorate([
|
||||
property({ reflect: true })
|
||||
], NavigationRailItem.prototype, "icon", void 0);
|
||||
__decorate([
|
||||
property({ reflect: true, attribute: 'active-icon' })
|
||||
], NavigationRailItem.prototype, "activeIcon", void 0);
|
||||
__decorate([
|
||||
property({ reflect: true })
|
||||
], NavigationRailItem.prototype, "value", void 0);
|
||||
__decorate([
|
||||
property({
|
||||
type: Boolean,
|
||||
reflect: true,
|
||||
converter: booleanConverter,
|
||||
})
|
||||
], NavigationRailItem.prototype, "active", void 0);
|
||||
__decorate([
|
||||
state()
|
||||
], NavigationRailItem.prototype, "isInitial", void 0);
|
||||
__decorate([
|
||||
state()
|
||||
], NavigationRailItem.prototype, "placement", void 0);
|
||||
__decorate([
|
||||
state()
|
||||
], NavigationRailItem.prototype, "disabled", void 0);
|
||||
NavigationRailItem = __decorate([
|
||||
customElement('mdui-navigation-rail-item')
|
||||
], NavigationRailItem);
|
||||
export { NavigationRailItem };
|
||||
1
mdui_patched/components/navigation-rail/navigation-rail-style.d.ts
vendored
Normal file
1
mdui_patched/components/navigation-rail/navigation-rail-style.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export declare const navigationRailStyle: import("lit").CSSResult;
|
||||
@@ -0,0 +1,2 @@
|
||||
import { css } from 'lit';
|
||||
export const navigationRailStyle = css `:host{--shape-corner:var(--mdui-shape-corner-none);--z-index:2000;position:fixed;top:0;bottom:0;left:0;display:flex;flex-direction:column;align-items:center;border-radius:0 var(--shape-corner) var(--shape-corner) 0;z-index:var(--z-index);width:5rem;background-color:rgb(var(--mdui-color-surface));padding:.375rem .75rem}:host([contained]:not([contained=false i])){position:absolute}:host([divider]:not([divider=false i])){border-right:.0625rem solid rgb(var(--mdui-color-surface-variant));width:5.0625rem}:host([placement=right]){left:initial;right:0;border-radius:var(--shape-corner) 0 0 var(--shape-corner)}:host([placement=right][divider]:not([divider=false i])){border-right:none;border-left:.0625rem solid rgb(var(--mdui-color-surface-variant))}.bottom,.items,.top{display:flex;flex-direction:column;align-items:center;width:100%}.top{margin-bottom:1.75rem}.bottom{margin-top:1.75rem}::slotted([slot=bottom]),::slotted([slot=top]),::slotted(mdui-navigation-rail-item){margin-top:.375rem;margin-bottom:.375rem}:host([alignment=start]) .top-spacer{flex-grow:0}:host([alignment=start]) .bottom-spacer{flex-grow:1}:host([alignment=end]) .top-spacer{flex-grow:1}:host([alignment=end]) .bottom-spacer{flex-grow:0}:host([alignment=center]){justify-content:center}:host([alignment=center]) .bottom,:host([alignment=center]) .top{position:absolute}:host([alignment=center]) .top{top:.375rem}:host([alignment=center]) .bottom{bottom:.375rem}`;
|
||||
88
mdui_patched/components/navigation-rail/navigation-rail.d.ts
vendored
Normal file
88
mdui_patched/components/navigation-rail/navigation-rail.d.ts
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
import '@mdui/jq/methods/css.js';
|
||||
import '@mdui/jq/methods/innerWidth.js';
|
||||
import { LayoutItemBase } from '../layout/layout-item-base.js';
|
||||
import type { LayoutPlacement } from '../layout/helper.js';
|
||||
import type { CSSResultGroup, TemplateResult } from 'lit';
|
||||
/**
|
||||
* @summary 侧边导航栏组件。需配合 `<mdui-navigation-rail-item>` 组件使用
|
||||
*
|
||||
* ```html
|
||||
* <mdui-navigation-rail>
|
||||
* ..<mdui-navigation-rail-item icon="watch_later">Recent</mdui-navigation-rail-item>
|
||||
* ..<mdui-navigation-rail-item icon="image">Images</mdui-navigation-rail-item>
|
||||
* ..<mdui-navigation-rail-item icon="library_music">Library</mdui-navigation-rail-item>
|
||||
* </mdui-navigation-rail>
|
||||
* ```
|
||||
*
|
||||
* @event change - 值变化时触发
|
||||
*
|
||||
* @slot - `<mdui-navigation-rail-item>` 组件
|
||||
* @slot top - 顶部的元素
|
||||
* @slot bottom - 底部的元素
|
||||
*
|
||||
* @csspart top - 顶部元素的容器
|
||||
* @csspart bottom - 底部元素的容器
|
||||
* @csspart items - `<mdui-navigation-rail-item>` 组件的容器
|
||||
*
|
||||
* @cssprop --shape-corner - 组件的圆角大小。可以指定一个具体的像素值;但更推荐引用[设计令牌](/docs/2/styles/design-tokens#shape-corner)
|
||||
* @cssprop --z-index - 组件的 CSS `z-index` 值
|
||||
*/
|
||||
export declare class NavigationRail extends LayoutItemBase<NavigationRailEventMap> {
|
||||
static styles: CSSResultGroup;
|
||||
/**
|
||||
* 当前选中的 `<mdui-navigation-rail-item>` 的值
|
||||
*/
|
||||
value?: string;
|
||||
/**
|
||||
* 导航栏的位置。可选值包括:
|
||||
*
|
||||
* * `left`:左侧
|
||||
* * `right`:右侧
|
||||
*/
|
||||
placement: /*左侧*/ 'left' | /*右侧*/ 'right';
|
||||
/**
|
||||
* `<mdui-navigation-rail-item>` 元素的对齐方式。可选值包括:
|
||||
*
|
||||
* * `start`:顶部对齐
|
||||
* * `center`:居中对齐
|
||||
* * `end`:底部对齐
|
||||
*/
|
||||
alignment: /*顶部对齐*/ 'start' | /*居中对齐*/ 'center' | /*底部对齐*/ 'end';
|
||||
/**
|
||||
* 默认情况下,导航栏相对于 `body` 元素显示。当该参数设置为 `true` 时,导航栏将相对于其父元素显示。
|
||||
*
|
||||
* **Note**:设置该属性时,必须在父元素上手动设置样式 `position: relative;`。
|
||||
*/
|
||||
contained: boolean;
|
||||
/**
|
||||
* 是否在导航栏和页面内容之间添加分割线
|
||||
*/
|
||||
divider: boolean;
|
||||
private activeKey;
|
||||
private readonly items;
|
||||
private readonly hasSlotController;
|
||||
private readonly definedController;
|
||||
private isInitial;
|
||||
protected get layoutPlacement(): LayoutPlacement;
|
||||
private get parentTarget();
|
||||
private get isRight();
|
||||
private get paddingValue();
|
||||
private onActiveKeyChange;
|
||||
private onValueChange;
|
||||
private onContainedChange;
|
||||
private onPlacementChange;
|
||||
connectedCallback(): void;
|
||||
disconnectedCallback(): void;
|
||||
protected render(): TemplateResult;
|
||||
private onClick;
|
||||
private updateItems;
|
||||
private onSlotChange;
|
||||
}
|
||||
export interface NavigationRailEventMap {
|
||||
change: CustomEvent<void>;
|
||||
}
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
'mdui-navigation-rail': NavigationRail;
|
||||
}
|
||||
}
|
||||
238
mdui_patched/components/navigation-rail/navigation-rail.js
Normal file
238
mdui_patched/components/navigation-rail/navigation-rail.js
Normal file
@@ -0,0 +1,238 @@
|
||||
import { __decorate } from "tslib";
|
||||
import { html } from 'lit';
|
||||
import { customElement, property, queryAssignedElements, state, } from 'lit/decorators.js';
|
||||
import { when } from 'lit/directives/when.js';
|
||||
import { $ } from '@mdui/jq/$.js';
|
||||
import '@mdui/jq/methods/css.js';
|
||||
import '@mdui/jq/methods/innerWidth.js';
|
||||
import { DefinedController } from '@mdui/shared/controllers/defined.js';
|
||||
import { HasSlotController } from '@mdui/shared/controllers/has-slot.js';
|
||||
import { watch } from '@mdui/shared/decorators/watch.js';
|
||||
import { booleanConverter } from '@mdui/shared/helpers/decorator.js';
|
||||
import { componentStyle } from '@mdui/shared/lit-styles/component-style.js';
|
||||
import { LayoutItemBase } from '../layout/layout-item-base.js';
|
||||
import { navigationRailStyle } from './navigation-rail-style.js';
|
||||
/**
|
||||
* @summary 侧边导航栏组件。需配合 `<mdui-navigation-rail-item>` 组件使用
|
||||
*
|
||||
* ```html
|
||||
* <mdui-navigation-rail>
|
||||
* ..<mdui-navigation-rail-item icon="watch_later">Recent</mdui-navigation-rail-item>
|
||||
* ..<mdui-navigation-rail-item icon="image">Images</mdui-navigation-rail-item>
|
||||
* ..<mdui-navigation-rail-item icon="library_music">Library</mdui-navigation-rail-item>
|
||||
* </mdui-navigation-rail>
|
||||
* ```
|
||||
*
|
||||
* @event change - 值变化时触发
|
||||
*
|
||||
* @slot - `<mdui-navigation-rail-item>` 组件
|
||||
* @slot top - 顶部的元素
|
||||
* @slot bottom - 底部的元素
|
||||
*
|
||||
* @csspart top - 顶部元素的容器
|
||||
* @csspart bottom - 底部元素的容器
|
||||
* @csspart items - `<mdui-navigation-rail-item>` 组件的容器
|
||||
*
|
||||
* @cssprop --shape-corner - 组件的圆角大小。可以指定一个具体的像素值;但更推荐引用[设计令牌](/docs/2/styles/design-tokens#shape-corner)
|
||||
* @cssprop --z-index - 组件的 CSS `z-index` 值
|
||||
*/
|
||||
let NavigationRail = class NavigationRail extends LayoutItemBase {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
/**
|
||||
* 导航栏的位置。可选值包括:
|
||||
*
|
||||
* * `left`:左侧
|
||||
* * `right`:右侧
|
||||
*/
|
||||
this.placement = 'left';
|
||||
/**
|
||||
* `<mdui-navigation-rail-item>` 元素的对齐方式。可选值包括:
|
||||
*
|
||||
* * `start`:顶部对齐
|
||||
* * `center`:居中对齐
|
||||
* * `end`:底部对齐
|
||||
*/
|
||||
this.alignment = 'start';
|
||||
/**
|
||||
* 默认情况下,导航栏相对于 `body` 元素显示。当该参数设置为 `true` 时,导航栏将相对于其父元素显示。
|
||||
*
|
||||
* **Note**:设置该属性时,必须在父元素上手动设置样式 `position: relative;`。
|
||||
*/
|
||||
this.contained = false;
|
||||
/**
|
||||
* 是否在导航栏和页面内容之间添加分割线
|
||||
*/
|
||||
this.divider = false;
|
||||
// 因为 navigation-rail-item 的 value 可能会重复,所以在每个 navigation-rail-item 元素上都添加了一个唯一的 key,通过 activeKey 来记录激活状态的 key
|
||||
this.activeKey = 0;
|
||||
this.hasSlotController = new HasSlotController(this, 'top', 'bottom');
|
||||
this.definedController = new DefinedController(this, {
|
||||
relatedElements: ['mdui-navigation-rail-item'],
|
||||
});
|
||||
// 是否是初始状态,初始状态不触发事件,不执行动画
|
||||
this.isInitial = true;
|
||||
}
|
||||
get layoutPlacement() {
|
||||
return this.placement;
|
||||
}
|
||||
get parentTarget() {
|
||||
return this.contained || this.isParentLayout
|
||||
? this.parentElement
|
||||
: document.body;
|
||||
}
|
||||
get isRight() {
|
||||
return this.placement === 'right';
|
||||
}
|
||||
get paddingValue() {
|
||||
return ['fixed', 'absolute'].includes($(this).css('position'))
|
||||
? this.offsetWidth
|
||||
: undefined;
|
||||
}
|
||||
async onActiveKeyChange() {
|
||||
await this.definedController.whenDefined();
|
||||
// 根据 activeKey 读取对应 navigation-rail-item 的值
|
||||
const item = this.items.find((item) => item.key === this.activeKey);
|
||||
this.value = item?.value;
|
||||
if (!this.isInitial) {
|
||||
this.emit('change');
|
||||
}
|
||||
}
|
||||
async onValueChange() {
|
||||
this.isInitial = !this.hasUpdated;
|
||||
await this.definedController.whenDefined();
|
||||
const item = this.items.find((item) => item.value === this.value);
|
||||
this.activeKey = item?.key ?? 0;
|
||||
this.updateItems();
|
||||
}
|
||||
async onContainedChange() {
|
||||
if (this.isParentLayout) {
|
||||
return;
|
||||
}
|
||||
await this.definedController.whenDefined();
|
||||
$(document.body).css({
|
||||
paddingLeft: this.contained || this.isRight ? null : this.paddingValue,
|
||||
paddingRight: this.contained || !this.isRight ? null : this.paddingValue,
|
||||
});
|
||||
$(this.parentElement).css({
|
||||
paddingLeft: this.contained && !this.isRight ? this.paddingValue : null,
|
||||
paddingRight: this.contained && this.isRight ? this.paddingValue : null,
|
||||
});
|
||||
}
|
||||
async onPlacementChange() {
|
||||
await this.definedController.whenDefined();
|
||||
this.layoutManager?.updateLayout(this);
|
||||
this.items.forEach((item) => {
|
||||
item.placement = this.placement;
|
||||
});
|
||||
if (!this.isParentLayout) {
|
||||
$(this.parentTarget).css({
|
||||
paddingLeft: this.isRight ? null : this.paddingValue,
|
||||
paddingRight: this.isRight ? this.paddingValue : null,
|
||||
});
|
||||
}
|
||||
}
|
||||
connectedCallback() {
|
||||
super.connectedCallback();
|
||||
if (!this.isParentLayout) {
|
||||
this.definedController.whenDefined().then(() => {
|
||||
$(this.parentTarget).css({
|
||||
paddingLeft: this.isRight ? null : this.paddingValue,
|
||||
paddingRight: this.isRight ? this.paddingValue : null,
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
disconnectedCallback() {
|
||||
super.disconnectedCallback();
|
||||
if (!this.isParentLayout && this.definedController.isDefined()) {
|
||||
$(this.parentTarget).css({
|
||||
paddingLeft: this.isRight ? undefined : null,
|
||||
paddingRight: this.isRight ? null : undefined,
|
||||
});
|
||||
}
|
||||
}
|
||||
render() {
|
||||
const hasTopSlot = this.hasSlotController.test('top');
|
||||
const hasBottomSlot = this.hasSlotController.test('bottom');
|
||||
return html `${when(hasTopSlot, () => html `<slot name="top" part="top" class="top"></slot>`)} <span class="top-spacer"></span><slot part="items" class="items" @slotchange="${this.onSlotChange}" @click="${this.onClick}"></slot><span class="bottom-spacer"></span> ${when(hasBottomSlot, () => html `<slot name="bottom" part="bottom" class="bottom"></slot>`)}`;
|
||||
}
|
||||
onClick(event) {
|
||||
// event.button 为 0 时,为鼠标左键点击。忽略鼠标中键和右键
|
||||
if (event.button) {
|
||||
return;
|
||||
}
|
||||
const target = event.target;
|
||||
const item = target.closest('mdui-navigation-rail-item');
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
this.activeKey = item.key;
|
||||
this.isInitial = false;
|
||||
this.updateItems();
|
||||
}
|
||||
updateItems() {
|
||||
this.items.forEach((item) => {
|
||||
item.active = this.activeKey === item.key;
|
||||
item.placement = this.placement;
|
||||
item.isInitial = this.isInitial;
|
||||
});
|
||||
}
|
||||
async onSlotChange() {
|
||||
await this.definedController.whenDefined();
|
||||
this.updateItems();
|
||||
}
|
||||
};
|
||||
NavigationRail.styles = [
|
||||
componentStyle,
|
||||
navigationRailStyle,
|
||||
];
|
||||
__decorate([
|
||||
property({ reflect: true })
|
||||
], NavigationRail.prototype, "value", void 0);
|
||||
__decorate([
|
||||
property({ reflect: true })
|
||||
// eslint-disable-next-line prettier/prettier
|
||||
], NavigationRail.prototype, "placement", void 0);
|
||||
__decorate([
|
||||
property({ reflect: true })
|
||||
], NavigationRail.prototype, "alignment", void 0);
|
||||
__decorate([
|
||||
property({
|
||||
type: Boolean,
|
||||
reflect: true,
|
||||
converter: booleanConverter,
|
||||
})
|
||||
], NavigationRail.prototype, "contained", void 0);
|
||||
__decorate([
|
||||
property({
|
||||
type: Boolean,
|
||||
reflect: true,
|
||||
converter: booleanConverter,
|
||||
})
|
||||
], NavigationRail.prototype, "divider", void 0);
|
||||
__decorate([
|
||||
state()
|
||||
], NavigationRail.prototype, "activeKey", void 0);
|
||||
__decorate([
|
||||
queryAssignedElements({
|
||||
selector: 'mdui-navigation-rail-item',
|
||||
flatten: true,
|
||||
})
|
||||
], NavigationRail.prototype, "items", void 0);
|
||||
__decorate([
|
||||
watch('activeKey', true)
|
||||
], NavigationRail.prototype, "onActiveKeyChange", null);
|
||||
__decorate([
|
||||
watch('value')
|
||||
], NavigationRail.prototype, "onValueChange", null);
|
||||
__decorate([
|
||||
watch('contained', true)
|
||||
], NavigationRail.prototype, "onContainedChange", null);
|
||||
__decorate([
|
||||
watch('placement', true)
|
||||
], NavigationRail.prototype, "onPlacementChange", null);
|
||||
NavigationRail = __decorate([
|
||||
customElement('mdui-navigation-rail')
|
||||
], NavigationRail);
|
||||
export { NavigationRail };
|
||||
Reference in New Issue
Block a user