import {classMap} from "lit/directives/class-map.js"; import {type CSSResultGroup, html, type PropertyValues, unsafeCSS} from 'lit'; import {property} from 'lit/decorators.js'; import ZincElement from '../../internal/zinc-element'; import ZnIcon from "../icon"; import ZnTooltip from "../tooltip"; import styles from './item.scss'; /** * @summary Used for listing items in a description list. Caption on the right, content on the left. * @documentation https://zinc.style/components/item * @status experimental * @since 1.0 * * @dependency zn-icon * @dependency zn-tooltip * * @slot - The default slot. Can either be slotted or use the value attribute * @slot actions - Used for adding actions to a zn-item. * * @csspart base - The items base wrapper * @csspart caption - The items caption * @csspart icon - The items icon */ export default class ZnItem extends ZincElement { static dependencies = { 'zn-icon': ZnIcon, 'zn-tooltip': ZnTooltip }; static styles: CSSResultGroup = unsafeCSS(styles); @property() caption: string; @property() description: string; @property({type: Boolean}) stacked: boolean; @property({reflect: true}) size: 'small' | 'medium' | 'large' = 'medium'; @property({attribute: 'edit-on-hover', type: Boolean}) editOnHover: boolean; @property({attribute: 'help-tooltip'}) helpTooltip: string; @property() icon: string; @property() value: string; @property({type: Boolean}) inline: boolean; @property({type: Boolean}) grid: boolean; @property({type: Boolean, attribute: 'no-padding'}) noPadding: boolean; // align items to the right @property({type: Boolean, attribute: 'align-end'}) alignEnd: boolean; // align items in the center @property({type: Boolean, attribute: 'align-center'}) alignCenter: boolean; connectedCallback() { super.connectedCallback(); this.setAttribute('role', 'listitem'); } protected updated(_changedProperties: PropertyValues) { super.updated(_changedProperties); const inlineEdit = this.querySelector('zn-inline-edit'); if (inlineEdit) { inlineEdit.setAttribute('size', this.size); } this.shadowRoot?.querySelector('.item')?.classList.toggle('item--with-content', this._hasContent()); } protected _hasContent(): boolean { const slotContent = this.querySelectorAll(":scope > :not([slot])")?.length || 0; return slotContent > 0 || this.innerText.length > 0 || !(this.value === undefined || this.value === null) } protected _hasRequiredSlot(): boolean { const slotElements = this.querySelectorAll(":scope > *:not([slot])"); return Array.from(slotElements).some(el => el.hasAttribute && el.hasAttribute('required')); } render() { const hasIcon = this.icon && this.icon.length > 0; const hasHelpTooltip = this.helpTooltip?.length > 0; const headings = html`