Skip to content

Commit

Permalink
refactor: rename theme property to _theme, deprecate theme (#3529)
Browse files Browse the repository at this point in the history
Co-authored-by: Marcin Sikorski <marcin.s@xml-int.com>
  • Loading branch information
vursen and Marcin Sikorski authored Mar 11, 2022
1 parent 189177b commit 7634ebc
Show file tree
Hide file tree
Showing 33 changed files with 153 additions and 92 deletions.
6 changes: 3 additions & 3 deletions packages/avatar-group/src/vaadin-avatar-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class AvatarGroup extends ResizeMixin(ElementMixin(ThemableMixin(PolymerElement)
abbr="[[item.abbr]]"
img="[[item.img]]"
part="avatar"
theme$="[[theme]]"
theme$="[[_theme]]"
i18n="[[i18n]]"
color-index="[[item.colorIndex]]"
></vaadin-avatar>
Expand All @@ -127,7 +127,7 @@ class AvatarGroup extends ResizeMixin(ElementMixin(ThemableMixin(PolymerElement)
part="avatar"
hidden$="[[__computeMoreHidden(items.length, __itemsInView, __maxReached)]]"
abbr="[[__computeMore(items.length, __itemsInView, maxItemsVisible)]]"
theme$="[[theme]]"
theme$="[[_theme]]"
on-click="_onOverflowClick"
on-keydown="_onOverflowKeyDown"
aria-haspopup="listbox"
Expand All @@ -144,7 +144,7 @@ class AvatarGroup extends ResizeMixin(ElementMixin(ThemableMixin(PolymerElement)
img="[[item.img]]"
i18n="[[i18n]]"
part="avatar"
theme$="[[theme]]"
theme$="[[_theme]]"
color-index="[[item.colorIndex]]"
tabindex="-1"
aria-hidden="true"
Expand Down
2 changes: 1 addition & 1 deletion packages/combo-box/src/vaadin-combo-box-light.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class ComboBoxLight extends ComboBoxDataProviderMixin(ComboBoxMixin(ThemableMixi
_item-id-path="[[itemIdPath]]"
_item-label-path="[[itemLabelPath]]"
loading="[[loading]]"
theme="[[theme]]"
theme="[[_theme]]"
></vaadin-combo-box-dropdown>
`;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/combo-box/src/vaadin-combo-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class ComboBox extends ComboBoxDataProviderMixin(
readonly="[[readonly]]"
disabled="[[disabled]]"
invalid="[[invalid]]"
theme$="[[theme]]"
theme$="[[_theme]]"
>
<slot name="prefix" slot="prefix"></slot>
<slot name="input"></slot>
Expand Down Expand Up @@ -207,7 +207,7 @@ class ComboBox extends ComboBoxDataProviderMixin(
_item-id-path="[[itemIdPath]]"
_item-label-path="[[itemLabelPath]]"
loading="[[loading]]"
theme="[[theme]]"
theme="[[_theme]]"
></vaadin-combo-box-dropdown>
`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class ConfirmDialogDialog extends Dialog {
on-opened-changed="_onOverlayOpened"
on-mousedown="_bringOverlayToFront"
on-touchstart="_bringOverlayToFront"
theme$="[[theme]]"
theme$="[[_theme]]"
modeless="[[modeless]]"
with-backdrop="[[!modeless]]"
resizable$="[[resizable]]"
Expand Down
2 changes: 1 addition & 1 deletion packages/confirm-dialog/src/vaadin-confirm-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class ConfirmDialog extends SlotMixin(ElementMixin(ThemePropertyMixin(PolymerEle
id="dialog"
opened="{{opened}}"
aria-label="[[_getAriaLabel(header)]]"
theme$="[[theme]]"
theme$="[[_theme]]"
no-close-on-outside-click
no-close-on-esc="[[noCloseOnEsc]]"
></vaadin-confirm-dialog-dialog>
Expand Down
2 changes: 1 addition & 1 deletion packages/context-menu/src/vaadin-context-menu-overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ContextMenuOverlay extends PositionMixin(OverlayElement) {
}

static get observers() {
return ['_themeChanged(theme)'];
return ['_themeChanged(_theme)'];
}

ready() {
Expand Down
2 changes: 1 addition & 1 deletion packages/context-menu/src/vaadin-context-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class ContextMenu extends ControllerMixin(ElementMixin(ThemePropertyMixin(ItemsM
with-backdrop="[[_phone]]"
phone$="[[_phone]]"
model="[[_context]]"
theme$="[[theme]]"
theme$="[[_theme]]"
>
</vaadin-context-menu-overlay>
`;
Expand Down
12 changes: 6 additions & 6 deletions packages/context-menu/src/vaadin-contextmenu-items-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ export const ItemsMixin = (superClass) =>
subMenuOverlay._setParentOverlay(parent);

// Set theme attribute from parent element
if (parent.theme) {
subMenu.setAttribute('theme', parent.theme);
if (parent.hasAttribute('theme')) {
subMenu.setAttribute('theme', parent.getAttribute('theme'));
} else {
subMenu.removeAttribute('theme');
}
Expand Down Expand Up @@ -217,7 +217,7 @@ export const ItemsMixin = (superClass) =>
component.setAttribute('role', 'separator');
}

this._setMenuItemTheme(component, item, this.theme);
this._setMenuItemTheme(component, item, this._theme);

component._item = item;

Expand Down Expand Up @@ -280,7 +280,7 @@ export const ItemsMixin = (superClass) =>
`;
flush();
const listBox = root.querySelector('vaadin-context-menu-list-box');
this.theme && listBox.setAttribute('theme', this.theme);
this._theme && listBox.setAttribute('theme', this._theme);
listBox.classList.add('vaadin-menu-list-box');
requestAnimationFrame(() => listBox.setAttribute('role', 'menu'));

Expand Down Expand Up @@ -377,8 +377,8 @@ export const ItemsMixin = (superClass) =>
});
} else {
const listBox = root.querySelector('vaadin-context-menu-list-box');
if (this.theme) {
listBox.setAttribute('theme', this.theme);
if (this._theme) {
listBox.setAttribute('theme', this._theme);
} else {
listBox.removeAttribute('theme');
}
Expand Down
2 changes: 1 addition & 1 deletion packages/crud/src/vaadin-crud-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class CrudDialog extends Dialog {
on-opened-changed="_onOverlayOpened"
on-mousedown="_bringOverlayToFront"
on-touchstart="_bringOverlayToFront"
theme$="[[theme]]"
theme$="[[_theme]]"
modeless="[[modeless]]"
with-backdrop="[[!modeless]]"
resizable$="[[resizable]]"
Expand Down
10 changes: 5 additions & 5 deletions packages/crud/src/vaadin-crud.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class Crud extends SlotMixin(ControllerMixin(ElementMixin(ThemableMixin(PolymerE
<div id="main">
<slot name="grid">
<vaadin-crud-grid
theme$="[[theme]]"
theme$="[[_theme]]"
id="grid"
include="[[include]]"
exclude="[[exclude]]"
Expand Down Expand Up @@ -282,12 +282,12 @@ class Crud extends SlotMixin(ControllerMixin(ElementMixin(ThemableMixin(PolymerE
aria-label="[[__editorAriaLabel]]"
no-close-on-outside-click="[[__isDirty]]"
no-close-on-esc="[[__isDirty]]"
theme$="[[theme]]"
theme$="[[_theme]]"
on-opened-changed="__onDialogOpened"
></vaadin-crud-dialog>
<vaadin-confirm-dialog
theme$="[[theme]]"
theme$="[[_theme]]"
id="confirmCancel"
on-confirm="__confirmCancel"
cancel
Expand All @@ -299,7 +299,7 @@ class Crud extends SlotMixin(ControllerMixin(ElementMixin(ThemableMixin(PolymerE
></vaadin-confirm-dialog>
<vaadin-confirm-dialog
theme$="[[theme]]"
theme$="[[_theme]]"
id="confirmDelete"
on-confirm="__confirmDelete"
cancel
Expand Down Expand Up @@ -608,7 +608,7 @@ class Crud extends SlotMixin(ControllerMixin(ElementMixin(ThemableMixin(PolymerE
static get observers() {
return [
'__headerNodeChanged(_headerNode, __isNew, i18n.newItem, i18n.editItem)',
'__formChanged(_form, theme, include, exclude)',
'__formChanged(_form, _theme, include, exclude)',
'__onI18Change(i18n, _grid)',
'__onEditOnClickChange(editOnClick, _grid)',
'__hostPropsChanged(' +
Expand Down
4 changes: 2 additions & 2 deletions packages/date-picker/src/vaadin-date-picker-light.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class DatePickerLight extends ThemableMixin(DatePickerMixin(PolymerElement)) {
on-vaadin-overlay-close="_onOverlayClosed"
restore-focus-on-close
restore-focus-node="[[inputElement]]"
theme$="[[__getOverlayTheme(theme, _overlayInitialized)]]"
theme$="[[__getOverlayTheme(_theme, _overlayInitialized)]]"
>
<template>
<vaadin-date-picker-overlay-content
Expand All @@ -92,7 +92,7 @@ class DatePickerLight extends ThemableMixin(DatePickerMixin(PolymerElement)) {
on-date-tap="_close"
role="dialog"
part="overlay-content"
theme$="[[__getOverlayTheme(theme, _overlayInitialized)]]"
theme$="[[__getOverlayTheme(_theme, _overlayInitialized)]]"
>
</vaadin-date-picker-overlay-content>
</template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class DatePickerOverlayContent extends ControllerMixin(ThemableMixin(DirMixin(Po
min-date="[[minDate]]"
max-date="[[maxDate]]"
part="month"
theme$="[[theme]]"
theme$="[[_theme]]"
on-keydown="__onMonthCalendarKeyDown"
>
</vaadin-month-calendar>
Expand Down
6 changes: 3 additions & 3 deletions packages/date-picker/src/vaadin-date-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class DatePicker extends DatePickerMixin(InputControlMixin(ThemableMixin(Element
readonly="[[readonly]]"
disabled="[[disabled]]"
invalid="[[invalid]]"
theme$="[[theme]]"
theme$="[[_theme]]"
>
<slot name="prefix" slot="prefix"></slot>
<slot name="input"></slot>
Expand All @@ -158,7 +158,7 @@ class DatePicker extends DatePickerMixin(InputControlMixin(ThemableMixin(Element
<vaadin-date-picker-overlay
id="overlay"
fullscreen$="[[_fullscreen]]"
theme$="[[__getOverlayTheme(theme, _overlayInitialized)]]"
theme$="[[__getOverlayTheme(_theme, _overlayInitialized)]]"
on-vaadin-overlay-open="_onOverlayOpened"
on-vaadin-overlay-close="_onOverlayClosed"
restore-focus-on-close
Expand All @@ -180,7 +180,7 @@ class DatePicker extends DatePickerMixin(InputControlMixin(ThemableMixin(Element
role="dialog"
on-date-tap="_close"
part="overlay-content"
theme$="[[__getOverlayTheme(theme, _overlayInitialized)]]"
theme$="[[__getOverlayTheme(_theme, _overlayInitialized)]]"
></vaadin-date-picker-overlay-content>
</template>
</vaadin-date-picker-overlay>
Expand Down
2 changes: 1 addition & 1 deletion packages/date-time-picker/src/vaadin-date-time-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ class DateTimePicker extends FieldMixin(
'__readonlyChanged(readonly)',
'__i18nChanged(i18n.*)',
'__autoOpenDisabledChanged(autoOpenDisabled)',
'__themeChanged(theme, __datePicker, __timePicker)',
'__themeChanged(_theme, __datePicker, __timePicker)',
'__pickersChanged(__datePicker, __timePicker)'
];
}
Expand Down
2 changes: 1 addition & 1 deletion packages/dialog/src/vaadin-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class Dialog extends ThemePropertyMixin(ElementMixin(DialogDraggableMixin(Dialog
on-opened-changed="_onOverlayOpened"
on-mousedown="_bringOverlayToFront"
on-touchstart="_bringOverlayToFront"
theme$="[[theme]]"
theme$="[[_theme]]"
modeless="[[modeless]]"
with-backdrop="[[!modeless]]"
resizable$="[[resizable]]"
Expand Down
2 changes: 1 addition & 1 deletion packages/login/src/vaadin-login-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class LoginForm extends LoginMixin(ElementMixin(ThemableMixin(PolymerElement)))
}
</style>
<vaadin-login-form-wrapper
theme$="[[theme]]"
theme$="[[_theme]]"
part="vaadin-login-native-form-wrapper"
action="{{action}}"
disabled="{{disabled}}"
Expand Down
2 changes: 1 addition & 1 deletion packages/login/src/vaadin-login-overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class LoginOverlay extends LoginMixin(ElementMixin(ThemableMixin(PolymerElement)
with-backdrop
title="[[title]]"
description="[[description]]"
theme$="[[theme]]"
theme$="[[_theme]]"
>
<vaadin-login-form
theme="with-overlay"
Expand Down
26 changes: 2 additions & 24 deletions packages/menu-bar/src/vaadin-menu-bar-buttons-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,29 +197,6 @@ export const ButtonsMixin = (superClass) =>
button.setAttribute('tabindex', disabled ? '-1' : '0');
}

/**
* @param {string | null} theme
* @protected
* @override
*/
_setTheme(theme) {
super._setTheme(theme);

// Initializing, do nothing
if (!this.shadowRoot) {
return;
}

this.__applyTheme(theme);
}

/** @private */
__applyTheme(theme) {
this._buttons.forEach((btn) => this._setButtonTheme(btn, theme));

this.__detectOverflow();
}

/** @protected */
_setButtonTheme(btn, hostTheme) {
let theme = hostTheme;
Expand Down Expand Up @@ -277,9 +254,10 @@ export const ButtonsMixin = (superClass) =>
this._appendButton(button);
this._setButtonDisabled(button, item.disabled);
this._initButtonAttrs(button);
this._setButtonTheme(button, this._theme);
});

this.__applyTheme(this.theme);
this.__detectOverflow();
}

/**
Expand Down
11 changes: 1 addition & 10 deletions packages/menu-bar/src/vaadin-menu-bar-interactions-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const InteractionsMixin = (superClass) =>
}

static get observers() {
return ['_itemsChanged(items, items.splices)', '_themeChanged(theme)'];
return ['_itemsChanged(items, items.splices)'];
}

/** @protected */
Expand All @@ -54,15 +54,6 @@ export const InteractionsMixin = (superClass) =>
return this.getAttribute('dir') === 'rtl';
}

/** @private */
_themeChanged(theme) {
if (theme) {
this._subMenu.setAttribute('theme', theme);
} else {
this._subMenu.removeAttribute('theme');
}
}

/** @protected */
_setExpanded(button, expanded) {
button.toggleAttribute('expanded', expanded);
Expand Down
6 changes: 6 additions & 0 deletions packages/menu-bar/src/vaadin-menu-bar.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ declare class MenuBar extends ButtonsMixin(DisabledMixin(InteractionsMixin(Eleme
*/
i18n: MenuBarI18n;

/**
* A callback for the `_theme` property observer.
* It propagates the host theme to the buttons and the sub menu.
*/
protected _themeChanged(theme: string | null): void;

addEventListener<K extends keyof MenuBarEventMap>(
type: K,
listener: (this: MenuBar, ev: MenuBarEventMap[K]) => void,
Expand Down
24 changes: 24 additions & 0 deletions packages/menu-bar/src/vaadin-menu-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ class MenuBar extends ButtonsMixin(DisabledMixin(InteractionsMixin(ElementMixin(
};
}

static get observers() {
return ['_themeChanged(_theme)'];
}

/**
* Override method inherited from `DisabledMixin`
* to update the `disabled` property for the buttons
Expand All @@ -218,6 +222,26 @@ class MenuBar extends ButtonsMixin(DisabledMixin(InteractionsMixin(ElementMixin(
}
}

/**
* A callback for the `_theme` property observer.
* It propagates the host theme to the buttons and the sub menu.
*
* @param {string | null} theme
* @protected
*/
_themeChanged(theme) {
if (this.shadowRoot) {
this._buttons.forEach((btn) => this._setButtonTheme(btn, theme));
this.__detectOverflow();
}

if (theme) {
this._subMenu.setAttribute('theme', theme);
} else {
this._subMenu.removeAttribute('theme');
}
}

/** @private */
__updateButtonsDisabled(disabled) {
this._buttons.forEach((btn) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/notification/src/vaadin-notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class Notification extends ThemePropertyMixin(ElementMixin(PolymerElement)) {
display: none;
}
</style>
<vaadin-notification-card theme$="[[theme]]"> </vaadin-notification-card>
<vaadin-notification-card theme$="[[_theme]]"> </vaadin-notification-card>
`;
}

Expand Down
Loading

0 comments on commit 7634ebc

Please sign in to comment.