@postnord/web-components
Version:
PostNord Web Components
53 lines (48 loc) • 5.06 kB
JavaScript
/*!
* Built with Stencil
* By PostNord.
*/
;
var index = require('./index-DWu-2oJc.js');
var close_small = require('./close_small-CTOfc4Qy.js');
var index$1 = require('./index.cjs.js');
const pnInputChipCss = () => `${index.transformTag("pn-input-chip")}{display:inline-block}${index.transformTag("pn-input-chip")} .pn-input-chip{position:relative;font-size:1em;font-weight:500;text-align:center;display:flex;align-items:center;gap:0.25em;padding:0.5em 0.5em 0.5em 1em;border:0.0625em solid #969087;border-radius:0.5em;background-color:#ffffff;cursor:pointer;transition-property:border-color, background-color;transition-duration:0.2s;transition-timing-function:cubic-bezier(0.7, 0, 0.3, 1)}@media (prefers-reduced-motion: reduce){${index.transformTag("pn-input-chip")} .pn-input-chip{transition-duration:0s;transition-delay:0s}}${index.transformTag("pn-input-chip")} .pn-input-chip{outline:0.2rem solid transparent;outline-offset:0.2rem}${index.transformTag("pn-input-chip")} .pn-input-chip[data-icon]{padding-left:0.75em}${index.transformTag("pn-input-chip")} .pn-input-chip[data-icon][data-small]{padding-left:0.5em}${index.transformTag("pn-input-chip")} .pn-input-chip[data-icon][data-large]{padding-left:1em}${index.transformTag("pn-input-chip")} .pn-input-chip[data-small]{padding:0.25em 0.25em 0.25em 0.75em}${index.transformTag("pn-input-chip")} .pn-input-chip[data-small] .pn-input-chip-label{line-height:1.25em;font-size:0.875em}${index.transformTag("pn-input-chip")} .pn-input-chip[data-large]{padding:0.6875em 0.6875em 0.6875em 1.25em}${index.transformTag("pn-input-chip")} .pn-input-chip:hover{background-color:#effbff;border-color:#005d92}${index.transformTag("pn-input-chip")} .pn-input-chip:hover .pn-input-chip-label{color:#005d92}${index.transformTag("pn-input-chip")} .pn-input-chip:hover .pn-input-chip-icon .pn-icon-svg path{fill:#005d92}${index.transformTag("pn-input-chip")} .pn-input-chip:focus-visible{outline-color:#005d92;border-color:#005d92}${index.transformTag("pn-input-chip")} .pn-input-chip:active{background-color:#e0f8ff;border-color:#005d92}${index.transformTag("pn-input-chip")} .pn-input-chip:active .pn-input-chip-label{color:#0d234b}${index.transformTag("pn-input-chip")} .pn-input-chip:active .pn-input-chip-icon .pn-icon-svg path{fill:#0d234b}${index.transformTag("pn-input-chip")} .pn-input-chip:disabled{background-color:#f3f2f2;border-color:#f3f2f2;cursor:not-allowed}${index.transformTag("pn-input-chip")} .pn-input-chip:disabled .pn-input-chip-label{color:#5e554a;margin-right:0.5em}${index.transformTag("pn-input-chip")} .pn-input-chip:disabled .pn-input-chip-icon .pn-icon-svg path{fill:#5e554a}${index.transformTag("pn-input-chip")} .pn-input-chip-icon{flex-shrink:0;width:1.5em;height:1.5em}${index.transformTag("pn-input-chip")} .pn-input-chip-label{color:#005d92;line-height:1.5em;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}${index.transformTag("pn-input-chip")} .pn-input-chip-close{flex-shrink:0;width:1.5em;height:1.5em;display:flex;align-items:center;justify-content:center}`;
const PnInputChip = class {
constructor(hostRef) {
index.registerInstance(this, hostRef);
this.pnDelete = index.createEvent(this, "pnDelete", 7);
}
id = `pn-input-chip-${index$1.uuidv4()}`;
/** The chip label text. */
label;
/** Optional value identifier emitted with the delete event. @category Native attributes */
value;
/** Add a leading icon to the chip. @category Features */
icon;
/** Use the small size for the input chip. @category Features */
small = false;
/** Use the large size for the input chip. @category Features */
large = false;
/** Disable the chip. When disabled, the chip is not interactive. @category Native attributes */
disabled = false;
/** Emitted when the chip is clicked (removed). */
pnDelete;
/**
* A unique HTML ID for the input chip.
* @category HTML attributes
*/
pnId;
handleDelete = () => {
if (!this.disabled) {
this.pnDelete.emit({ label: this.label, value: this.value });
}
};
getId() {
return this.pnId || this.id;
}
render() {
return (index.h(index.Host, { key: '38bf6d618ac176e63fc2da44b20aa45b744c3ff8' }, index.h("button", { key: '43a8fa2b75eedefef49ce8881c72e86cf1323486', type: "button", class: "pn-input-chip", id: this.getId(), "data-icon": !!this.icon, "data-small": this.small, "data-large": this.large, disabled: this.disabled, "aria-label": `Remove ${this.label}`, onClick: this.handleDelete }, !!this.icon && index.h("pn-icon", { key: '53b015eba2c0a074febc78089bcdefc9cb799ad1', class: "pn-input-chip-icon", icon: this.icon }), index.h("span", { key: '0baa4ef7ebe84ac5102f295c02ad3f0e08a6516e', class: "pn-input-chip-label" }, this.label), !this.disabled && index.h("pn-icon", { key: '320c04a05bb38411734a77c085bd536c29296423', color: "blue700", icon: close_small.close_small }))));
}
};
PnInputChip.style = pnInputChipCss();
exports.pn_input_chip = PnInputChip;