Skip to content

Commit

Permalink
chore: type enhancements SlotMixin, LocalizeMixin, SelectRichInvoker
Browse files Browse the repository at this point in the history
  • Loading branch information
tlouisse committed Oct 26, 2020
1 parent 51732b0 commit 20ba0ca
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
11 changes: 11 additions & 0 deletions .changeset/large-walls-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@lion/core': patch
'@lion/localize': patch
'@lion/select-rich': patch
---

Type enhancements

- LocalizeMixinTypes.d.ts extend from LitElement
- Make `slots` a getter in SlotMixin types
- selectedElement of type 'LionOption' in SelectRichInvoker
2 changes: 1 addition & 1 deletion packages/core/types/SlotMixinTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export declare class SlotHost {
/**
* Obtains all the slots to create
*/
slots: SlotsMap;
get slots(): SlotsMap;

/**
* Starts the creation of slots
Expand Down
3 changes: 2 additions & 1 deletion packages/localize/types/LocalizeMixinTypes.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Constructor } from '@open-wc/dedupe-mixin';
import { LitElement } from '@lion/core';

export interface FormatNumberPart {
type: string;
Expand Down Expand Up @@ -68,7 +69,7 @@ declare class LocalizeMixinHost {
private __localizeOnLocaleChanged(event: CustomEvent): void;
}

declare function LocalizeMixinImplementation<T extends Constructor<HTMLElement>>(
declare function LocalizeMixinImplementation<T extends Constructor<LitElement>>(
superclass: T,
): T & Constructor<LocalizeMixinHost> & typeof LocalizeMixinHost;

Expand Down
5 changes: 3 additions & 2 deletions packages/select-rich/src/LionSelectInvoker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { css, html } from '@lion/core';

/**
* @typedef {import('@lion/core').CSSResult} CSSResult
* @typedef {import('@lion/listbox').LionOption} LionOption
*/

/**
Expand Down Expand Up @@ -66,8 +67,8 @@ export class LionSelectInvoker extends LionButton {
*/
this.readOnly = false;
/**
* The option Element that is currently selected
* @type {HTMLElement | null}
* The option element that is currently selected
* @type {LionOption | null}
*/
this.selectedElement = null;
/**
Expand Down
12 changes: 8 additions & 4 deletions packages/select-rich/test/lion-select-invoker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { defineCE, expect, fixture, html } from '@open-wc/testing';
import '../lion-select-invoker.js';
import { LionSelectInvoker } from '../src/LionSelectInvoker.js';

/**
* @typedef {import('@lion/listbox').LionOption} LionOption
*/

describe('lion-select-invoker', () => {
it('should behave as a button', async () => {
const el = await fixture(html`<lion-select-invoker></lion-select-invoker>`);
Expand All @@ -13,7 +17,7 @@ describe('lion-select-invoker', () => {
const el = /** @type {LionSelectInvoker} */ (await fixture(
html`<lion-select-invoker></lion-select-invoker>`,
));
el.selectedElement = /** @type {HTMLElement} */ (await fixture(
el.selectedElement = /** @type {LionOption} */ (await fixture(
`<div class="option">Textnode<h2>I am</h2><p>2 lines</p></div>`,
));
await el.updateComplete;
Expand All @@ -34,7 +38,7 @@ describe('lion-select-invoker', () => {
const el = /** @type {LionSelectInvoker} */ (await fixture(
html`<lion-select-invoker></lion-select-invoker>`,
));
el.selectedElement = /** @type {HTMLElement} */ (await fixture(
el.selectedElement = /** @type {LionOption} */ (await fixture(
`<div class="option">just textContent</div>`,
));
await el.updateComplete;
Expand Down Expand Up @@ -81,13 +85,13 @@ describe('lion-select-invoker', () => {
);
const el = /** @type {LionSelectInvoker} */ (await fixture(`<${myTag}></${myTag}>`));

el.selectedElement = /** @type {HTMLElement} */ (await fixture(
el.selectedElement = /** @type {LionOption} */ (await fixture(
`<div class="option">cat</div>`,
));
await el.updateComplete;
expect(el._contentWrapperNode).lightDom.to.equal('cat selected');

el.selectedElement = /** @type {HTMLElement} */ (await fixture(
el.selectedElement = /** @type {LionOption} */ (await fixture(
`<div class="option">dog</div>`,
));
await el.updateComplete;
Expand Down

0 comments on commit 20ba0ca

Please sign in to comment.