sveltacular 0.0.42 → 0.0.43

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.
@@ -1,7 +1,11 @@
1
1
  <script>export let text = "No data to display";
2
+ export let size = "md";
3
+ export let orientation = "vertical";
4
+ export let reverse = false;
5
+ export let align = "center";
2
6
  </script>
3
7
 
4
- <div class="empty">
8
+ <div class="empty {size} {orientation} {reverse ? 'reverse' : ''} {align}">
5
9
  {#if $$slots.default}
6
10
  <div class="icon">
7
11
  <slot />
@@ -19,20 +23,61 @@
19
23
  justify-content: center;
20
24
  text-align: center;
21
25
  color: var(--color-text-secondary, rgba(150, 150, 150, 0.5));
22
- font-size: 1.5rem;
23
26
  font-weight: 500;
24
- line-height: 2rem;
25
- margin: 2rem 0;
26
27
  }
27
28
 
28
- .icon {
29
+ .start {
30
+ justify-content: flex-start;
31
+ }
32
+
33
+ .end {
34
+ justify-content: flex-end;
35
+ }
36
+
37
+ .horizontal {
38
+ flex-direction: row;
39
+ gap: 1rem;
40
+ }
41
+ .horizontal.reverse {
42
+ flex-direction: row-reverse;
43
+ }
44
+
45
+ .vertical.reverse {
46
+ flex-direction: column-reverse;
47
+ }
48
+
49
+ .sm {
50
+ font-size: 1rem;
51
+ line-height: 1.5rem;
52
+ }
53
+ .sm .icon {
54
+ height: 1.5rem;
55
+ width: 1.5rem;
56
+ }
57
+
58
+ .md {
59
+ font-size: 1.25rem;
60
+ line-height: 1.75rem;
61
+ }
62
+ .md .icon {
29
63
  height: 2rem;
30
64
  width: 2rem;
31
- margin-bottom: 1rem;
32
65
  }
33
66
 
34
- .text {
67
+ .lg {
35
68
  font-size: 1.5rem;
36
- font-weight: 500;
37
69
  line-height: 2rem;
70
+ }
71
+ .lg .icon {
72
+ height: 3rem;
73
+ width: 3rem;
74
+ }
75
+
76
+ .xl {
77
+ font-size: 2rem;
78
+ line-height: 2.5rem;
79
+ }
80
+ .xl .icon {
81
+ height: 4rem;
82
+ width: 4rem;
38
83
  }</style>
@@ -2,6 +2,10 @@ import { SvelteComponent } from "svelte";
2
2
  declare const __propDef: {
3
3
  props: {
4
4
  text?: string | undefined;
5
+ size?: "sm" | "md" | "lg" | "xl" | undefined;
6
+ orientation?: "horizontal" | "vertical" | undefined;
7
+ reverse?: boolean | undefined;
8
+ align?: "center" | "end" | "start" | undefined;
5
9
  };
6
10
  events: {
7
11
  [evt: string]: CustomEvent<any>;
package/dist/index.d.ts CHANGED
@@ -61,6 +61,7 @@ export { default as AppNavItem } from './navigation/app-bar/app-nav-item.svelte'
61
61
  export { default as AppBranding } from './navigation/app-bar/app-branding.svelte';
62
62
  export { default as Wizard } from './navigation/wizard/wizard.svelte';
63
63
  export { default as WizardStep } from './navigation/wizard/wizard-step.svelte';
64
+ export { default as Pagination } from './navigation/pagination/pagination.svelte';
64
65
  export { default as DataGrid } from './tables/data-grid.svelte';
65
66
  export { default as Table } from './tables/table.svelte';
66
67
  export { default as TableBody } from './tables/table-body.svelte';
package/dist/index.js CHANGED
@@ -66,6 +66,7 @@ export { default as AppNavItem } from './navigation/app-bar/app-nav-item.svelte'
66
66
  export { default as AppBranding } from './navigation/app-bar/app-branding.svelte';
67
67
  export { default as Wizard } from './navigation/wizard/wizard.svelte';
68
68
  export { default as WizardStep } from './navigation/wizard/wizard-step.svelte';
69
+ export { default as Pagination } from './navigation/pagination/pagination.svelte';
69
70
  // Tables
70
71
  export { default as DataGrid } from './tables/data-grid.svelte';
71
72
  export { default as Table } from './tables/table.svelte';
@@ -0,0 +1,109 @@
1
+ <script>import { createEventDispatcher } from "svelte";
2
+ export let currentPage = 1;
3
+ export let totalPages = 1;
4
+ export let align = "center";
5
+ const dispatch = createEventDispatcher();
6
+ const changePage = (page) => {
7
+ if (page < 1 || page > totalPages)
8
+ return;
9
+ currentPage = page;
10
+ dispatch("page", page);
11
+ };
12
+ $:
13
+ previousPages = currentPage > 1 ? (() => {
14
+ const pages = [];
15
+ for (let i = currentPage - 1; i > 0 && i >= currentPage - 3; i--) {
16
+ pages.push(i);
17
+ }
18
+ return pages.reverse();
19
+ })() : [];
20
+ $:
21
+ nextPages = currentPage < totalPages ? (() => {
22
+ const pages = [];
23
+ for (let i = currentPage + 1; i <= totalPages && i <= currentPage + 3; i++) {
24
+ pages.push(i);
25
+ }
26
+ return pages;
27
+ })() : [];
28
+ $:
29
+ showFirst = currentPage > 4;
30
+ $:
31
+ showLast = currentPage < totalPages - 3;
32
+ </script>
33
+
34
+ <nav class={align}>
35
+ {#if currentPage > 1}
36
+ <button on:click={() => changePage(currentPage - 1)} class="previous">Previous</button>
37
+ {/if}
38
+ {#if showFirst}
39
+ <button on:click={() => changePage(1)} class="first">1</button>
40
+ <div class="ellipsis">...</div>
41
+ {/if}
42
+ {#each previousPages as page}
43
+ <button on:click={() => changePage(page)}>{page}</button>
44
+ {/each}
45
+ <div class="current">{currentPage}</div>
46
+ {#each nextPages as page}
47
+ <button on:click={() => changePage(page)}>{page}</button>
48
+ {/each}
49
+ {#if showLast}
50
+ <div class="ellipsis">...</div>
51
+ <button on:click={() => changePage(totalPages)} class="last">{totalPages}</button>
52
+ {/if}
53
+ {#if currentPage < totalPages}
54
+ <button on:click={() => changePage(currentPage + 1)} class="next">Next</button>
55
+ {/if}
56
+ </nav>
57
+
58
+ <style>nav {
59
+ display: flex;
60
+ align-items: center;
61
+ justify-content: center;
62
+ gap: 0rem;
63
+ }
64
+ nav button {
65
+ appearance: none;
66
+ padding-left: 1rem;
67
+ padding-right: 1rem;
68
+ font-size: 1rem;
69
+ line-height: 1.4rem;
70
+ height: 1.5rem;
71
+ border: none;
72
+ cursor: pointer;
73
+ background-color: var(--form-input-background, white);
74
+ color: var(--form-input-text, black);
75
+ }
76
+ nav button:hover {
77
+ background-color: var(--form-input-border, black);
78
+ color: var(--form-input-background, white);
79
+ }
80
+ nav button.previous {
81
+ border-radius: 0.5rem 0 0 0.5rem;
82
+ border-right: solid 1px var(--form-input-border, black);
83
+ }
84
+ nav button.next {
85
+ border-radius: 0 0.5rem 0.5rem 0;
86
+ border-left: solid 1px var(--form-input-border, black);
87
+ }
88
+ nav .ellipsis {
89
+ height: 1.5rem;
90
+ font-size: 1rem;
91
+ line-height: 1rem;
92
+ padding-left: 0.1rem;
93
+ padding-right: 0.1rem;
94
+ background-color: var(--form-input-background, white);
95
+ color: var(--form-input-text, black);
96
+ }
97
+ nav .current {
98
+ padding: 0.5rem 1rem;
99
+ border: 1px solid var(--form-input-border, black);
100
+ border-radius: 0.5rem;
101
+ background-color: var(--form-input-background, white);
102
+ color: var(--form-input-text, black);
103
+ }
104
+ nav.start {
105
+ justify-content: flex-start;
106
+ }
107
+ nav.end {
108
+ justify-content: flex-end;
109
+ }</style>
@@ -0,0 +1,20 @@
1
+ import { SvelteComponent } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ currentPage?: number | undefined;
5
+ totalPages?: number | undefined;
6
+ align?: "center" | "end" | "start" | undefined;
7
+ };
8
+ events: {
9
+ page: CustomEvent<number>;
10
+ } & {
11
+ [evt: string]: CustomEvent<any>;
12
+ };
13
+ slots: {};
14
+ };
15
+ export type PaginationProps = typeof __propDef.props;
16
+ export type PaginationEvents = typeof __propDef.events;
17
+ export type PaginationSlots = typeof __propDef.slots;
18
+ export default class Pagination extends SvelteComponent<PaginationProps, PaginationEvents, PaginationSlots> {
19
+ }
20
+ export {};
@@ -3,6 +3,7 @@ export type WizardState = {
3
3
  currentStep: number;
4
4
  totalSteps: number;
5
5
  disabled: boolean;
6
+ errors: string[];
6
7
  };
7
8
  export interface WizardContext {
8
9
  state: Subscribable<WizardState>;
@@ -1,4 +1,5 @@
1
1
  <script>import { getContext, onDestroy } from "svelte";
2
+ import Notice from "../../generic/notice/notice.svelte";
2
3
  const wizard = getContext("wizard");
3
4
  const state = wizard.state;
4
5
  export let step;
@@ -6,9 +7,18 @@ export let subtitle;
6
7
  wizard.register(step, subtitle);
7
8
  $:
8
9
  isCurrentStep = $state.currentStep === step;
10
+ $:
11
+ errors = $state.errors;
9
12
  </script>
10
13
 
11
14
  <div class="step {isCurrentStep ? 'current' : ''}">
15
+ {#if errors.length}
16
+ <div class="errors">
17
+ {#each errors as error}
18
+ <Notice style="error">{error}</Notice>
19
+ {/each}
20
+ </div>
21
+ {/if}
12
22
  <slot />
13
23
  </div>
14
24
 
@@ -17,4 +27,10 @@ $:
17
27
  }
18
28
  .step.current {
19
29
  display: block;
30
+ }
31
+ .step .errors {
32
+ margin-bottom: 1rem;
33
+ display: flex;
34
+ flex-direction: column;
35
+ gap: 1rem;
20
36
  }</style>
@@ -9,18 +9,21 @@ export let disabled = false;
9
9
  export let onNext = async () => [];
10
10
  export let onSubmit = async () => [];
11
11
  let currentStep = 0;
12
+ let errors = [];
12
13
  const dispatch = createEventDispatcher();
13
14
  const steps = {};
14
15
  const wizardStore = writable({
15
16
  currentStep,
16
17
  totalSteps: 0,
17
- disabled
18
+ disabled,
19
+ errors
18
20
  });
19
21
  const publish = () => {
20
22
  wizardStore.set({
21
23
  currentStep,
22
24
  totalSteps: Object.values(steps).length,
23
- disabled
25
+ disabled,
26
+ errors
24
27
  });
25
28
  };
26
29
  const register = (stepNumber, subtitle2) => {
@@ -29,7 +32,7 @@ const register = (stepNumber, subtitle2) => {
29
32
  };
30
33
  const validate = async (callback) => {
31
34
  disabled = true;
32
- const errors = await callback();
35
+ errors = await callback() || [];
33
36
  disabled = false;
34
37
  dispatch("errors", errors);
35
38
  return errors;
@@ -37,9 +40,9 @@ const validate = async (callback) => {
37
40
  const next = async () => {
38
41
  if (currentStep >= Object.values(steps).length || disabled)
39
42
  return;
40
- const errors = await validate(() => onNext(currentStep));
41
- if (errors.length)
42
- return;
43
+ const errors2 = await validate(() => onNext(currentStep));
44
+ if (errors2.length)
45
+ return publish();
43
46
  currentStep++;
44
47
  dispatch("next", currentStep);
45
48
  publish();
@@ -48,6 +51,7 @@ const previous = () => {
48
51
  if (currentStep <= 1 || disabled)
49
52
  return;
50
53
  currentStep--;
54
+ errors = [];
51
55
  dispatch("previous", currentStep);
52
56
  publish();
53
57
  };
@@ -57,9 +61,9 @@ const reset = () => {
57
61
  publish();
58
62
  };
59
63
  const done = async () => {
60
- const errors = await validate(onSubmit);
61
- if (errors.length)
62
- return;
64
+ const errors2 = await validate(onSubmit);
65
+ if (errors2.length)
66
+ return publish();
63
67
  dispatch("done");
64
68
  reset();
65
69
  };
@@ -5,8 +5,8 @@ declare const __propDef: {
5
5
  title: string;
6
6
  level?: SectionLevel | undefined;
7
7
  disabled?: boolean | undefined;
8
- onNext?: ((step: number) => Promise<string[]>) | undefined;
9
- onSubmit?: (() => Promise<string[]>) | undefined;
8
+ onNext?: ((step: number) => Promise<string[] | void>) | undefined;
9
+ onSubmit?: (() => Promise<string[] | void>) | undefined;
10
10
  };
11
11
  events: {
12
12
  done: CustomEvent<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sveltacular",
3
- "version": "0.0.42",
3
+ "version": "0.0.43",
4
4
  "description": "A Svelte component library",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",