diff --git a/src/components.d.ts b/src/components.d.ts index 85ac00e..ec6e6c4 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -753,7 +753,7 @@ export namespace Components { "external": boolean; "styleClass": string; "theme": string; - "toBeRemoved": boolean; + "url": string; "variant": string; } interface EclText { @@ -814,6 +814,10 @@ export interface EclSelectCustomEvent extends CustomEvent { detail: T; target: HTMLEclSelectElement; } +export interface EclTagCustomEvent extends CustomEvent { + detail: T; + target: HTMLEclTagElement; +} export interface EclTextareaCustomEvent extends CustomEvent { detail: T; target: HTMLEclTextareaElement; @@ -1310,7 +1314,18 @@ declare global { prototype: HTMLEclSpinnerElement; new (): HTMLEclSpinnerElement; }; + interface HTMLEclTagElementEventMap { + "removeTag": boolean; + } interface HTMLEclTagElement extends Components.EclTag, HTMLStencilElement { + addEventListener(type: K, listener: (this: HTMLEclTagElement, ev: EclTagCustomEvent) => any, options?: boolean | AddEventListenerOptions): void; + addEventListener(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; + addEventListener(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; + addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; + removeEventListener(type: K, listener: (this: HTMLEclTagElement, ev: EclTagCustomEvent) => any, options?: boolean | EventListenerOptions): void; + removeEventListener(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | EventListenerOptions): void; + removeEventListener(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | EventListenerOptions): void; + removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void; } var HTMLEclTagElement: { prototype: HTMLEclTagElement; @@ -2193,9 +2208,10 @@ declare namespace LocalJSX { } interface EclTag { "external"?: boolean; + "onRemoveTag"?: (event: EclTagCustomEvent) => void; "styleClass"?: string; "theme"?: string; - "toBeRemoved"?: boolean; + "url"?: string; "variant"?: string; } interface EclText { diff --git a/src/components/ecl-tag/ecl-tag.stories.ts b/src/components/ecl-tag/ecl-tag.stories.ts index 58c9242..9bbfb4f 100644 --- a/src/components/ecl-tag/ecl-tag.stories.ts +++ b/src/components/ecl-tag/ecl-tag.stories.ts @@ -1,7 +1,9 @@ +import { randomizedLink } from "../../utils/randomizedLink"; + const getArgs = () => { return { variant: 'link', - url: '', + url: randomizedLink('/example.html'), external: false, ariaLabel: 'aria label', }; @@ -14,6 +16,11 @@ const getArgTypes = () => { options: ['link', 'removable'], description: "Tag variant" }, + url: { + type: { name: 'string' }, + description: "Link url", + if: { arg: 'variant', eq: 'link' }, + }, external: { name: 'external', type: { name: 'boolean' }, diff --git a/src/components/ecl-tag/ecl-tag.tsx b/src/components/ecl-tag/ecl-tag.tsx index b0f9bbc..36fdf95 100644 --- a/src/components/ecl-tag/ecl-tag.tsx +++ b/src/components/ecl-tag/ecl-tag.tsx @@ -1,4 +1,4 @@ -import { Component, Prop, h, Element } from '@stencil/core'; +import { Component, Prop, h, State, Event, EventEmitter } from '@stencil/core'; @Component({ tag: 'ecl-tag', @@ -10,12 +10,14 @@ import { Component, Prop, h, Element } from '@stencil/core'; scoped: true, }) export class EclTag { - @Element() el: HTMLElement; @Prop() theme: string = 'ec'; @Prop() styleClass: string; @Prop() external: boolean = false; @Prop() variant: string = 'display'; - @Prop() toBeRemoved: boolean = false; + @Prop() url: string = ''; + @State() toBeRemoved: boolean = false; + + @Event() removeTag: EventEmitter; getClass(): string { return [ @@ -28,7 +30,7 @@ export class EclTag { getTag(variant) { switch (variant) { case 'link': - return 'a' + return 'a'; case 'display': return 'span'; @@ -36,7 +38,7 @@ export class EclTag { case 'removable': return 'button'; - default: + default: } } @@ -45,7 +47,7 @@ export class EclTag { ) @@ -55,6 +57,10 @@ export class EclTag { return ( { + this.toBeRemoved = true; + this.removeTag.emit(true); // Emit the custom event + }} > { - this.toBeRemoved = true; - }); - } - } - render() { const Element = this.getTag(this.variant); return ( { this.variant === 'link' && this.external ? this.getExternal() : '' } @@ -91,4 +88,4 @@ export class EclTag { ) } -} \ No newline at end of file +} diff --git a/src/components/ecl-tag/readme.md b/src/components/ecl-tag/readme.md index c773a03..2481b3c 100644 --- a/src/components/ecl-tag/readme.md +++ b/src/components/ecl-tag/readme.md @@ -7,13 +7,20 @@ ## Properties -| Property | Attribute | Description | Type | Default | -| ------------- | --------------- | ----------- | --------- | ----------- | -| `external` | `external` | | `boolean` | `false` | -| `styleClass` | `style-class` | | `string` | `undefined` | -| `theme` | `theme` | | `string` | `'ec'` | -| `toBeRemoved` | `to-be-removed` | | `boolean` | `false` | -| `variant` | `variant` | | `string` | `'display'` | +| Property | Attribute | Description | Type | Default | +| ------------ | ------------- | ----------- | --------- | ----------- | +| `external` | `external` | | `boolean` | `false` | +| `styleClass` | `style-class` | | `string` | `undefined` | +| `theme` | `theme` | | `string` | `'ec'` | +| `url` | `url` | | `string` | `''` | +| `variant` | `variant` | | `string` | `'display'` | + + +## Events + +| Event | Description | Type | +| ----------- | ----------- | ---------------------- | +| `removeTag` | | `CustomEvent` | ## Dependencies