`, representing a registered
* section type. Drag it onto the canvas to add that section. Unlike zn-page-section-card
* (host-wired), this element wires its own drag behaviour so it is draggable standalone.
* @documentation https://zinc.style/components/page-palette-item
* @status experimental
* @since 1.0
*
* @dependency zn-icon
*
* @csspart base - The card row.
*/
export default class ZnPagePaletteItem extends ZincElement {
static styles: CSSResultGroup = unsafeCSS(styles);
static dependencies = {'zn-icon': ZnIcon};
/** The section type id this item creates when dropped. */
@property() type: string;
@property() label: string;
@property() description: string;
@property() icon: string;
@property({attribute: 'icon-library'}) iconLibrary: string;
@property() color: string;
connectedCallback() {
super.connectedCallback();
this.draggable = true;
this.addEventListener('dragstart', this._onDragStart);
}
disconnectedCallback() {
this.removeEventListener('dragstart', this._onDragStart);
super.disconnectedCallback();
}
protected updated(changed: PropertyValues) {
super.updated(changed);
this.style.setProperty('--section-accent', this.color ?? 'rgb(var(--zn-color-primary))');
}
private _onDragStart = (e: DragEvent) => {
if (!e.dataTransfer || !this.type) return;
e.dataTransfer.setData(PAGE_TYPE_MIME, this.type);
e.dataTransfer.effectAllowed = 'copy';
};
render() {
return html`
${this.label ?? ''}
${this.description ? html`${this.description}` : ''}
`;
}
}