drab 2.4.0 → 2.5.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.
@@ -17,7 +17,7 @@ Displays a list of `details` elements.
17
17
  - `icon`
18
18
  - `id`
19
19
  - `items` - array of `AccordionItem` elements
20
- - `transition` - rotates the icon, slides the content, defaults to empty object, set to false to remove
20
+ - `transition` - rotates the icon, slides the content, set to `false` to remove
21
21
 
22
22
  @slots
23
23
 
@@ -31,10 +31,15 @@ Displays a list of `details` elements.
31
31
 
32
32
  ```svelte
33
33
  <script>
34
- import { Accordion } from "drab";
34
+ import { Accordion } from "drab";
35
+ import { Chevron } from "../../site/svg/Chevron.svelte";
35
36
  </script>
36
37
 
37
- <Accordion
38
+ <Accordion
39
+ icon={Chevron}
40
+ classDetails="border-b"
41
+ classHeader="flex gap-8 cursor-pointer items-center justify-between py-4 font-bold hover:underline"
42
+ classContent="pb-4"
38
43
  items={[
39
44
  { summary: "Is it accessible?", content: "Yes." },
40
45
  {
@@ -48,27 +53,11 @@ Displays a list of `details` elements.
48
53
  { summary: "Does it work without Javascript?", content: "Yes." },
49
54
  ]}
50
55
  >
51
- <div slot="content" let:item let:index>
52
- <span>{index + 1}.</span>
53
- <span>{item.content}</span>
54
- </div>
55
- </Accordion>
56
-
57
- <Accordion
58
- items={[
59
- {
60
- summary: "A Component",
61
- content: "Rendered only on this item.",
62
- data: { component: FullscreenButton },
63
- },
64
- { summary: "Summary", content: "Some other content" },
65
- ]}
66
- >
67
- <svelte:fragment slot="content" let:item>
68
- {item.content}
69
- {#if item.data?.component}
70
- <svelte:component this={item.data.component} />
71
- {/if}
56
+ <svelte:fragment slot="content" let:item let:index>
57
+ <div class="mb-4">
58
+ <span>{index + 1}.</span>
59
+ <span>{item.content}</span>
60
+ </div>
72
61
  </svelte:fragment>
73
62
  </Accordion>
74
63
  ```
@@ -79,6 +68,7 @@ Displays a list of `details` elements.
79
68
  <script>import { onMount } from "svelte";
80
69
  import { slide } from "svelte/transition";
81
70
  import { prefersReducedMotion } from "../util/accessibility";
71
+ import { duration } from "../util/transition";
82
72
  let className = "";
83
73
  export { className as class };
84
74
  export let id = "";
@@ -89,7 +79,8 @@ export let classHeader = "";
89
79
  export let classSummary = "";
90
80
  export let classContent = "";
91
81
  export let classIcon = "";
92
- export let transition = {};
82
+ export let transition = { duration };
83
+ const cssDuration = transition ? transition.duration : 0;
93
84
  export let autoClose = true;
94
85
  let clientJs = false;
