Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

experiment: add LitElement based version of app-layout #8344

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/app-layout/src/vaadin-app-layout-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const AppLayoutMixin = (superclass) =>
i18n: {
type: Object,
observer: '__i18nChanged',
sync: true,
value: () => {
return {
drawer: 'Drawer',
Expand All @@ -64,6 +65,7 @@ export const AppLayoutMixin = (superclass) =>
notify: true,
reflectToAttribute: true,
observer: '__primarySectionChanged',
sync: true,
},

/**
Expand All @@ -80,6 +82,7 @@ export const AppLayoutMixin = (superclass) =>
value: true,
reflectToAttribute: true,
observer: '__drawerOpenedChanged',
sync: true,
},

/**
Expand All @@ -93,6 +96,7 @@ export const AppLayoutMixin = (superclass) =>
readOnly: true,
value: false,
reflectToAttribute: true,
sync: true,
},

/**
Expand Down
1 change: 1 addition & 0 deletions packages/app-layout/src/vaadin-lit-app-layout.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './vaadin-app-layout.js';
59 changes: 59 additions & 0 deletions packages/app-layout/src/vaadin-lit-app-layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* @license
* Copyright (c) 2018 - 2024 Vaadin Ltd.
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
*/
import './detect-ios-navbar.js';
import './safe-area-inset.js';
import { html, LitElement } from 'lit';
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
import { AppLayoutMixin } from './vaadin-app-layout-mixin.js';
import { appLayoutStyles } from './vaadin-app-layout-styles.js';

/**
* LitElement based version of `<vaadin-app-layout>` web component.
*
* ## Disclaimer
*
* This component is an experiment and not yet a part of Vaadin platform.
* There is no ETA regarding specific Vaadin version where it'll land.
* Feel free to try this code in your apps as per Apache 2.0 license.
*/
class AppLayout extends AppLayoutMixin(ElementMixin(ThemableMixin(PolylitMixin(LitElement)))) {
static get is() {
return 'vaadin-app-layout';
}

static get styles() {
return appLayoutStyles;
}

/** @protected */
render() {
return html`
<div part="navbar" id="navbarTop">
<slot name="navbar" @slotchange="${this._updateTouchOptimizedMode}"></slot>
</div>
<div part="backdrop" @click="${this._onBackdropClick}" @touchend="${this._onBackdropTouchend}"></div>
<div part="drawer" id="drawer">
<slot name="drawer" id="drawerSlot" @slotchange="${this._updateDrawerSize}"></slot>
</div>
<div content>
<slot></slot>
</div>
<div part="navbar" id="navbarBottom" bottom hidden>
<slot name="navbar-bottom"></slot>
</div>
<div hidden>
<slot id="touchSlot" name="navbar touch-optimized" @slotchange="${this._updateTouchOptimizedMode}"></slot>
</div>
`;
}
}

defineCustomElement(AppLayout);

export { AppLayout };
1 change: 1 addition & 0 deletions packages/app-layout/src/vaadin-lit-drawer-toggle.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './vaadin-drawer-toggle.js';
87 changes: 87 additions & 0 deletions packages/app-layout/src/vaadin-lit-drawer-toggle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/**
* @license
* Copyright (c) 2018 - 2024 Vaadin Ltd.
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
*/
import { html, LitElement } from 'lit';
import { buttonStyles } from '@vaadin/button/src/vaadin-button-base.js';
import { ButtonMixin } from '@vaadin/button/src/vaadin-button-mixin.js';
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
import { isEmptyTextNode } from '@vaadin/component-base/src/dom-utils.js';
import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
import { drawerToggle } from './vaadin-drawer-toggle-styles.js';

/**
* LitElement based version of `<vaadin-drawer-toggle>` web component.
*
* ## Disclaimer
*
* This component is an experiment and not yet a part of Vaadin platform.
* There is no ETA regarding specific Vaadin version where it'll land.
* Feel free to try this code in your apps as per Apache 2.0 license.
*/
class DrawerToggle extends ButtonMixin(DirMixin(ThemableMixin(PolylitMixin(LitElement)))) {
static get is() {
return 'vaadin-drawer-toggle';
}

static get styles() {
return [buttonStyles, drawerToggle];
}

static get properties() {
return {
ariaLabel: {
type: String,
value: 'Toggle navigation panel',
reflectToAttribute: true,
sync: true,
},

/** @private */
_showFallbackIcon: {
type: Boolean,
value: false,
},
};
}

constructor() {
super();

this.addEventListener('click', () => {
this.dispatchEvent(new CustomEvent('drawer-toggle-click', { bubbles: true, composed: true }));
});
}

/** @protected */
render() {
return html`
<slot id="slot" @slotchange="${this._toggleFallbackIcon}">
<div part="icon"></div>
</slot>
<div part="icon" ?hidden="${!this._showFallbackIcon}"></div>
`;
}

/** @protected */
ready() {
super.ready();

this._toggleFallbackIcon();
}

/** @private */
_toggleFallbackIcon() {
const nodes = this.$.slot.assignedNodes();

// Show fallback icon if there are 1-2 empty text nodes assigned to the default slot.
this._showFallbackIcon = nodes.length > 0 && nodes.every((node) => isEmptyTextNode(node));
}
}

defineCustomElement(DrawerToggle);

export { DrawerToggle };
3 changes: 3 additions & 0 deletions packages/app-layout/test/app-layout-lit.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import '../src/vaadin-lit-app-layout.js';
import '../src/vaadin-lit-drawer-toggle.js';
import './app-layout.common.js';
3 changes: 3 additions & 0 deletions packages/app-layout/test/app-layout-polymer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import '../vaadin-app-layout.js';
import '../vaadin-drawer-toggle.js';
import './app-layout.common.js';
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import {
oneEvent,
} from '@vaadin/testing-helpers';
import sinon from 'sinon';
import '../vaadin-app-layout.js';
import '../vaadin-drawer-toggle.js';

/**
* Resolves once the function is invoked on the given object.
Expand Down
2 changes: 2 additions & 0 deletions packages/app-layout/test/drawer-toggle-lit.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import '../src/vaadin-lit-drawer-toggle.js';
import './drawer-toggle.common.js';
2 changes: 2 additions & 0 deletions packages/app-layout/test/drawer-toggle-polymer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import '../vaadin-drawer-toggle.js';
import './drawer-toggle.common.js';
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { expect } from '@vaadin/chai-plugins';
import { enter, fixtureSync, nextFrame, space } from '@vaadin/testing-helpers';
import sinon from 'sinon';
import '../vaadin-drawer-toggle.js';

describe('drawer-toggle', () => {
let toggle;
Expand Down
3 changes: 3 additions & 0 deletions packages/app-layout/test/keyboard-desktop-lit.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import '../src/vaadin-lit-app-layout.js';
import '../src/vaadin-lit-drawer-toggle.js';
import './keyboard-desktop.common.js';
3 changes: 3 additions & 0 deletions packages/app-layout/test/keyboard-desktop-polymer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import '../vaadin-app-layout.js';
import '../vaadin-drawer-toggle.js';
import './keyboard-desktop.common.js';
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { expect } from '@vaadin/chai-plugins';
import { fixtureSync, nextFrame, nextRender } from '@vaadin/testing-helpers';
import { setViewport } from '@web/test-runner-commands';
import '../vaadin-app-layout.js';
import '../vaadin-drawer-toggle.js';
import { tab } from './helpers.js';

describe('desktop navigation', () => {
Expand Down
3 changes: 3 additions & 0 deletions packages/app-layout/test/keyboard-mobile-lit.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import '../src/vaadin-lit-app-layout.js';
import '../src/vaadin-lit-drawer-toggle.js';
import './keyboard-mobile.common.js';
3 changes: 3 additions & 0 deletions packages/app-layout/test/keyboard-mobile-polymer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import '../vaadin-app-layout.js';
import '../vaadin-drawer-toggle.js';
import './keyboard-mobile.common.js';
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { expect } from '@vaadin/chai-plugins';
import { fixtureSync, nextFrame, nextRender } from '@vaadin/testing-helpers';
import { setViewport } from '@web/test-runner-commands';
import '../vaadin-app-layout.js';
import '../vaadin-drawer-toggle.js';
import { esc, shiftTab, tab } from './helpers.js';

describe('mobile navigation', () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/app-layout/theme/lumo/vaadin-lit-app-layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import './vaadin-app-layout-styles.js';
import '../../src/vaadin-lit-app-layout.js';
2 changes: 2 additions & 0 deletions packages/app-layout/theme/lumo/vaadin-lit-drawer-toggle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import './vaadin-drawer-toggle-styles.js';
import '../../src/vaadin-lit-drawer-toggle.js';
2 changes: 2 additions & 0 deletions packages/app-layout/theme/material/vaadin-lit-app-layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import './vaadin-app-layout-styles.js';
import '../../src/vaadin-lit-app-layout.js';
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import './vaadin-drawer-toggle-styles.js';
import '../../src/vaadin-lit-drawer-toggle.js';
1 change: 1 addition & 0 deletions packages/app-layout/vaadin-lit-app-layout.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './src/vaadin-app-layout.js';
2 changes: 2 additions & 0 deletions packages/app-layout/vaadin-lit-app-layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import './theme/lumo/vaadin-lit-app-layout.js';
export * from './src/vaadin-lit-app-layout.js';
1 change: 1 addition & 0 deletions packages/app-layout/vaadin-lit-drawer-toggle.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './src/vaadin-drawer-toggle.js';
2 changes: 2 additions & 0 deletions packages/app-layout/vaadin-lit-drawer-toggle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import './theme/lumo/vaadin-lit-drawer-toggle.js';
export * from './src/vaadin-lit-drawer-toggle.js';
Loading