drab 3.0.2 → 3.0.4

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.
@@ -1,41 +1,46 @@
1
- <!--
2
- @component
3
-
4
- ### CopyButton
5
-
6
- Uses the [Clipboard API](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard) to copy data to the clipboard. Falls back to `writeText` if `write` is not supported and `blob.type` is text.
7
-
8
- @props
9
-
10
- - `blobParts` - array of `BlobParts` to copy - [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#parameters)
11
- - `blob` - use a blob in instead of `blobParts` and `options`, defaults to `new Blob(blobParts, options)`
12
- - `class`
13
- - `id`
14
- - `options` - defaults to `{ type: "text/plain" }` - [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#parameters)
15
- - `title`
16
-
17
- @slots
18
-
19
- | name | purpose | default value |
20
- | ---------- | ------------------------------- | ------------- |
21
- | `default` | default | `Copy` |
22
- | `complete` | displays after copy is complete | `Copied` |
23
-
24
- @example
25
-
26
- ```svelte
27
- <script lang="ts">
28
- import { CopyButton } from "drab";
29
-
30
- let value = "Text to copy";
31
- </script>
32
-
33
- <input class="input mb-4" type="text" bind:value />
34
-
35
- <CopyButton class="btn" blobParts={[value]} />
36
- ```
37
- -->
38
-
1
+ <!--
2
+ @component
3
+
4
+ ### CopyButton
5
+
6
+ Uses the [Clipboard API](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard) to copy data to the clipboard. Falls back to `writeText` if `write` is not supported and `blob.type` is text.
7
+
8
+ @props
9
+
10
+ - `blobParts` - array of `BlobParts` to copy - [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#parameters)
11
+ - `blob` - use a blob in instead of `blobParts` and `options`, defaults to `new Blob(blobParts, options)`
12
+ - `class`
13
+ - `id`
14
+ - `options` - defaults to `{ type: "text/plain" }` - [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#parameters)
15
+ - `title`
16
+
17
+ @slots
18
+
19
+ | name | purpose | default value |
20
+ | ---------- | ------------------------------- | ------------- |
21
+ | `default` | default | `Copy` |
22
+ | `complete` | displays after copy is complete | `Copied` |
23
+
24
+ @example
25
+
26
+ ```svelte
27
+ <script lang="ts">
28
+ import { CopyButton } from "drab";
29
+
30
+ let value = "";
31
+ </script>
32
+
33
+ <input
34
+ class="input mb-4"
35
+ type="text"
36
+ placeholder="Enter text to copy"
37
+ bind:value
38
+ />
39
+
40
+ <CopyButton class="button button-primary" blobParts={[value]} />
41
+ ```
42
+ -->
43
+
39
44
  <script>import { onMount } from "svelte";
40
45
  import { delay } from "../util/delay";
41
46
  let className = "";
@@ -78,19 +83,19 @@ $:
78
83
  blob = new Blob(blobParts, options);
79
84
  $:
80
85
  setBlobText(blob);
81
- </script>
82
-
83
- <button
84
- type="button"
85
- {disabled}
86
- on:click={copyText}
87
- class={className}
88
- {id}
89
- {title}
90
- >
91
- {#if complete}
92
- <slot name="complete">Copied</slot>
93
- {:else}
94
- <slot>Copy</slot>
95
- {/if}
96
- </button>
86
+ </script>
87
+
88
+ <button
89
+ type="button"
90
+ {disabled}
91
+ on:click={copyText}
92
+ class={className}
93
+ {id}
94
+ {title}
95
+ >
96
+ {#if complete}
97
+ <slot name="complete">Copied</slot>
98
+ {:else}
99
+ <slot>Copy</slot>
100
+ {/if}
101
+ </button>
@@ -46,12 +46,17 @@ export type CopyButtonSlots = typeof __propDef.slots;
46
46
  * <script lang="ts">
47
47
  * import { CopyButton } from "drab";
48
48
  *
49
- * let value = "Text to copy";
49
+ * let value = "";
50
50
  * </script>
51
51
  *
52
- * <input class="input mb-4" type="text" bind:value />
52
+ * <input
53
+ * class="input mb-4"
54
+ * type="text"
55
+ * placeholder="Enter text to copy"
56
+ * bind:value
57
+ * />
53
58
  *
54
- * <CopyButton class="btn" blobParts={[value]} />
59
+ * <CopyButton class="button button-primary" blobParts={[value]} />
55
60
  * ```
56
61
  */
57
62
  export default class CopyButton extends SvelteComponent<CopyButtonProps, CopyButtonEvents, CopyButtonSlots> {
@@ -1,116 +1,116 @@
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-neutral-50"
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="btn"
93
- disabled={currentPage < 1}
94
- on:click={() => currentPage--}
95
- >
96
- Previous
97
- </button>
98
- <button
99
- type="button"
100
- class="btn"
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
-
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
114
  <script>let className = "";
115
115
  export { className as class };
116
116
  export let id = "";
@@ -176,33 +176,33 @@ const showRow = (i, currentPage2) => {
176
176
  return overMin && underMax;
177
177
  };
178
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} />
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} />
@@ -108,7 +108,7 @@ export type DataTableSlots = typeof __propDef.slots;
108
108
  * maxRows={4}
109
109
  * class="tabular-nums"
110
110
  * classTh="cursor-pointer capitalize"
111
- * classTbodyTr="transition hover:bg-neutral-50"
111
+ * classTbodyTr="transition hover:bg-muted"
112
112
  * >
113
113
  * <svelte:fragment slot="th" let:key let:sortBy>
114
114
  * <span class:uppercase={key === "awd"} class:underline={key === sortBy}>
@@ -129,7 +129,7 @@ export type DataTableSlots = typeof __propDef.slots;
129
129
  * <div class="flex gap-2">
130
130
  * <button
131
131
  * type="button"
132
- * class="btn"
132
+ * class="button button-primary"
133
133
  * disabled={currentPage < 1}
134
134
  * on:click={() => currentPage--}
135
135
  * >
@@ -137,7 +137,7 @@ export type DataTableSlots = typeof __propDef.slots;
137
137
  * </button>
138
138
  * <button
139
139
  * type="button"
140
- * class="btn"
140
+ * class="button button-primary"
141
141
  * disabled={currentPage >= numberOfPages - 1}
142
142
  * on:click={() => currentPage++}
143
143
  * >
@@ -1,50 +1,48 @@
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
33
- class="flex cursor-pointer items-center justify-between gap-8 p-4 underline hover:decoration-dotted"
34
- >
35
- <div>Does it work without JavaScript?</div>
36
- <div class="transition" class:rotate-180={open}>
37
- <Chevron />
38
- </div>
39
- </div>
40
- </svelte:fragment>
41
- <svelte:fragment slot="content">
42
- <div class="px-4 pb-4">Yes.</div>
43
- </svelte:fragment>
44
- </Details>
45
- ```
46
- -->
47
-
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
+
48
46
  <script>import { onMount } from "svelte";
49
47
  import { slide } from "svelte/transition";
50
48
  import { prefersReducedMotion } from "../util/accessibility";
@@ -63,41 +61,41 @@ onMount(() => {
63
61
  if (prefersReducedMotion())
64
62
  transition = false;
65
63
  });
66
- </script>
67
-
68
- <div class={className} {id}>
69
- <details bind:open>
70
- <!-- svelte-ignore a11y-no-redundant-roles -->
71
- <summary
72
- role="button"
73
- tabindex="0"
74
- on:click|preventDefault={toggleOpen}
75
- on:keydown={(e) => {
76
- if (e.key === "Enter") {
77
- e.preventDefault();
78
- toggleOpen();
79
- }
80
- }}
81
- >
82
- <slot name="summary" {open} />
83
- </summary>
84
- {#if !clientJs || !transition}
85
- <slot name="content" />
86
- {/if}
87
- </details>
88
- {#if clientJs && open && transition}
89
- <!-- outside the details for the transition -->
90
- <div transition:slide={transition}>
91
- <slot name="content" />
92
- </div>
93
- {/if}
94
- </div>
95
-
96
- <style>
97
- summary {
98
- list-style: none;
99
- }
100
- summary::-webkit-details-marker {
101
- display: none;
102
- }
103
- </style>
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>
@@ -49,9 +49,7 @@ export type DetailsSlots = typeof __propDef.slots;
49
49
  *
50
50
  * <Details class="border-b">
51
51
  * <svelte:fragment slot="summary" let:open>
52
- * <div
53
- * class="flex cursor-pointer items-center justify-between gap-8 p-4 underline hover:decoration-dotted"
54
- * >
52
+ * <div class="link flex items-center justify-between gap-8 p-4">
55
53
  * <div>Does it work without JavaScript?</div>
56
54
  * <div class="transition" class:rotate-180={open}>
57
55
  * <Chevron />