drab 2.8.7 → 3.0.1

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/README.md CHANGED
@@ -1,23 +1,19 @@
1
1
  # An Unstyled Svelte Component Library
2
2
 
3
+ - [Docs](https://drab.robino.dev)
3
4
  - [GitHub](https://github.com/rossrobino/drab)
4
5
  - [npm](https://www.npmjs.com/package/drab)
5
6
  - [MIT License](https://github.com/rossrobino/drab/blob/main/LICENSE.md)
6
- - One dependency - [Svelte](https://svelte.dev)
7
7
 
8
8
  ## About
9
9
 
10
- **drab** focuses on providing JavaScript functionality where it's most useful. Whenever possible, components are [progressively enhanced](/docs/ShareButton) or provide a fallback [noscript](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/noscript) message. Additionally, transitions are disabled for users who prefer reduced motion.
10
+ **drab** focuses on providing JavaScript functionality where it's most useful. Many of the components are helpful wrappers around browser APIs. Whenever possible, components are [progressively enhanced](https://drab.robino.dev/docs/ShareButton) or provide a fallback [noscript](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/noscript) message. Additionally, transitions are disabled for users who prefer reduced motion.
11
11
 
12
- This library takes a more opinionated approach compared to some headless UI libraries by providing the basic HTML structure for every component, as well as default positioning for elements like the [sheet](/docs/Sheet) or [popover](/docs/Popover). However, these components can still be further customized using styles, [slots](https://svelte.dev/tutorial/slots), and [slot props](https://svelte.dev/tutorial/slot-props).
13
-
14
- Components without styles can appear rather drab. You have the freedom to bring your own styles to these components! Using unstyled components allows you to selectively choose what you need, seamlessly integrate with existing designs, and avoid being tied to any specific library.
15
-
16
- To style the components, you can make use of [global styles](https://joyofcode.xyz/global-styles-in-sveltekit). This process can be expedited by utilizing CSS frameworks like [TailwindCSS](https://tailwindcss.com/). TailwindCSS generates a global stylesheet based on the utility classes used in your project. Each component exports `class` and `id` props that can be leveraged for this purpose.
12
+ This library takes a more opinionated approach compared to some headless UI libraries by providing the basic HTML structure for every component, as well as default positioning for elements like the [sheet](https://drab.robino.dev/docs/Sheet). However, these components can still be further customized using styles, [slots](https://svelte.dev/tutorial/slots), and [slot props](https://svelte.dev/tutorial/slot-props).
17
13
 
18
14
  ## Install
19
15
 
20
- If you haven't used Svelte before, start with the [tutorial](https://svelte.dev/tutorial/basics).
16
+ If you haven't used Svelte before, start with the [tutorial](https://svelte.dev/tutorial/basics). **drab** works anywhere Svelte does.
21
17
 
22
18
  - [SvelteKit](https://kit.svelte.dev)
23
19
  - [Astro](https://docs.astro.build/en/tutorial/1-setup/2/)
@@ -33,18 +29,80 @@ The library provides inline documentation for each component, allowing you to co
33
29
 
34
30
  These docs use the [TailwindCSS Typography plugin](https://tailwindcss.com/docs/typography-plugin) for base styles along with a few custom utility classes you can find [here](https://github.com/rossrobino/drab/blob/main/src/app.postcss). Styles on this site are based on [shadcn/ui](https://ui.shadcn.com/).
35
31
 
36
- ## Alternatives
32
+ ## Other UI Libraries
37
33
 
38
- If **drab** isn't what you are looking for, here are some other Svelte UI libraries to check out.
34
+ **drab** is a collection of useful components, not a complete UI kit. If **drab** isn't what you are looking for, here are some other libraries to check out.
39
35
 
40
36
  - [Skeleton](https://skeleton.dev)
41
37
  - [Melt UI](https://www.melt-ui.com/)
42
38
  - [shadcn-svelte](https://www.shadcn-svelte.com/)
43
39
  - [Svelte-HeadlessUI](https://captaincodeman.github.io/svelte-headlessui/)
44
40
 
41
+ ## Styling
42
+
43
+ Components without styles can appear rather drab. You have the freedom to bring your own styles to these components. Using unstyled components allows you to selectively choose what you need and avoid being tied to any specific library.
44
+
45
+ To style the markup provided by the components, you can make use of [global styles](https://joyofcode.xyz/global-styles-in-sveltekit). Each component exports `class` and `id` props that can be leveraged for this purpose. This process can be expedited by utilizing CSS frameworks like [TailwindCSS](https://tailwindcss.com/). Tailwind generates a global stylesheet based on the utility classes used in your project. The examples in this documentation are styled with Tailwind classes, but Tailwind does not have to be used with this library.
46
+
47
+ ### Stylesheet
48
+
49
+ Here's a SvelteKit example using CSS imported in a layout. By using a layout, these styles can be accessed anywhere.
50
+
51
+ ```css
52
+ /* src/app.css */
53
+ .btn {
54
+ color: white;
55
+ background-color: black;
56
+ border-radius: 5px;
57
+ padding: 5px;
58
+ }
59
+ ```
60
+
61
+ ```svelte
62
+ <!-- src/routes/+layout.svelte -->
63
+ <script>
64
+ import "../app.css";
65
+ </script>
66
+
67
+ <slot />
68
+ ```
69
+
70
+ ```svelte
71
+ <!-- src/routes/+page.svelte -->
72
+ <script>
73
+ import { FullscreenButton } from "drab";
74
+ </script>
75
+
76
+ <FullscreenButton class="btn" />
77
+ ```
78
+
79
+ ### Global modifier
80
+
81
+ Alternatively, the [`:global()` modifier](https://svelte.dev/docs/svelte-components#style) can be used instead of a separate stylesheet.
82
+
83
+ ```svelte
84
+ <!-- src/routes/+page.svelte -->
85
+ <script>
86
+ import { FullscreenButton } from "drab";
87
+ </script>
88
+
89
+ <FullscreenButton class="btn" />
90
+
91
+ <style>
92
+ :global(.btn) {
93
+ color: white;
94
+ background-color: black;
95
+ border-radius: 5px;
96
+ padding: 5px;
97
+ }
98
+ </style>
99
+ ```
100
+
45
101
  ## Contributing
46
102
 
47
- Find an bug or have an idea? Feel free to create an issue on [GitHub](https://github.com/rossrobino/drab).
103
+ Find an bug or have an idea? Feel free to create an issue on [GitHub](https://github.com/rossrobino/drab). **drab** is meant to house all kinds of components including ones outside of the standard UI elements.
104
+
105
+ Currently, **drab** has only one dependency - Svelte. Not to say it will never have another, but please consider this when proposing additional functionality. **drab** is meant to make the most of what Svelte and the web platform provide.
48
106
 
49
107
  Since this is an unstyled library, simple components like a badge that can be easily created with HTML and CSS are not included.
50
108
 
@@ -60,8 +118,8 @@ Contribute to the project, or use **drab** as a template for another component l
60
118
 
61
119
  #### Add or edit a component
62
120
 
63
- 1. Add/edit the component in `src/lib/components/Component.svelte`, if you're adding a new one, copy and paste an existing one to get started with the conventions
64
- 2. Add/edit the example in `src/routes/docs/Component/+page.svelte`
65
- 3. Document the component with an `@component` comment, include a description, and the `@slots` available. Add a placeholder `@props` and `@example` to the comment. These sections will be generated based on the JSDoc comment above each prop and the example route created upon running `npm run doc`
121
+ 1. Add or edit the component in `src/lib/components/Component.svelte` - if you're adding a new one, copy and paste an existing one to get started with the conventions
122
+ 2. Add or edit the example in `src/routes/docs/Component/+page.svelte`
123
+ 3. Document the component with an `@component` comment, include a description, and the `@slots` available. Add a placeholder `@props` and `@example` to the comment. These sections will be generated based on the JSDoc comment above each prop and the example route upon running `npm run doc`
66
124
  4. If new, add the link to `src/site/components/NavItems.svelte`
67
125
  5. Run `npm run build` to verify your build
@@ -21,7 +21,7 @@ With SvelteKit, this component can be wrapped in an `{#if dev}` block that check
21
21
  </script>
22
22
 
23
23
  <Breakpoint
24
- class="inline-block rounded border px-2 py-1 font-mono tabular-nums shadow"
24
+ class="inline-block rounded border bg-white px-2 py-1 font-mono tabular-nums shadow"
25
25
  />
26
26
  ```
27
27
  -->
@@ -37,7 +37,7 @@ export type BreakpointSlots = typeof __propDef.slots;
37
37
  * </script>
38
38
  *
39
39
  * <Breakpoint
40
- * class="inline-block rounded border px-2 py-1 font-mono tabular-nums shadow"
40
+ * class="inline-block rounded border bg-white px-2 py-1 font-mono tabular-nums shadow"
41
41
  * />
42
42
  * ```
43
43
  */
@@ -43,7 +43,7 @@ Displays when the `target` element is right clicked, or long pressed on mobile.
43
43
  <button type="button" class="btn" bind:this={target}>Target Right Click</button>
44
44
  <ContextMenu {target}>
45
45
  <div class="flex w-48 flex-col gap-2 rounded border bg-white p-2 shadow">
46
- <div class="font-bold">Context Menu</div>
46
+ <div class="font-bold">Target</div>
47
47
  <button role="menuitem" class="btn">Button</button>
48
48
  <button role="menuitem" class="btn">Button</button>
49
49
  <button role="menuitem" class="btn">Button</button>
@@ -144,6 +144,5 @@ onMount(async () => {
144
144
  }
145
145
  div {
146
146
  position: absolute;
147
- z-index: 10;
148
147
  }
149
148
  </style>
@@ -61,7 +61,7 @@ export type ContextMenuSlots = typeof __propDef.slots;
61
61
  * <button type="button" class="btn" bind:this={target}>Target Right Click</button>
62
62
  * <ContextMenu {target}>
63
63
  * <div class="flex w-48 flex-col gap-2 rounded border bg-white p-2 shadow">
64
- * <div class="font-bold">Context Menu</div>
64
+ * <div class="font-bold">Target</div>
65
65
  * <button role="menuitem" class="btn">Button</button>
66
66
  * <button role="menuitem" class="btn">Button</button>
67
67
  * <button role="menuitem" class="btn">Button</button>
@@ -3,7 +3,13 @@
3
3
 
4
4
  ### DataTable
5
5
 
6
- Data table to display an array of JS objects. Provides pagination and sorting for `number`, `string`, `boolean`, and `Date`. Set the `maxRows` prop to enable pagination. Data can be styled conditionally with slot props.
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
7
13
 
8
14
  @props
9
15
 
@@ -25,11 +31,11 @@ Data table to display an array of JS objects. Provides pagination and sorting fo
25
31
 
26
32
  @slots
27
33
 
28
- | name | purpose | default value | slot props |
29
- | ---------- | ----------------------------------------------------- | ------------- | ------------------------------- |
30
- | `controls` | helper that passes back `maxRows` and `numberOfPages` | none | `maxRows`, `numberOfPages` |
31
- | `td` | td contents | `value` | `item`, `key`, `sortBy` `value` |
32
- | `th` | th contents | `key` | `key`, `sortBy` |
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` |
33
39
 
34
40
  @example
35
41
 
@@ -78,9 +84,9 @@ Data table to display an array of JS objects. Provides pagination and sorting fo
78
84
  </svelte:fragment>
79
85
  <svelte:fragment slot="controls" let:maxRows let:numberOfPages>
80
86
  {#if maxRows}
81
- <div class="flex items-center justify-between">
82
- <div>{currentPage + 1} / {numberOfPages}</div>
83
- <div>
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">
84
90
  <button
85
91
  type="button"
86
92
  class="btn"
@@ -129,6 +135,7 @@ const sort = (key, toggleAscending = true) => {
129
135
  } else {
130
136
  ascending = true;
131
137
  }
138
+ const collator = new Intl.Collator();
132
139
  data.sort((a, b) => {
133
140
  const aVal = a[key];
134
141
  const bVal = b[key];
@@ -139,7 +146,6 @@ const sort = (key, toggleAscending = true) => {
139
146
  return bVal - aVal;
140
147
  }
141
148
  } else if (typeof aVal === "string" && typeof bVal === "string") {
142
- const collator = new Intl.Collator();
143
149
  if (ascending) {
144
150
  return collator.compare(aVal, bVal);
145
151
  } else {
@@ -43,7 +43,13 @@ export type DataTableSlots = typeof __propDef.slots;
43
43
  /**
44
44
  * ### DataTable
45
45
  *
46
- * Data table to display an array of JS objects. Provides pagination and sorting for `number`, `string`, `boolean`, and `Date`. Set the `maxRows` prop to enable pagination. Data can be styled conditionally with slot props.
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
47
53
  *
48
54
  * @props
49
55
  *
@@ -65,11 +71,11 @@ export type DataTableSlots = typeof __propDef.slots;
65
71
  *
66
72
  * @slots
67
73
  *
68
- * | name | purpose | default value | slot props |
69
- * | ---------- | ----------------------------------------------------- | ------------- | ------------------------------- |
70
- * | `controls` | helper that passes back `maxRows` and `numberOfPages` | none | `maxRows`, `numberOfPages` |
71
- * | `td` | td contents | `value` | `item`, `key`, `sortBy` `value` |
72
- * | `th` | th contents | `key` | `key`, `sortBy` |
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` |
73
79
  *
74
80
  * @example
75
81
  *
@@ -118,9 +124,9 @@ export type DataTableSlots = typeof __propDef.slots;
118
124
  * </svelte:fragment>
119
125
  * <svelte:fragment slot="controls" let:maxRows let:numberOfPages>
120
126
  * {#if maxRows}
121
- * <div class="flex items-center justify-between">
122
- * <div>{currentPage + 1} / {numberOfPages}</div>
123
- * <div>
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">
124
130
  * <button
125
131
  * type="button"
126
132
  * class="btn"
@@ -16,8 +16,8 @@ Displays a `details` element with helpful defaults and transitions. Can be used
16
16
 
17
17
  | name | purpose | default value | slot props |
18
18
  | --------- | ------------------------------- | -------------- | ---------- |
19
- | `summary` | `summary` element contents | none | `open` |
20
- | `content` | contents when details is `open` | none | none |
19
+ | `summary` | `summary` element contents | empty | `open` |
20
+ | `content` | contents when details is `open` | empty | none |
21
21
 
22
22
  @example
23
23
 
@@ -36,8 +36,8 @@ export type DetailsSlots = typeof __propDef.slots;
36
36
  *
37
37
  * | name | purpose | default value | slot props |
38
38
  * | --------- | ------------------------------- | -------------- | ---------- |
39
- * | `summary` | `summary` element contents | none | `open` |
40
- * | `content` | contents when details is `open` | none | none |
39
+ * | `summary` | `summary` element contents | empty | `open` |
40
+ * | `content` | contents when details is `open` | empty | none |
41
41
  *
42
42
  * @example
43
43
  *
@@ -3,7 +3,7 @@
3
3
 
4
4
  ### Editor
5
5
 
6
- `textarea` element with controls to add content and keyboard shortcuts. Compared to other WYSIWYG editors, this component's value is just a `string` so you can easily store it in a database or manipulate it without learning a separate API.
6
+ `textarea` element with controls to add content and keyboard shortcuts. Compared to other WYSIWYG editors, the `valueTextarea` is just a `string`, so you can easily store it in a database or manipulate it without learning a separate API.
7
7
 
8
8
  - This component is used to create [Typo](https://typo.robino.dev)
9
9
 
@@ -35,13 +35,13 @@
35
35
  placeholderTextarea="asterisk: ctrl+i, anchor: ctrl+["
36
36
  contentElements={[
37
37
  {
38
- name: "Bullet",
38
+ title: "Bullet",
39
39
  text: "- ",
40
40
  display: "block",
41
41
  icon: "Bullet",
42
42
  },
43
43
  {
44
- name: "Italic",
44
+ title: "Italic",
45
45
  text: "*",
46
46
  display: "wrap",
47
47
  icon: "Italic",
@@ -49,7 +49,7 @@
49
49
  class: "italic",
50
50
  },
51
51
  {
52
- name: "Anchor",
52
+ title: "Anchor",
53
53
  text: "[text](href)",
54
54
  display: "inline",
55
55
  icon: "Anchor",
@@ -177,7 +177,7 @@ const onKeyDown = async (e) => {
177
177
  display: "inline",
178
178
  text: " ",
179
179
  icon: "tab",
180
- name: "tab"
180
+ title: "tab"
181
181
  });
182
182
  }
183
183
  } else if (e.key === "Enter") {
@@ -197,7 +197,7 @@ const onKeyDown = async (e) => {
197
197
  text: `
198
198
  ${repeat}`,
199
199
  icon: "",
200
- name: ""
200
+ title: ""
201
201
  });
202
202
  } else if (repeat && original.length === columnNumber) {
203
203
  e.preventDefault();
@@ -217,7 +217,7 @@ ${repeat}`,
217
217
  text: `
218
218
  `,
219
219
  icon: "",
220
- name: ""
220
+ title: ""
221
221
  });
222
222
  }, 0);
223
223
  }
@@ -241,7 +241,7 @@ ${repeat}`,
241
241
  display: "wrap",
242
242
  text: e.key,
243
243
  icon: "",
244
- name: ""
244
+ title: ""
245
245
  });
246
246
  openChars.push(e.key);
247
247
  }
@@ -363,7 +363,7 @@ onMount(() => clientJs = true);
363
363
  type="button"
364
364
  class={el.class ? `${classButton} ${el.class}` : classButton}
365
365
  on:click={() => addContent(el)}
366
- title={el.name}
366
+ title={el.title}
367
367
  disabled={!clientJs}
368
368
  >
369
369
  {#if typeof el.icon !== "string"}
@@ -3,8 +3,8 @@ import { type ComponentType } from "svelte";
3
3
  declare const __propDef: {
4
4
  props: {
5
5
  /** an array of `EditorContentElement`s for the controls */ contentElements?: {
6
- /** name of element */
7
- name: string;
6
+ /** title of element and it's corresponding button */
7
+ title: string;
8
8
  /** text to add */
9
9
  text: string;
10
10
  /** controls how the text is added */
@@ -42,7 +42,7 @@ export type EditorSlots = typeof __propDef.slots;
42
42
  /**
43
43
  * ### Editor
44
44
  *
45
- * `textarea` element with controls to add content and keyboard shortcuts. Compared to other WYSIWYG editors, this component's value is just a `string` so you can easily store it in a database or manipulate it without learning a separate API.
45
+ * `textarea` element with controls to add content and keyboard shortcuts. Compared to other WYSIWYG editors, the `valueTextarea` is just a `string`, so you can easily store it in a database or manipulate it without learning a separate API.
46
46
  *
47
47
  * - This component is used to create [Typo](https://typo.robino.dev)
48
48
  *
@@ -74,13 +74,13 @@ export type EditorSlots = typeof __propDef.slots;
74
74
  * placeholderTextarea="asterisk: ctrl+i, anchor: ctrl+["
75
75
  * contentElements={[
76
76
  * {
77
- * name: "Bullet",
77
+ * title: "Bullet",
78
78
  * text: "- ",
79
79
  * display: "block",
80
80
  * icon: "Bullet",
81
81
  * },
82
82
  * {
83
- * name: "Italic",
83
+ * title: "Italic",
84
84
  * text: "*",
85
85
  * display: "wrap",
86
86
  * icon: "Italic",
@@ -88,7 +88,7 @@ export type EditorSlots = typeof __propDef.slots;
88
88
  * class: "italic",
89
89
  * },
90
90
  * {
91
- * name: "Anchor",
91
+ * title: "Anchor",
92
92
  * text: "[text](href)",
93
93
  * display: "inline",
94
94
  * icon: "Anchor",
@@ -1,9 +1,11 @@
1
1
  <!--
2
2
  @component
3
3
 
4
- ### Chord
4
+ ### FrettedChord
5
5
 
6
- Generates a guitar chord `svg`.
6
+ Generates a fretted chord `svg` for instruments like guitar and ukulele.
7
+
8
+ Try it out and generate code: [FrettedChord Creator](https://svelte.dev/repl/5771d5c3f3c34137a174c8c402ca0b2d?version=4.2.0)
7
9
 
8
10
  @props
9
11
 
@@ -11,18 +13,18 @@ Generates a guitar chord `svg`.
11
13
  - `id`
12
14
  - `name` - name of chord
13
15
  - `notes` - list of the positioning of the notes required for the chord
14
- - `size` - total size of chord square
16
+ - `size` - total size of chord square in pixels, defaults to `150`
15
17
  - `strings` - total number of strings for the instrument
16
18
 
17
19
  @example
18
20
 
19
21
  ```svelte
20
22
  <script lang="ts">
21
- import { Chord } from "drab";
23
+ import { FrettedChord } from "drab";
22
24
  </script>
23
25
 
24
- <Chord
25
- class="text-neutral-950"
26
+ <FrettedChord
27
+ class="font-mono text-neutral-950"
26
28
  name="D"
27
29
  notes={[
28
30
  {
@@ -55,7 +57,7 @@ export { className as class };
55
57
  export let id = "";
56
58
  export let strings = 6;
57
59
  export let name = "";
58
- export let size = 200;
60
+ export let size = 150;
59
61
  const boxSize = size * 0.61;
60
62
  const offset = (size - boxSize) / 2;
61
63
  const strokeWidth = size / 60;
@@ -5,7 +5,7 @@ declare const __propDef: {
5
5
  id?: string | undefined;
6
6
  /** total number of strings for the instrument */ strings?: number | undefined;
7
7
  /** name of chord */ name?: string | undefined;
8
- /** total size of chord square */ size?: number | undefined;
8
+ /** total size of chord square in pixels, defaults to `150` */ size?: number | undefined;
9
9
  /** list of the positioning of the notes required for the chord */ notes?: {
10
10
  /** recommended finger to use */
11
11
  finger: number | string;
@@ -20,13 +20,15 @@ declare const __propDef: {
20
20
  };
21
21
  slots: {};
22
22
  };
23
- export type ChordProps = typeof __propDef.props;
24
- export type ChordEvents = typeof __propDef.events;
25
- export type ChordSlots = typeof __propDef.slots;
23
+ export type FrettedChordProps = typeof __propDef.props;
24
+ export type FrettedChordEvents = typeof __propDef.events;
25
+ export type FrettedChordSlots = typeof __propDef.slots;
26
26
  /**
27
- * ### Chord
27
+ * ### FrettedChord
28
28
  *
29
- * Generates a guitar chord `svg`.
29
+ * Generates a fretted chord `svg` for instruments like guitar and ukulele.
30
+ *
31
+ * Try it out and generate code: [FrettedChord Creator](https://svelte.dev/repl/5771d5c3f3c34137a174c8c402ca0b2d?version=4.2.0)
30
32
  *
31
33
  * @props
32
34
  *
@@ -34,18 +36,18 @@ export type ChordSlots = typeof __propDef.slots;
34
36
  * - `id`
35
37
  * - `name` - name of chord
36
38
  * - `notes` - list of the positioning of the notes required for the chord
37
- * - `size` - total size of chord square
39
+ * - `size` - total size of chord square in pixels, defaults to `150`
38
40
  * - `strings` - total number of strings for the instrument
39
41
  *
40
42
  * @example
41
43
  *
42
44
  * ```svelte
43
45
  * <script lang="ts">
44
- * import { Chord } from "drab";
46
+ * import { FrettedChord } from "drab";
45
47
  * </script>
46
48
  *
47
- * <Chord
48
- * class="text-neutral-950"
49
+ * <FrettedChord
50
+ * class="font-mono text-neutral-950"
49
51
  * name="D"
50
52
  * notes={[
51
53
  * {
@@ -72,6 +74,6 @@ export type ChordSlots = typeof __propDef.slots;
72
74
  * />
73
75
  * ```
74
76
  */
75
- export default class Chord extends SvelteComponent<ChordProps, ChordEvents, ChordSlots> {
77
+ export default class FrettedChord extends SvelteComponent<FrettedChordProps, FrettedChordEvents, FrettedChordSlots> {
76
78
  }
77
79
  export {};
@@ -3,7 +3,7 @@
3
3
 
4
4
  ### FullscreenButton
5
5
 
6
- Make the document or a specific element fullscreen.
6
+ Make the document or a `target` element fullscreen.
7
7
 
8
8
  @props
9
9
 
@@ -64,15 +64,20 @@ const onClick = () => {
64
64
  }
65
65
  }
66
66
  };
67
+ const syncFullscreen = () => {
68
+ fullscreen = document.fullscreenElement !== null;
69
+ };
67
70
  onMount(() => {
68
- if (document.documentElement.requestFullscreen)
71
+ if (document.documentElement.requestFullscreen) {
72
+ syncFullscreen();
69
73
  disabled = false;
74
+ }
70
75
  if (!target)
71
76
  target = document.documentElement;
72
77
  });
73
78
  </script>
74
79
 
75
- <svelte:window on:fullscreenchange={() => (fullscreen = !fullscreen)} />
80
+ <svelte:window on:fullscreenchange={syncFullscreen} />
76
81
 
77
82
  <button
78
83
  type="button"
@@ -21,7 +21,7 @@ export type FullscreenButtonSlots = typeof __propDef.slots;
21
21
  /**
22
22
  * ### FullscreenButton
23
23
  *
24
- * Make the document or a specific element fullscreen.
24
+ * Make the document or a `target` element fullscreen.
25
25
  *
26
26
  * @props
27
27
  *
@@ -3,7 +3,10 @@
3
3
 
4
4
  ### Popover
5
5
 
6
- Displays a popover relatively positioned to the target. Does not require the target to be `position: relative;`.
6
+ Displays a popover in relation to the `target`.
7
+
8
+ - Does not require the target to be `position: relative;`
9
+ - Adjusts position in case the popover renders outside of the viewport
7
10
 
8
11
  @props
9
12
 
@@ -57,22 +60,22 @@ let className = "";
57
60
  export { className as class };
58
61
  export let id = "";
59
62
  export let display = true;
60
- export let position = "bottom";
63
+ export let position = "b";
61
64
  export let target;
62
65
  export let transition = { duration, start };
63
66
  let popover;
64
67
  let coordinates = { x: 0, y: 0 };
65
68
  const setPosition = async () => {
66
- if (position === "top" || position === "bottom") {
69
+ if (position === "t" || position === "b") {
67
70
  coordinates.x = target.offsetWidth / 2 - popover.offsetWidth / 2;
68
- if (position === "top") {
71
+ if (position === "t") {
69
72
  coordinates.y = -popover.offsetHeight;
70
73
  } else {
71
74
  coordinates.y = target.offsetHeight;
72
75
  }
73
76
  } else {
74
77
  coordinates.y = target.offsetHeight / 2 - popover.offsetHeight / 2;
75
- if (position === "left") {
78
+ if (position === "l") {
76
79
  coordinates.x = -popover.offsetWidth;
77
80
  } else {
78
81
  coordinates.x = target.offsetWidth;
@@ -5,7 +5,7 @@ declare const __propDef: {
5
5
  class?: string | undefined;
6
6
  id?: string | undefined;
7
7
  /** shows / hides the popover */ display?: boolean | undefined;
8
- /** where the popover is displayed in relation to the `target` */ position?: "top" | "bottom" | "left" | "right" | undefined;
8
+ /** where the popover is displayed in relation to the `target` */ position?: "t" | "b" | "l" | "r" | undefined;
9
9
  /** target element to position the popover in relation to */ target: HTMLElement;
10
10
  /** scales the popover, set to `false` to disable */ transition?: false | ScaleParams | undefined;
11
11
  };
@@ -22,7 +22,10 @@ export type PopoverSlots = typeof __propDef.slots;
22
22
  /**
23
23
  * ### Popover
24
24
  *
25
- * Displays a popover relatively positioned to the target. Does not require the target to be `position: relative;`.
25
+ * Displays a popover in relation to the `target`.
26
+ *
27
+ * - Does not require the target to be `position: relative;`
28
+ * - Adjusts position in case the popover renders outside of the viewport
26
29
  *
27
30
  * @props
28
31
  *
@@ -22,6 +22,13 @@ Creates a sheet element based on the `position` provided. `maxSize` is set to wi
22
22
  | ---------- | ------------------------------- | ------------- |
23
23
  | `default` | content | `Content` |
24
24
 
25
+ @events
26
+
27
+ | name | event |
28
+ | --------- | ------------------ |
29
+ | `mount` | sheet is mounted |
30
+ | `destroy` | sheet is destroyed |
31
+
25
32
  @example
26
33
 
27
34
  ```svelte
@@ -39,7 +46,7 @@ Creates a sheet element based on the `position` provided. `maxSize` is set to wi
39
46
  bind:display
40
47
  class="backdrop-blur"
41
48
  classSheet="p-4 shadow bg-white"
42
- position="right"
49
+ position="r"
43
50
  >
44
51
  <div class="mb-4 flex items-center justify-between">
45
52
  <h2 class="my-0">Sheet</h2>
@@ -58,7 +65,7 @@ Creates a sheet element based on the `position` provided. `maxSize` is set to wi
58
65
  ```
59
66
  -->
60
67
 
61
- <script>import { onMount } from "svelte";
68
+ <script>import { createEventDispatcher, onMount } from "svelte";
62
69
  import {
63
70
  blur,
64
71
  fly
@@ -71,25 +78,28 @@ export let id = "";
71
78
  export let classSheet = "";
72
79
  export let display = false;
73
80
  export let transition = { duration };
74
- export let position = "left";
81
+ export let position = "l";
75
82
  export let maxSize = 488;
76
83
  export let transitionSheet = { duration };
77
84
  let sheet;
85
+ const dispatch = createEventDispatcher();
86
+ const close = () => display = false;
78
87
  const onKeyDown = (e) => {
79
- if (e.key === "Escape") {
80
- display = false;
81
- }
88
+ if (e.key === "Escape")
89
+ close();
82
90
  };
83
- const focusElement = (node) => {
91
+ const lifecycle = (node) => {
92
+ dispatch("mount");
84
93
  if (node instanceof HTMLElement)
85
94
  node.focus();
95
+ return { destroy: () => dispatch("destroy") };
86
96
  };
87
97
  if (transitionSheet && !transitionSheet.x && !transitionSheet.y) {
88
- if (position === "bottom") {
98
+ if (position === "b") {
89
99
  transitionSheet.y = maxSize;
90
- } else if (position === "top") {
100
+ } else if (position === "t") {
91
101
  transitionSheet.y = -maxSize;
92
- } else if (position === "right") {
102
+ } else if (position === "r") {
93
103
  transitionSheet.x = maxSize;
94
104
  } else {
95
105
  transitionSheet.x = -maxSize;
@@ -108,26 +118,26 @@ onMount(() => {
108
118
  {#if display}
109
119
  <div
110
120
  transition:blur={transition ? transition : { duration: 0 }}
111
- use:focusElement
112
121
  class="d-backdrop {className}"
113
- class:d-backdrop-bottom={position === "bottom"}
114
- class:d-backdrop-top={position === "top"}
115
- class:d-backdrop-right={position === "right"}
122
+ class:d-backdrop-bottom={position === "b"}
123
+ class:d-backdrop-top={position === "t"}
124
+ class:d-backdrop-right={position === "r"}
116
125
  {id}
117
- tabindex="-1"
118
126
  >
119
127
  <div
120
- role="dialog"
121
128
  bind:this={sheet}
122
129
  transition:fly={transitionSheet ? transitionSheet : { duration: 0 }}
123
- style={position === "top" || position === "bottom"
130
+ use:lifecycle
131
+ role="dialog"
132
+ tabindex="-1"
133
+ style={position === "t" || position === "b"
124
134
  ? `max-height: ${maxSize}px;`
125
135
  : `max-width: ${maxSize}px`}
126
136
  class={classSheet}
127
137
  >
128
138
  <slot>Content</slot>
129
139
  </div>
130
- <button title="Close" on:click={() => (display = false)}></button>
140
+ <button title="Close" on:click={close}></button>
131
141
  </div>
132
142
  {/if}
133
143
 
@@ -7,11 +7,14 @@ declare const __propDef: {
7
7
  /** sheet class - not the backdrop */ classSheet?: string | undefined;
8
8
  /** controls whether the sheet is displayed*/ display?: boolean | undefined;
9
9
  /** blurs the entire component, set to `false` to remove */ transition?: false | BlurParams | undefined;
10
- /** determines the position of sheet */ position?: "top" | "bottom" | "left" | "right" | undefined;
10
+ /** determines the position of sheet */ position?: "t" | "b" | "l" | "r" | undefined;
11
11
  /** max width/height of sheet based on the `side` - can also use css instead */ maxSize?: number | undefined;
12
12
  /** flies the sheet, set to `false` to remove */ transitionSheet?: false | FlyParams | undefined;
13
13
  };
14
14
  events: {
15
+ mount: CustomEvent<any>;
16
+ destroy: CustomEvent<any>;
17
+ } & {
15
18
  [evt: string]: CustomEvent<any>;
16
19
  };
17
20
  slots: {
@@ -43,6 +46,13 @@ export type SheetSlots = typeof __propDef.slots;
43
46
  * | ---------- | ------------------------------- | ------------- |
44
47
  * | `default` | content | `Content` |
45
48
  *
49
+ * @events
50
+ *
51
+ * | name | event |
52
+ * | --------- | ------------------ |
53
+ * | `mount` | sheet is mounted |
54
+ * | `destroy` | sheet is destroyed |
55
+ *
46
56
  * @example
47
57
  *
48
58
  * ```svelte
@@ -60,7 +70,7 @@ export type SheetSlots = typeof __propDef.slots;
60
70
  * bind:display
61
71
  * class="backdrop-blur"
62
72
  * classSheet="p-4 shadow bg-white"
63
- * position="right"
73
+ * position="r"
64
74
  * >
65
75
  * <div class="mb-4 flex items-center justify-between">
66
76
  * <h2 class="my-0">Sheet</h2>
package/dist/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import Breakpoint from "./components/Breakpoint.svelte";
2
- import Chord from "./components/Chord.svelte";
3
2
  import ContextMenu from "./components/ContextMenu.svelte";
4
3
  import CopyButton from "./components/CopyButton.svelte";
5
4
  import DataTable from "./components/DataTable.svelte";
6
5
  import Details from "./components/Details.svelte";
7
6
  import Editor from "./components/Editor.svelte";
7
+ import FrettedChord from "./components/FrettedChord.svelte";
8
8
  import FullscreenButton from "./components/FullscreenButton.svelte";
9
9
  import Popover from "./components/Popover.svelte";
10
10
  import ShareButton from "./components/ShareButton.svelte";
11
11
  import Sheet from "./components/Sheet.svelte";
12
12
  import YouTube from "./components/YouTube.svelte";
13
- export { Breakpoint, Chord, ContextMenu, CopyButton, DataTable, Details, Editor, FullscreenButton, Popover, ShareButton, Sheet, YouTube, };
13
+ export { Breakpoint, ContextMenu, CopyButton, DataTable, Details, Editor, FrettedChord, FullscreenButton, Popover, ShareButton, Sheet, YouTube, };
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import Breakpoint from "./components/Breakpoint.svelte";
2
- import Chord from "./components/Chord.svelte";
3
2
  import ContextMenu from "./components/ContextMenu.svelte";
4
3
  import CopyButton from "./components/CopyButton.svelte";
5
4
  import DataTable from "./components/DataTable.svelte";
6
5
  import Details from "./components/Details.svelte";
7
6
  import Editor from "./components/Editor.svelte";
7
+ import FrettedChord from "./components/FrettedChord.svelte";
8
8
  import FullscreenButton from "./components/FullscreenButton.svelte";
9
9
  import Popover from "./components/Popover.svelte";
10
10
  import ShareButton from "./components/ShareButton.svelte";
11
11
  import Sheet from "./components/Sheet.svelte";
12
12
  import YouTube from "./components/YouTube.svelte";
13
- export { Breakpoint, Chord, ContextMenu, CopyButton, DataTable, Details, Editor, FullscreenButton, Popover, ShareButton, Sheet, YouTube, };
13
+ export { Breakpoint, ContextMenu, CopyButton, DataTable, Details, Editor, FrettedChord, FullscreenButton, Popover, ShareButton, Sheet, YouTube, };
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "drab",
3
- "version": "2.8.7",
4
- "description": "An unstyled Svelte component library",
3
+ "version": "3.0.1",
4
+ "description": "An Unstyled Svelte Component Library",
5
5
  "keywords": [
6
6
  "components",
7
7
  "Svelte",
8
8
  "SvelteKit",
9
9
  "Breakpoint",
10
- "Chord",
11
10
  "ContextMenu",
12
11
  "Copy",
13
12
  "DataTable",
14
13
  "Details",
15
14
  "Editor",
15
+ "FrettedChord",
16
16
  "Fullscreen",
17
17
  "Popover",
18
18
  "Share",