46 lines
2.8 KiB
Plaintext
46 lines
2.8 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}">
|
|
{#if title}<strong>{title}</strong>{/if}{#if description}<p>{description}</p>{/if}
|
|
<div class="wrn-list-group__items" role="group" aria-label="{title}">{#each items as item, index}<button type="button" disabled="{item.disabled}" aria-pressed="{selectedValue === String(item.value || index)}" @click="choose(item, index)">{#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">{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-md); overflow:hidden; }
|
|
.wrn-list-group button { display:flex; align-items:center; gap:.75rem; width:100%; padding:.85rem 1rem; text-align:start; border:0; color:inherit; background:var(--wrn-color-surface); font:inherit; font-size:.875rem; cursor:pointer; }
|
|
.wrn-list-group button + button { border-top:1px solid var(--wrn-color-border); }
|
|
.wrn-list-group button[aria-pressed="true"] { background:var(--wrn-color-primary-soft); color:var(--wrn-color-primary-text); }
|
|
.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; }
|
|
}
|
|
}
|