chore(ui): lint and types fixes
This commit is contained in:
parent
f1b1c46aab
commit
45fe0b4bb3
23 changed files with 6230 additions and 13217 deletions
|
|
@ -56,6 +56,8 @@ export class CustomCollapsible extends LionCollapsible {
|
||||||
contentNode.style.setProperty('opacity', '1');
|
contentNode.style.setProperty('opacity', '1');
|
||||||
contentNode.style.setProperty('padding', '12px 0');
|
contentNode.style.setProperty('padding', '12px 0');
|
||||||
contentNode.style.setProperty('max-height', '0px');
|
contentNode.style.setProperty('max-height', '0px');
|
||||||
|
// @ts-ignore
|
||||||
|
// eslint-disable-next-line no-promise-executor-return
|
||||||
await new Promise(resolve => requestAnimationFrame(() => resolve()));
|
await new Promise(resolve => requestAnimationFrame(() => resolve()));
|
||||||
contentNode.style.setProperty('max-height', expectedHeight);
|
contentNode.style.setProperty('max-height', expectedHeight);
|
||||||
await this._waitForTransition({ contentNode });
|
await this._waitForTransition({ contentNode });
|
||||||
|
|
@ -105,6 +107,8 @@ export class CustomCollapsible extends LionCollapsible {
|
||||||
*/
|
*/
|
||||||
async __calculateHeight(contentNode) {
|
async __calculateHeight(contentNode) {
|
||||||
contentNode.style.setProperty('max-height', '');
|
contentNode.style.setProperty('max-height', '');
|
||||||
|
// @ts-ignore
|
||||||
|
// eslint-disable-next-line no-promise-executor-return
|
||||||
await new Promise(resolve => requestAnimationFrame(() => resolve()));
|
await new Promise(resolve => requestAnimationFrame(() => resolve()));
|
||||||
return this._contentHeight; // Expected height i.e. actual size once collapsed after animation
|
return this._contentHeight; // Expected height i.e. actual size once collapsed after animation
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { OverlaysManager , OverlaysManager as OverlaysManager2 } from 'overlays';
|
import { OverlaysManager, OverlaysManager as OverlaysManager2 } from 'overlays';
|
||||||
import { singletonManager } from 'singleton-manager';
|
import { singletonManager } from 'singleton-manager';
|
||||||
|
|
||||||
let compatibleManager1;
|
let compatibleManager1;
|
||||||
|
|
|
||||||
19204
package-lock.json
generated
19204
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -25,6 +25,7 @@ describe('cache interceptors', () => {
|
||||||
*/
|
*/
|
||||||
const returnResponseOnTick = (timeout, i) =>
|
const returnResponseOnTick = (timeout, i) =>
|
||||||
new Promise(resolve =>
|
new Promise(resolve =>
|
||||||
|
// eslint-disable-next-line no-promise-executor-return
|
||||||
window.setTimeout(() => resolve(new Response(`mock response ${i}`)), timeout),
|
window.setTimeout(() => resolve(new Response(`mock response ${i}`)), timeout),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -815,7 +815,7 @@ export class LionCalendar extends LocalizeMixin(LitElement) {
|
||||||
) {
|
) {
|
||||||
this.__focusedDate = /** @type {HTMLButtonElement & { date: Date }} */ (
|
this.__focusedDate = /** @type {HTMLButtonElement & { date: Date }} */ (
|
||||||
this.shadowRoot?.activeElement
|
this.shadowRoot?.activeElement
|
||||||
).date;
|
)?.date;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ export class DayObject {
|
||||||
|
|
||||||
get weekdayNameShort() {
|
get weekdayNameShort() {
|
||||||
const weekdayEls = Array.from(
|
const weekdayEls = Array.from(
|
||||||
/** @type {HTMLElement} */ (this.el.parentElement?.parentElement).querySelectorAll(
|
/** @type {HTMLElement} */ (this.el.parentElement?.parentElement)?.querySelectorAll(
|
||||||
'.calendar__day-cell',
|
'.calendar__day-cell',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
@ -73,7 +73,7 @@ export class DayObject {
|
||||||
|
|
||||||
get weekdayNameLong() {
|
get weekdayNameLong() {
|
||||||
const weekdayEls = Array.from(
|
const weekdayEls = Array.from(
|
||||||
/** @type {HTMLElement} */ (this.el.parentElement?.parentElement).querySelectorAll(
|
/** @type {HTMLElement} */ (this.el.parentElement?.parentElement)?.querySelectorAll(
|
||||||
'.calendar__day-cell',
|
'.calendar__day-cell',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -115,6 +115,7 @@ export class LionDrawer extends LionCollapsible {
|
||||||
const prop = this.position === 'top' ? 'height' : 'width';
|
const prop = this.position === 'top' ? 'height' : 'width';
|
||||||
|
|
||||||
contentNode.style.setProperty(prop, /** @type {string} */ (min));
|
contentNode.style.setProperty(prop, /** @type {string} */ (min));
|
||||||
|
// eslint-disable-next-line no-promise-executor-return
|
||||||
await new Promise(resolve => requestAnimationFrame(() => resolve(true)));
|
await new Promise(resolve => requestAnimationFrame(() => resolve(true)));
|
||||||
contentNode.style.setProperty(prop, /** @type {string} */ (max));
|
contentNode.style.setProperty(prop, /** @type {string} */ (max));
|
||||||
await this._waitForTransition({ contentNode });
|
await this._waitForTransition({ contentNode });
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,7 @@
|
||||||
import { Validator } from '@lion/ui/form-core.js';
|
import { Validator } from '@lion/ui/form-core.js';
|
||||||
|
|
||||||
export class AlwaysInvalid extends Validator {
|
export class AlwaysInvalid extends Validator {
|
||||||
static get validatorName() {
|
static validatorName = 'AlwaysInvalid';
|
||||||
return 'AlwaysInvalid';
|
|
||||||
}
|
|
||||||
|
|
||||||
execute() {
|
execute() {
|
||||||
const showMessage = true;
|
const showMessage = true;
|
||||||
|
|
|
||||||
|
|
@ -165,6 +165,7 @@ export const runRegistrationSuite = customConfig => {
|
||||||
it('works for components that have a delayed render', async () => {
|
it('works for components that have a delayed render', async () => {
|
||||||
class PerformUpdate extends FormRegistrarMixin(LitElement) {
|
class PerformUpdate extends FormRegistrarMixin(LitElement) {
|
||||||
async performUpdate() {
|
async performUpdate() {
|
||||||
|
// eslint-disable-next-line no-promise-executor-return
|
||||||
await new Promise(resolve => setTimeout(() => resolve(undefined), 10));
|
await new Promise(resolve => setTimeout(() => resolve(undefined), 10));
|
||||||
await super.performUpdate();
|
await super.performUpdate();
|
||||||
}
|
}
|
||||||
|
|
@ -359,6 +360,7 @@ export const runRegistrationSuite = customConfig => {
|
||||||
const delayedPortalString = defineCE(
|
const delayedPortalString = defineCE(
|
||||||
class extends FormRegistrarPortalMixin(LitElement) {
|
class extends FormRegistrarPortalMixin(LitElement) {
|
||||||
async performUpdate() {
|
async performUpdate() {
|
||||||
|
// eslint-disable-next-line no-promise-executor-return
|
||||||
await new Promise(resolve => setTimeout(() => resolve(undefined), 10));
|
await new Promise(resolve => setTimeout(() => resolve(undefined), 10));
|
||||||
await super.performUpdate();
|
await super.performUpdate();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -517,7 +517,11 @@ export function runValidateMixinFeedbackPart() {
|
||||||
.submitted=${true}
|
.submitted=${true}
|
||||||
.validators=${[constructorValidator]}
|
.validators=${[constructorValidator]}
|
||||||
.modelValue=${'cat'}
|
.modelValue=${'cat'}
|
||||||
.fieldName=${new Promise(resolve => resolve('myField'))}
|
.fieldName=${new Promise(
|
||||||
|
(
|
||||||
|
resolve, // eslint-disable-next-line no-promise-executor-return
|
||||||
|
) => resolve('myField'),
|
||||||
|
)}
|
||||||
>${lightDom}</${tag}>
|
>${lightDom}</${tag}>
|
||||||
`)
|
`)
|
||||||
);
|
);
|
||||||
|
|
@ -537,6 +541,7 @@ export function runValidateMixinFeedbackPart() {
|
||||||
|
|
||||||
it('".getMessage()" gets .fieldName defined on Validator config', async () => {
|
it('".getMessage()" gets .fieldName defined on Validator config', async () => {
|
||||||
const constructorValidator = new MinLength(4, {
|
const constructorValidator = new MinLength(4, {
|
||||||
|
// eslint-disable-next-line no-promise-executor-return
|
||||||
fieldName: new Promise(resolve => resolve('myFieldViaCfg')),
|
fieldName: new Promise(resolve => resolve('myFieldViaCfg')),
|
||||||
});
|
});
|
||||||
const ctorValidator = /** @type {typeof MinLength} */ (constructorValidator.constructor);
|
const ctorValidator = /** @type {typeof MinLength} */ (constructorValidator.constructor);
|
||||||
|
|
@ -548,7 +553,11 @@ export function runValidateMixinFeedbackPart() {
|
||||||
.submitted=${true}
|
.submitted=${true}
|
||||||
.validators=${[constructorValidator]}
|
.validators=${[constructorValidator]}
|
||||||
.modelValue=${'cat'}
|
.modelValue=${'cat'}
|
||||||
.fieldName=${new Promise(resolve => resolve('myField'))}
|
.fieldName=${new Promise(
|
||||||
|
(
|
||||||
|
resolve, // eslint-disable-next-line no-promise-executor-return
|
||||||
|
) => resolve('myField'),
|
||||||
|
)}
|
||||||
>${lightDom}</${tag}>
|
>${lightDom}</${tag}>
|
||||||
`)
|
`)
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,7 @@ describe('String Validation', () => {
|
||||||
isEnabled = validator.execute('#LionRests');
|
isEnabled = validator.execute('#LionRests');
|
||||||
expect(isEnabled).to.be.true;
|
expect(isEnabled).to.be.true;
|
||||||
|
|
||||||
validator = new Pattern(new RegExp('#LionRocks'));
|
validator = new Pattern(/#LionRocks/);
|
||||||
isEnabled = validator.execute('Some string #LionRocks');
|
isEnabled = validator.execute('Some string #LionRocks');
|
||||||
expect(isEnabled).to.be.false;
|
expect(isEnabled).to.be.false;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import { css, html, LitElement, render } from 'lit';
|
||||||
export class SbActionLogger extends LitElement {
|
export class SbActionLogger extends LitElement {
|
||||||
static get properties() {
|
static get properties() {
|
||||||
return {
|
return {
|
||||||
|
// eslint-disable-next-line lit/no-native-attributes
|
||||||
title: { type: String, reflect: true },
|
title: { type: String, reflect: true },
|
||||||
simple: { type: Boolean, reflect: true },
|
simple: { type: Boolean, reflect: true },
|
||||||
__logCounter: { type: Number },
|
__logCounter: { type: Number },
|
||||||
|
|
|
||||||
|
|
@ -57,14 +57,6 @@ export class LionIcon extends LitElement {
|
||||||
type: String,
|
type: String,
|
||||||
attribute: 'icon-id',
|
attribute: 'icon-id',
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
role: {
|
|
||||||
type: String,
|
|
||||||
attribute: 'role',
|
|
||||||
reflect: true,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -101,7 +93,6 @@ export class LionIcon extends LitElement {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.role = 'img';
|
|
||||||
this.ariaLabel = '';
|
this.ariaLabel = '';
|
||||||
this.iconId = '';
|
this.iconId = '';
|
||||||
/**
|
/**
|
||||||
|
|
@ -131,6 +122,7 @@ export class LionIcon extends LitElement {
|
||||||
// ensures that aria-hidden is set if there is no aria-label attribute
|
// ensures that aria-hidden is set if there is no aria-label attribute
|
||||||
this._onLabelChanged();
|
this._onLabelChanged();
|
||||||
super.connectedCallback();
|
super.connectedCallback();
|
||||||
|
this.setAttribute('role', 'img');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -185,10 +185,12 @@ describe('lion-icon', () => {
|
||||||
try {
|
try {
|
||||||
icons.addIconResolver(
|
icons.addIconResolver(
|
||||||
'foo',
|
'foo',
|
||||||
|
// eslint-disable-next-line no-promise-executor-return
|
||||||
() => new Promise(resolve => setTimeout(() => resolve(heartSvg), 10)),
|
() => new Promise(resolve => setTimeout(() => resolve(heartSvg), 10)),
|
||||||
);
|
);
|
||||||
icons.addIconResolver(
|
icons.addIconResolver(
|
||||||
'bar',
|
'bar',
|
||||||
|
// eslint-disable-next-line no-promise-executor-return
|
||||||
() => new Promise(resolve => setTimeout(() => resolve(hammerSvg), 4)),
|
() => new Promise(resolve => setTimeout(() => resolve(hammerSvg), 4)),
|
||||||
);
|
);
|
||||||
const el = await fixture(html`<lion-icon icon-id="foo:lorem:ipsum"></lion-icon>`);
|
const el = await fixture(html`<lion-icon icon-id="foo:lorem:ipsum"></lion-icon>`);
|
||||||
|
|
|
||||||
|
|
@ -19,10 +19,14 @@ describe('<lion-input-range>', () => {
|
||||||
<lion-input-range .modelValue=${75} unit="${`%`}"></lion-input-range>
|
<lion-input-range .modelValue=${75} unit="${`%`}"></lion-input-range>
|
||||||
`);
|
`);
|
||||||
expect(
|
expect(
|
||||||
/** @type {HTMLElement} */ (el.shadowRoot?.querySelector('.input-range__value')).innerText,
|
/** @type {HTMLElement} */ (
|
||||||
|
/** @type {ShadowRoot} */ (el.shadowRoot).querySelector('.input-range__value')
|
||||||
|
).innerText,
|
||||||
).to.equal('75');
|
).to.equal('75');
|
||||||
expect(
|
expect(
|
||||||
/** @type {HTMLElement} */ (el.shadowRoot?.querySelector('.input-range__unit')).innerText,
|
/** @type {HTMLElement} */ (
|
||||||
|
/** @type {ShadowRoot} */ (el.shadowRoot).querySelector('.input-range__unit')
|
||||||
|
).innerText,
|
||||||
).to.equal('%');
|
).to.equal('%');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -30,12 +34,14 @@ describe('<lion-input-range>', () => {
|
||||||
const el = await fixture(`<lion-input-range min="100" max="200"></lion-input-range>`);
|
const el = await fixture(`<lion-input-range min="100" max="200"></lion-input-range>`);
|
||||||
expect(el.shadowRoot?.querySelectorAll('.input-range__limits span').length).to.equal(2);
|
expect(el.shadowRoot?.querySelectorAll('.input-range__limits span').length).to.equal(2);
|
||||||
expect(
|
expect(
|
||||||
/** @type {HTMLElement} */ (el.shadowRoot?.querySelectorAll('.input-range__limits span')[0])
|
/** @type {HTMLElement} */ (
|
||||||
.innerText,
|
/** @type {ShadowRoot} */ (el.shadowRoot).querySelectorAll('.input-range__limits span')[0]
|
||||||
|
).innerText,
|
||||||
).to.equal(el.min.toString());
|
).to.equal(el.min.toString());
|
||||||
expect(
|
expect(
|
||||||
/** @type {HTMLElement} */ (el.shadowRoot?.querySelectorAll('.input-range__limits span')[1])
|
/** @type {HTMLElement} */ (
|
||||||
.innerText,
|
/** @type {ShadowRoot} */ (el.shadowRoot).querySelectorAll('.input-range__limits span')[1]
|
||||||
|
).innerText,
|
||||||
).to.equal(el.max.toString());
|
).to.equal(el.max.toString());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,6 @@ import { FormRegistrarPortalMixin } from '@lion/ui/form-core.js';
|
||||||
export class LionOptions extends FormRegistrarPortalMixin(LitElement) {
|
export class LionOptions extends FormRegistrarPortalMixin(LitElement) {
|
||||||
static get properties() {
|
static get properties() {
|
||||||
return {
|
return {
|
||||||
role: {
|
|
||||||
type: String,
|
|
||||||
reflect: true,
|
|
||||||
},
|
|
||||||
tabIndex: {
|
tabIndex: {
|
||||||
type: Number,
|
type: Number,
|
||||||
reflect: true,
|
reflect: true,
|
||||||
|
|
@ -21,10 +17,14 @@ export class LionOptions extends FormRegistrarPortalMixin(LitElement) {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.role = 'listbox';
|
|
||||||
this.tabIndex = 0;
|
this.tabIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
connectedCallback() {
|
||||||
|
super.connectedCallback();
|
||||||
|
this.setAttribute('role', 'listbox');
|
||||||
|
}
|
||||||
|
|
||||||
createRenderRoot() {
|
createRenderRoot() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ import { forceFRBESymbols, forceSymbols } from './forceSymbols.js';
|
||||||
* @param {string} _locale
|
* @param {string} _locale
|
||||||
* @returns {FormatNumberPart[]}
|
* @returns {FormatNumberPart[]}
|
||||||
*/
|
*/
|
||||||
|
// eslint-disable-next-line default-param-last
|
||||||
export function normalizeIntl(formattedParts, options = {}, _locale) {
|
export function normalizeIntl(formattedParts, options = {}, _locale) {
|
||||||
let normalize = forceNormalSpaces(formattedParts);
|
let normalize = forceNormalSpaces(formattedParts);
|
||||||
// Dutch and Belgian currency must be moved to end of number
|
// Dutch and Belgian currency must be moved to end of number
|
||||||
|
|
|
||||||
|
|
@ -56,5 +56,6 @@ export async function fakeImport(path, ms = 0) {
|
||||||
setTimeout(() => resolveOrReject(result, resolve, reject), ms);
|
setTimeout(() => resolveOrReject(result, resolve, reject), ms);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
// eslint-disable-next-line no-promise-executor-return
|
||||||
return new Promise((resolve, reject) => resolveOrReject(result, resolve, reject));
|
return new Promise((resolve, reject) => resolveOrReject(result, resolve, reject));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ describe('lion-select', () => {
|
||||||
expect(lionSelect.formattedValue).to.equal('');
|
expect(lionSelect.formattedValue).to.equal('');
|
||||||
|
|
||||||
const select = /** @type {HTMLSlotElement} */ (
|
const select = /** @type {HTMLSlotElement} */ (
|
||||||
lionSelect.shadowRoot?.querySelector('slot[name=input]')
|
/** @type {ShadowRoot} */ (lionSelect.shadowRoot).querySelector('slot[name=input]')
|
||||||
).assignedElements()[0];
|
).assignedElements()[0];
|
||||||
const options = select.querySelectorAll('option');
|
const options = select.querySelectorAll('option');
|
||||||
options[1].textContent = 'Item 2';
|
options[1].textContent = 'Item 2';
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,6 @@ import { DisabledWithTabIndexMixin } from '@lion/ui/core.js';
|
||||||
export class LionSwitchButton extends DisabledWithTabIndexMixin(LitElement) {
|
export class LionSwitchButton extends DisabledWithTabIndexMixin(LitElement) {
|
||||||
static get properties() {
|
static get properties() {
|
||||||
return {
|
return {
|
||||||
role: {
|
|
||||||
type: String,
|
|
||||||
reflect: true,
|
|
||||||
},
|
|
||||||
checked: {
|
checked: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
reflect: true,
|
reflect: true,
|
||||||
|
|
@ -76,7 +72,6 @@ export class LionSwitchButton extends DisabledWithTabIndexMixin(LitElement) {
|
||||||
// inputNode = this, which always requires a value prop
|
// inputNode = this, which always requires a value prop
|
||||||
this.value = '';
|
this.value = '';
|
||||||
|
|
||||||
this.role = 'switch';
|
|
||||||
this.checked = false;
|
this.checked = false;
|
||||||
this.__initialized = false;
|
this.__initialized = false;
|
||||||
/** @protected */
|
/** @protected */
|
||||||
|
|
@ -89,6 +84,7 @@ export class LionSwitchButton extends DisabledWithTabIndexMixin(LitElement) {
|
||||||
|
|
||||||
connectedCallback() {
|
connectedCallback() {
|
||||||
super.connectedCallback();
|
super.connectedCallback();
|
||||||
|
this.setAttribute('role', 'switch');
|
||||||
this.setAttribute('aria-checked', `${this.checked}`);
|
this.setAttribute('aria-checked', `${this.checked}`);
|
||||||
this.addEventListener('click', this._toggleChecked);
|
this.addEventListener('click', this._toggleChecked);
|
||||||
this.addEventListener('keydown', this.__handleKeydown);
|
this.addEventListener('keydown', this.__handleKeydown);
|
||||||
|
|
|
||||||
|
|
@ -345,6 +345,13 @@ export class LionTabs extends LitElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {number}
|
||||||
|
*/
|
||||||
|
get selectedIndex() {
|
||||||
|
return this.__selectedIndex || 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {number} value The new index
|
* @param {number} value The new index
|
||||||
*/
|
*/
|
||||||
|
|
@ -371,13 +378,6 @@ export class LionTabs extends LitElement {
|
||||||
this.requestUpdate('selectedIndex', stale);
|
this.requestUpdate('selectedIndex', stale);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return {number}
|
|
||||||
*/
|
|
||||||
get selectedIndex() {
|
|
||||||
return this.__selectedIndex || 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @protected */
|
/** @protected */
|
||||||
get _pairCount() {
|
get _pairCount() {
|
||||||
return (this.__store && this.__store.length) || 0;
|
return (this.__store && this.__store.length) || 0;
|
||||||
|
|
|
||||||
|
|
@ -198,7 +198,7 @@ export class LionTextarea extends NativeTextFieldMixin(LionFieldWithTextArea) {
|
||||||
let count = 3; // max tasks to wait for
|
let count = 3; // max tasks to wait for
|
||||||
// @ts-ignore this property is added by webcomponentsjs polyfill for old browsers
|
// @ts-ignore this property is added by webcomponentsjs polyfill for old browsers
|
||||||
while (count !== 0 && !this.__shady_native_contains(this._inputNode)) {
|
while (count !== 0 && !this.__shady_native_contains(this._inputNode)) {
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop, no-promise-executor-return
|
||||||
await new Promise(resolve => setTimeout(resolve));
|
await new Promise(resolve => setTimeout(resolve));
|
||||||
count -= 1;
|
count -= 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,115 +0,0 @@
|
||||||
import { LionCollapsible } from '@lion/ui/collapsible.js';
|
|
||||||
|
|
||||||
const EVENT = {
|
|
||||||
TRANSITION_END: 'transitionend',
|
|
||||||
TRANSITION_START: 'transitionstart',
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* `CustomCollapsible` is a class for custom collapsible element (`<custom-collapsible>` web component).
|
|
||||||
* @customElement custom-collapsible
|
|
||||||
*/
|
|
||||||
// @ts-expect-error false positive for incompatible static get properties. Lit-element merges super properties already for you.
|
|
||||||
export class CustomCollapsible extends LionCollapsible {
|
|
||||||
static get properties() {
|
|
||||||
return {
|
|
||||||
transitioning: {
|
|
||||||
type: Boolean,
|
|
||||||
reflect: true,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
this.transitioning = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
connectedCallback() {
|
|
||||||
super.connectedCallback();
|
|
||||||
this._contentNode?.style.setProperty(
|
|
||||||
'transition',
|
|
||||||
'max-height 0.35s, padding 0.35s, opacity 0.35s',
|
|
||||||
);
|
|
||||||
if (this.opened) {
|
|
||||||
this._contentNode?.style.setProperty('padding', '12px 0');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wait until transition is finished.
|
|
||||||
* @override
|
|
||||||
*/
|
|
||||||
toggle() {
|
|
||||||
if (!this.transitioning) {
|
|
||||||
super.toggle();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Trigger show animation and wait for transition to be finished.
|
|
||||||
* @param {Object} options - element node and its options
|
|
||||||
* @param {HTMLElement} options.contentNode
|
|
||||||
* @override
|
|
||||||
*/
|
|
||||||
async _showAnimation({ contentNode }) {
|
|
||||||
const expectedHeight = await this.__calculateHeight(contentNode);
|
|
||||||
contentNode.style.setProperty('opacity', '1');
|
|
||||||
contentNode.style.setProperty('padding', '12px 0');
|
|
||||||
contentNode.style.setProperty('max-height', '0px');
|
|
||||||
// eslint-disable-next-line no-promise-executor-return
|
|
||||||
await new Promise(resolve => requestAnimationFrame(() => resolve(undefined)));
|
|
||||||
contentNode.style.setProperty('max-height', expectedHeight);
|
|
||||||
await this._waitForTransition({ contentNode });
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Trigger hide animation and wait for transition to be finished.
|
|
||||||
* @param {Object} options - element node and its options
|
|
||||||
* @param {HTMLElement} options.contentNode
|
|
||||||
* @override
|
|
||||||
*/
|
|
||||||
async _hideAnimation({ contentNode }) {
|
|
||||||
if (this._contentHeight === '0px') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
['opacity', 'padding', 'max-height'].map(prop => contentNode.style.setProperty(prop, '0'));
|
|
||||||
await this._waitForTransition({ contentNode });
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wait until the transition event is finished.
|
|
||||||
* @param {Object} options - element node and its options
|
|
||||||
* @param {HTMLElement} options.contentNode
|
|
||||||
* @returns {Promise<void>} transition event
|
|
||||||
*/
|
|
||||||
_waitForTransition({ contentNode }) {
|
|
||||||
return new Promise(resolve => {
|
|
||||||
const transitionStarted = () => {
|
|
||||||
contentNode.removeEventListener(EVENT.TRANSITION_START, transitionStarted);
|
|
||||||
this.transitioning = true;
|
|
||||||
};
|
|
||||||
contentNode.addEventListener(EVENT.TRANSITION_START, transitionStarted);
|
|
||||||
|
|
||||||
const transitionEnded = () => {
|
|
||||||
contentNode.removeEventListener(EVENT.TRANSITION_END, transitionEnded);
|
|
||||||
this.transitioning = false;
|
|
||||||
resolve();
|
|
||||||
};
|
|
||||||
contentNode.addEventListener(EVENT.TRANSITION_END, transitionEnded);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculate total content height after collapsible opens
|
|
||||||
* @param {HTMLElement} contentNode content node
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
async __calculateHeight(contentNode) {
|
|
||||||
contentNode.style.setProperty('max-height', '');
|
|
||||||
// eslint-disable-next-line no-promise-executor-return
|
|
||||||
await new Promise(resolve => requestAnimationFrame(() => resolve(undefined)));
|
|
||||||
return this._contentHeight; // Expected height i.e. actual size once collapsed after animation
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
customElements.define('custom-collapsible', CustomCollapsible);
|
|
||||||
Loading…
Reference in a new issue