Build vertical or horizontal lists from data (items) or compose ListgroupItem children. Set active to render interactive button items.
Setup
<script lang="ts">
import { Listgroup, ListgroupItem } from '.';
</script> Default list
- Profile
- Settings
- Messages
- Download
<script lang="ts">
import { Listgroup } from '.';
</script>
<Listgroup items={['Profile', 'Settings', 'Messages', 'Download']} /> Object items
Pass objects with name, href, current, disabled, and onclick.
<script lang="ts">
import { Listgroup } from '.';
</script>
<Listgroup
items={[
{ name: 'Profile', href: '#', current: true },
{ name: 'Settings', href: '#' },
{ name: 'Billing', href: '#', disabled: true }
]}
/> Links and current item
<script lang="ts">
import { Listgroup, ListgroupItem } from '.';
</script>
<Listgroup>
<ListgroupItem href="/docs" current>Docs</ListgroupItem>
<ListgroupItem href="/">Home</ListgroupItem>
<ListgroupItem href="#" disabled>Disabled</ListgroupItem>
</Listgroup> Active buttons
active on the group renders items as buttons with hover styles.
<script lang="ts">
import { Listgroup, ListgroupItem } from '.';
</script>
<Listgroup active>
<ListgroupItem onclick={() => {}}>Profile</ListgroupItem>
<ListgroupItem onclick={() => {}} current>Messages</ListgroupItem>
</Listgroup> Horizontal
- Profile
- Settings
- Messages
<script lang="ts">
import { Listgroup } from '.';
</script>
<Listgroup horizontal items={['Profile', 'Settings', 'Messages']} /> Without border / rounded
- One
- Two
- Three
- One
- Two
- Three
<Listgroup border={false} items={['One', 'Two', 'Three']} />
<Listgroup rounded={false} items={['One', 'Two', 'Three']} /> Item with icon
<script lang="ts">
import { Listgroup, ListgroupItem } from '.';
import type { Component } from 'svelte';
const UserIcon: Component = () => null; // replace with your icon component
</script>
<Listgroup>
<ListgroupItem Icon={UserIcon} name="Profile" />
</Listgroup> Props
Listgroup (ListgroupProps)
| Prop | Type | Default | Description |
|---|---|---|---|
items | (string \| ListgroupItemType)[] | — | Data-driven items |
children | Snippet<[item]> | — | Custom item renderer / ListgroupItem children |
active | boolean | — | Render as button list (div root) |
horizontal | boolean | false | Row layout with vertical dividers |
rounded | boolean | true | Rounded corners |
border | boolean | true | Outer border |
onclick | (event: MouseEvent) => void | — | Shared click handler |
class / classes | theme slots | — | base / item / icon overrides |
...rest | HTML attributes | — | Root element attrs |
ListgroupItemType
| Field | Type | Description |
|---|---|---|
name | string | Label |
href | string | Link target |
current | boolean | Current/active style |
disabled | boolean | Disabled state |
onclick | (event: MouseEvent) => void | Item click |
ListgroupItem (ListgroupItemProps)
| Prop | Type | Default | Description |
|---|---|---|---|
children | Snippet | — | Item content |
name | string | — | Text when no children |
href | string | — | Render as link |
current | boolean | — | Current/active style |
disabled | boolean | — | Disabled state |
active | boolean | — | Override group active context |
horizontal | boolean | — | Override group horizontal context |
Icon | Component | — | Leading icon component |
type | button type | — | When rendered as button |
class | ClassValue | — | Extra classes |
...rest | button / anchor attrs | — | onclick, etc. |