Skip to content

Commit

Permalink
feat: prepare for TS defs generation (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan authored May 11, 2020
1 parent 788deea commit e68664d
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 26 deletions.
1 change: 1 addition & 0 deletions @types/interfaces.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type PrimarySection = 'navbar' | 'drawer';
6 changes: 3 additions & 3 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
],
"dependencies": {
"polymer": "^2.0.0",
"vaadin-themable-mixin": "vaadin/vaadin-themable-mixin#^1.2.0",
"vaadin-element-mixin": "vaadin/vaadin-element-mixin#^2.3.0",
"vaadin-themable-mixin": "vaadin/vaadin-themable-mixin#^1.6.1",
"vaadin-element-mixin": "vaadin/vaadin-element-mixin#^2.4.1",
"vaadin-lumo-styles": "vaadin/vaadin-lumo-styles#^1.6.0",
"vaadin-material-styles": "vaadin/vaadin-material-styles#^1.3.2",
"vaadin-button": "vaadin/vaadin-button#^2.3.0"
"vaadin-button": "vaadin/vaadin-button#^2.4.0-alpha1"
},
"devDependencies": {
"iron-component-page": "^3.0.0",
Expand Down
16 changes: 16 additions & 0 deletions gen-tsd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"excludeFiles": [
"wct.conf.js",
"index.html",
"src/detect-ios-navbar.js",
"src/safe-area-inset.js",
"demo/**/*",
"test/**/*",
"theme/**/*"
],
"autoImport": {
"./@types/interfaces": [
"PrimarySection"
]
}
}
12 changes: 12 additions & 0 deletions magi-p3-post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
files: [
'vaadin-app-layout.js',
'vaadin-drawer-toggle.js'
],
from: [
/import '\.\/theme\/lumo\/vaadin-(.+)\.js';/
],
to: [
`import './theme/lumo/vaadin-$1.js';\nexport * from './src/vaadin-$1.js';`
]
};
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
},
"homepage": "https://vaadin.com/components",
"files": [
"vaadin-*.d.ts",
"vaadin-*.js",
"@types",
"src",
"theme"
],
Expand Down
48 changes: 31 additions & 17 deletions src/vaadin-app-layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@
* Defines whether navbar or drawer will come first visually.
* - By default (`primary-section="navbar"`), the navbar takes the full available width and moves the drawer down.
* - If `primary-section="drawer"` is set, then the drawer will move the navbar, taking the full available height.
* @type {!PrimarySection}
*/
primarySection: {
type: String,
Expand All @@ -330,6 +331,7 @@
* Its default value depends on the viewport:
* - `true`, for desktop size views
* - `false`, for mobile size views
* @type {boolean}
*/
drawerOpened: {
type: Boolean,
Expand All @@ -342,6 +344,7 @@
/**
* Drawer is an overlay on top of the content
* Controlled via CSS using `--vaadin-app-layout-drawer-overlay: true|false`;
* @type {boolean}
*/
overlay: {
type: Boolean,
Expand All @@ -361,9 +364,7 @@
this.__closeOverlayDrawerListener = this.__closeOverlayDrawer.bind(this);
}

/**
* @private
*/
/** @protected */
connectedCallback() {
super.connectedCallback();

Expand Down Expand Up @@ -406,9 +407,7 @@
window.addEventListener('close-overlay-drawer', this.__closeOverlayDrawerListener);
}

/**
* @private
*/
/** @protected */
disconnectedCallback() {
super.disconnectedCallback();

Expand All @@ -427,13 +426,15 @@
window.dispatchEvent(new CustomEvent('close-overlay-drawer'));
}

/** @private */
_primarySectionObserver(value) {
const isValid = ['navbar', 'drawer'].indexOf(value) !== -1;
if (!isValid) {
this.set('primarySection', 'navbar');
}
}

/** @private */
_drawerOpenedObserver() {
const drawer = this.$.drawer;

Expand All @@ -448,37 +449,31 @@
}
}


/** @private */
_isShadyCSS() {
return window.ShadyCSS && !window.ShadyCSS.nativeCss;
}

/** @protected */
_afterFirstRender() {
this._blockAnimationUntilAfterNextRender();
this._updateOffsetSize();
}

/** @private */
_drawerToggleClick(e) {
e.stopPropagation();
this.drawerOpened = !this.drawerOpened;
}

/**
* App Layout listens to `close-overlay-drawer` on the window level.
* A custom event can be dispatched and the App Layout will close the drawer in overlay.
*
* That can be used, for instance, when a navigation occurs when user clicks in a menu item inside the drawer.
*
* See `dispatchCloseOverlayDrawerEvent()` helper method.
*
* @event close-overlay-drawer
*/
/** @private */
__closeOverlayDrawer() {
if (this.overlay) {
this.drawerOpened = false;
}
}

/** @protected */
_updateDrawerSize() {
const childCount = this.querySelectorAll('[slot=drawer]').length;
const drawer = this.$.drawer;
Expand All @@ -491,12 +486,14 @@
this._updateOffsetSize();
}

/** @private */
_resize() {
this._blockAnimationUntilAfterNextRender();
this._updateTouchOptimizedMode();
this._updateOverlayMode();
}

/** @protected */
_updateOffsetSize() {
const navbar = this.shadowRoot.querySelector('[part="navbar"]');
const navbarRect = navbar.getBoundingClientRect();
Expand Down Expand Up @@ -528,6 +525,7 @@
}
}

