Skip to content

Commit

Permalink
refactor: use LitElement for field highlighter internal elements (#8548)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomivirkki authored Jan 22, 2025
1 parent 5f48d70 commit 83ae201
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const userTagsOverlayStyles = css`
box-shadow: none;
}
[part='overlay'] {
:scope [part='overlay'] {
box-shadow: none;
background: transparent;
position: relative;
Expand All @@ -86,7 +86,7 @@ export const userTagsOverlayStyles = css`
right: -4px;
}
[part='content'] {
:scope [part='content'] {
padding: 0;
}
Expand Down
15 changes: 9 additions & 6 deletions packages/field-highlighter/src/vaadin-field-outline.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
* Copyright (c) 2021 - 2025 Vaadin Ltd.
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
*/
import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
import { html, LitElement } from 'lit';
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
import { registerStyles, ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
import { fieldOutlineStyles } from './vaadin-field-highlighter-styles.js';

Expand All @@ -19,15 +20,11 @@ registerStyles('vaadin-field-outline', fieldOutlineStyles, { moduleId: 'vaadin-f
* @mixes ThemableMixin
* @private
*/
export class FieldOutline extends ThemableMixin(DirMixin(PolymerElement)) {
export class FieldOutline extends ThemableMixin(DirMixin(PolylitMixin(LitElement))) {
static get is() {
return 'vaadin-field-outline';
}

static get template() {
return html``;
}

static get properties() {
return {
/**
Expand All @@ -37,10 +34,16 @@ export class FieldOutline extends ThemableMixin(DirMixin(PolymerElement)) {
type: Object,
value: null,
observer: '_userChanged',
sync: true,
},
};
}

/** @protected */
render() {
return html``;
}

/** @protected */
ready() {
super.ready();
Expand Down
18 changes: 11 additions & 7 deletions packages/field-highlighter/src/vaadin-user-tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
* Copyright (c) 2021 - 2025 Vaadin Ltd.
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
*/
import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
import { html, LitElement } from 'lit';
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
import { registerStyles, ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
import { userTagStyles } from './vaadin-field-highlighter-styles.js';

registerStyles('vaadin-user-tag', userTagStyles, { moduleId: 'vaadin-user-tag-styles' });

/**
* An element used internally by `<vaadin-field-highlighter>`. Not intended to be used separately.
*
Expand All @@ -20,13 +19,18 @@ registerStyles('vaadin-user-tag', userTagStyles, { moduleId: 'vaadin-user-tag-st
* @mixes ThemableMixin
* @private
*/
export class UserTag extends ThemableMixin(DirMixin(PolymerElement)) {
export class UserTag extends ThemableMixin(DirMixin(PolylitMixin(LitElement))) {
static get is() {
return 'vaadin-user-tag';
}

static get template() {
return html`<div part="name">[[name]]</div>`;
static get styles() {
return userTagStyles;
}

/** @protected */
render() {
return html`<div part="name">${this.name}</div>`;
}

static get properties() {
Expand Down
18 changes: 11 additions & 7 deletions packages/field-highlighter/src/vaadin-user-tags-overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
* Copyright (c) 2021 - 2025 Vaadin Ltd.
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
*/
import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
import { html, LitElement } from 'lit';
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
import { OverlayMixin } from '@vaadin/overlay/src/vaadin-overlay-mixin.js';
import { PositionMixin } from '@vaadin/overlay/src/vaadin-overlay-position-mixin.js';
import { overlayStyles } from '@vaadin/overlay/src/vaadin-overlay-styles.js';
import { registerStyles, ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
import { userTagsOverlayStyles } from './vaadin-field-highlighter-styles.js';

registerStyles('vaadin-user-tags-overlay', [overlayStyles, userTagsOverlayStyles]);

/**
* An element used internally by `<vaadin-field-highlighter>`. Not intended to be used separately.
*
Expand All @@ -25,14 +24,19 @@ registerStyles('vaadin-user-tags-overlay', [overlayStyles, userTagsOverlayStyles
* @mixes ThemableMixin
* @private
*/
class UserTagsOverlay extends PositionMixin(OverlayMixin(DirMixin(ThemableMixin(PolymerElement)))) {
class UserTagsOverlay extends PositionMixin(OverlayMixin(DirMixin(ThemableMixin(PolylitMixin(LitElement))))) {
static get is() {
return 'vaadin-user-tags-overlay';
}

static get template() {
static get styles() {
return [overlayStyles, userTagsOverlayStyles];
}

/** @protected */
render() {
return html`
<div id="backdrop" part="backdrop" hidden$="[[!withBackdrop]]"></div>
<div id="backdrop" part="backdrop" ?hidden="${!this.withBackdrop}"></div>
<div part="overlay" id="overlay">
<div part="content" id="content">
<slot></slot>
Expand Down
36 changes: 21 additions & 15 deletions packages/field-highlighter/src/vaadin-user-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
*/
import './vaadin-user-tag.js';
import './vaadin-user-tags-overlay.js';
import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
import { css, html, LitElement } from 'lit';
import { timeOut } from '@vaadin/component-base/src/async.js';
import { Debouncer } from '@vaadin/component-base/src/debounce.js';
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';

const listenOnce = (elem, type) => {
return new Promise((resolve) => {
Expand All @@ -27,24 +28,28 @@ const listenOnce = (elem, type) => {
* @extends HTMLElement
* @private
*/
export class UserTags extends PolymerElement {
export class UserTags extends PolylitMixin(LitElement) {
static get is() {
return 'vaadin-user-tags';
}

static get template() {
static get styles() {
return css`
:host {
position: absolute;
}
`;
}

/** @protected */
render() {
return html`
<style>
:host {
position: absolute;
}
</style>
<vaadin-user-tags-overlay
id="overlay"
modeless
opened="[[opened]]"
.opened="${this.opened}"
no-vertical-overlap
on-vaadin-overlay-open="_onOverlayOpen"
@vaadin-overlay-open="${this._onOverlayOpen}"
></vaadin-user-tags-overlay>
`;
}
Expand All @@ -67,6 +72,7 @@ export class UserTags extends PolymerElement {
opened: {
type: Boolean,
value: false,
sync: true,
},

/**
Expand Down Expand Up @@ -288,7 +294,7 @@ export class UserTags extends PolymerElement {

this.__flashQueue.forEach((tags) => {
if (tags.some((tag) => tag.uid === user.id)) {
this.splice('__flashQueue', i, 1);
this.__flashQueue = this.__flashQueue.filter((_, index) => index !== i);
}
});
});
Expand All @@ -311,7 +317,7 @@ export class UserTags extends PolymerElement {

if (this.flashing || !this.__isTargetVisible) {
// Schedule next flash later
this.push('__flashQueue', addedTags);
this.__flashQueue = [...this.__flashQueue, addedTags];
} else {
this.flashTags(addedTags);
}
Expand Down Expand Up @@ -382,7 +388,7 @@ export class UserTags extends PolymerElement {
}).then(() => {
if (this.__flashQueue.length > 0) {
const tags = this.__flashQueue[0];
this.splice('__flashQueue', 0, 1);
this.__flashQueue = [...this.__flashQueue].slice(1);
this.flashTags(tags);
}
});
Expand All @@ -404,7 +410,7 @@ export class UserTags extends PolymerElement {
this.applyTagsStart(changed);

this._debounceRender = Debouncer.debounce(this._debounceRender, timeOut.after(this.duration), () => {
this.set('users', users);
this.users = users;

this.applyTagsEnd(changed);

Expand All @@ -416,7 +422,7 @@ export class UserTags extends PolymerElement {

updateTagsSync(users, changed) {
this.applyTagsStart(changed);
this.set('users', users);
this.users = users;
this.applyTagsEnd(changed);
}

Expand Down

0 comments on commit 83ae201

Please sign in to comment.