drab 3.0.0 → 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
@@ -7,13 +7,9 @@
7
7
 
8
8
  ## About
9
9
 
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](/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). 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). 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.
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
 
@@ -33,20 +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
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.
48
104
 
49
- Currently, **drab** has only one dependency - Svelte. Not to say it will never have another, but please consider this when adding in additional functionality. **drab** is meant to make the web platform easier to use with Svelte.
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.
50
106
 
51
107
  Since this is an unstyled library, simple components like a badge that can be easily created with HTML and CSS are not included.
52
108
 
@@ -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
@@ -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
@@ -75,14 +82,17 @@ 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
98
  if (position === "b") {
@@ -108,18 +118,18 @@ 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
122
  class:d-backdrop-bottom={position === "b"}
114
123
  class:d-backdrop-top={position === "t"}
115
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 }}
130
+ use:lifecycle
131
+ role="dialog"
132
+ tabindex="-1"
123
133
  style={position === "t" || position === "b"
124
134
  ? `max-height: ${maxSize}px;`
125
135
  : `max-width: ${maxSize}px`}
@@ -127,7 +137,7 @@ onMount(() => {
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
 
@@ -12,6 +12,9 @@ declare const __propDef: {
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drab",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "An Unstyled Svelte Component Library",
5
5
  "keywords": [
6
6
  "components",