Accordion
An accordion component that allows users to show and hide sections of content. It uses collapse functionality internally to create collapsible panels.
#Import
use gpui_kit::component::accordion::Accordion;// Installed in ui/components. That directory is on the Slint include path, so import by file name:
import { AccordionEntry, AccordionItem, Accordion } from "accordion.slint";use std::collections::BTreeSet;import { signal, Text, View } from "nsh";
import { Accordion } from "./accordion";
import { Avatar } from "./avatar";
import { Button } from "./button";
import { Switch } from "./switch";
import { tokens } from "./theme";#Usage
const faqOpen = signal<string[]>(["email"]);
const usage = (
<Accordion
bordered
value={faqOpen()}
onChange={(next) => faqOpen.set(next)}
items={[
{
id: "history",
title: "Can I access my account history?",
content: (
<Text style={{ fontSize: 13, lineHeight: 19, color: tokens.mutedForeground }}>
Your history is kept for twelve months. Open Account → History to filter by
date, device or action.
</Text>
),
},
{
id: "premium",
title: "Premium feature information",
description: "Locked on this plan.",
disabled: true,
content: (
<Text style={{ fontSize: 13, color: tokens.mutedForeground }}>
Upgrade to unlock the full history.
</Text>
),
},
{
id: "email",
title: "How do I update my email address?",
content: (
<Text style={{ fontSize: 13, lineHeight: 19, color: tokens.mutedForeground }}>
You can update your email address in your account settings. You’ll receive a
verification email at your new address to confirm the change.
</Text>
),
},
]}
/>
);#Single
Accordion::new("my-accordion")
.item(|item| {
item.title("Section 1")
.child("Content for section 1")
})
.item(|item| {
item.title("Section 2")
.child("Content for section 2")
})
.item(|item| {
item.title("Section 3")
.child("Content for section 3")
})Accordion {
open-index: 0;
items: [
{ title: "What is GPUI Kit?", content: "A Rust desktop application framework built on GPUI, with styled components inspired by macOS and Windows controls." },
{ title: "Which platforms are supported?", content: "macOS on Apple silicon and Intel, Linux on x86_64, and Windows on x86_64." },
{ title: "Can I restyle the components?", content: "Yes. Every component reads semantic theme tokens, so switching the palette restyles the whole application." },
];
toggled(index, open) => {
root.last-toggle = open ? "Section \{index + 1} opened." : "Section \{index + 1} closed.";
}
}
Text {
text: root.last-toggle;
color: Theme.muted-foreground;
font-size: Theme.font-size-xs;
}// Opening one section closes the others: single mode is the caller's own
// rule over its open set, which is why the last of these three is not open.
let single = panel(
app,
SINGLE,
true,
ControlSize::Medium,
true,
&[
(
"What is Iced?",
"A Rust desktop application framework built on iced, with styled \
components inspired by macOS and Windows controls.",
),
(
"Which platforms are supported?",
"macOS on Apple silicon and Intel, Linux on x86_64, and Windows on \
x86_64.",
),
(
"Can I restyle the components?",
"Yes. Every component reads semantic theme tokens, so switching the \
palette restyles the whole application.",
),
],
);const accountOpen = signal<string[]>(["account"]);
const single = (
<Accordion
type="single"
separated
value={accountOpen()}
onChange={(next) => accountOpen.set(next)}
items={[
{
id: "account",
title: "Account Settings",
description: "Profile, security and personal information.",
icon: "settings",
badge: "New",
badgeTone: "success",
content: (
<Text style={{ fontSize: 13, lineHeight: 19, color: tokens.mutedForeground }}>
Manage your account preferences, security settings, and personal information.
You can also configure two-factor authentication here.
</Text>
),
},
{
id: "privacy",
title: "Privacy & Security",
icon: "lock",
content: (
<Text style={{ fontSize: 13, lineHeight: 19, color: tokens.mutedForeground }}>
Control sessions, recovery codes and which devices can reach the account.
</Text>
),
},
{
id: "help",
title: "Help & Support",
icon: "message-circle",
content: (
<Text style={{ fontSize: 13, lineHeight: 19, color: tokens.mutedForeground }}>
Search the guides or open a conversation with the support team.
</Text>
),
},
]}
/>
);#Multiple
// The open set holds every open section, so an accordion the caller does not
// close on a toggle simply allows several — two are open on boot.
let multiple = panel(
app,
MULTIPLE,
false,
ControlSize::Medium,
true,
&[
(
"Shipping",
"Orders ship within two business days from our warehouse.",
),
(
"Returns",
"Return any unused item within 30 days for a full refund.",
),
(
"Warranty",
"Hardware is covered for two years against manufacturing defects.",
),
],
);const nestedOpen = signal<string[]>(["specs"]);
const multiple = (
<Accordion
bordered
type="multiple"
defaultValue={["details"]}
items={[
{
id: "overview",
title: "Product Overview",
content: (
<Text style={{ fontSize: 13, lineHeight: 19, color: tokens.mutedForeground }}>
A compact summary of what is in the box and who it is for.
</Text>
),
},
{
id: "details",
title: "Additional Details",
content: (
<Accordion
separated
size="small"
value={nestedOpen()}
onChange={(next) => nestedOpen.set(next)}
items={[
{
id: "specs",
title: "Technical Specifications",
content: (
<Text style={{ fontSize: 12, lineHeight: 18, color: tokens.mutedForeground }}>
Detailed technical specs including dimensions, weight, and power
requirements.
</Text>
),
},
{
id: "compatibility",
title: "Compatibility",
content: (
<Text style={{ fontSize: 12, lineHeight: 18, color: tokens.mutedForeground }}>
Works with the current and previous release.
</Text>
),
},
]}
/>
),
},
{
id: "shipping",
title: "Shipping & Returns",
content: (
<Text style={{ fontSize: 13, lineHeight: 19, color: tokens.mutedForeground }}>
Delivery takes two to four business days. Returns are open for thirty days.
</Text>
),
},
]}
/>
);By default, only one accordion item can be open at a time. Use multiple() to allow multiple items to be open:
Accordion::new("my-accordion")
.multiple(true)
.item(|item| item.title("Section 1").child("Content 1"))
.item(|item| item.title("Section 2").child("Content 2"))Accordion {
multiple: true;
open-index: 0;
items: [
{ title: "Shipping", content: "Orders ship within two business days from our warehouse." },
{ title: "Returns", content: "Return any unused item within 30 days for a full refund." },
{ title: "Warranty", content: "Hardware is covered for two years against manufacturing defects." },
];
}#Icons and custom content
Accordion::new("my-accordion")
.item(|item| {
item.title(
h_flex()
.gap_2()
.child(Icon::new(IconName::Settings))
.child("Settings")
)
.child("Settings content here")
})Accordion {
AccordionItem {
title: "Notifications";
icon: "bell";
open: true;
VerticalLayout {
spacing: 8px;
Text {
text: root.notifications == 0 ? "You're all caught up." : "\{root.notifications} unread notifications.";
color: Theme.foreground;
font-size: Theme.font-size-sm;
}
GridLayout {
spacing: 8px;
Button {
horizontal-stretch: 0;
text: "Mark all as read";
size: ControlSize.small;
enabled: root.notifications > 0;
clicked => {
root.notifications = 0;
}
}
Button {
horizontal-stretch: 0;
text: "Simulate new";
size: ControlSize.small;
variant: ButtonVariant.ghost;
icon: "plus";
clicked => {
root.notifications += 1;
}
}
}
}
}
AccordionItem {
title: "Settings";
icon: "settings";
Text {
text: "Preferences for appearance, keyboard shortcuts, and updates.";
color: Theme.foreground;
font-size: Theme.font-size-sm;
wrap: word-wrap;
}
}
AccordionItem {
title: "Nested sections";
icon: "layers";
last: true;
Accordion {
size: ControlSize.small;
items: [
{ title: "Child section 1", content: "Content of the first child section." },
{ title: "Child section 2", content: "Content of the second child section." },
];
}
}
}// The header is the caller's element, so a leading icon is just another
// child; the panel is the caller's too, so the notification controls below
// live inside a section.
let unread = if app.notifications == 0 {
"You're all caught up.".to_string()
} else {
format!("{} unread notifications.", app.notifications)
};
let icons = Accordion::new([
Section::new(labeled_header(
mark(BELL, 14.0, muted),
"Notifications",
theme::FONT_SIZE_SM,
8.0,
))
.on_toggle(toggle(app, ICONS, 0, "Notifications", false))
.open(is_open(app, ICONS, 0))
.content(column![
text(unread)
.size(theme::FONT_SIZE_SM)
.style(|theme: &Theme| text::Style {
color: Some(Tokens::of(theme).foreground),
}),
row![
Button::new("Mark all as read")
.size(ControlSize::XSmall)
.on_press(Message::MarkAllRead),
Button::new("Simulate new")
.variant(Variant::Ghost)
.size(ControlSize::XSmall)
.icon(mark(PLUS, 14.0, |theme| {
Tokens::of(theme).muted_foreground
}))
.on_press(Message::SimulateNew),
]
.spacing(8.0),
]),
Section::new(labeled_header(
mark(SETTINGS, 14.0, muted),
"Settings",
theme::FONT_SIZE_SM,
8.0,
))
.on_toggle(toggle(app, ICONS, 1, "Settings", false))
.open(is_open(app, ICONS, 1))
.content(line(
"Preferences for appearance, keyboard shortcuts, and updates.",
theme::FONT_SIZE_SM,
muted,
)),
])
.size(ControlSize::Medium);const teamOpen = signal<string[]>(["alex"]);
const icons = (
<Accordion
bordered
value={teamOpen()}
onChange={(next) => teamOpen.set(next)}
items={[
{
id: "alex",
leading: <Avatar name="Alex Johnson" size="md" />,
title: "Alex Johnson",
badge: "Admin",
badgeTone: "success",
content: (
<Text style={{ fontSize: 13, lineHeight: 19, color: tokens.mutedForeground }}>
Alex has full administrative access, including billing management, user
provisioning, and security configurations.
</Text>
),
},
{
id: "sarah",
leading: <Avatar name="Sarah Chen" size="md" />,
title: "Sarah Chen",
badge: "Viewer",
badgeTone: "neutral",
content: (
<Text style={{ fontSize: 13, lineHeight: 19, color: tokens.mutedForeground }}>
Sarah can view projects and comment, but cannot change workspace settings.
</Text>
),
},
{
id: "michael",
leading: <Avatar name="Michael Rodriguez" size="md" />,
title: "Michael Rodriguez",
badge: "Editor",
badgeTone: "info",
content: (
<Text style={{ fontSize: 13, lineHeight: 19, color: tokens.mutedForeground }}>
Michael can create and edit project content, and invite collaborators.
</Text>
),
},
]}
/>
);#Icons and custom content — 2 of 2
// The marker repeats the heading above because the page has no heading of
// its own for a caller-supplied disclosure: this example sits under the
// closest one the page documents. `Section::disclosure` hands the trailing
// lane the caller's element — here Lucide's arrow in place of the
// component's default chevron — so the icon set stays the caller's.
let custom_icon = Accordion::new([
arrow_section(
app,
CUSTOM_ICON,
0,
"Custom arrow",
"The disclosure in the trailing lane is the caller's arrow.",
),
arrow_section(
app,
CUSTOM_ICON,
1,
"Second section",
"Each section draws the mark its own open state wants.",
),
])
.size(ControlSize::Medium);#Sizes
use gpui_kit::component::{Sizable as _, Size};
Accordion::new("my-accordion")
.small()
.item(|item| item.title("Small Section").child("Content"))
Accordion::new("my-accordion")
.large()
.item(|item| item.title("Large Section").child("Content"))GridLayout {
spacing: 16px;
Accordion {
horizontal-stretch: 1;
size: ControlSize.xsmall;
open-index: 0;
items: [
{ title: "Extra small", content: "Compact rows for dense panels." },
{ title: "Second section", content: "Content." },
];
}
Accordion {
horizontal-stretch: 1;
size: ControlSize.small;
open-index: 0;
items: [
{ title: "Small", content: "Rows for sidebars and inspectors." },
{ title: "Second section", content: "Content." },
];
}
Accordion {
horizontal-stretch: 1;
size: ControlSize.large;
open-index: 0;
items: [
{ title: "Large", content: "Roomy rows for settings pages." },
{ title: "Second section", content: "Content." },
];
}
}// The size ladder: compact rows at xsmall, sidebar rows at small, roomy rows
// at large. iced has no wrapping grid, so the three stack.
let sizes = column![
caption("Extra small"),
panel(
app,
XSMALL,
false,
ControlSize::XSmall,
true,
&[
("Extra small", "Compact rows for dense panels."),
("Second section", "Content."),
],
),
caption("Small"),
panel(
app,
SMALL,
false,
ControlSize::Small,
true,
&[
("Small", "Rows for sidebars and inspectors."),
("Second section", "Content."),
],
),
caption("Large"),
panel(
app,
LARGE,
false,
ControlSize::Large,
true,
&[
("Large", "Roomy rows for settings pages."),
("Second section", "Content."),
],
),
]
.spacing(8.0);const sizes = (
<Column gap={10}>
<Accordion
bordered
size="small"
defaultValue={["compact"]}
items={[
{
id: "compact",
title: "Compact rows",
description: "For a sidebar or a dense settings column.",
content: (
<Text style={{ fontSize: 12, lineHeight: 18, color: tokens.mutedForeground }}>
The same disclosure, with tighter padding and a smaller title.
</Text>
),
},
{
id: "shortcuts",
title: "Shortcuts",
content: (
<Text style={{ fontSize: 12, lineHeight: 18, color: tokens.mutedForeground }}>
Chevron and content stay aligned at every size.
</Text>
),
},
]}
/>
<Accordion
bordered
size="large"
defaultValue={["roomy"]}
items={[
{
id: "roomy",
title: "Roomy rows",
description: "For a long answer that deserves space.",
content: (
<Text style={{ fontSize: 13, lineHeight: 19, color: tokens.mutedForeground }}>
Padding and the title grow together; the hierarchy does not change.
</Text>
),
},
]}
/>
</Column>
);#Borderless and disabled
Accordion::new("my-accordion")
.disabled(true)
.item(|item| item.title("Disabled Section").child("Content"))GridLayout {
spacing: 24px;
Accordion {
horizontal-stretch: 1;
bordered: false;
open-index: 0;
items: [
{ title: "Borderless", content: "Items are still separated by a line." },
{ title: "Second section", content: "Content." },
];
}
Accordion {
horizontal-stretch: 1;
enabled: false;
items: [
{ title: "Disabled section", content: "Content." },
{ title: "Another disabled section", content: "Content." },
];
}
}// Borderless drops the card but keeps the separating rule; disabled is the
// caller not wiring a header at all, drawn in the muted ink the component's
// `ink` helper gives a disabled title.
let borderless_and_disabled = column![
panel(
app,
BORDERLESS,
false,
ControlSize::Medium,
false,
&[
("Borderless", "Items are still separated by a line."),
("Second section", "Content."),
],
),
Accordion::new([
Section::new(disabled_header(
"Disabled section",
label_size(ControlSize::Medium)
))
.open(false)
.content(line("Content.", theme::FONT_SIZE_SM, muted)),
Section::new(disabled_header(
"Another disabled section",
label_size(ControlSize::Medium),
)),
])
.size(ControlSize::Medium),
]
.spacing(16.0);const borderless = (
<Accordion
defaultValue={["workspace"]}
items={[
{
id: "workspace",
title: "Workspace",
description: "No outer frame.",
icon: "sparkles",
content: (
<Text style={{ fontSize: 13, lineHeight: 19, color: tokens.mutedForeground }}>
Borderless is the default. Use it inside a settings page where the surrounding
layout already provides the surface.
</Text>
),
},
{
id: "legacy",
title: "Legacy API",
description: "Available on the Enterprise plan.",
icon: "lock",
disabled: true,
content: (
<Text style={{ fontSize: 13, color: tokens.mutedForeground }}>
A disabled section cannot be opened.
</Text>
),
},
]}
/>
);#With Borders
Accordion::new("my-accordion")
.bordered(true)
.item(|item| item.title("Section 1").child("Content 1"))// `bordered(true)` is the default and draws the single rounded card the
// sections sit in, with the padding that keeps the border off the rows.
let with_borders = panel(
app,
BORDERED,
false,
ControlSize::Medium,
true,
&[("Section 1", "Content 1"), ("Section 2", "Content 2")],
);const surfaces = (
<Column gap={12}>
<Accordion
bordered
defaultValue={["billing"]}
items={[
{
id: "billing",
title: "Billing",
description: "Plan, invoices and receipts.",
content: (
<Text style={{ fontSize: 13, lineHeight: 19, color: tokens.mutedForeground }}>
One surface holds the stack; the hairline between sections stays inside it.
</Text>
),
},
{
id: "shipping",
title: "Shipping",
content: (
<Text style={{ fontSize: 13, lineHeight: 19, color: tokens.mutedForeground }}>
The open row stays quiet; content does the work.
</Text>
),
},
]}
/>
<Accordion
separated
defaultValue={["profile"]}
items={[
{
id: "profile",
title: "Profile",
description: "Its own card.",
content: (
<Text style={{ fontSize: 13, lineHeight: 19, color: tokens.mutedForeground }}>
Separated sections drop the hairline and space the cards apart.
</Text>
),
},
{
id: "security",
title: "Security",
content: (
<Text style={{ fontSize: 13, lineHeight: 19, color: tokens.mutedForeground }}>
Two-factor, sessions and the recovery code.
</Text>
),
},
]}
/>
</Column>
);#Handle Toggle Events
Accordion::new("my-accordion")
.on_toggle_click(|open_indices, window, cx| {
println!("Open items: {:?}", open_indices);
})
.item(|item| item.title("Section 1").child("Content 1"))// Every header reports the caller's message with the section's new state, so
// the caller writes the open set and can show what it received.
let events = panel(
app,
EVENTS,
true,
ControlSize::Medium,
true,
&[
("Section 1", "The first section."),
("Section 2", "The second section."),
("Section 3", "The third section."),
],
);
let events = column![
events,
line(
app.notice
.as_deref()
.unwrap_or("Click a section title to toggle it."),
theme::FONT_SIZE_XS,
muted,
),
]
.spacing(8.0);const eventsOpen = signal<string[]>([]);
const events = (
<Column gap={8}>
<Accordion
bordered
type="multiple"
value={eventsOpen()}
onChange={(next) => eventsOpen.set(next)}
items={[
{
id: "package",
title: "Package",
content: (
<Text style={{ fontSize: 13, lineHeight: 19, color: tokens.mutedForeground }}>
The bundle, its assets and the version the registry publishes.
</Text>
),
},
{
id: "runtime",
title: "Runtime",
content: (
<Text style={{ fontSize: 13, lineHeight: 19, color: tokens.mutedForeground }}>
The VM, its capabilities and the platform it runs on.
</Text>
),
},
]}
/>
<Row>
<Button label="Open all" size="small" onPress={() => eventsOpen.set(["package", "runtime"])} />
<Button label="Close all" size="small" variant="ghost" onPress={() => eventsOpen.set([])} />
</Row>
</Column>
);#Nested Accordions
Accordion::new("outer")
.item(|item| {
item.title("Parent Section")
.child(
Accordion::new("inner")
.item(|item| item.title("Child 1").child("Content"))
.item(|item| item.title("Child 2").child("Content"))
)
})// A section's content is the caller's, so it can be another accordion; the
// inner one reveals inside the outer one's reveal.
let inner = Accordion::new([
Section::new(header(
"Child section 1",
label_size(ControlSize::Small),
|theme| Tokens::of(theme).foreground,
))
.on_toggle(toggle(app, INNER, 0, "Child section 1", true))
.open(is_open(app, INNER, 0))
.content(line(
"Content of the first child section.",
theme::FONT_SIZE_SM,
muted,
)),
Section::new(header(
"Child section 2",
label_size(ControlSize::Small),
|theme| Tokens::of(theme).foreground,
))
.on_toggle(toggle(app, INNER, 1, "Child section 2", true))
.open(is_open(app, INNER, 1))
.content(line(
"Content of the second child section.",
theme::FONT_SIZE_SM,
muted,
)),
])
.size(ControlSize::Small);
let nested = Accordion::new([Section::new(header(
"Parent section",
label_size(ControlSize::Medium),
|theme| Tokens::of(theme).foreground,
))
.on_toggle(toggle(app, OUTER, 0, "Parent section", false))
.open(is_open(app, OUTER, 0))
.content(inner)])
.size(ControlSize::Medium);const nested = (
<Accordion
bordered
defaultValue={["components"]}
items={[
{
id: "components",
title: "Components",
description: "The files an app installs.",
icon: "folder",
content: (
<View style={{ gap: 8 }}>
<Text style={{ fontSize: 13, lineHeight: 19, color: tokens.mutedForeground }}>
A section holds any element, including another accordion.
</Text>
<Accordion
separated
size="small"
defaultValue={["theme"]}
items={[
{
id: "theme",
title: "theme.ts",
content: (
<Text style={{ fontSize: 12, lineHeight: 18, color: tokens.mutedForeground }}>
The reactive face of the palette.
</Text>
),
},
{
id: "tokens",
title: "tokens.ts",
content: (
<Text style={{ fontSize: 12, lineHeight: 18, color: tokens.mutedForeground }}>
The two palettes and the scales.
</Text>
),
},
]}
/>
</View>
),
},
{
id: "registry",
title: "Registry",
description: "What the CLI copies from.",
content: (
<Text style={{ fontSize: 13, lineHeight: 19, color: tokens.mutedForeground }}>
The manifest lists every component, its example and the files it installs.
</Text>
),
},
]}
/>
);#API Reference
#Sizing
Implements Sizable trait:
small()- Small sizemedium()- Medium size (default)large()- Large sizexsmall()- Extra small size
#AccordionEntry
One section of a data-driven `Accordion`.
| Name | Kind | Type | Default |
|---|---|---|---|
title | field | string | |
icon | field | string | |
content | field | string |
#AccordionItem
One collapsible section. Mirrors GPUI Component's `AccordionItem`: a title row with an optional leading icon that toggles a content panel, sizes, a disabled state, and an animated chevron and reveal. Put the content in `@children`, and set `last` on the final item to drop its separator.
| Name | Kind | Type | Default |
|---|---|---|---|
title | in | string | |
icon | in | string | |
size | in | ControlSize | ControlSize.medium |
enabled | in | bool | true |
last | in | bool | |
open | in-out | bool | |
toggled | callback | (open: bool) |
#Accordion
A vertical stack of collapsible sections. Mirrors GPUI Component's `Accordion`: one open section at a time, or several with `multiple`, a bordered card by default, sizes, a disabled state, and a toggle event. Pass text sections through `items`, or compose `AccordionItem` children for rich content; `open-index` is the open section in single mode.
| Name | Kind | Type | Default |
|---|---|---|---|
items | in | [AccordionEntry] | |
multiple | in | bool | |
bordered | in | bool | true |
enabled | in | bool | true |
size | in | ControlSize | ControlSize.medium |
open-index | in-out | int | -1 |
toggled | callback | (index: int, open: bool) |