sveltacular 0.0.10 → 0.0.12

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,11 +1,31 @@
1
- # Sveltacular
1
+ ![Sveltacular](https://raw.githubusercontent.com/jasonbyrne/sveltacular/main/static/sveltacular.png)
2
2
 
3
- I got tired of creating the same components over and over, so I decided to make an open source library of Svelte components.
3
+ Sveltacular is TypeScript and SASS based component library for Svelte, with no other dependencies.
4
4
 
5
- This library is TypeScript and SASS based. It uses vanilla CSS without any frameworks to get in the way.
5
+ Why did I create it when there are other options? Well, mainly because the best options out there were based on Tailwind. And, no disrespect to those who love it, but I didn't want to use Tailwind. So since I didn't find what I was loooking for, I made my own.
6
6
 
7
7
  ## Run Storybook
8
8
 
9
- ```
9
+ I don't have great documentation for now, but you can browse all of the available components by running Storybook locally. Check out the repo and then run this command:
10
+
11
+ ```bash
10
12
  npm run storybook
11
13
  ```
14
+
15
+ ## Usage
16
+
17
+ Install it in your project
18
+
19
+ ```bash
20
+ npm i sveltacular
21
+ ```
22
+
23
+ Then use it like this:
24
+
25
+ ```svelte
26
+ <script lang="ts">
27
+ import { Button } from 'sveltacular';
28
+ </script>
29
+
30
+ <Button>Hello World</Button>
31
+ ```
@@ -0,0 +1,15 @@
1
+ <svg
2
+ class="w-6 h-6 text-gray-800 dark:text-white"
3
+ aria-hidden="true"
4
+ xmlns="http://www.w3.org/2000/svg"
5
+ fill="none"
6
+ viewBox="0 0 17 14"
7
+ >
8
+ <path
9
+ stroke="currentColor"
10
+ stroke-linecap="round"
11
+ stroke-linejoin="round"
12
+ stroke-width="2"
13
+ d="M1 1h15M1 7h15M1 13h15"
14
+ />
15
+ </svg>
@@ -0,0 +1,23 @@
1
+ /** @typedef {typeof __propDef.props} HamburgerIconProps */
2
+ /** @typedef {typeof __propDef.events} HamburgerIconEvents */
3
+ /** @typedef {typeof __propDef.slots} HamburgerIconSlots */
4
+ export default class HamburgerIcon extends SvelteComponent<{
5
+ [x: string]: never;
6
+ }, {
7
+ [evt: string]: CustomEvent<any>;
8
+ }, {}> {
9
+ }
10
+ export type HamburgerIconProps = typeof __propDef.props;
11
+ export type HamburgerIconEvents = typeof __propDef.events;
12
+ export type HamburgerIconSlots = typeof __propDef.slots;
13
+ import { SvelteComponent } from "svelte";
14
+ declare const __propDef: {
15
+ props: {
16
+ [x: string]: never;
17
+ };
18
+ events: {
19
+ [evt: string]: CustomEvent<any>;
20
+ };
21
+ slots: {};
22
+ };
23
+ export {};
@@ -1,7 +1,14 @@
1
- <script>export let isFixed = true;
1
+ <script>import { setContext } from "svelte";
2
+ export let isFixed = true;
2
3
  export let position = "top";
3
4
  export let size = "md";
4
5
  export let padding = "md";
6
+ setContext("app-bar", {
7
+ isFixed,
8
+ position,
9
+ size,
10
+ padding
11
+ });
5
12
  </script>
6
13
 
7
14
  <header class="{position} {size} padding-{padding} {isFixed ? 'fixed' : 'absolute'}">
@@ -1,17 +1,28 @@
1
- <script>export let href;
1
+ <script>import { navigateTo } from "../../index.js";
2
+ import { createEventDispatcher, getContext } from "svelte";
3
+ export let href = void 0;
2
4
  export let title;
5
+ const dispatch = createEventDispatcher();
6
+ const open = getContext("app-nav-state");
7
+ const click = () => {
8
+ if (href)
9
+ navigateTo(href);
10
+ dispatch("click");
11
+ };
3
12
  </script>
4
13
 
5
- <a {href}>
14
+ <button class={$open ? 'open' : 'closed'} on:click={click}>
6
15
  {#if $$slots.default}
7
16
  <div class="icon">
8
17
  <slot />
9
18
  </div>
10
19
  {/if}
11
- <div class="title">{title}</div>
12
- </a>
20
+ <div class="title">
21
+ {title}
22
+ </div>
23
+ </button>
13
24
 
14
- <style>a {
25
+ <style>button {
15
26
  display: flex;
16
27
  flex-direction: column;
17
28
  gap: 0.2rem;
@@ -19,12 +30,36 @@ export let title;
19
30
  height: 100%;
20
31
  color: var(--nav-link-color, black);
21
32
  text-decoration: none;
33
+ appearance: none;
34
+ border: none;
35
+ background-color: transparent;
36
+ cursor: pointer;
22
37
  }
23
- a:hover {
38
+ button:hover {
24
39
  color: var(--nav-link-hover-color, black);
25
40
  text-decoration: underline;
26
41
  }
27
- a .icon {
42
+ button .icon {
28
43
  width: 100%;
29
44
  height: 1.5rem;
45
+ }
46
+
47
+ @media (max-width: 640px) {
48
+ button.open {
49
+ flex-direction: row;
50
+ gap: 1rem;
51
+ width: 100%;
52
+ padding: 1rem;
53
+ text-align: left;
54
+ }
55
+ button.open:hover {
56
+ text-decoration: none;
57
+ background-color: #bbb;
58
+ }
59
+ button.open .title {
60
+ flex-grow: 1;
61
+ }
62
+ button.open .icon {
63
+ width: 1.5rem;
64
+ }
30
65
  }</style>
@@ -1,10 +1,12 @@
1
1
  import { SvelteComponent } from "svelte";
2
2
  declare const __propDef: {
3
3
  props: {
4
- href: string;
4
+ href?: string | undefined;
5
5
  title: string;
6
6
  };
7
7
  events: {
8
+ click: CustomEvent<void>;
9
+ } & {
8
10
  [evt: string]: CustomEvent<any>;
9
11
  };
10
12
  slots: {
@@ -1,57 +1,110 @@
1
- <script>export let grow = false;
1
+ <script>import HamburgerIcon from "../../icons/hamburger-icon.svelte";
2
+ import { getContext, setContext } from "svelte";
3
+ import { get, writable } from "svelte/store";
2
4
  export let align = "right";
3
5
  export let spacing = "medium";
6
+ const open = writable(false);
7
+ setContext("app-nav-state", open);
8
+ const toggle = () => open.set(!get(open));
9
+ const context = getContext("app-bar");
10
+ const collapse = context.position !== "bottom" ? "collapse" : "";
4
11
  </script>
5
12
 
6
- <nav class="{grow ? 'grow' : ''} {align} {spacing}">
13
+ <div class="icon {$open ? 'open' : 'closed'} {collapse}">
14
+ <button on:click={toggle}>
15
+ <HamburgerIcon />
16
+ </button>
17
+ </div>
18
+ <nav class="{align} {spacing} {collapse} {$open ? 'open' : 'closed'}">
7
19
  <slot />
8
20
  </nav>
9
21
 
10
- <style>
11
- nav {
12
- display: flex;
13
- flex-grow: 0;
14
- gap: 1rem;
15
- margin: 1rem;
16
- width: 100%;
22
+ <style>.icon {
23
+ display: none;
24
+ }
17
25
 
18
- &.grow {
19
- flex-grow: 1;
20
- }
26
+ nav {
27
+ display: flex;
28
+ flex-direction: row;
29
+ flex-grow: 0;
30
+ gap: 1rem;
31
+ margin: 1rem;
32
+ width: 100%;
33
+ align-items: center;
34
+ justify-content: center;
35
+ }
36
+ nav.left, nav.start {
37
+ justify-content: flex-start;
38
+ }
39
+ nav.center {
40
+ justify-content: center;
41
+ }
42
+ nav.right {
43
+ justify-content: flex-end;
44
+ }
45
+ nav.none {
46
+ gap: 0;
47
+ }
48
+ nav.tight {
49
+ gap: 0.5rem;
50
+ }
51
+ nav.medium {
52
+ gap: 1rem;
53
+ }
54
+ nav.loose {
55
+ gap: 2rem;
56
+ }
57
+ nav.space-evenly {
58
+ justify-content: space-evenly;
59
+ }
60
+ nav.space-between {
61
+ justify-content: space-between;
62
+ }
63
+ nav.space-around {
64
+ justify-content: space-around;
65
+ }
21
66
 
22
- &.left {
23
- justify-content: left;
24
- align-items: left;
25
- }
26
-
27
- &.center {
28
- justify-content: center;
29
- align-items: center;
30
- }
31
-
32
- &.right {
33
- justify-content: right;
34
- align-items: right;
35
- }
36
-
37
- &.none {
38
- gap: 0;
39
- }
40
-
41
- &.tight {
42
- gap: 0.5rem;
43
- }
44
-
45
- &.medium {
46
- gap: 1rem;
47
- }
48
-
49
- &.loose {
50
- gap: 2rem;
51
- }
52
-
53
- &.spread {
54
- justify-content: space-evenly;
55
- }
56
- }
57
- </style>
67
+ /* Small screens */
68
+ @media (max-width: 640px) {
69
+ .icon.collapse {
70
+ display: block;
71
+ justify-content: flex-end;
72
+ align-content: center;
73
+ width: 30%;
74
+ height: 100%;
75
+ text-align: right;
76
+ padding-right: 0.5rem;
77
+ padding-left: 0.5rem;
78
+ }
79
+ .icon.collapse button {
80
+ appearance: none;
81
+ border: none;
82
+ background-color: transparent;
83
+ width: 100%;
84
+ height: 100%;
85
+ max-width: 2.5rem;
86
+ cursor: pointer;
87
+ }
88
+ .icon.collapse.open {
89
+ opacity: 0.3;
90
+ }
91
+ nav.collapse {
92
+ display: none;
93
+ }
94
+ nav.collapse.open {
95
+ display: flex;
96
+ flex-direction: column;
97
+ align-items: flex-end;
98
+ position: absolute;
99
+ top: 100%;
100
+ right: 0;
101
+ width: auto;
102
+ min-width: 50%;
103
+ box-shadow: -2px 4px 3px 0px black;
104
+ background: var(--nav-bg, #fff);
105
+ color: var(--nav-fg, #000);
106
+ margin: 0;
107
+ padding: 0;
108
+ gap: 0;
109
+ }
110
+ }</style>
@@ -1,9 +1,8 @@
1
1
  import { SvelteComponent } from "svelte";
2
2
  declare const __propDef: {
3
3
  props: {
4
- grow?: boolean | undefined;
5
- align?: "center" | "left" | "right" | undefined;
6
- spacing?: "none" | "medium" | "tight" | "loose" | "spread" | undefined;
4
+ align?: "center" | "end" | "start" | "left" | "right" | undefined;
5
+ spacing?: "none" | "medium" | "tight" | "loose" | "space-evenly" | "space-around" | "space-between" | undefined;
7
6
  };
8
7
  events: {
9
8
  [evt: string]: CustomEvent<any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sveltacular",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "scripts": {
5
5
  "watch": "npm run dev -- --open",
6
6
  "dev": "vite dev",