From 6a134b5f4d197625dc2cd17fd938a1f3232f2935 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benny=20Powers=20-=20=D7=A2=D7=9D=20=D7=99=D7=A9=D7=A8?= =?UTF-8?q?=D7=90=D7=9C=20=D7=97=D7=99!?= Date: Mon, 23 Oct 2023 19:04:11 +0300 Subject: [PATCH] fix(tag): remove baselabel (#1279) Closes #1278 --- .changeset/remove-baselabel.md | 4 +++ elements/rh-tag/rh-tag.ts | 63 ++++++++++++++++++---------------- 2 files changed, 37 insertions(+), 30 deletions(-) create mode 100644 .changeset/remove-baselabel.md diff --git a/.changeset/remove-baselabel.md b/.changeset/remove-baselabel.md new file mode 100644 index 0000000000..77790185d6 --- /dev/null +++ b/.changeset/remove-baselabel.md @@ -0,0 +1,4 @@ +--- +"@rhds/elements": patch +--- +``: remove dependency on `@patternfly/elements` diff --git a/elements/rh-tag/rh-tag.ts b/elements/rh-tag/rh-tag.ts index fa863fdad9..0943b76dd4 100644 --- a/elements/rh-tag/rh-tag.ts +++ b/elements/rh-tag/rh-tag.ts @@ -1,31 +1,31 @@ -import { html } from 'lit'; +import { html, LitElement } from 'lit'; import { classMap } from 'lit/directives/class-map.js'; import { customElement } from 'lit/decorators/custom-element.js'; import { property } from 'lit/decorators/property.js'; import { colorContextConsumer, type ColorTheme } from '../../lib/context/color/consumer.js'; -import { BaseLabel } from '@patternfly/elements/pf-label/BaseLabel.js'; +import { SlotController } from '@patternfly/pfe-core/controllers/slot-controller.js'; import '@patternfly/elements/pf-icon/pf-icon.js'; import styles from './rh-tag.css'; -export type TagColor = ( - | 'blue' - | 'cyan' - | 'green' - | 'orange' - | 'purple' - | 'red' - | 'grey' -) - - /** * A tag is a caption added to an element for better clarity and user convenience. * * @summary Highlights an element to add clarity or draw attention + * + * @fires close - when a removable label's close button is clicked + * + * @slot icon + * Contains the labels's icon, e.g. web-icon-alert-success. + * + * @slot + * Must contain the text for the label. + * + * @csspart icon - container for the label icon + * * @cssprop {} --rh-tag-margin-inline-end * The margin at the end of the direction parallel to the flow of the text. * {@default 4px} @@ -45,7 +45,7 @@ export type TagColor = ( * */ @customElement('rh-tag') -export class RhTag extends BaseLabel { +export class RhTag extends LitElement { static readonly styles = [styles]; /** The icon to display in the label. */ @@ -55,32 +55,35 @@ export class RhTag extends BaseLabel { @property() variant?: 'filled' | 'outline' = 'filled'; /** The color of the label. */ - @property() color?: TagColor; + @property() color?: 'blue' | 'cyan' | 'green' | 'orange' | 'purple' | 'red' | 'grey'; @colorContextConsumer() private on?: ColorTheme; - /** - * RhIcon does not yet exist, so we are using pfe-icon until available - * - */ - protected renderDefaultIcon() { - return !this.icon ? '' : html` - - `; - } + /** Represents the state of the anonymous and icon slots */ + #slots = new SlotController(this, 'icon', null); override render() { - const { on = '' } = this; + const { variant, color, icon, on = '' } = this; + const hasIcon = !!icon || this.#slots.hasSlotted('icon'); return html` - ${super.render()} + + + + + + `; } - - protected renderSuffix() { - return html``; - } } +export type TagColor = RhTag['color']; + declare global { interface HTMLElementTagNameMap { 'rh-tag': RhTag;