drab 4.1.6 → 5.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/animate/define.d.ts +2 -0
- package/animate/define.iife.js +1 -0
- package/animate/define.js +1 -0
- package/animate.d.ts +54 -0
- package/animate.iife.js +1 -0
- package/animate.js +1 -0
- package/base/define.d.ts +2 -0
- package/base/define.iife.js +1 -0
- package/base/define.js +1 -0
- package/base.d.ts +69 -0
- package/base.iife.js +1 -0
- package/base.js +1 -0
- package/breakpoint/define.d.ts +2 -0
- package/breakpoint/define.iife.js +1 -0
- package/breakpoint/define.js +1 -0
- package/breakpoint.d.ts +24 -0
- package/breakpoint.iife.js +1 -0
- package/breakpoint.js +1 -0
- package/chunk-2ZZQECRY.js +1 -0
- package/chunk-57VEEUFG.js +1 -0
- package/chunk-5JV4T7GM.js +1 -0
- package/chunk-6HYPZWQ4.js +1 -0
- package/chunk-7F7CQUEG.js +1 -0
- package/chunk-7KU2PRW5.js +1 -0
- package/chunk-7S6DTKGH.js +1 -0
- package/chunk-FNJ7AESC.js +9 -0
- package/chunk-IQJQPZUL.js +1 -0
- package/chunk-JMJUWKN2.js +1 -0
- package/chunk-MXKU7AKV.js +1 -0
- package/chunk-T7RZI3ZL.js +1 -0
- package/chunk-TSTTUEAF.js +1 -0
- package/chunk-VEVFQB5N.js +1 -0
- package/contextmenu/define.d.ts +2 -0
- package/contextmenu/define.iife.js +1 -0
- package/contextmenu/define.js +1 -0
- package/contextmenu.d.ts +15 -0
- package/contextmenu.iife.js +1 -0
- package/contextmenu.js +1 -0
- package/copy/define.d.ts +2 -0
- package/copy/define.iife.js +1 -0
- package/copy/define.js +1 -0
- package/copy.d.ts +13 -0
- package/copy.iife.js +1 -0
- package/copy.js +1 -0
- package/define.d.ts +2 -0
- package/define.iife.js +9 -0
- package/define.js +1 -0
- package/details/define.d.ts +2 -0
- package/details/define.iife.js +1 -0
- package/details/define.js +1 -0
- package/details.d.ts +23 -0
- package/details.iife.js +1 -0
- package/details.js +1 -0
- package/dialog/define.d.ts +2 -0
- package/dialog/define.iife.js +1 -0
- package/dialog/define.js +1 -0
- package/dialog.d.ts +20 -0
- package/dialog.iife.js +1 -0
- package/dialog.js +1 -0
- package/editor/define.d.ts +2 -0
- package/editor/define.iife.js +9 -0
- package/editor/define.js +1 -0
- package/editor.d.ts +58 -0
- package/editor.iife.js +9 -0
- package/editor.js +1 -0
- package/fullscreen/define.d.ts +2 -0
- package/fullscreen/define.iife.js +1 -0
- package/fullscreen/define.js +1 -0
- package/fullscreen.d.ts +23 -0
- package/fullscreen.iife.js +1 -0
- package/fullscreen.js +1 -0
- package/index-22PHGcPf.d.ts +17 -0
- package/index.d.ts +14 -0
- package/index.iife.js +9 -0
- package/index.js +1 -0
- package/package.json +131 -59
- package/popover/define.d.ts +2 -0
- package/popover/define.iife.js +1 -0
- package/popover/define.js +1 -0
- package/popover.d.ts +29 -0
- package/popover.iife.js +1 -0
- package/popover.js +1 -0
- package/share/define.d.ts +2 -0
- package/share/define.iife.js +1 -0
- package/share/define.js +1 -0
- package/share.d.ts +19 -0
- package/share.iife.js +1 -0
- package/share.js +1 -0
- package/tablesort/define.d.ts +2 -0
- package/tablesort/define.iife.js +1 -0
- package/tablesort/define.js +1 -0
- package/tablesort.d.ts +21 -0
- package/tablesort.iife.js +1 -0
- package/tablesort.js +1 -0
- package/youtube/define.d.ts +2 -0
- package/youtube/define.iife.js +1 -0
- package/youtube/define.js +1 -0
- package/youtube.d.ts +29 -0
- package/youtube.iife.js +1 -0
- package/youtube.js +1 -0
- package/LICENSE.md +0 -21
- package/README.md +0 -131
- package/dist/components/Breakpoint.svelte +0 -55
- package/dist/components/Breakpoint.svelte.d.ts +0 -46
- package/dist/components/ContextMenu.svelte +0 -150
- package/dist/components/ContextMenu.svelte.d.ts +0 -76
- package/dist/components/CopyButton.svelte +0 -97
- package/dist/components/CopyButton.svelte.d.ts +0 -60
- package/dist/components/DataTable.svelte +0 -208
- package/dist/components/DataTable.svelte.d.ts +0 -155
- package/dist/components/Details.svelte +0 -101
- package/dist/components/Details.svelte.d.ts +0 -67
- package/dist/components/Editor.svelte +0 -404
- package/dist/components/Editor.svelte.d.ts +0 -111
- package/dist/components/FrettedChord.svelte +0 -213
- package/dist/components/FrettedChord.svelte.d.ts +0 -79
- package/dist/components/FullscreenButton.svelte +0 -95
- package/dist/components/FullscreenButton.svelte.d.ts +0 -62
- package/dist/components/Popover.svelte +0 -153
- package/dist/components/Popover.svelte.d.ts +0 -80
- package/dist/components/ShareButton.svelte +0 -133
- package/dist/components/ShareButton.svelte.d.ts +0 -93
- package/dist/components/Sheet.svelte +0 -180
- package/dist/components/Sheet.svelte.d.ts +0 -99
- package/dist/components/Tablature.svelte +0 -173
- package/dist/components/Tablature.svelte.d.ts +0 -93
- package/dist/components/YouTube.svelte +0 -51
- package/dist/components/YouTube.svelte.d.ts +0 -49
- package/dist/index.d.ts +0 -14
- package/dist/index.js +0 -14
- package/dist/util/accessibility.d.ts +0 -6
- package/dist/util/accessibility.js +0 -11
- package/dist/util/delay.d.ts +0 -1
- package/dist/util/delay.js +0 -1
- package/dist/util/transition.d.ts +0 -2
- package/dist/util/transition.js +0 -2
@@ -1,208 +0,0 @@
|
|
1
|
-
<!--
|
2
|
-
@component
|
3
|
-
|
4
|
-
### DataTable
|
5
|
-
|
6
|
-
Data table to display an array of objects. Works with zero configuration, just pass an array of objects into the `data` prop.
|
7
|
-
|
8
|
-
- Set the `maxRows` prop to enable pagination, bind to `currentPage` to navigate (see second example below)
|
9
|
-
- Provides sorting for `number`, `string`, `boolean`, and `Date`
|
10
|
-
- Strings are sorted using `Intl.Collator`
|
11
|
-
- Style or modify the rendering of data with slot props
|
12
|
-
- `numberOfPages` is calculated and sent back through the `controls` slot
|
13
|
-
|
14
|
-
@props
|
15
|
-
|
16
|
-
- `ascending` - current sort order
|
17
|
-
- `classTbodyTr` - `tbody tr` class
|
18
|
-
- `classTbody` - `tbody` class
|
19
|
-
- `classTd` - `td` class
|
20
|
-
- `classTh` - `th` class
|
21
|
-
- `classTheadTr` - `thead tr` class
|
22
|
-
- `classThead` - `thead` class
|
23
|
-
- `classTr` - `tr` class
|
24
|
-
- `class`
|
25
|
-
- `currentPage` - current page index, defaults to `0`
|
26
|
-
- `data` - an array of items to render in the table
|
27
|
-
- `id`
|
28
|
-
- `keys` - table columns to include in the table, in order. Defaults to first item's keys
|
29
|
-
- `maxRows` - maximum number of rows to show on each page, defaults to `0` - no pagination
|
30
|
-
- `sortBy` - key (column) to sort by, defaults to first key
|
31
|
-
|
32
|
-
@slots
|
33
|
-
|
34
|
-
| name | purpose | default value | slot props |
|
35
|
-
| ---------- | ---------------------------------------------------------------- | ------------- | ------------------------------- |
|
36
|
-
| `controls` | helper that passes back `maxRows` and calculated `numberOfPages` | empty | `maxRows`, `numberOfPages` |
|
37
|
-
| `td` | td contents | `value` | `item`, `key`, `sortBy` `value` |
|
38
|
-
| `th` | th contents | `key` | `key`, `sortBy` |
|
39
|
-
|
40
|
-
@example
|
41
|
-
|
42
|
-
```svelte
|
43
|
-
<script lang="ts">
|
44
|
-
import type { ComponentProps } from "svelte";
|
45
|
-
import { DataTable } from "drab";
|
46
|
-
|
47
|
-
let currentPage = 0;
|
48
|
-
|
49
|
-
const data: ComponentProps<DataTable>["data"] = [
|
50
|
-
{ make: "Honda", model: "CR-V", year: 2011, awd: true },
|
51
|
-
{ make: "Volvo", model: "XC-40", year: 2024, awd: true },
|
52
|
-
{ make: "Ferrari", model: "458 Italia", year: 2015, awd: false },
|
53
|
-
{ make: "Chevrolet", model: "Silverado", year: 2022, awd: true },
|
54
|
-
{ make: "Ford", model: "Model A", year: 1931, awd: false },
|
55
|
-
{ make: "Subaru", model: "Outback", year: 2021, awd: true },
|
56
|
-
{ make: "Ford", model: "Bronco", year: 1970, awd: true },
|
57
|
-
{ make: "GMC", model: "Acadia", year: 2008, awd: true },
|
58
|
-
{ make: "BMW", model: "X3", year: 2023, awd: true },
|
59
|
-
];
|
60
|
-
</script>
|
61
|
-
|
62
|
-
<DataTable {data} class="mb-12" />
|
63
|
-
|
64
|
-
<DataTable
|
65
|
-
{data}
|
66
|
-
bind:currentPage
|
67
|
-
sortBy="year"
|
68
|
-
maxRows={4}
|
69
|
-
class="tabular-nums"
|
70
|
-
classTh="cursor-pointer capitalize"
|
71
|
-
classTbodyTr="transition hover:bg-muted"
|
72
|
-
>
|
73
|
-
<svelte:fragment slot="th" let:key let:sortBy>
|
74
|
-
<span class:uppercase={key === "awd"} class:underline={key === sortBy}>
|
75
|
-
{key}
|
76
|
-
</span>
|
77
|
-
</svelte:fragment>
|
78
|
-
<svelte:fragment slot="td" let:value>
|
79
|
-
{#if typeof value === "boolean"}
|
80
|
-
{value ? "Yes" : "No"}
|
81
|
-
{:else}
|
82
|
-
{value}
|
83
|
-
{/if}
|
84
|
-
</svelte:fragment>
|
85
|
-
<svelte:fragment slot="controls" let:maxRows let:numberOfPages>
|
86
|
-
{#if maxRows}
|
87
|
-
<div class="flex items-center justify-between gap-4">
|
88
|
-
<div class="min-w-fit">{currentPage + 1} / {numberOfPages}</div>
|
89
|
-
<div class="flex gap-2">
|
90
|
-
<button
|
91
|
-
type="button"
|
92
|
-
class="button button-primary"
|
93
|
-
disabled={currentPage < 1}
|
94
|
-
on:click={() => currentPage--}
|
95
|
-
>
|
96
|
-
Previous
|
97
|
-
</button>
|
98
|
-
<button
|
99
|
-
type="button"
|
100
|
-
class="button button-primary"
|
101
|
-
disabled={currentPage >= numberOfPages - 1}
|
102
|
-
on:click={() => currentPage++}
|
103
|
-
>
|
104
|
-
Next
|
105
|
-
</button>
|
106
|
-
</div>
|
107
|
-
</div>
|
108
|
-
{/if}
|
109
|
-
</svelte:fragment>
|
110
|
-
</DataTable>
|
111
|
-
```
|
112
|
-
-->
|
113
|
-
|
114
|
-
<script>let className = "";
|
115
|
-
export { className as class };
|
116
|
-
export let id = "";
|
117
|
-
export let data;
|
118
|
-
export let keys = Object.keys(data[0]);
|
119
|
-
export let sortBy = keys[0];
|
120
|
-
export let ascending = true;
|
121
|
-
export let classThead = "";
|
122
|
-
export let classTbody = "";
|
123
|
-
export let classTr = "";
|
124
|
-
export let classTheadTr = "";
|
125
|
-
export let classTbodyTr = "";
|
126
|
-
export let classTh = "";
|
127
|
-
export let classTd = "";
|
128
|
-
export let maxRows = 0;
|
129
|
-
export let currentPage = 0;
|
130
|
-
$:
|
131
|
-
numberOfPages = Math.floor(data.length / maxRows) + 1;
|
132
|
-
const sort = (key, toggleAscending = true) => {
|
133
|
-
if (key === sortBy && toggleAscending) {
|
134
|
-
ascending = !ascending;
|
135
|
-
} else {
|
136
|
-
ascending = true;
|
137
|
-
}
|
138
|
-
const collator = new Intl.Collator();
|
139
|
-
data.sort((a, b) => {
|
140
|
-
const aVal = a[key];
|
141
|
-
const bVal = b[key];
|
142
|
-
if (typeof aVal === "number" && typeof bVal === "number") {
|
143
|
-
if (ascending) {
|
144
|
-
return aVal - bVal;
|
145
|
-
} else {
|
146
|
-
return bVal - aVal;
|
147
|
-
}
|
148
|
-
} else if (typeof aVal === "string" && typeof bVal === "string") {
|
149
|
-
if (ascending) {
|
150
|
-
return collator.compare(aVal, bVal);
|
151
|
-
} else {
|
152
|
-
return collator.compare(bVal, aVal);
|
153
|
-
}
|
154
|
-
} else if (aVal instanceof Date && bVal instanceof Date) {
|
155
|
-
if (ascending) {
|
156
|
-
return aVal.getTime() - bVal.getTime();
|
157
|
-
} else {
|
158
|
-
return bVal.getTime() - aVal.getTime();
|
159
|
-
}
|
160
|
-
} else {
|
161
|
-
if (ascending) {
|
162
|
-
return aVal === bVal ? 0 : aVal ? -1 : 1;
|
163
|
-
} else {
|
164
|
-
return aVal === bVal ? 0 : aVal ? 1 : -1;
|
165
|
-
}
|
166
|
-
}
|
167
|
-
});
|
168
|
-
data = data;
|
169
|
-
sortBy = key;
|
170
|
-
};
|
171
|
-
const showRow = (i, currentPage2) => {
|
172
|
-
if (!maxRows)
|
173
|
-
return true;
|
174
|
-
const overMin = i >= maxRows * currentPage2;
|
175
|
-
const underMax = i < maxRows * (currentPage2 + 1);
|
176
|
-
return overMin && underMax;
|
177
|
-
};
|
178
|
-
sort(sortBy, false);
|
179
|
-
</script>
|
180
|
-
|
181
|
-
<table class={className} {id}>
|
182
|
-
<thead class={classThead}>
|
183
|
-
<tr class="{classTr} {classTheadTr}">
|
184
|
-
{#each keys as key}
|
185
|
-
<th class={classTh} on:click={() => sort(key)}>
|
186
|
-
<slot name="th" {key} {sortBy}>{key}</slot>
|
187
|
-
</th>
|
188
|
-
{/each}
|
189
|
-
</tr>
|
190
|
-
</thead>
|
191
|
-
<tbody class={classTbody}>
|
192
|
-
{#each data as item, i}
|
193
|
-
{#if showRow(i, currentPage)}
|
194
|
-
<tr class="{classTr} {classTbodyTr}">
|
195
|
-
{#each keys as key}
|
196
|
-
<td class={classTd}>
|
197
|
-
<slot name="td" {item} {key} {sortBy} value={item[key]}>
|
198
|
-
{item[key]}
|
199
|
-
</slot>
|
200
|
-
</td>
|
201
|
-
{/each}
|
202
|
-
</tr>
|
203
|
-
{/if}
|
204
|
-
{/each}
|
205
|
-
</tbody>
|
206
|
-
</table>
|
207
|
-
|
208
|
-
<slot name="controls" {maxRows} {numberOfPages} />
|
@@ -1,155 +0,0 @@
|
|
1
|
-
import { SvelteComponent } from "svelte";
|
2
|
-
declare const __propDef: {
|
3
|
-
props: {
|
4
|
-
class?: string | undefined;
|
5
|
-
id?: string | undefined;
|
6
|
-
/** an array of items to render in the table */ data: Record<string | number, string | number | boolean | Date | null | undefined>[];
|
7
|
-
/** table columns to include in the table, in order. Defaults to first item's keys */ keys?: string[] | undefined;
|
8
|
-
/** key (column) to sort by, defaults to first key */ sortBy?: string | undefined;
|
9
|
-
/** current sort order */ ascending?: boolean | undefined;
|
10
|
-
/** `thead` class */ classThead?: string | undefined;
|
11
|
-
/** `tbody` class */ classTbody?: string | undefined;
|
12
|
-
/** `tr` class */ classTr?: string | undefined;
|
13
|
-
/** `thead tr` class */ classTheadTr?: string | undefined;
|
14
|
-
/** `tbody tr` class */ classTbodyTr?: string | undefined;
|
15
|
-
/** `th` class */ classTh?: string | undefined;
|
16
|
-
/** `td` class */ classTd?: string | undefined;
|
17
|
-
/** maximum number of rows to show on each page, defaults to `0` - no pagination */ maxRows?: number | undefined;
|
18
|
-
/** current page index, defaults to `0` */ currentPage?: number | undefined;
|
19
|
-
};
|
20
|
-
events: {
|
21
|
-
[evt: string]: CustomEvent<any>;
|
22
|
-
};
|
23
|
-
slots: {
|
24
|
-
th: {
|
25
|
-
key: string;
|
26
|
-
sortBy: string;
|
27
|
-
};
|
28
|
-
td: {
|
29
|
-
item: Record<string | number, string | number | boolean | Date | null | undefined>;
|
30
|
-
key: string;
|
31
|
-
sortBy: string;
|
32
|
-
value: string | number | boolean | Date | null | undefined;
|
33
|
-
};
|
34
|
-
controls: {
|
35
|
-
maxRows: number;
|
36
|
-
numberOfPages: number;
|
37
|
-
};
|
38
|
-
};
|
39
|
-
};
|
40
|
-
export type DataTableProps = typeof __propDef.props;
|
41
|
-
export type DataTableEvents = typeof __propDef.events;
|
42
|
-
export type DataTableSlots = typeof __propDef.slots;
|
43
|
-
/**
|
44
|
-
* ### DataTable
|
45
|
-
*
|
46
|
-
* Data table to display an array of objects. Works with zero configuration, just pass an array of objects into the `data` prop.
|
47
|
-
*
|
48
|
-
* - Set the `maxRows` prop to enable pagination, bind to `currentPage` to navigate (see second example below)
|
49
|
-
* - Provides sorting for `number`, `string`, `boolean`, and `Date`
|
50
|
-
* - Strings are sorted using `Intl.Collator`
|
51
|
-
* - Style or modify the rendering of data with slot props
|
52
|
-
* - `numberOfPages` is calculated and sent back through the `controls` slot
|
53
|
-
*
|
54
|
-
* @props
|
55
|
-
*
|
56
|
-
* - `ascending` - current sort order
|
57
|
-
* - `classTbodyTr` - `tbody tr` class
|
58
|
-
* - `classTbody` - `tbody` class
|
59
|
-
* - `classTd` - `td` class
|
60
|
-
* - `classTh` - `th` class
|
61
|
-
* - `classTheadTr` - `thead tr` class
|
62
|
-
* - `classThead` - `thead` class
|
63
|
-
* - `classTr` - `tr` class
|
64
|
-
* - `class`
|
65
|
-
* - `currentPage` - current page index, defaults to `0`
|
66
|
-
* - `data` - an array of items to render in the table
|
67
|
-
* - `id`
|
68
|
-
* - `keys` - table columns to include in the table, in order. Defaults to first item's keys
|
69
|
-
* - `maxRows` - maximum number of rows to show on each page, defaults to `0` - no pagination
|
70
|
-
* - `sortBy` - key (column) to sort by, defaults to first key
|
71
|
-
*
|
72
|
-
* @slots
|
73
|
-
*
|
74
|
-
* | name | purpose | default value | slot props |
|
75
|
-
* | ---------- | ---------------------------------------------------------------- | ------------- | ------------------------------- |
|
76
|
-
* | `controls` | helper that passes back `maxRows` and calculated `numberOfPages` | empty | `maxRows`, `numberOfPages` |
|
77
|
-
* | `td` | td contents | `value` | `item`, `key`, `sortBy` `value` |
|
78
|
-
* | `th` | th contents | `key` | `key`, `sortBy` |
|
79
|
-
*
|
80
|
-
* @example
|
81
|
-
*
|
82
|
-
* ```svelte
|
83
|
-
* <script lang="ts">
|
84
|
-
* import type { ComponentProps } from "svelte";
|
85
|
-
* import { DataTable } from "drab";
|
86
|
-
*
|
87
|
-
* let currentPage = 0;
|
88
|
-
*
|
89
|
-
* const data: ComponentProps<DataTable>["data"] = [
|
90
|
-
* { make: "Honda", model: "CR-V", year: 2011, awd: true },
|
91
|
-
* { make: "Volvo", model: "XC-40", year: 2024, awd: true },
|
92
|
-
* { make: "Ferrari", model: "458 Italia", year: 2015, awd: false },
|
93
|
-
* { make: "Chevrolet", model: "Silverado", year: 2022, awd: true },
|
94
|
-
* { make: "Ford", model: "Model A", year: 1931, awd: false },
|
95
|
-
* { make: "Subaru", model: "Outback", year: 2021, awd: true },
|
96
|
-
* { make: "Ford", model: "Bronco", year: 1970, awd: true },
|
97
|
-
* { make: "GMC", model: "Acadia", year: 2008, awd: true },
|
98
|
-
* { make: "BMW", model: "X3", year: 2023, awd: true },
|
99
|
-
* ];
|
100
|
-
* </script>
|
101
|
-
*
|
102
|
-
* <DataTable {data} class="mb-12" />
|
103
|
-
*
|
104
|
-
* <DataTable
|
105
|
-
* {data}
|
106
|
-
* bind:currentPage
|
107
|
-
* sortBy="year"
|
108
|
-
* maxRows={4}
|
109
|
-
* class="tabular-nums"
|
110
|
-
* classTh="cursor-pointer capitalize"
|
111
|
-
* classTbodyTr="transition hover:bg-muted"
|
112
|
-
* >
|
113
|
-
* <svelte:fragment slot="th" let:key let:sortBy>
|
114
|
-
* <span class:uppercase={key === "awd"} class:underline={key === sortBy}>
|
115
|
-
* {key}
|
116
|
-
* </span>
|
117
|
-
* </svelte:fragment>
|
118
|
-
* <svelte:fragment slot="td" let:value>
|
119
|
-
* {#if typeof value === "boolean"}
|
120
|
-
* {value ? "Yes" : "No"}
|
121
|
-
* {:else}
|
122
|
-
* {value}
|
123
|
-
* {/if}
|
124
|
-
* </svelte:fragment>
|
125
|
-
* <svelte:fragment slot="controls" let:maxRows let:numberOfPages>
|
126
|
-
* {#if maxRows}
|
127
|
-
* <div class="flex items-center justify-between gap-4">
|
128
|
-
* <div class="min-w-fit">{currentPage + 1} / {numberOfPages}</div>
|
129
|
-
* <div class="flex gap-2">
|
130
|
-
* <button
|
131
|
-
* type="button"
|
132
|
-
* class="button button-primary"
|
133
|
-
* disabled={currentPage < 1}
|
134
|
-
* on:click={() => currentPage--}
|
135
|
-
* >
|
136
|
-
* Previous
|
137
|
-
* </button>
|
138
|
-
* <button
|
139
|
-
* type="button"
|
140
|
-
* class="button button-primary"
|
141
|
-
* disabled={currentPage >= numberOfPages - 1}
|
142
|
-
* on:click={() => currentPage++}
|
143
|
-
* >
|
144
|
-
* Next
|
145
|
-
* </button>
|
146
|
-
* </div>
|
147
|
-
* </div>
|
148
|
-
* {/if}
|
149
|
-
* </svelte:fragment>
|
150
|
-
* </DataTable>
|
151
|
-
* ```
|
152
|
-
*/
|
153
|
-
export default class DataTable extends SvelteComponent<DataTableProps, DataTableEvents, DataTableSlots> {
|
154
|
-
}
|
155
|
-
export {};
|
@@ -1,101 +0,0 @@
|
|
1
|
-
<!--
|
2
|
-
@component
|
3
|
-
|
4
|
-
### Details
|
5
|
-
|
6
|
-
Displays a `details` element with helpful defaults and transitions. Can be used to make an accordion, or a collapse.
|
7
|
-
|
8
|
-
@props
|
9
|
-
|
10
|
-
- `class`
|
11
|
-
- `id`
|
12
|
-
- `open`
|
13
|
-
- `transition` - slides the content, set to `false` to remove
|
14
|
-
|
15
|
-
@slots
|
16
|
-
|
17
|
-
| name | purpose | default value | slot props |
|
18
|
-
| --------- | ------------------------------- | -------------- | ---------- |
|
19
|
-
| `summary` | `summary` element contents | empty | `open` |
|
20
|
-
| `content` | contents when details is `open` | empty | none |
|
21
|
-
|
22
|
-
@example
|
23
|
-
|
24
|
-
```svelte
|
25
|
-
<script lang="ts">
|
26
|
-
import { Details } from "drab";
|
27
|
-
import Chevron from "../../site/svg/Chevron.svelte";
|
28
|
-
</script>
|
29
|
-
|
30
|
-
<Details class="border-b">
|
31
|
-
<svelte:fragment slot="summary" let:open>
|
32
|
-
<div class="link flex items-center justify-between gap-8 p-4">
|
33
|
-
<div>Does it work without JavaScript?</div>
|
34
|
-
<div class="transition" class:rotate-180={open}>
|
35
|
-
<Chevron />
|
36
|
-
</div>
|
37
|
-
</div>
|
38
|
-
</svelte:fragment>
|
39
|
-
<svelte:fragment slot="content">
|
40
|
-
<div class="px-4 pb-4">Yes.</div>
|
41
|
-
</svelte:fragment>
|
42
|
-
</Details>
|
43
|
-
```
|
44
|
-
-->
|
45
|
-
|
46
|
-
<script>import { onMount } from "svelte";
|
47
|
-
import { slide } from "svelte/transition";
|
48
|
-
import { prefersReducedMotion } from "../util/accessibility";
|
49
|
-
import { duration } from "../util/transition";
|
50
|
-
let className = "";
|
51
|
-
export { className as class };
|
52
|
-
export let id = "";
|
53
|
-
export let transition = { duration };
|
54
|
-
export let open = false;
|
55
|
-
let clientJs = false;
|
56
|
-
const toggleOpen = () => {
|
57
|
-
open = !open;
|
58
|
-
};
|
59
|
-
onMount(() => {
|
60
|
-
clientJs = true;
|
61
|
-
if (prefersReducedMotion())
|
62
|
-
transition = false;
|
63
|
-
});
|
64
|
-
</script>
|
65
|
-
|
66
|
-
<div class={className} {id}>
|
67
|
-
<details bind:open>
|
68
|
-
<!-- svelte-ignore a11y-no-redundant-roles -->
|
69
|
-
<summary
|
70
|
-
role="button"
|
71
|
-
tabindex="0"
|
72
|
-
on:click|preventDefault={toggleOpen}
|
73
|
-
on:keydown={(e) => {
|
74
|
-
if (e.key === "Enter") {
|
75
|
-
e.preventDefault();
|
76
|
-
toggleOpen();
|
77
|
-
}
|
78
|
-
}}
|
79
|
-
>
|
80
|
-
<slot name="summary" {open} />
|
81
|
-
</summary>
|
82
|
-
{#if !clientJs || !transition}
|
83
|
-
<slot name="content" />
|
84
|
-
{/if}
|
85
|
-
</details>
|
86
|
-
{#if clientJs && open && transition}
|
87
|
-
<!-- outside the details for the transition -->
|
88
|
-
<div transition:slide={transition}>
|
89
|
-
<slot name="content" />
|
90
|
-
</div>
|
91
|
-
{/if}
|
92
|
-
</div>
|
93
|
-
|
94
|
-
<style>
|
95
|
-
summary {
|
96
|
-
list-style: none;
|
97
|
-
}
|
98
|
-
summary::-webkit-details-marker {
|
99
|
-
display: none;
|
100
|
-
}
|
101
|
-
</style>
|
@@ -1,67 +0,0 @@
|
|
1
|
-
import { SvelteComponent } from "svelte";
|
2
|
-
import { type SlideParams } from "svelte/transition";
|
3
|
-
declare const __propDef: {
|
4
|
-
props: {
|
5
|
-
class?: string | undefined;
|
6
|
-
id?: string | undefined;
|
7
|
-
/** slides the content, set to `false` to remove */ transition?: false | SlideParams | undefined;
|
8
|
-
open?: boolean | undefined;
|
9
|
-
};
|
10
|
-
events: {
|
11
|
-
[evt: string]: CustomEvent<any>;
|
12
|
-
};
|
13
|
-
slots: {
|
14
|
-
summary: {
|
15
|
-
open: boolean;
|
16
|
-
};
|
17
|
-
content: {};
|
18
|
-
};
|
19
|
-
};
|
20
|
-
export type DetailsProps = typeof __propDef.props;
|
21
|
-
export type DetailsEvents = typeof __propDef.events;
|
22
|
-
export type DetailsSlots = typeof __propDef.slots;
|
23
|
-
/**
|
24
|
-
* ### Details
|
25
|
-
*
|
26
|
-
* Displays a `details` element with helpful defaults and transitions. Can be used to make an accordion, or a collapse.
|
27
|
-
*
|
28
|
-
* @props
|
29
|
-
*
|
30
|
-
* - `class`
|
31
|
-
* - `id`
|
32
|
-
* - `open`
|
33
|
-
* - `transition` - slides the content, set to `false` to remove
|
34
|
-
*
|
35
|
-
* @slots
|
36
|
-
*
|
37
|
-
* | name | purpose | default value | slot props |
|
38
|
-
* | --------- | ------------------------------- | -------------- | ---------- |
|
39
|
-
* | `summary` | `summary` element contents | empty | `open` |
|
40
|
-
* | `content` | contents when details is `open` | empty | none |
|
41
|
-
*
|
42
|
-
* @example
|
43
|
-
*
|
44
|
-
* ```svelte
|
45
|
-
* <script lang="ts">
|
46
|
-
* import { Details } from "drab";
|
47
|
-
* import Chevron from "../../site/svg/Chevron.svelte";
|
48
|
-
* </script>
|
49
|
-
*
|
50
|
-
* <Details class="border-b">
|
51
|
-
* <svelte:fragment slot="summary" let:open>
|
52
|
-
* <div class="link flex items-center justify-between gap-8 p-4">
|
53
|
-
* <div>Does it work without JavaScript?</div>
|
54
|
-
* <div class="transition" class:rotate-180={open}>
|
55
|
-
* <Chevron />
|
56
|
-
* </div>
|
57
|
-
* </div>
|
58
|
-
* </svelte:fragment>
|
59
|
-
* <svelte:fragment slot="content">
|
60
|
-
* <div class="px-4 pb-4">Yes.</div>
|
61
|
-
* </svelte:fragment>
|
62
|
-
* </Details>
|
63
|
-
* ```
|
64
|
-
*/
|
65
|
-
export default class Details extends SvelteComponent<DetailsProps, DetailsEvents, DetailsSlots> {
|
66
|
-
}
|
67
|
-
export {};
|