69 lines
3.7 KiB
Plaintext
69 lines
3.7 KiB
Plaintext
component ListGroup {
|
|
outputs {
|
|
select(payload: { value?: string | number | boolean | null; values?: Array<string | number | boolean | null | object>; sourceEvent?: Event; [key: string]: string | number | boolean | null | object } | string | number | boolean | null)
|
|
change(payload: { value?: string | number | boolean | null; values?: Array<string | number | boolean | null | object>; sourceEvent?: Event; [key: string]: string | number | boolean | null | object } | string | number | boolean | null)
|
|
}
|
|
|
|
props {
|
|
size: string = "default"
|
|
color: string = "primary"
|
|
title: string = "List Group"
|
|
description: string = ""
|
|
items: unknown[] = []
|
|
variant: string = "default"
|
|
value: string = ""
|
|
class: string = ""
|
|
}
|
|
state selectedValue = value
|
|
functions {
|
|
client function choose(item, index) {
|
|
if (item.disabled) { return }
|
|
selectedValue = String(item.value || index)
|
|
output.select({ value: selectedValue, item: item, index: index })
|
|
output.change({ value: selectedValue, item: item, index: index })
|
|
}
|
|
}
|
|
view {
|
|
<section {...attrs} class="wrn-list-group {class}" data-wrn-owner="ListGroup" data-wrn-part="root" data-wrn-component="ListGroup" data-wrn-axis-size="{size}" data-wrn-axis-color="{color}" data-wrn-axis-variant="{variant}">
|
|
{#if title}<strong>{title}</strong>{/if}{#if description}<p>{description}</p>{/if}
|
|
<div class="wrn-list-group__items" role="group" aria-label="{title}" data-wrn-owner="ListGroup" data-wrn-part="items" data-wrn-axis-size="{size}" data-wrn-axis-color="{color}" data-wrn-axis-variant="{variant}">{#each items as item, index}<button type="button" disabled="{item.disabled}" aria-pressed="{selectedValue === String(item.value || index)}" @click="choose(item, index)" data-wrn-owner="ListGroup" data-wrn-part="button" data-wrn-axis-size="{size}" data-wrn-axis-color="{color}" data-wrn-axis-variant="{variant}">{#if item.icon}<span class="{item.icon}" aria-hidden="true"></span>{/if}<span><strong>{item.label}</strong>{#if item.description}<small>{item.description}</small>{/if}</span>{#if item.badge}<span class="wrn-list-group__badge" data-wrn-owner="ListGroup" data-wrn-part="badge" data-wrn-axis-size="{size}" data-wrn-axis-color="{color}" data-wrn-axis-variant="{variant}">{item.badge}</span>{/if}</button>{/each}</div><slot />
|
|
</section>
|
|
}
|
|
|
|
style {
|
|
.wrn-list-group { display:grid; gap:.75rem; color:var(--wrn-color-text); }
|
|
.wrn-list-group > p { margin:0; font-size:.875rem; color:var(--wrn-color-muted); }
|
|
.wrn-list-group__items {
|
|
border: 1px solid var(--wrn-color-border);
|
|
border-radius: var(--wrn-radius);
|
|
overflow: hidden;
|
|
box-shadow: var(--wrn-shadow-1);
|
|
}
|
|
.wrn-list-group button {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: .75rem;
|
|
width: 100%;
|
|
padding: .75rem 1rem;
|
|
text-align: start;
|
|
border: 0;
|
|
color: inherit;
|
|
background: var(--wrn-color-surface);
|
|
font: inherit;
|
|
font-size: .875rem;
|
|
cursor: pointer;
|
|
transition: background-color 120ms ease;
|
|
}
|
|
.wrn-list-group button + button { border-top:1px solid var(--wrn-color-border); }
|
|
.wrn-list-group button[aria-pressed="true"] {
|
|
background: color-mix(in srgb, var(--wrn-color-primary) 8%, var(--wrn-color-surface));
|
|
color: var(--wrn-color-text);
|
|
box-shadow: inset 2px 0 0 var(--wrn-color-primary);
|
|
}
|
|
.wrn-list-group button > [class*="icon-"] { width:1.1rem; height:1.1rem; flex:none; }
|
|
.wrn-list-group small { display:block; margin-top:.2rem; color:var(--wrn-color-muted); font-size:.8rem; }
|
|
.wrn-list-group__badge { margin-inline-start:auto; font-size:.75rem; }
|
|
.wrn-list-group button:disabled { opacity:.5; cursor:not-allowed; }
|
|
}
|
|
}
|