344 lines
9.1 KiB
Plaintext
344 lines
9.1 KiB
Plaintext
component Badge {
|
|
outputs {
|
|
dismiss(payload: { sourceEvent?: Event; [key: string]: string | number | boolean | null | object })
|
|
}
|
|
|
|
props {
|
|
label: string = "Badge"
|
|
size: string = "md"
|
|
color: string = "primary"
|
|
variant: string = "solid"
|
|
shape: string = "pill"
|
|
class: string = ""
|
|
|
|
icon: string = ""
|
|
iconPosition: string = "start"
|
|
dot: boolean = false
|
|
dotOnly: boolean = false
|
|
dotLabel: string = "Status"
|
|
animated: boolean = false
|
|
|
|
avatarSrc: string = ""
|
|
avatarAlt: string = ""
|
|
dismissible: boolean = false
|
|
dismissLabel: string = "Remove badge"
|
|
truncate: boolean = false
|
|
maxWidth: string = "12rem"
|
|
|
|
anchorLabel: string = ""
|
|
anchorIcon: string = ""
|
|
placement: string = "inline"
|
|
anchorLabelText: string = "Badge anchor"
|
|
|
|
}
|
|
|
|
state visible: boolean = true
|
|
|
|
functions {
|
|
// output.dismiss reaches a parent @dismiss binding; a raw dispatchEvent on
|
|
// the root does not. The runtime registers parent handlers in a registry
|
|
// that only the output proxy consults, so the CustomEvent this used to
|
|
// build bubbled past every binding and was never seen by anyone.
|
|
client function dismissBadge() {
|
|
visible = false
|
|
output.dismiss({ component: "Badge", label: label })
|
|
}
|
|
}
|
|
|
|
view {
|
|
<span
|
|
{...attrs}
|
|
class="wire-next wire-next--badge-root {anchorLabel || anchorIcon ? 'wire-next--badge-anchored' : ''} {class}"
|
|
data-wrn-badge
|
|
data-placement="{placement}"
|
|
data-show="visible"
|
|
aria-hidden="{visible ? 'false' : 'true'}"
|
|
>
|
|
{#if anchorLabel || anchorIcon}
|
|
<button type="button" class="wire-next__badge-anchor" aria-label="{anchorLabelText}">
|
|
{#if anchorIcon}<span class="{anchorIcon}" aria-hidden="true"></span>{/if}
|
|
{#if anchorLabel}<span>{anchorLabel}</span>{/if}
|
|
</button>
|
|
{/if}
|
|
|
|
<span
|
|
class="wire-next__badge"
|
|
data-size="{size}"
|
|
data-color="{color}"
|
|
data-variant="{variant}"
|
|
data-shape="{shape}"
|
|
data-animated="{animated ? 'true' : 'false'}"
|
|
style="--wire-badge-max-width:{maxWidth}"
|
|
role="{dotOnly ? 'status' : ''}"
|
|
aria-label="{dotOnly ? dotLabel : ''}"
|
|
>
|
|
{#if animated}
|
|
<span class="wire-next__badge-ping" aria-hidden="true"></span>
|
|
{/if}
|
|
{#if avatarSrc}
|
|
<img class="wire-next__badge-avatar" src="{avatarSrc}" alt="{avatarAlt}" loading="lazy" />
|
|
{/if}
|
|
{#if dot || dotOnly}
|
|
<span class="wire-next__badge-dot" aria-hidden="true"></span>
|
|
{/if}
|
|
{#if icon && iconPosition === "start"}
|
|
<span class="wire-next__badge-icon {icon}" aria-hidden="true"></span>
|
|
{/if}
|
|
{#if !dotOnly}
|
|
<span class="wire-next__badge-label {truncate ? 'wire-next__badge-label--truncate' : ''}">
|
|
{label}
|
|
</span>
|
|
{/if}
|
|
{#if icon && iconPosition === "end"}
|
|
<span class="wire-next__badge-icon {icon}" aria-hidden="true"></span>
|
|
{/if}
|
|
{#if dismissible}
|
|
<button type="button" class="wire-next__badge-dismiss" aria-label="{dismissLabel}" @click="dismissBadge(event)">
|
|
<span class="icon-[lucide--x]" aria-hidden="true"></span>
|
|
</button>
|
|
{/if}
|
|
</span>
|
|
</span>
|
|
}
|
|
|
|
style {
|
|
/* --- Badge --------------------------------------------------------------- */
|
|
.wire-next--badge-root {
|
|
position: relative;
|
|
display: inline-flex;
|
|
width: fit-content;
|
|
max-width: 100%;
|
|
vertical-align: middle;
|
|
}
|
|
|
|
.wire-next__badge {
|
|
--wire-badge-color: var(--wire-color-primary);
|
|
position: relative;
|
|
isolation: isolate;
|
|
display: inline-flex;
|
|
min-width: 0;
|
|
min-height: 1.65rem;
|
|
align-items: center;
|
|
justify-content: center;
|
|
gap: 0.35rem;
|
|
max-width: var(--wire-badge-max-width);
|
|
padding: 0.25rem 0.6rem;
|
|
color: white;
|
|
border: 1px solid var(--wire-badge-color);
|
|
border-radius: 999px;
|
|
background: var(--wire-badge-color);
|
|
box-shadow: 0 4px 12px color-mix(in srgb, var(--wire-badge-color) 18%, transparent);
|
|
font-size: 0.75rem;
|
|
font-weight: 750;
|
|
line-height: 1;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.wire-next__badge[data-size="xs"] {
|
|
min-height: 1.25rem;
|
|
padding: 0.15rem 0.4rem;
|
|
font-size: 0.625rem;
|
|
}
|
|
|
|
.wire-next__badge[data-size="sm"] {
|
|
min-height: 1.45rem;
|
|
padding: 0.2rem 0.5rem;
|
|
font-size: 0.6875rem;
|
|
}
|
|
|
|
.wire-next__badge[data-size="lg"] {
|
|
min-height: 2rem;
|
|
padding: 0.35rem 0.75rem;
|
|
font-size: 0.825rem;
|
|
}
|
|
|
|
.wire-next__badge[data-color="secondary"] {
|
|
--wire-badge-color: #737373;
|
|
}
|
|
|
|
.wire-next__badge[data-color="success"] {
|
|
--wire-badge-color: #0f9f8f;
|
|
}
|
|
|
|
.wire-next__badge[data-color="info"] {
|
|
--wire-badge-color: #2563eb;
|
|
}
|
|
|
|
.wire-next__badge[data-color="danger"] {
|
|
--wire-badge-color: #ef3340;
|
|
}
|
|
|
|
.wire-next__badge[data-color="warning"] {
|
|
--wire-badge-color: #eab308;
|
|
}
|
|
|
|
.wire-next__badge[data-color="dark"] {
|
|
--wire-badge-color: #27272a;
|
|
}
|
|
|
|
.wire-next__badge[data-color="light"] {
|
|
--wire-badge-color: #f4f4f5;
|
|
}
|
|
|
|
.wire-next__badge[data-color="warning"][data-variant="solid"],
|
|
.wire-next__badge[data-color="light"][data-variant="solid"] {
|
|
color: #18181b;
|
|
}
|
|
|
|
.wire-next__badge[data-variant="soft"] {
|
|
color: var(--wire-badge-color);
|
|
border-color: transparent;
|
|
background: color-mix(in srgb, var(--wire-badge-color) 15%, var(--wire-color-surface));
|
|
box-shadow: none;
|
|
}
|
|
|
|
.wire-next__badge[data-variant="outline"] {
|
|
color: var(--wire-badge-color);
|
|
background: transparent;
|
|
box-shadow: none;
|
|
}
|
|
|
|
.wire-next__badge[data-variant="white"] {
|
|
color: var(--wire-color-text);
|
|
border-color: var(--wire-color-border);
|
|
background: var(--wire-color-surface);
|
|
box-shadow: 0 4px 12px rgb(0 0 0 / 0.12);
|
|
}
|
|
|
|
.wire-next__badge[data-shape="rounded"] {
|
|
border-radius: 0.4rem;
|
|
}
|
|
|
|
.wire-next__badge[data-shape="square"] {
|
|
border-radius: 0;
|
|
}
|
|
|
|
.wire-next__badge-label {
|
|
min-width: 0;
|
|
}
|
|
|
|
.wire-next__badge-label--truncate {
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
}
|
|
|
|
.wire-next__badge-dot {
|
|
width: 0.42rem;
|
|
height: 0.42rem;
|
|
flex: none;
|
|
border-radius: 999px;
|
|
background: currentColor;
|
|
}
|
|
|
|
.wire-next__badge:has(.wire-next__badge-dot):not(:has(.wire-next__badge-label)) {
|
|
width: 0.7rem;
|
|
min-width: 0.7rem;
|
|
height: 0.7rem;
|
|
min-height: 0.7rem;
|
|
padding: 0;
|
|
border: 2px solid var(--wire-color-bg);
|
|
}
|
|
|
|
.wire-next__badge:has(.wire-next__badge-dot):not(:has(.wire-next__badge-label))
|
|
.wire-next__badge-dot {
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
|
|
.wire-next__badge-icon {
|
|
width: 0.9rem;
|
|
height: 0.9rem;
|
|
flex: none;
|
|
}
|
|
|
|
.wire-next__badge-avatar {
|
|
width: 1.25rem;
|
|
height: 1.25rem;
|
|
margin-left: -0.35rem;
|
|
object-fit: cover;
|
|
border: 1px solid color-mix(in srgb, currentColor 35%, transparent);
|
|
border-radius: 999px;
|
|
}
|
|
|
|
.wire-next__badge-dismiss {
|
|
display: grid;
|
|
width: 1.15rem;
|
|
height: 1.15rem;
|
|
margin-right: -0.3rem;
|
|
padding: 0;
|
|
place-items: center;
|
|
color: currentColor;
|
|
border: 0;
|
|
border-radius: 999px;
|
|
background: color-mix(in srgb, currentColor 12%, transparent);
|
|
cursor: pointer;
|
|
}
|
|
|
|
.wire-next__badge-dismiss:hover {
|
|
background: color-mix(in srgb, currentColor 22%, transparent);
|
|
}
|
|
|
|
.wire-next__badge-dismiss:focus-visible {
|
|
outline: 2px solid currentColor;
|
|
outline-offset: 2px;
|
|
}
|
|
|
|
.wire-next__badge-dismiss span {
|
|
width: 0.75rem;
|
|
height: 0.75rem;
|
|
}
|
|
|
|
.wire-next__badge-anchor {
|
|
display: inline-flex;
|
|
min-height: 2.75rem;
|
|
align-items: center;
|
|
justify-content: center;
|
|
gap: 0.5rem;
|
|
padding: 0.65rem 0.9rem;
|
|
color: var(--wire-color-text);
|
|
border: 1px solid var(--wire-color-border);
|
|
border-radius: 0.5rem;
|
|
background: var(--wire-color-surface);
|
|
font: inherit;
|
|
font-size: 0.875rem;
|
|
font-weight: 700;
|
|
}
|
|
|
|
.wire-next__badge-anchor > [class*="icon-"] {
|
|
width: 1rem;
|
|
height: 1rem;
|
|
}
|
|
|
|
.wire-next--badge-anchored[data-placement="inline"] {
|
|
align-items: center;
|
|
}
|
|
|
|
.wire-next--badge-anchored[data-placement="inline"] .wire-next__badge {
|
|
margin-left: -0.55rem;
|
|
}
|
|
|
|
.wire-next--badge-anchored[data-placement="top-right"] .wire-next__badge {
|
|
position: absolute;
|
|
top: -0.55rem;
|
|
right: -0.75rem;
|
|
z-index: 2;
|
|
}
|
|
|
|
.wire-next__badge-ping {
|
|
position: absolute;
|
|
z-index: -1;
|
|
inset: -0.25rem;
|
|
border-radius: inherit;
|
|
background: var(--wire-badge-color);
|
|
opacity: 0.5;
|
|
animation: wire-badge-ping 1.4s cubic-bezier(0, 0, 0.2, 1) infinite;
|
|
}
|
|
|
|
@media (prefers-reduced-motion: reduce) {
|
|
.wire-next__badge-ping {
|
|
animation: none;
|
|
}
|
|
}
|
|
}
|
|
}
|