Skip to content

Commit 2c8e483

Browse files
committed
docs(data-table): add "Custom expand icon" example
1 parent 65349c4 commit 2c8e483

2 files changed

Lines changed: 74 additions & 0 deletions

File tree

docs/src/pages/components/DataTable.svx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,12 @@ Set `expandable` to `true` to make rows expandable. Use the `expanded-row` slot
12171217
</svelte:fragment>
12181218
</DataTable>
12191219

1220+
## Custom expand icon
1221+
1222+
Use the `expandIcon` slot to customize the expand/collapse icon. The slot receives `expanded` (whether the row is expanded), `row` (the row data, or `undefined` for the header expand-all button), and `props` (object with `aria-hidden` and `class` to spread onto your icon).
1223+
1224+
<FileSource src="/framed/DataTable/DataTableExpandIcon" />
1225+
12201226
## Non-expandable rows
12211227

12221228
Use `nonExpandableRowIds` to prevent expansion of specific rows.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<script>
2+
import { DataTable } from "carbon-components-svelte";
3+
import Add from "carbon-icons-svelte/lib/Add.svelte";
4+
</script>
5+
6+
<DataTable
7+
expandable
8+
headers={[
9+
{ key: "name", value: "Name" },
10+
{ key: "protocol", value: "Protocol" },
11+
{ key: "port", value: "Port" },
12+
{ key: "rule", value: "Rule" },
13+
]}
14+
rows={[
15+
{
16+
id: "a",
17+
name: "Load Balancer 3",
18+
protocol: "HTTP",
19+
port: 3000,
20+
rule: "Round robin",
21+
},
22+
{
23+
id: "b",
24+
name: "Load Balancer 1",
25+
protocol: "HTTP",
26+
port: 443,
27+
rule: "Round robin",
28+
},
29+
{
30+
id: "c",
31+
name: "Load Balancer 2",
32+
protocol: "HTTP",
33+
port: 80,
34+
rule: "DNS delegation",
35+
},
36+
{
37+
id: "d",
38+
name: "Load Balancer 6",
39+
protocol: "HTTP",
40+
port: 3000,
41+
rule: "Round robin",
42+
},
43+
{
44+
id: "e",
45+
name: "Load Balancer 4",
46+
protocol: "HTTP",
47+
port: 443,
48+
rule: "Round robin",
49+
},
50+
{
51+
id: "f",
52+
name: "Load Balancer 5",
53+
protocol: "HTTP",
54+
port: 80,
55+
rule: "DNS delegation",
56+
},
57+
]}
58+
>
59+
<svelte:fragment slot="expandIcon" let:expanded let:props>
60+
<Add
61+
{...props}
62+
style="display: inline-block; transition: transform 0.2s ease; transform: {expanded ? 'rotate(45deg)' : 'rotate(0deg)'}"
63+
/>
64+
</svelte:fragment>
65+
<svelte:fragment slot="expanded-row" let:row>
66+
<pre>{JSON.stringify(row, null, 2)}</pre>
67+
</svelte:fragment>
68+
</DataTable>

0 commit comments

Comments
 (0)