Skip to content

Commit

Permalink
experiment: add LitElement based version of app-layout
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan committed Dec 13, 2024
1 parent 885d7e9 commit 16c3aa1
Show file tree
Hide file tree
Showing 25 changed files with 195 additions and 9 deletions.
8 changes: 8 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 Expand Up @@ -138,6 +142,10 @@ export const AppLayoutMixin = (superclass) =>
connectedCallback() {
super.connectedCallback();

if (this.performUpdate) {
this.performUpdate();
}

this._blockAnimationUntilAfterNextRender();

window.addEventListener('resize', this.__boundResizeListener);
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,13 +1,13 @@
import { expect } from '@vaadin/chai-plugins';
import { enter, fixtureSync, nextFrame, space } from '@vaadin/testing-helpers';
import { enter, fixtureSync, nextFrame, nextRender, space } from '@vaadin/testing-helpers';
import sinon from 'sinon';
import '../vaadin-drawer-toggle.js';

describe('drawer-toggle', () => {
let toggle;

beforeEach(() => {
beforeEach(async () => {
toggle = fixtureSync('<vaadin-drawer-toggle></vaadin-drawer-toggle>');
await nextRender();
});

describe('custom element definition', () => {
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';

0 comments on commit 16c3aa1

Please sign in to comment.