/** @protected */
_updateDrawerHeight() {
const {scrollHeight, offsetHeight} = this.$.drawer;
const height = scrollHeight > offsetHeight ? `${scrollHeight}px` : '100%';
Expand All @@ -541,6 +539,7 @@
}
}

/** @protected */
_updateOverlayMode() {
const overlay = this._getCustomPropertyValue('--vaadin-app-layout-drawer-overlay') == 'true';
const drawer = this.$.drawer;
Expand Down Expand Up @@ -572,10 +571,12 @@
// TODO(jouni): ARIA attributes. The drawer should act similar to a modal dialog when in ”overlay” mode
}

/** @protected */
_close() {
this.drawerOpened = false;
}

/** @private */
_getCustomPropertyValue(customProperty) {
let customPropertyValue;

Expand All @@ -589,6 +590,7 @@
return (customPropertyValue || '').trim().toLowerCase();
}

/** @protected */
_updateTouchOptimizedMode() {
const touchOptimized = this._getCustomPropertyValue('--vaadin-app-layout-touch-optimized') == 'true';

Expand Down Expand Up @@ -623,6 +625,7 @@
this._updateOffsetSize();
}

/** @protected */
_blockAnimationUntilAfterNextRender() {
this.setAttribute('no-anim', '');
Polymer.RenderStatus.afterNextRender(this, () => {
Expand All @@ -632,6 +635,17 @@
}
});
}

/**
* App Layout listens to `close-overlay-drawer` on the window level.
* A custom event can be dispatched and the App Layout will close the drawer in overlay.
*
* That can be used, for instance, when a navigation occurs when user clicks in a menu item inside the drawer.
*
* See `dispatchCloseOverlayDrawerEvent()` helper method.
*
* @event close-overlay-drawer
*/
}

customElements.define(AppLayoutElement.is, AppLayoutElement);
Expand Down
6 changes: 0 additions & 6 deletions src/vaadin-drawer-toggle.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
* </vaadin-app-layout>
* ```
*
* @memberof Vaadin
* @extends Vaadin.ButtonElement
* @demo demo/index.html
*/
Expand All @@ -95,11 +94,6 @@
this.dispatchEvent(new CustomEvent('drawer-toggle-click', {bubbles: true, composed: true}));
});
}

connectedCallback() {
super.connectedCallback();
}

}

customElements.define(DrawerToggleElement.is, DrawerToggleElement);
Expand Down

0 comments on commit e68664d

Please sign in to comment.