import { html } from 'lit' import { customElement, property } from 'lit/decorators.js' import { styleMap } from 'lit-html/directives/style-map.js' import { sliceAddress } from '@/shared/tools/slice-address' import { TailwindElement } from '@/shared/tailwind-element' import { customClassMap } from '@/shared/directives' export type UsernameSize = 'small' | 'large' @customElement('lukso-username') export class LuksoUsername extends TailwindElement { @property({ type: String }) name = '' @property({ type: String }) address = '' @property({ type: Number, attribute: 'max-width' }) maxWidth = 200 @property({ type: 'string' }) size: UsernameSize = 'large' @property({ type: Number, attribute: 'slice-by' }) sliceBy = 8 @property({ type: String, attribute: 'address-color' }) addressColor = 'neutral-20' /** Width of the first 4 bytes of the address */ private bytesWidth = 52 /** * Template for 4byte address * e.g: #1234 */ private addressBytesTemplate() { return html`
#${this.address.slice(2, 6)}
` } /** * Template for name * e.g: @John */ private nameTemplate() { return html`
@${this.name}
` } /** * Template for address * e.g: 0x123...789 */ private addressTemplate() { return html`
${sliceAddress(this.address, this.sliceBy, this.sliceBy)}
` } render() { const template = (() => { if (this.name && this.address) { return html`${this.nameTemplate()}${this.addressBytesTemplate()}` } if (this.name) { return this.nameTemplate() } if (this.address) { return this.addressTemplate() } })() return html`
${template}
` } } declare global { interface HTMLElementTagNameMap { 'lukso-username': LuksoUsername } }