sveltacular 0.0.35 → 0.0.37

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.
@@ -8,7 +8,12 @@ export let block = false;
8
8
  export let flex = false;
9
9
  export let disabled = false;
10
10
  const dispatch = createEventDispatcher();
11
- const click = () => {
11
+ const click = (e) => {
12
+ if (disabled) {
13
+ e.preventDefault();
14
+ e.stopPropagation();
15
+ return;
16
+ }
12
17
  dispatch("click");
13
18
  if (href) {
14
19
  navigateTo(href);
@@ -44,6 +49,10 @@ const click = () => {
44
49
  font-family: var(--base-font-family, sans-serif);
45
50
  text-shadow: 0 0 0.125rem rgba(0, 0, 0, 0.5);
46
51
  }
52
+ button[disabled] {
53
+ opacity: 0.5;
54
+ cursor: not-allowed;
55
+ }
47
56
  button.flex {
48
57
  flex-grow: 1;
49
58
  }
@@ -11,6 +11,6 @@ $:
11
11
  decimals = allowCents ? 2 : 0;
12
12
  </script>
13
13
 
14
- <NumberBox bind:value {symbol} {decimals} {placeholder} {size} {min} {max} {step}
14
+ <NumberBox bind:value prefix={symbol} {decimals} {placeholder} {size} {min} {max} {step}
15
15
  ><slot /></NumberBox
16
16
  >
@@ -1,4 +1,4 @@
1
- <script>import { roundToDecimals } from "../../helpers/round-to-decimals.js";
1
+ <script>import { formatNumber, roundToDecimals } from "../../helpers/round-to-decimals.js";
2
2
  import { uniqueId } from "../../helpers/unique-id.js";
3
3
  import FormField from "../form-field.svelte";
4
4
  import FormLabel from "../form-label.svelte";
@@ -7,12 +7,12 @@ export let value = 0;
7
7
  export let placeholder = "";
8
8
  export let size = "full";
9
9
  export let type = "number";
10
- export let step = 1;
11
10
  export let min = 0;
12
11
  export let max = 1e6;
13
12
  export let decimals = 0;
14
13
  export let prefix = null;
15
14
  export let suffix = null;
15
+ export let step = 1;
16
16
  const valueChanged = () => {
17
17
  value = roundToDecimals(value, decimals);
18
18
  };
@@ -6,12 +6,12 @@ declare const __propDef: {
6
6
  placeholder?: string | undefined;
7
7
  size?: FormFieldSizeOptions | undefined;
8
8
  type?: ("number" | "currency") | undefined;
9
- step?: number | undefined;
10
9
  min?: number | undefined;
11
10
  max?: number | undefined;
12
11
  decimals?: number | undefined;
13
12
  prefix?: string | null | undefined;
14
13
  suffix?: string | null | undefined;
14
+ step?: number | undefined;
15
15
  };
16
16
  events: {
17
17
  [evt: string]: CustomEvent<any>;
@@ -25,7 +25,7 @@ export let underline = false;
25
25
 
26
26
  <style>header {
27
27
  margin-bottom: 1rem;
28
- font-family: var(--base-head-font-family, sans-serif);
28
+ font-family: var(--base-headline-font-family, sans-serif);
29
29
  }
30
30
  header.underline {
31
31
  padding-bottom: 0.5rem;
@@ -0,0 +1,159 @@
1
+ <script>import { createEventDispatcher } from "svelte";
2
+ const dispatch = createEventDispatcher();
3
+ export let title = void 0;
4
+ export let style = "info";
5
+ export let size = "full";
6
+ export let dismissable = false;
7
+ let visible = true;
8
+ let fading = false;
9
+ const goodbye = () => {
10
+ dispatch("dismiss");
11
+ fading = true;
12
+ setTimeout(() => {
13
+ visible = false;
14
+ dispatch("hidden");
15
+ }, 500);
16
+ };
17
+ const onClick = (e) => {
18
+ e.preventDefault();
19
+ e.stopPropagation();
20
+ goodbye();
21
+ };
22
+ </script>
23
+
24
+ <div class="notice {style} {size} {visible ? 'visible' : 'hidden'} {fading ? 'fading' : ''}">
25
+ {#if $$slots.icon}
26
+ <div class="icon">
27
+ <slot name="icon" />
28
+ </div>
29
+ {/if}
30
+ <div class="content">
31
+ {#if title}
32
+ <strong>{title}</strong>
33
+ {/if}
34
+ <div class="message">
35
+ <slot />
36
+ </div>
37
+ </div>
38
+
39
+ {#if dismissable}
40
+ <div class="dismiss">
41
+ <button type="button" on:click={onClick}>X</button>
42
+ </div>
43
+ {/if}
44
+ </div>
45
+
46
+ <style>.notice {
47
+ display: flex;
48
+ flex-direction: row;
49
+ gap: 1rem;
50
+ align-items: center;
51
+ justify-content: flex-start;
52
+ position: relative;
53
+ width: 100%;
54
+ max-width: 100%;
55
+ padding: 1rem;
56
+ border-radius: 0.2rem;
57
+ border: 2px solid var(--base-fg, black);
58
+ background: var(--base-bg, white);
59
+ color: var(--base-fg, black);
60
+ position: relative;
61
+ opacity: 1;
62
+ transition: opacity 0.3s ease-in-out, transform 0.5s ease-in-out;
63
+ }
64
+ .notice.hidden {
65
+ display: none;
66
+ }
67
+ .notice.fading {
68
+ transform: translateY(-100%);
69
+ opacity: 0;
70
+ }
71
+ .notice .icon {
72
+ position: relative;
73
+ width: 3rem;
74
+ min-width: 3rem;
75
+ height: 100%;
76
+ }
77
+ .notice .content {
78
+ display: flex;
79
+ flex-direction: column;
80
+ gap: 0.5rem;
81
+ align-items: flex-start;
82
+ justify-content: flex-start;
83
+ }
84
+ .notice.info {
85
+ background-color: rgb(225, 225, 225);
86
+ color: rgb(78, 78, 78);
87
+ border-color: rgb(144, 144, 144);
88
+ }
89
+ .notice.attention {
90
+ background-color: rgb(255, 248, 219);
91
+ color: rgb(117, 82, 0);
92
+ border-color: rgb(181, 129, 5);
93
+ }
94
+ .notice.success {
95
+ background-color: rgb(229, 248, 230);
96
+ color: rgb(0, 100, 0);
97
+ border-color: rgb(30, 188, 47);
98
+ }
99
+ .notice.error {
100
+ background-color: rgb(255, 232, 230);
101
+ color: rgb(100, 0, 0);
102
+ border-color: rgb(218, 40, 40);
103
+ }
104
+ .notice.xl {
105
+ width: 60rem;
106
+ }
107
+ .notice.lg {
108
+ width: 40rem;
109
+ }
110
+ .notice.lg .icon {
111
+ width: 2.5rem;
112
+ min-width: 2.5rem;
113
+ }
114
+ .notice.lg .content {
115
+ font-size: 0.95rem;
116
+ }
117
+ .notice.md {
118
+ width: 25rem;
119
+ border-width: 1px;
120
+ border-radius: 3px;
121
+ }
122
+ .notice.md .icon {
123
+ width: 2rem;
124
+ min-width: 2rem;
125
+ }
126
+ .notice.md .content {
127
+ font-size: 0.85rem;
128
+ }
129
+ .notice.sm {
130
+ width: 15rem;
131
+ border-width: 1px;
132
+ border-radius: 2px;
133
+ }
134
+ .notice.sm .icon {
135
+ width: 1.5rem;
136
+ min-width: 1.5rem;
137
+ }
138
+ .notice.sm .content {
139
+ font-size: 0.75rem;
140
+ }
141
+
142
+ button {
143
+ appearance: none;
144
+ border: none;
145
+ background-color: transparent;
146
+ font-size: 1rem;
147
+ cursor: pointer;
148
+ position: absolute;
149
+ top: 0.4rem;
150
+ right: 0.4rem;
151
+ width: 1rem;
152
+ height: 1rem;
153
+ line-height: 1rem;
154
+ text-align: center;
155
+ border-radius: 0.5rem;
156
+ }
157
+ button:hover {
158
+ font-weight: bold;
159
+ }</style>
@@ -0,0 +1,25 @@
1
+ import { SvelteComponent } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ title?: string | undefined;
5
+ style?: ("outline" | "attention" | "success" | "error" | "info") | undefined;
6
+ size?: ("sm" | "md" | "lg" | "xl" | "full") | undefined;
7
+ dismissable?: boolean | undefined;
8
+ };
9
+ events: {
10
+ dismiss: CustomEvent<void>;
11
+ hidden: CustomEvent<void>;
12
+ } & {
13
+ [evt: string]: CustomEvent<any>;
14
+ };
15
+ slots: {
16
+ icon: {};
17
+ default: {};
18
+ };
19
+ };
20
+ export type NoticeProps = typeof __propDef.props;
21
+ export type NoticeEvents = typeof __propDef.events;
22
+ export type NoticeSlots = typeof __propDef.slots;
23
+ export default class Notice extends SvelteComponent<NoticeProps, NoticeEvents, NoticeSlots> {
24
+ }
25
+ export {};
@@ -6,3 +6,7 @@
6
6
  * @returns
7
7
  */
8
8
  export declare const roundToDecimals: (value: number, decimals: number) => number;
9
+ /**
10
+ * Format a number to a string with a specific number of decimals
11
+ */
12
+ export declare const formatNumber: (value: number, decimals: number) => string;
@@ -10,3 +10,9 @@ export const roundToDecimals = (value, decimals) => {
10
10
  return Math.round(value);
11
11
  return Number(Math.round(Number(`${value}e${decimals}`)) + `e-${decimals}`);
12
12
  };
13
+ /**
14
+ * Format a number to a string with a specific number of decimals
15
+ */
16
+ export const formatNumber = (value, decimals) => {
17
+ return roundToDecimals(value, decimals).toLocaleString();
18
+ };
@@ -0,0 +1,6 @@
1
+ /// <reference types="svelte" />
2
+ import type { Writable } from 'svelte/store';
3
+ export declare const subscribable: <T>(subject: Writable<T>) => {
4
+ subscribe: (this: void, run: import("svelte/store").Subscriber<T>, invalidate?: import("svelte/store").Invalidator<T> | undefined) => import("svelte/store").Unsubscriber;
5
+ };
6
+ export type Subscribable<T> = ReturnType<typeof subscribable<T>>;
@@ -0,0 +1,3 @@
1
+ export const subscribable = (subject) => {
2
+ return { subscribe: subject.subscribe };
3
+ };
package/dist/index.d.ts CHANGED
@@ -34,6 +34,7 @@ export { default as Panel } from './generic/panel/panel.svelte';
34
34
  export { default as Section } from './generic/section/section.svelte';
35
35
  export { default as Header } from './generic/header/header.svelte';
36
36
  export { default as Dot } from './generic/dot/dot.svelte';
37
+ export { default as Notice } from './generic/notice/notice.svelte';
37
38
  export { default as FlexCol } from './layout/flex-col.svelte';
38
39
  export { default as FlexRow } from './layout/flex-row.svelte';
39
40
  export { default as FlexItem } from './layout/flex-item.svelte';
@@ -55,6 +56,8 @@ export { default as AppLogo } from './navigation/app-bar/app-logo.svelte';
55
56
  export { default as AppNav } from './navigation/app-bar/app-nav.svelte';
56
57
  export { default as AppNavItem } from './navigation/app-bar/app-nav-item.svelte';
57
58
  export { default as AppBranding } from './navigation/app-bar/app-branding.svelte';
59
+ export { default as Wizard } from './navigation/wizard/wizard.svelte';
60
+ export { default as WizardStep } from './navigation/wizard/wizard-step.svelte';
58
61
  export { default as DataGrid } from './tables/data-grid.svelte';
59
62
  export { default as Table } from './tables/table.svelte';
60
63
  export { default as TableBody } from './tables/table-body.svelte';
@@ -82,4 +85,5 @@ export * from './helpers/date.js';
82
85
  export * from './helpers/navigate-to.js';
83
86
  export * from './helpers/round-to-decimals.js';
84
87
  export * from './helpers/unique-id.js';
88
+ export * from './helpers/subscribable.js';
85
89
  export * as Data from './data/index.js';
package/dist/index.js CHANGED
@@ -36,6 +36,7 @@ export { default as Panel } from './generic/panel/panel.svelte';
36
36
  export { default as Section } from './generic/section/section.svelte';
37
37
  export { default as Header } from './generic/header/header.svelte';
38
38
  export { default as Dot } from './generic/dot/dot.svelte';
39
+ export { default as Notice } from './generic/notice/notice.svelte';
39
40
  // Layout
40
41
  export { default as FlexCol } from './layout/flex-col.svelte';
41
42
  export { default as FlexRow } from './layout/flex-row.svelte';
@@ -60,6 +61,8 @@ export { default as AppLogo } from './navigation/app-bar/app-logo.svelte';
60
61
  export { default as AppNav } from './navigation/app-bar/app-nav.svelte';
61
62
  export { default as AppNavItem } from './navigation/app-bar/app-nav-item.svelte';
62
63
  export { default as AppBranding } from './navigation/app-bar/app-branding.svelte';
64
+ export { default as Wizard } from './navigation/wizard/wizard.svelte';
65
+ export { default as WizardStep } from './navigation/wizard/wizard-step.svelte';
63
66
  // Tables
64
67
  export { default as DataGrid } from './tables/data-grid.svelte';
65
68
  export { default as Table } from './tables/table.svelte';
@@ -93,5 +96,6 @@ export * from './helpers/date.js';
93
96
  export * from './helpers/navigate-to.js';
94
97
  export * from './helpers/round-to-decimals.js';
95
98
  export * from './helpers/unique-id.js';
99
+ export * from './helpers/subscribable.js';
96
100
  // Data
97
101
  export * as Data from './data/index.js';
@@ -0,0 +1,10 @@
1
+ import type { Subscribable } from '../../helpers/subscribable.js';
2
+ export type WizardState = {
3
+ currentStep: number;
4
+ totalSteps: number;
5
+ disabled: boolean;
6
+ };
7
+ export interface WizardContext {
8
+ state: Subscribable<WizardState>;
9
+ register: (step: number, title: string) => void;
10
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,20 @@
1
+ <script>import { getContext, onDestroy } from "svelte";
2
+ const wizard = getContext("wizard");
3
+ const state = wizard.state;
4
+ export let step;
5
+ export let subtitle;
6
+ wizard.register(step, subtitle);
7
+ $:
8
+ isCurrentStep = $state.currentStep === step;
9
+ </script>
10
+
11
+ <div class="step {isCurrentStep ? 'current' : ''}">
12
+ <slot />
13
+ </div>
14
+
15
+ <style>.step {
16
+ display: none;
17
+ }
18
+ .step.current {
19
+ display: block;
20
+ }</style>
@@ -0,0 +1,19 @@
1
+ import { SvelteComponent } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ step: number;
5
+ subtitle: string;
6
+ };
7
+ events: {
8
+ [evt: string]: CustomEvent<any>;
9
+ };
10
+ slots: {
11
+ default: {};
12
+ };
13
+ };
14
+ export type WizardStepProps = typeof __propDef.props;
15
+ export type WizardStepEvents = typeof __propDef.events;
16
+ export type WizardStepSlots = typeof __propDef.slots;
17
+ export default class WizardStep extends SvelteComponent<WizardStepProps, WizardStepEvents, WizardStepSlots> {
18
+ }
19
+ export {};
@@ -0,0 +1,95 @@
1
+ <script>import { createEventDispatcher, setContext } from "svelte";
2
+ import { writable } from "svelte/store";
3
+ import { subscribable } from "../../helpers/subscribable.js";
4
+ import Section from "../../generic/section/section.svelte";
5
+ import Header from "../../generic/header/header.svelte";
6
+ import Button from "../../forms/button/button.svelte";
7
+ export let title;
8
+ export let level = 3;
9
+ export let disabled = false;
10
+ let currentStep = 0;
11
+ const dispatch = createEventDispatcher();
12
+ const steps = {};
13
+ const wizardStore = writable({
14
+ currentStep,
15
+ totalSteps: 0,
16
+ disabled
17
+ });
18
+ const publish = () => {
19
+ wizardStore.set({
20
+ currentStep,
21
+ totalSteps: Object.values(steps).length,
22
+ disabled
23
+ });
24
+ };
25
+ const register = (stepNumber, subtitle2) => {
26
+ steps[stepNumber] = subtitle2;
27
+ publish();
28
+ };
29
+ const next = () => {
30
+ if (currentStep >= Object.values(steps).length || disabled)
31
+ return;
32
+ currentStep++;
33
+ dispatch("next", currentStep);
34
+ publish();
35
+ };
36
+ const previous = () => {
37
+ if (currentStep <= 1 || disabled)
38
+ return;
39
+ currentStep--;
40
+ dispatch("previous", currentStep);
41
+ publish();
42
+ };
43
+ const done = () => {
44
+ disabled = true;
45
+ dispatch("submit");
46
+ };
47
+ setContext("wizard", {
48
+ state: subscribable(wizardStore),
49
+ register
50
+ });
51
+ setTimeout(next, 100);
52
+ $:
53
+ isFirstStep = currentStep <= 1;
54
+ $:
55
+ isLastStep = currentStep >= Object.values(steps).length;
56
+ $:
57
+ subtitle = steps[currentStep - 1];
58
+ $:
59
+ total = Object.values(steps).length;
60
+ </script>
61
+
62
+ <section class:disabled>
63
+ <Header {title} {subtitle} {level} />
64
+ <div class="content">
65
+ <slot />
66
+ </div>
67
+ <footer>
68
+ <div>
69
+ {#if !isFirstStep}
70
+ <Button type="button" style="secondary" on:click={previous} {disabled}>Previous</Button>
71
+ {/if}
72
+ </div>
73
+ <div>
74
+ <div>Step {currentStep} of {total}</div>
75
+ </div>
76
+ <div>
77
+ {#if isLastStep}
78
+ <Button type="submit" style="primary" on:click={done} {disabled}>Done</Button>
79
+ {:else}
80
+ <Button type="button" style="primary" on:click={next} {disabled}>Next</Button>
81
+ {/if}
82
+ </div>
83
+ </footer>
84
+ </section>
85
+
86
+ <style>section.disabled {
87
+ opacity: 0.5;
88
+ }
89
+
90
+ footer {
91
+ margin-top: 1rem;
92
+ display: flex;
93
+ justify-content: space-between;
94
+ align-items: center;
95
+ }</style>
@@ -0,0 +1,25 @@
1
+ import { SvelteComponent } from "svelte";
2
+ import type { SectionLevel } from '../../types/generic.js';
3
+ declare const __propDef: {
4
+ props: {
5
+ title: string;
6
+ level?: SectionLevel | undefined;
7
+ disabled?: boolean | undefined;
8
+ };
9
+ events: {
10
+ submit: CustomEvent<void>;
11
+ next: CustomEvent<number>;
12
+ previous: CustomEvent<number>;
13
+ } & {
14
+ [evt: string]: CustomEvent<any>;
15
+ };
16
+ slots: {
17
+ default: {};
18
+ };
19
+ };
20
+ export type WizardProps = typeof __propDef.props;
21
+ export type WizardEvents = typeof __propDef.events;
22
+ export type WizardSlots = typeof __propDef.slots;
23
+ export default class Wizard extends SvelteComponent<WizardProps, WizardEvents, WizardSlots> {
24
+ }
25
+ export {};
package/package.json CHANGED
@@ -1,6 +1,34 @@
1
1
  {
2
2
  "name": "sveltacular",
3
- "version": "0.0.35",
3
+ "version": "0.0.37",
4
+ "description": "A Svelte component library",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/jasonbyrne/sveltacular.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/jasonbyrne/sveltacular/issues"
14
+ },
15
+ "homepage": "https://github.com/jasonbyrne/sveltacular#readme",
16
+ "license": "Apache-2.0",
17
+ "author": "Jason Byrne <jasonbyrne662@gmail.com>",
18
+ "keywords": [
19
+ "svelte",
20
+ "sveltekit",
21
+ "component",
22
+ "library",
23
+ "ui",
24
+ "kit",
25
+ "storybook",
26
+ "vite",
27
+ "typescript",
28
+ "css",
29
+ "scss",
30
+ "helpers"
31
+ ],
4
32
  "scripts": {
5
33
  "watch": "npm run dev -- --open",
6
34
  "dev": "vite dev",
@@ -69,6 +97,5 @@
69
97
  "vitest": "^0.34.0"
70
98
  },
71
99
  "svelte": "./dist/index.js",
72
- "types": "./dist/index.d.ts",
73
100
  "type": "module"
74
101
  }