95
86
  const toggleOpen = (i) => {
@@ -135,6 +126,7 @@ onMount(() => {
135
126
  class={classIcon}
136
127
  class:d-rotate-180={item.open}
137
128
  class:d-transition={transition}
129
+ style="--duration: {cssDuration}ms;"
138
130
  >
139
131
  {#if typeof icon !== "string"}
140
132
  <svelte:component this={icon} />
@@ -173,6 +165,6 @@ onMount(() => {
173
165
  .d-transition {
174
166
  transition-property: transform;
175
167
  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
176
- transition-duration: 150ms;
168
+ transition-duration: var(--duration);
177
169
  }
178
170
  </style>
@@ -22,7 +22,7 @@ declare const __propDef: {
22
22
  /** class of all the `div`s that wrap the `summary` slot */ classSummary?: string | undefined;
23
23
  /** class of all the `div`s that wrap the `content` slot */ classContent?: string | undefined;
24
24
  /** class of the `div` that wrap the icon if displayed */ classIcon?: string | undefined;
25
- /** rotates the icon, slides the content, defaults to empty object, set to false to remove */ transition?: false | SlideParams | undefined;
25
+ /** rotates the icon, slides the content, set to `false` to remove */ transition?: false | SlideParams | undefined;
26
26
  /** if `true`, other items close when a new one is opened */ autoClose?: boolean | undefined;
27
27
  };
28
28
  events: {
@@ -63,7 +63,7 @@ export type AccordionSlots = typeof __propDef.slots;
63
63
  * - `icon`
64
64
  * - `id`
65
65
  * - `items` - array of `AccordionItem` elements
66
- * - `transition` - rotates the icon, slides the content, defaults to empty object, set to false to remove
66
+ * - `transition` - rotates the icon, slides the content, set to `false` to remove
67
67
  *
68
68
  * @slots
69
69
  *
@@ -77,10 +77,15 @@ export type AccordionSlots = typeof __propDef.slots;
77
77
  *
78
78
  * ```svelte
79
79
  * <script>
80
- * import { Accordion } from "drab";
80
+ * import { Accordion } from "drab";
81
+ * import { Chevron } from "../../site/svg/Chevron.svelte";
81
82
  * </script>
82
83
  *
83
84
  * <Accordion
85
+ * icon={Chevron}
86
+ * classDetails="border-b"
87
+ * classHeader="flex gap-8 cursor-pointer items-center justify-between py-4 font-bold hover:underline"
88
+ * classContent="pb-4"
84
89
  * items={[
85
90
  * { summary: "Is it accessible?", content: "Yes." },
86
91
  * {
@@ -94,27 +99,11 @@ export type AccordionSlots = typeof __propDef.slots;
94
99
  * { summary: "Does it work without Javascript?", content: "Yes." },
95
100
  * ]}
96
101
  * >
97
- * <div slot="content" let:item let:index>
98
- * <span>{index + 1}.</span>
99
- * <span>{item.content}</span>
100
- * </div>
101
- * </Accordion>
102
- *
103
- * <Accordion
104
- * items={[
105
- * {
106
- * summary: "A Component",
107
- * content: "Rendered only on this item.",
108
- * data: { component: FullscreenButton },
109
- * },
110
- * { summary: "Summary", content: "Some other content" },
111
- * ]}
112
- * >
113
- * <svelte:fragment slot="content" let:item>
114
- * {item.content}
115
- * {#if item.data?.component}
116
- * <svelte:component this={item.data.component} />
117
- * {/if}
102
+ * <svelte:fragment slot="content" let:item let:index>
103
+ * <div class="mb-4">
104
+ * <span>{index + 1}.</span>
105
+ * <span>{item.content}</span>
106
+ * </div>
118
107
  * </svelte:fragment>
119
108
  * </Accordion>
120
109
  * ```
@@ -21,7 +21,10 @@ Generates a guitar chord `svg`.
21
21
  import { Chord } from "drab";
22
22
  </script>
23
23
 
24
- <Chord name="D" notes={[
24
+ <Chord
25
+ class="text-gray-950"
26
+ name="D"
27
+ notes={[
25
28
  {
26
29
  finger: 0,
27
30
  string: 4,
@@ -45,7 +45,10 @@ export type ChordSlots = typeof __propDef.slots;
45
45
  * import { Chord } from "drab";
46
46
  * </script>
47
47
  *
48
- * <Chord name="D" notes={[
48
+ * <Chord
49
+ * class="text-gray-950"
50
+ * name="D"
51
+ * notes={[
49
52
  * {
50
53
  * finger: 0,
51
54
  * string: 4,
@@ -22,17 +22,17 @@ Displays when the parent element is right clicked.
22
22
 
23
23
  ```svelte
24
24
  <script>
25
- import { ContextMenu } from "drab";
25
+ import { ContextMenu } from "drab";
26
26
  </script>
27
27
 
28
- <div>
28
+ <div class="flex justify-center rounded border border-dashed p-12">
29
29
  <div>Right click here</div>
30
- <ContextMenu>
31
- <div>
32
- <div>Context Menu</div>
33
- <button>Button</button>
34
- <button>Button</button>
35
- <button>Button</button>
30
+ <ContextMenu class="transition">
31
+ <div class="card flex w-48 flex-col gap-2">
32
+ <div class="font-bold">Context Menu</div>
33
+ <button class="btn">Button</button>
34
+ <button class="btn">Button</button>
35
+ <button class="btn">Button</button>
36
36
  </div>
37
37
  </ContextMenu>
38
38
  </div>
@@ -81,7 +81,7 @@ onMount(() => {
81
81
  });
82
82
  </script>
83
83
 
84
- <svelte:document on:click={hide} on:keydown={onKeyDown} />
84
+ <svelte:body on:click={hide} on:keydown={onKeyDown} />
85
85
 
86
86
  <div
87
87
  class={className}
@@ -38,17 +38,17 @@ export type ContextMenuSlots = typeof __propDef.slots;
38
38
  *
39
39
  * ```svelte
40
40
  * <script>
41
- * import { ContextMenu } from "drab";
41
+ * import { ContextMenu } from "drab";
42
42
  * </script>
43
43
  *
44
- * <div>
44
+ * <div class="flex justify-center rounded border border-dashed p-12">
45
45
  * <div>Right click here</div>
46
- * <ContextMenu>
47
- * <div>
48
- * <div>Context Menu</div>
49
- * <button>Button</button>
50
- * <button>Button</button>
51
- * <button>Button</button>
46
+ * <ContextMenu class="transition">
47
+ * <div class="card flex w-48 flex-col gap-2">
48
+ * <div class="font-bold">Context Menu</div>
49
+ * <button class="btn">Button</button>
50
+ * <button class="btn">Button</button>
51
+ * <button class="btn">Button</button>
52
52
  * </div>
53
53
  * </ContextMenu>
54
54
  * </div>
@@ -24,10 +24,12 @@ Uses the navigator api to copy text to the clipboard.
24
24
 
25
25
  ```svelte
26
26
  <script>
27
- import { CopyButton } from "drab";
27
+ import { CopyButton } from "drab";
28
28
  </script>
29
29
 
30
- <CopyButton text="Text to copy" />
30
+ <div>
31
+ <CopyButton class="btn" text="Text to copy" />
32
+ </div>
31
33
  ```
32
34
  -->
33
35
 
@@ -45,7 +45,9 @@ export type CopyButtonSlots = typeof __propDef.slots;
45
45
  * import { CopyButton } from "drab";
46
46
  * </script>
47
47
  *
48
- * <CopyButton text="Text to copy" />
48
+ * <div>
49
+ * <CopyButton class="btn" text="Text to copy" />
50
+ * </div>
49
51
  * ```
50
52
  */
51
53
  export default class CopyButton extends SvelteComponent<CopyButtonProps, CopyButtonEvents, CopyButtonSlots> {
@@ -22,10 +22,12 @@ Data table to display an array of JS objects. Click a column header to sort.
22
22
  - `classTh` - `th` class
23
23
  - `classTheadTr` - `thead tr` class
24
24
  - `classThead` - `thead` class
25
+ - `class`
25
26
  - `columns` - table columns, in order
26
27
  - `currentPage` - current page, defaults to `1`
27
28
  - `data` - a list of objects to render in the table
28
29
  - `idTable` - `table` id
30
+ - `id`
29
31
  - `paginate` - number of rows to show on each page, defaults to `0` - no pagination
30
32
  - `sortBy` - column to sort by--defaults to first column
31
33
 
@@ -43,15 +45,26 @@ Data table to display an array of JS objects. Click a column header to sort.
43
45
  import { DataTable } from "drab";
44
46
  </script>
45
47
 
46
- <DataTable
48
+ <DataTable
47
49
  data={[
48
50
  { make: "Honda", model: "CR-V", year: 2011, awd: true },
49
51
  { make: "Volvo", model: "XC-40", year: 2024, awd: true },
50
52
  { make: "Ferrari", model: "458 Italia", year: 2015, awd: false },
51
53
  { make: "Chevrolet", model: "Silverado", year: 2022, awd: true },
52
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 },
53
59
  ]}
54
60
  sortBy="make"
61
+ paginate={4}
62
+ class="tabular-nums"
63
+ classTh="cursor-pointer uppercase"
64
+ classThSorted="underline"
65
+ classTbodyTr="transition hover:bg-gray-50"
66
+ classFooter="flex justify-between items-center"
67
+ classButton="btn"
55
68
  />
56
69
  ```
57
70
  -->
@@ -60,6 +73,9 @@ Data table to display an array of JS objects. Click a column header to sort.
60
73
 
61
74
  <script>import { messageNoScript } from "../util/messages";
62
75
  import { onMount } from "svelte";
76
+ let className = "";
77
+ export { className as class };
78
+ export let id = "";
63
79
  export let data;
64
80
  export let columns = [];
65
81
  if (!columns.length && data[0]) {
@@ -125,60 +141,62 @@ sort(sortBy, false);
125
141
  onMount(() => clientJs = true);
126
142
  </script>
127
143
 
128
- <table class={classTable} id={idTable}>
129
- <thead class={classThead}>
130
- <tr class={classTheadTr}>
131
- {#each columns as column}
132
- <th
133
- class="{classTh} {sortBy === column ? classThSorted : ''}"
134
- on:click={() => sort(column)}
135
- >
136
- {column}
137
- </th>
144
+ <div class={className} {id}>
145
+ <table class={classTable} id={idTable}>
146
+ <thead class={classThead}>
147
+ <tr class={classTheadTr}>
148
+ {#each columns as column}
149
+ <th
150
+ class="{classTh} {sortBy === column ? classThSorted : ''}"
151
+ on:click={() => sort(column)}
152
+ >
153
+ {column}
154
+ </th>
155
+ {/each}
156
+ </tr>
157
+ </thead>
158
+ <tbody class={classTbody}>
159
+ {#each data as row, i}
160
+ {@const showRow =
161
+ i < paginate * currentPage && i >= paginate * (currentPage - 1)}
162
+ {#if paginate ? showRow : true}
163
+ <tr class={classTbodyTr}>
164
+ {#each columns as column}
165
+ <td class="{classTd} {sortBy === column ? classTdSorted : ''}">
166
+ {row[column]}
167
+ </td>
168
+ {/each}
169
+ </tr>
170
+ {/if}
138
171
  {/each}
139
- </tr>
140
- </thead>
141
- <tbody class={classTbody}>
142
- {#each data as row, i}
143
- {@const showRow =
144
- i < paginate * currentPage && i >= paginate * (currentPage - 1)}
145
- {#if paginate ? showRow : true}
146
- <tr class={classTbodyTr}>
147
- {#each columns as column}
148
- <td class="{classTd} {sortBy === column ? classTdSorted : ''}">
149
- {row[column]}
150
- </td>
151
- {/each}
152
- </tr>
153
- {/if}
154
- {/each}
155
- </tbody>
156
- </table>
172
+ </tbody>
173
+ </table>
157
174
 
158
- {#if paginate}
159
- <div class={classFooter}>
160
- <div class={classPageNumber}>{currentPage} / {numberOfPages}</div>
161
- <div class={classPageControls}>
162
- <button
163
- class={classButton}
164
- disabled={!clientJs || currentPage < 2}
165
- on:click={() => currentPage--}
166
- >
167
- <slot name="previous">Previous</slot>
168
- </button>
169
- <button
170
- class={classButton}
171
- disabled={!clientJs || currentPage >= numberOfPages}
172
- on:click={() => currentPage++}
173
- >
174
- <slot name="next">Next</slot>
175
- </button>
175
+ {#if paginate}
176
+ <div class={classFooter}>
177
+ <div class={classPageNumber}>{currentPage} / {numberOfPages}</div>
178
+ <div class={classPageControls}>
179
+ <button
180
+ class={classButton}
181
+ disabled={!clientJs || currentPage < 2}
182
+ on:click={() => currentPage--}
183
+ >
184
+ <slot name="previous">Previous</slot>
185
+ </button>
186
+ <button
187
+ class={classButton}
188
+ disabled={!clientJs || currentPage >= numberOfPages}
189
+ on:click={() => currentPage++}
190
+ >
191
+ <slot name="next">Next</slot>
192
+ </button>
193
+ </div>
176
194
  </div>
177
- </div>
178
195
 
179
- <noscript>
180
- <div class={classNoscript}>
181
- {messageNoScript}
182
- </div>
183
- </noscript>
184
- {/if}
196
+ <noscript>
197
+ <div class={classNoscript}>
198
+ {messageNoScript}
199
+ </div>
200
+ </noscript>
201
+ {/if}
202
+ </div>
@@ -4,6 +4,8 @@ export type DataTableRow<T> = {
4
4
  };
5
5
  declare const __propDef: {
6
6
  props: {
7
+ class?: string | undefined;
8
+ id?: string | undefined;
7
9
  /** a list of objects to render in the table */ data: DataTableRow<any>[];
8
10
  /** table columns, in order */ columns?: string[] | undefined;
9
11
  /** column to sort by--defaults to first column */ sortBy?: string | undefined;
@@ -59,10 +61,12 @@ export type DataTableSlots = typeof __propDef.slots;
59
61
  * - `classTh` - `th` class
60
62
  * - `classTheadTr` - `thead tr` class
61
63
  * - `classThead` - `thead` class
64
+ * - `class`
62
65
  * - `columns` - table columns, in order
63
66
  * - `currentPage` - current page, defaults to `1`
64
67
  * - `data` - a list of objects to render in the table
65
68
  * - `idTable` - `table` id
69
+ * - `id`
66
70
  * - `paginate` - number of rows to show on each page, defaults to `0` - no pagination
67
71
  * - `sortBy` - column to sort by--defaults to first column
68
72
  *
@@ -87,8 +91,19 @@ export type DataTableSlots = typeof __propDef.slots;
87
91
  * { make: "Ferrari", model: "458 Italia", year: 2015, awd: false },
88
92
  * { make: "Chevrolet", model: "Silverado", year: 2022, awd: true },
89
93
  * { make: "Ford", model: "Model A", year: 1931, awd: false },
94
+ * { make: "Subaru", model: "Outback", year: 2021, awd: true },
95
+ * { make: "Ford", model: "Bronco", year: 1970, awd: true },
96
+ * { make: "GMC", model: "Acadia", year: 2008, awd: true },
97
+ * { make: "BMW", model: "X3", year: 2023, awd: true },
90
98
  * ]}
91
99
  * sortBy="make"
100
+ * paginate={4}
101
+ * class="tabular-nums"
102
+ * classTh="cursor-pointer uppercase"
103
+ * classThSorted="underline"
104
+ * classTbodyTr="transition hover:bg-gray-50"
105
+ * classFooter="flex justify-between items-center"
106
+ * classButton="btn"
92
107
  * />
93
108
  * ```
94
109
  */
@@ -27,7 +27,12 @@ Text editor with controls to add elements and keyboard shortcuts.
27
27
  import { Editor } from "drab";
28
28
  </script>
29
29
 
30
- <Editor contentElements={[
30
+ <Editor
31
+ classButton="btn"
32
+ classControls="flex gap-2"
33
+ classTextarea="border w-full h-36 p-2 rounded"
34
+ placeholderTextarea="asterisk: ctrl+i, anchor: ctrl+["
35
+ contentElements={[
31
36
  {
32
37
  name: "Bullet",
33
38
  text: "- ",
@@ -73,7 +73,12 @@ export type EditorSlots = typeof __propDef.slots;
73
73
  * import { Editor } from "drab";
74
74
  * </script>
75
75
  *
76
- * <Editor contentElements={[
76
+ * <Editor
77
+ * classButton="btn"
78
+ * classControls="flex gap-2"
79
+ * classTextarea="border w-full h-36 p-2 rounded"
80
+ * placeholderTextarea="asterisk: ctrl+i, anchor: ctrl+["
81
+ * contentElements={[
77
82
  * {
78
83
  * name: "Bullet",
79
84
  * text: "- ",
@@ -30,13 +30,18 @@ Make the document or a specific element fullscreen.
30
30
  let fullscreenDiv;
31
31
  </script>
32
32
 
33
- <FullscreenButton />
33
+ <div>
34
+ <FullscreenButton class="btn" />
35
+ </div>
34
36
 
35
- <div bind:this={fullscreenDiv}>
36
- <div>Target element fullscreen</div>
37
- <FullscreenButton targetElement={fullscreenDiv}>
37
+ <div
38
+ bind:this={fullscreenDiv}
39
+ class="mt-4 rounded bg-gray-800 p-4 text-gray-50"
40
+ >
41
+ <div class="mb-2">Target element fullscreen</div>
42
+ <FullscreenButton targetElement={fullscreenDiv} class="btn">
43
+ <span>Enable Element Fullscreen</span>
38
44
  <span slot="enabled">Exit Element Fullscreen</span>
39
- <span slot="disabled">Enable Element Fullscreen</span>
40
45
  </FullscreenButton>
41
46
  </div>
42
47
  ```
@@ -49,13 +49,18 @@ export type FullscreenButtonSlots = typeof __propDef.slots;
49
49
  * let fullscreenDiv;
50
50
  * </script>
51
51
  *
52
- * <FullscreenButton />
52
+ * <div>
53
+ * <FullscreenButton class="btn" />
54
+ * </div>
53
55
  *
54
- * <div bind:this={fullscreenDiv}>
55
- * <div>Target element fullscreen</div>
56
- * <FullscreenButton targetElement={fullscreenDiv}>
56
+ * <div
57
+ * bind:this={fullscreenDiv}
58
+ * class="mt-4 rounded bg-gray-800 p-4 text-gray-50"
59
+ * >
60
+ * <div class="mb-2">Target element fullscreen</div>
61
+ * <FullscreenButton targetElement={fullscreenDiv} class="btn">
62
+ * <span>Enable Element Fullscreen</span>
57
63
  * <span slot="enabled">Exit Element Fullscreen</span>
58
- * <span slot="disabled">Enable Element Fullscreen</span>
59
64
  * </FullscreenButton>
60
65
  * </div>
61
66
  * ```
@@ -28,16 +28,30 @@ Displays a popover relatively positioned to the button.
28
28
 
29
29
  ```svelte
30
30
  <script>
31
- import { Popover } from "drab";
31
+ import { Popover } from "drab";
32
32
  </script>
33
33
 
34
- <Popover>
34
+ <Popover classButton="btn" classPopover="p-2 transition">
35
35
  <span slot="button">Hover</span>
36
- <div>
37
- <div>Popover</div>
38
- <button>Button</button>
39
- <button>Button</button>
40
- <button>Button</button>
36
+ <div class="card flex w-48 flex-col gap-2">
37
+ <div class="font-bold">Bottom</div>
38
+ <button class="btn">Button</button>
39
+ <button class="btn">Button</button>
40
+ <button class="btn">Button</button>
41
+ </div>
42
+ </Popover>
43
+ <Popover
44
+ classButton="btn"
45
+ classPopover="p-2 transition"
46
+ eventType="click"
47
+ position="right"
48
+ >
49
+ <span slot="button">Click</span>
50
+ <div class="card flex w-48 flex-col gap-2">
51
+ <div class="font-bold">Right</div>
52
+ <button class="btn">Button</button>
53
+ <button class="btn">Button</button>
54
+ <button class="btn">Button</button>
41
55
  </div>
42
56
  </Popover>
43
57
  ```
@@ -109,7 +123,7 @@ onMount(() => {
109
123
  });
110
124
  </script>
111
125
 
112
- <svelte:document on:keydown={onKeyDown} on:click={clickOutside} />
126
+ <svelte:body on:keydown={onKeyDown} on:click={clickOutside} />
113
127
 
114
128
  <div class="db-relative {className}" {id}>
115
129
  <button
@@ -50,16 +50,30 @@ export type PopoverSlots = typeof __propDef.slots;
50
50
  *
51
51
  * ```svelte
52
52
  * <script>
53
- * import { Popover } from "drab";
53
+ * import { Popover } from "drab";
54
54
  * </script>
55
55
  *
56
- * <Popover>
56
+ * <Popover classButton="btn" classPopover="p-2 transition">
57
57
  * <span slot="button">Hover</span>
58
- * <div>
59
- * <div>Popover</div>
60
- * <button>Button</button>
61
- * <button>Button</button>
62
- * <button>Button</button>
58
+ * <div class="card flex w-48 flex-col gap-2">
59
+ * <div class="font-bold">Bottom</div>
60
+ * <button class="btn">Button</button>
61
+ * <button class="btn">Button</button>
62
+ * <button class="btn">Button</button>
63
+ * </div>
64
+ * </Popover>
65
+ * <Popover
66
+ * classButton="btn"
67
+ * classPopover="p-2 transition"
68
+ * eventType="click"
69
+ * position="right"
70
+ * >
71
+ * <span slot="button">Click</span>
72
+ * <div class="card flex w-48 flex-col gap-2">
73
+ * <div class="font-bold">Right</div>
74
+ * <button class="btn">Button</button>
75
+ * <button class="btn">Button</button>
76
+ * <button class="btn">Button</button>
63
77
  * </div>
64
78
  * </Popover>
65
79
  * ```
@@ -25,14 +25,17 @@ Uses the navigator api to share or copy a url link depending on browser support.
25
25
 
26
26
  ```svelte
27
27
  <script>
28
- import { ShareButton } from "drab";
28
+ import { ShareButton } from "drab";
29
29
  </script>
30
30
 
31
- <ShareButton
32
- text="Check out this page: "
33
- title="drab"
34
- url="https://drab.robino.dev"
35
- />
31
+ <div>
32
+ <ShareButton
33
+ class="btn"
34
+ text="Check out this page: "
35
+ title="drab"
36
+ url="https://drab.robino.dev"
37
+ />
38
+ </div>
36
39
  ```
37
40
  -->
38
41
 
@@ -44,14 +44,17 @@ export type ShareButtonSlots = typeof __propDef.slots;
44
44
  *
45
45
  * ```svelte
46
46
  * <script>
47
- * import { ShareButton } from "drab";
47
+ * import { ShareButton } from "drab";
48
48
  * </script>
49
49
  *
50
+ * <div>
50
51
  * <ShareButton
51
- * text="Check out this page: "
52
- * title="drab"
53
- * url="https://drab.robino.dev"
52
+ * class="btn"
53
+ * text="Check out this page: "
54
+ * title="drab"
55
+ * url="https://drab.robino.dev"
54
56
  * />
57
+ * </div>
55
58
  * ```
56
59
  */
57
60
  export default class ShareButton extends SvelteComponent<ShareButtonProps, ShareButtonEvents, ShareButtonSlots> {
@@ -0,0 +1,166 @@
1
+ <!--
2
+ @component
3
+
4
+ ### Sheet
5
+
6
+ Creates a sheet element based on the `position` provided.
7
+
8
+ @props
9
+
10
+ - `classSheet` - sheet class - not the backdrop
11
+ - `class`
12
+ - `display` - controls whether the sheet is displayed
13
+ - `id`
14
+ - `position` - determines the position of sheet
15
+ - `size` - size of sheet based on position - can also use css instead
16
+ - `transitionSheet` - slides the sheet, set to `false` to remove
17
+ - `transition` - fades the entire component, set to `false` to remove
18
+
19
+ @slots
20
+
21
+ | name | purpose | default value |
22
+ | ---------- | ------------------------------- | ------------- |
23
+ | `default` | content | `Content` |
24
+
25
+ @example
26
+
27
+ ```svelte
28
+ <script lang="ts">
29
+ import { Sheet } from "drab";
30
+
31
+ let display = false;
32
+ </script>
33
+
34
+ <div>
35
+ <button class="btn" on:click={() => (display = true)}>Open</button>
36
+ </div>
37
+
38
+ <Sheet
39
+ bind:display
40
+ class="bg-gray-50/80 backdrop-blur"
41
+ classSheet="p-4 shadow bg-white"
42
+ >
43
+ <div class="mb-4 flex items-center justify-between">
44
+ <div class="text-lg font-bold">Sheet</div>
45
+ <button class="btn" on:click={() => (display = false)}>Close</button>
46
+ </div>
47
+ <div>
48
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
49
+ tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
50
+ quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
51
+ consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
52
+ cillum dolore eu fugiat nulla pariatur.
53
+ </div>
54
+ </Sheet>
55
+ ```
56
+ -->
57
+
58
+ <script>import { onMount } from "svelte";
59
+ import {
60
+ fade,
61
+ fly
62
+ } from "svelte/transition";
63
+ import { prefersReducedMotion } from "../util/accessibility";
64
+ import { duration } from "../util/transition";
65
+ let className = "";
66
+ export { className as class };
67
+ export let id = "";
68
+ export let classSheet = "";
69
+ export let display = true;
70
+ export let transition = { duration };
71
+ export let position = "right";
72
+ export let size = 488;
73
+ export let transitionSheet = { duration };
74
+ let sheet;
75
+ const clickOutside = (e) => {
76
+ if (e.target instanceof Node && !sheet.contains(e.target)) {
77
+ display = false;
78
+ }
79
+ };
80
+ const onKeyDown = (e) => {
81
+ if (e.key === "Escape") {
82
+ display = false;
83
+ }
84
+ };
85
+ if (transitionSheet && !transitionSheet.x && !transitionSheet.y) {
86
+ if (position === "bottom") {
87
+ transitionSheet.y = size;
88
+ } else if (position === "top") {
89
+ transitionSheet.y = -size;
90
+ } else if (position === "right") {
91
+ transitionSheet.x = size;
92
+ } else {
93
+ transitionSheet.x = -size;
94
+ }
95
+ }
96
+ onMount(() => {
97
+ if (prefersReducedMotion()) {
98
+ if (transition)
99
+ transition.duration = 0;
100
+ if (transitionSheet)
101
+ transitionSheet.duration = 0;
102
+ }
103
+ });
104
+ </script>
105
+
106
+ <svelte:body on:keydown={onKeyDown} />
107
+
108
+ {#if display}
109
+ <div
110
+ role="button"
111
+ tabindex="0"
112
+ on:click={clickOutside}
113
+ on:keydown={onKeyDown}
114
+ transition:fade={transition ? transition : { duration: 0 }}
115
+ class="d-backdrop {className}"
116
+ {id}
117
+ >
118
+ <div
119
+ bind:this={sheet}
120
+ transition:fly={transitionSheet ? transitionSheet : { duration: 0 }}
121
+ style={position === "top" || position === "bottom"
122
+ ? `max-height: ${size}px;`
123
+ : `max-width: ${size}px`}
124
+ class="d-sheet {classSheet}"
125
+ class:d-bottom={position === "bottom"}
126
+ class:d-top={position === "top"}
127
+ class:d-left={position === "left"}
128
+ class:d-right={position === "right"}
129
+ >
130
+ <slot>Content</slot>
131
+ </div>
132
+ </div>
133
+ {/if}
134
+
135
+ <style>
136
+ .d-backdrop {
137
+ position: fixed;
138
+ display: grid;
139
+ z-index: 10;
140
+ top: 0;
141
+ bottom: 0;
142
+ left: 0;
143
+ right: 0;
144
+ overflow: hidden;
145
+ cursor: default;
146
+ }
147
+ .d-sheet {
148
+ margin: auto;
149
+ }
150
+ .d-bottom {
151
+ margin-bottom: 0;
152
+ width: 100%;
153
+ }
154
+ .d-top {
155
+ margin-top: 0;
156
+ width: 100%;
157
+ }
158
+ .d-right {
159
+ margin-right: 0;
160
+ height: 100%;
161
+ }
162
+ .d-left {
163
+ margin-left: 0;
164
+ height: 100%;
165
+ }
166
+ </style>
@@ -0,0 +1,80 @@
1
+ import { SvelteComponent } from "svelte";
2
+ import { type FadeParams, type FlyParams } from "svelte/transition";
3
+ declare const __propDef: {
4
+ props: {
5
+ class?: string | undefined;
6
+ id?: string | undefined;
7
+ /** sheet class - not the backdrop */ classSheet?: string | undefined;
8
+ /** controls whether the sheet is displayed*/ display?: boolean | undefined;
9
+ /** fades the entire component, set to `false` to remove */ transition?: false | FadeParams | undefined;
10
+ /** determines the position of sheet */ position?: "top" | "bottom" | "left" | "right" | undefined;
11
+ /** size of sheet based on position - can also use css instead */ size?: number | undefined;
12
+ /** slides the sheet, set to `false` to remove */ transitionSheet?: false | FlyParams | undefined;
13
+ };
14
+ events: {
15
+ [evt: string]: CustomEvent<any>;
16
+ };
17
+ slots: {
18
+ default: {};
19
+ };
20
+ };
21
+ export type SheetProps = typeof __propDef.props;
22
+ export type SheetEvents = typeof __propDef.events;
23
+ export type SheetSlots = typeof __propDef.slots;
24
+ /**
25
+ * ### Sheet
26
+ *
27
+ * Creates a sheet element based on the `position` provided.
28
+ *
29
+ * @props
30
+ *
31
+ * - `classSheet` - sheet class - not the backdrop
32
+ * - `class`
33
+ * - `display` - controls whether the sheet is displayed
34
+ * - `id`
35
+ * - `position` - determines the position of sheet
36
+ * - `size` - size of sheet based on position - can also use css instead
37
+ * - `transitionSheet` - slides the sheet, set to `false` to remove
38
+ * - `transition` - fades the entire component, set to `false` to remove
39
+ *
40
+ * @slots
41
+ *
42
+ * | name | purpose | default value |
43
+ * | ---------- | ------------------------------- | ------------- |
44
+ * | `default` | content | `Content` |
45
+ *
46
+ * @example
47
+ *
48
+ * ```svelte
49
+ * <script lang="ts">
50
+ * import { Sheet } from "drab";
51
+ *
52
+ * let display = false;
53
+ * </script>
54
+ *
55
+ * <div>
56
+ * <button class="btn" on:click={() => (display = true)}>Open</button>
57
+ * </div>
58
+ *
59
+ * <Sheet
60
+ * bind:display
61
+ * class="bg-gray-50/80 backdrop-blur"
62
+ * classSheet="p-4 shadow bg-white"
63
+ * >
64
+ * <div class="mb-4 flex items-center justify-between">
65
+ * <div class="text-lg font-bold">Sheet</div>
66
+ * <button class="btn" on:click={() => (display = false)}>Close</button>
67
+ * </div>
68
+ * <div>
69
+ * Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
70
+ * tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
71
+ * quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
72
+ * consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
73
+ * cillum dolore eu fugiat nulla pariatur.
74
+ * </div>
75
+ * </Sheet>
76
+ * ```
77
+ */
78
+ export default class Sheet extends SvelteComponent<SheetProps, SheetEvents, SheetSlots> {
79
+ }
80
+ export {};
@@ -29,19 +29,30 @@ Displays tabs and the active tab's content.
29
29
 
30
30
  ```svelte
31
31
  <script>
32
- import { Tabs } from "drab";
32
+ import { Tabs } from "drab";
33
+ import { FullscreenButton } from "drab";
33
34
  </script>
34
35
 
35
- <Tabs
36
- items={[
37
- { name: "Tab 1", content: "Content 1" },
38
- { name: "Tab 2", content: "Content 2" },
36
+ <Tabs
37
+ classHeader="grid grid-flow-col grid-rows-1 gap-1 rounded bg-gray-200 p-1"
38
+ classTitle="btn rounded-sm p-0.5"
39
+ classTitleActive="bg-white text-gray-950"
40
+ classTitleInactive="bg-gray-200 text-gray-500"
41
+ classContent="py-2"
42
+ tabs={[
43
+ { title: "Tab 1", content: "Content 1" },
44
+ { title: "Tab 2", content: "Content 2" },
39
45
  ]}
40
46
  />
41
47
 
42
48
  <Tabs
49
+ classHeader="grid grid-flow-col grid-rows-1 gap-1 rounded bg-gray-200 p-1"
50
+ classTitle="btn rounded-sm p-0.5"
51
+ classTitleActive="bg-white text-gray-950"
52
+ classTitleInactive="bg-gray-200 text-gray-500"
53
+ classContent="py-2"
43
54
  tabs={[
44
- { title: "Tab", content: "Content 1" },
55
+ { title: "Tab", content: "Generated indexes" },
45
56
  {
46
57
  title: "Tab",
47
58
  content: "A tab with a component",
@@ -56,7 +67,7 @@ Displays tabs and the active tab's content.
56
67
  </svelte:fragment>
57
68
  <div>{activeTab.content}</div>
58
69
  {#if activeTab.data?.component}
59
- <svelte:component this={activeTab.data.component} />
70
+ <svelte:component this={activeTab.data.component} class="btn" />
60
71
  {/if}
61
72
  </Tabs>
62
73
  ```
@@ -65,19 +65,30 @@ export type TabsSlots = typeof __propDef.slots;
65
65
  *
66
66
  * ```svelte
67
67
  * <script>
68
- * import { Tabs } from "drab";
68
+ * import { Tabs } from "drab";
69
+ * import { FullscreenButton } from "drab";
69
70
  * </script>
70
71
  *
71
72
  * <Tabs
72
- * items={[
73
- * { name: "Tab 1", content: "Content 1" },
74
- * { name: "Tab 2", content: "Content 2" },
73
+ * classHeader="grid grid-flow-col grid-rows-1 gap-1 rounded bg-gray-200 p-1"
74
+ * classTitle="btn rounded-sm p-0.5"
75
+ * classTitleActive="bg-white text-gray-950"
76
+ * classTitleInactive="bg-gray-200 text-gray-500"
77
+ * classContent="py-2"
78
+ * tabs={[
79
+ * { title: "Tab 1", content: "Content 1" },
80
+ * { title: "Tab 2", content: "Content 2" },
75
81
  * ]}
76
82
  * />
77
83
  *
78
84
  * <Tabs
85
+ * classHeader="grid grid-flow-col grid-rows-1 gap-1 rounded bg-gray-200 p-1"
86
+ * classTitle="btn rounded-sm p-0.5"
87
+ * classTitleActive="bg-white text-gray-950"
88
+ * classTitleInactive="bg-gray-200 text-gray-500"
89
+ * classContent="py-2"
79
90
  * tabs={[
80
- * { title: "Tab", content: "Content 1" },
91
+ * { title: "Tab", content: "Generated indexes" },
81
92
  * {
82
93
  * title: "Tab",
83
94
  * content: "A tab with a component",
@@ -92,7 +103,7 @@ export type TabsSlots = typeof __propDef.slots;
92
103
  * </svelte:fragment>
93
104
  * <div>{activeTab.content}</div>
94
105
  * {#if activeTab.data?.component}
95
- * <svelte:component this={activeTab.data.component} />
106
+ * <svelte:component this={activeTab.data.component} class="btn" />
96
107
  * {/if}
97
108
  * </Tabs>
98
109
  * ```
@@ -21,7 +21,11 @@ Embeds a YouTube video into a website with the video `uid`, using [www.youtube-n
21
21
  import { YouTube } from "drab";
22
22
  </script>
23
23
 
24
- <YouTube title="Video Title" uid="youtube_uid" />
24
+ <YouTube
25
+ class="aspect-video w-full rounded"
26
+ title="Renegade - Kevin Olusola"
27
+ uid="gouiY85kD2o"
28
+ />
25
29
  ```
26
30
  -->
27
31
 
@@ -37,7 +37,11 @@ export type YouTubeSlots = typeof __propDef.slots;
37
37
  * import { YouTube } from "drab";
38
38
  * </script>
39
39
  *
40
- * <YouTube title="Video Title" uid="youtube_uid" />
40
+ * <YouTube
41
+ * class="aspect-video w-full rounded"
42
+ * title="Renegade - Kevin Olusola"
43
+ * uid="gouiY85kD2o"
44
+ * />
41
45
  * ```
42
46
  */
43
47
  export default class YouTube extends SvelteComponent<YouTubeProps, YouTubeEvents, YouTubeSlots> {
package/dist/index.d.ts CHANGED
@@ -11,7 +11,8 @@ import type { EditorContentElement } from "./components/Editor.svelte";
11
11
  import FullscreenButton from "./components/FullscreenButton.svelte";
12
12
  import Popover from "./components/Popover.svelte";
13
13
  import ShareButton from "./components/ShareButton.svelte";
14
+ import Sheet from "./components/Sheet.svelte";
14
15
  import Tabs from "./components/Tabs.svelte";
15
16
  import type { TabsTab } from "./components/Tabs.svelte";
16
17
  import YouTube from "./components/YouTube.svelte";
17
- export { Accordion, type AccordionItem, Chord, type ChordNote, ContextMenu, CopyButton, DataTable, type DataTableRow, Editor, type EditorContentElement, FullscreenButton, Popover, ShareButton, Tabs, type TabsTab, YouTube, };
18
+ export { Accordion, type AccordionItem, Chord, type ChordNote, ContextMenu, CopyButton, DataTable, type DataTableRow, Editor, type EditorContentElement, FullscreenButton, Popover, ShareButton, Sheet, Tabs, type TabsTab, YouTube, };
package/dist/index.js CHANGED
@@ -7,6 +7,7 @@ import Editor from "./components/Editor.svelte";
7
7
  import FullscreenButton from "./components/FullscreenButton.svelte";
8
8
  import Popover from "./components/Popover.svelte";
9
9
  import ShareButton from "./components/ShareButton.svelte";
10
+ import Sheet from "./components/Sheet.svelte";
10
11
  import Tabs from "./components/Tabs.svelte";
11
12
  import YouTube from "./components/YouTube.svelte";
12
- export { Accordion, Chord, ContextMenu, CopyButton, DataTable, Editor, FullscreenButton, Popover, ShareButton, Tabs, YouTube, };
13
+ export { Accordion, Chord, ContextMenu, CopyButton, DataTable, Editor, FullscreenButton, Popover, ShareButton, Sheet, Tabs, YouTube, };
@@ -0,0 +1 @@
1
+ export declare const duration = 200;
@@ -0,0 +1 @@
1
+ export const duration = 200;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drab",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "description": "An unstyled Svelte component library",
5
5
  "keywords": [
6
6
  "components",
@@ -36,7 +36,7 @@
36
36
  "lint": "prettier --check . && eslint .",
37
37
  "format": "prettier --write . --plugin=prettier-plugin-svelte --plugin=prettier-plugin-tailwindcss",
38
38
  "pub": "npm publish --access public",
39
- "doc": "node scripts/buildDocs.js"
39
+ "doc": "node src/scripts/buildDocs.js"
40
40
  },
41
41
  "exports": {
42
42
  ".": {