spaper 0.1.2 → 0.2.5

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.
Files changed (44) hide show
  1. package/README.md +30 -0
  2. package/components/Alert.svelte +7 -5
  3. package/components/Alert.svelte.d.ts +3 -1
  4. package/components/Button.svelte +14 -6
  5. package/components/Button.svelte.d.ts +5 -3
  6. package/components/Card.svelte +2 -1
  7. package/components/Card.svelte.d.ts +2 -1
  8. package/components/CloseButton.svelte +23 -0
  9. package/components/CloseButton.svelte.d.ts +19 -0
  10. package/components/Collapsible.svelte +34 -16
  11. package/components/Collapsible.svelte.d.ts +1 -0
  12. package/components/Form/Form.svelte +4 -0
  13. package/components/Form/Form.svelte.d.ts +20 -0
  14. package/components/Form/Input.svelte +6 -4
  15. package/components/Form/Switch.svelte +15 -13
  16. package/components/Form/index.d.ts +2 -1
  17. package/components/Form/index.js +2 -1
  18. package/components/Modal/Modal.svelte +3 -13
  19. package/components/Navbar.svelte +6 -1
  20. package/components/Navbar.svelte.d.ts +1 -0
  21. package/components/Pagination/Arrow.svelte +17 -0
  22. package/components/Pagination/Arrow.svelte.d.ts +19 -0
  23. package/components/Pagination/NavigationButton.svelte +23 -0
  24. package/components/Pagination/NavigationButton.svelte.d.ts +23 -0
  25. package/components/Pagination/Pagination.svelte +122 -0
  26. package/components/Pagination/Pagination.svelte.d.ts +34 -0
  27. package/components/Pagination/arrow-dimension.d.ts +3 -0
  28. package/components/Pagination/arrow-dimension.js +6 -0
  29. package/components/Pagination/index.d.ts +3 -0
  30. package/components/Pagination/index.js +2 -0
  31. package/components/Popover.svelte.d.ts +2 -2
  32. package/components/Tabs/Tabs.svelte +11 -0
  33. package/components/Toast/Toast.svelte +78 -0
  34. package/components/Toast/Toast.svelte.d.ts +26 -0
  35. package/components/Toast/ToastContainer.svelte +37 -0
  36. package/components/Toast/ToastContainer.svelte.d.ts +18 -0
  37. package/components/Toast/index.d.ts +32 -0
  38. package/components/Toast/index.js +37 -0
  39. package/index.d.ts +4 -2
  40. package/index.js +4 -2
  41. package/package.json +11 -1
  42. package/types.d.ts +4 -0
  43. package/utils.d.ts +8 -0
  44. package/utils.js +6 -0
package/README.md CHANGED
@@ -48,3 +48,33 @@ npm i spaper
48
48
  <Alert>...</Alert>
49
49
  <Button>Click me</Button>
50
50
  ```
51
+
52
+ <hr />
53
+
54
+ #### Components
55
+
56
+ - Alert
57
+ - Article
58
+ - Badge
59
+ - Breadcrumb
60
+ - Button
61
+ - Card
62
+ - Collapsible
63
+ - Checkbox
64
+ - Input
65
+ - Radio
66
+ - Select
67
+ - Slider
68
+ - Switch
69
+ - Modal
70
+ - Navbar
71
+ - Pagination
72
+ - Popover
73
+ - Progress
74
+ - Table
75
+ - Tabs
76
+
77
+ ##### Coming soon:
78
+ - Form
79
+ - Toast
80
+ - Step
@@ -1,13 +1,16 @@
1
- <div class={classes}
1
+ <div {...$$restProps}
2
+ class={classes}
2
3
  class:closed class:dismissible
3
4
  role="alert">
4
5
  <slot />
5
6
  {#if dismissible}
6
- <span class="btn-close" on:click={close}>X</span>
7
+ <CloseButton on:click={close} />
7
8
  {/if}
8
9
  </div>
9
10
 
10
- <script lang="ts">;
11
+ <script lang="ts">var _a;
12
+ ;
13
+ import CloseButton from './CloseButton.svelte';
11
14
  import { computeClasses } from '../utils';
12
15
  export let type = 'primary';
13
16
  export let dismissible = false;
@@ -15,8 +18,7 @@ let closed = false;
15
18
  function close() {
16
19
  closed = true;
17
20
  }
18
- let classes;
19
- $: classes = `alert ${computeClasses('alert', { type })}`;
21
+ $: classes = `${(_a = $$restProps.class) !== null && _a !== void 0 ? _a : ''} alert ${computeClasses('alert', { type })}`;
20
22
  </script>
21
23
 
22
24
  <style lang="scss">.alert {
@@ -1,7 +1,9 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
+ import type { PaperType } from '../types';
2
3
  declare const __propDef: {
3
4
  props: {
4
- type?: any;
5
+ [x: string]: any;
6
+ type?: PaperType;
5
7
  dismissible?: boolean;
6
8
  };
7
9
  events: {
@@ -1,5 +1,5 @@
1
1
  {#if isLink || href}
2
- <a class={classes}
2
+ <a {...attr}
3
3
  class:disabled
4
4
  role="button"
5
5
  {href}
@@ -8,7 +8,7 @@
8
8
  <slot />
9
9
  </a>
10
10
  {:else}
11
- <button class={classes}
11
+ <button {...attr}
12
12
  class:disabled
13
13
  disabled={disabled}
14
14
  on:click>
@@ -16,16 +16,24 @@
16
16
  </button>
17
17
  {/if}
18
18
 
19
- <script lang="ts">;
20
- import { computeClasses } from '../utils';
19
+ <script lang="ts">var _a;
20
+ ;
21
+ import { computeClasses, getDomAttributes } from '../utils';
21
22
  export let type = null;
22
23
  export let size = 'default';
23
24
  export let block = false;
24
25
  export let disabled = false;
25
26
  export let outline = null;
26
27
  export let isLink = false;
27
- export let href = '';
28
+ export let href = 'javascript:void(0);';
28
29
  export let external = false;
30
+ let attr;
31
+ $: {
32
+ attr = getDomAttributes({
33
+ props: $$restProps,
34
+ classes,
35
+ });
36
+ }
29
37
  let classes;
30
- $: classes = `paper-btn ${computeClasses('btn', { size, block, type, outline })}`;
38
+ $: classes = `paper-btn ${(_a = $$restProps.class) !== null && _a !== void 0 ? _a : ''} ${computeClasses('btn', { size, block, type, outline })}`;
31
39
  </script>
@@ -1,11 +1,13 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
+ import type { PaperSize, PaperType } from '../types';
2
3
  declare const __propDef: {
3
4
  props: {
4
- type?: any;
5
- size?: any;
5
+ [x: string]: any;
6
+ type?: PaperType;
7
+ size?: PaperSize;
6
8
  block?: boolean;
7
9
  disabled?: boolean;
8
- outline?: any;
10
+ outline?: PaperType;
9
11
  isLink?: boolean;
10
12
  href?: string;
11
13
  external?: boolean;
@@ -57,7 +57,8 @@
57
57
  {/if}
58
58
  </div>
59
59
 
60
- <script lang="ts">export let title = '';
60
+ <script lang="ts">;
61
+ export let title = '';
61
62
  export let subTitle = '';
62
63
  export let image = '';
63
64
  export let imageAlt = '';
@@ -1,11 +1,12 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
+ import type { PositionY } from "../types";
2
3
  declare const __propDef: {
3
4
  props: {
4
5
  title?: string;
5
6
  subTitle?: string;
6
7
  image?: string;
7
8
  imageAlt?: string;
8
- imagePlacement?: 'top' | 'bottom';
9
+ imagePlacement?: PositionY;
9
10
  header?: string;
10
11
  footer?: string;
11
12
  width?: string;
@@ -0,0 +1,23 @@
1
+ <button {...$$restProps}
2
+ class="{$$restProps.class ?? ''} btn-close"
3
+ aria-label={ariaLabel}
4
+ on:click>
5
+ X
6
+ </button>
7
+
8
+ <script lang="ts">export let ariaLabel = 'close';
9
+ </script>
10
+
11
+ <style lang="scss">button {
12
+ float: right;
13
+ border: 0;
14
+ padding: 0;
15
+ background: none;
16
+ box-shadow: none;
17
+ transform: none;
18
+ }
19
+ button:hover, button:focus {
20
+ transform: none;
21
+ box-shadow: none;
22
+ border: 0;
23
+ }</style>
@@ -0,0 +1,19 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ [x: string]: any;
5
+ ariaLabel?: string;
6
+ };
7
+ events: {
8
+ click: MouseEvent;
9
+ } & {
10
+ [evt: string]: CustomEvent<any>;
11
+ };
12
+ slots: {};
13
+ };
14
+ export declare type CloseButtonProps = typeof __propDef.props;
15
+ export declare type CloseButtonEvents = typeof __propDef.events;
16
+ export declare type CloseButtonSlots = typeof __propDef.slots;
17
+ export default class CloseButton extends SvelteComponentTyped<CloseButtonProps, CloseButtonEvents, CloseButtonSlots> {
18
+ }
19
+ export {};
@@ -1,31 +1,49 @@
1
- <div class="collapsible">
2
- <label on:click={toggle}>
1
+ <section {...$$restProps}
2
+ class="{$$restProps.class ?? ''} collapsible">
3
+ <input id={domId} type="checkbox"
4
+ bind:checked={open}>
5
+ <label for={domId}>
3
6
  {#if $$slots.trigger}
4
7
  <slot name="trigger" />
5
8
  {:else}
6
9
  {label}
7
10
  {/if}
8
11
  </label>
9
- <div class="collapsible-body"
10
- class:open>
12
+ <div class="collapsible-body">
11
13
  <slot />
12
14
  </div>
13
- </div>
15
+ </section>
14
16
 
15
- <script lang="ts">import { createEventDispatcher } from 'svelte';
17
+ <script lang="ts" context="module">let count = 0;
18
+ </script>
19
+
20
+ <script lang="ts">var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
21
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
22
+ return new (P || (P = Promise))(function (resolve, reject) {
23
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
24
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
25
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
26
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
27
+ });
28
+ };
29
+ import { createEventDispatcher, onMount } from 'svelte';
16
30
  export let label = '';
17
31
  export let open = false;
32
+ let id;
33
+ onMount(() => __awaiter(void 0, void 0, void 0, function* () {
34
+ id = count++;
35
+ }));
18
36
  const dispatch = createEventDispatcher();
19
37
  const ANIMATION_DELAY = 235;
20
- function toggle() {
21
- open = !open;
22
- setTimeout(dispatch.bind(this, open ? 'open' : 'close'), ANIMATION_DELAY);
38
+ let eventEnabled = false;
39
+ let domId;
40
+ // Needs to start with 'collapsible'
41
+ $: domId = `collapsible-input-${id}`;
42
+ $: {
43
+ // Prevent event from initialization
44
+ if (eventEnabled) {
45
+ setTimeout(dispatch.bind(this, open ? 'open' : 'close'), ANIMATION_DELAY);
46
+ }
47
+ eventEnabled = true;
23
48
  }
24
49
  </script>
25
-
26
- <style lang="scss">.collapsible-body.open {
27
- margin: 0;
28
- max-height: 960px;
29
- opacity: 1;
30
- padding: 0.75rem;
31
- }</style>
@@ -1,6 +1,7 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
2
  declare const __propDef: {
3
3
  props: {
4
+ [x: string]: any;
4
5
  label?: string;
5
6
  open?: boolean;
6
7
  };
@@ -0,0 +1,4 @@
1
+ <form {...$$restProps}
2
+ class="{$$restProps.class ?? ''} form-group">
3
+ <slot />
4
+ </form>
@@ -0,0 +1,20 @@
1
+ /** @typedef {typeof __propDef.props} FormProps */
2
+ /** @typedef {typeof __propDef.events} FormEvents */
3
+ /** @typedef {typeof __propDef.slots} FormSlots */
4
+ export default class Form {
5
+ }
6
+ export type FormProps = typeof __propDef.props;
7
+ export type FormEvents = typeof __propDef.events;
8
+ export type FormSlots = typeof __propDef.slots;
9
+ declare const __propDef: {
10
+ props: {
11
+ [x: string]: any;
12
+ };
13
+ events: {
14
+ [evt: string]: CustomEvent<any>;
15
+ };
16
+ slots: {
17
+ default: {};
18
+ };
19
+ };
20
+ export {};
@@ -31,8 +31,7 @@
31
31
 
32
32
  <script lang="ts">var _a;
33
33
  import { createEventDispatcher } from 'svelte';
34
- import omit from 'lodash.omit';
35
- import { computeClasses } from '../../utils';
34
+ import { computeClasses, getDomAttributes } from '../../utils';
36
35
  ;
37
36
  ;
38
37
  export let label = '';
@@ -51,8 +50,11 @@ $: if (valid) {
51
50
  }
52
51
  let attr;
53
52
  $: {
54
- const props = omit($$props, ['block', 'value', 'valid', 'noResize']);
55
- attr = Object.assign(Object.assign({}, props), { class: classes });
53
+ attr = getDomAttributes({
54
+ props: $$props,
55
+ classes,
56
+ toOmit: ['block', 'value', 'valid', 'noResize']
57
+ });
56
58
  }
57
59
  let classes;
58
60
  $: classes = `${(_a = $$restProps.class) !== null && _a !== void 0 ? _a : ''} ${computeClasses('input', { block })}`;
@@ -5,13 +5,11 @@
5
5
  type="checkbox"
6
6
  {disabled} />
7
7
  <div class="paper-switch-tile-card border">
8
- <div class={`paper-switch-tile-card-front
9
- border
8
+ <div class={`paper-switch-tile-card-front border
10
9
  ${bgClass(tile.off.background)}`}>
11
10
  {tile.off.label}
12
11
  </div>
13
- <div class={`paper-switch-tile-card-back
14
- border
12
+ <div class={`paper-switch-tile-card-back border
15
13
  ${bgClass(tile.on.background)}`}>
16
14
  {tile.on.label}
17
15
  </div>
@@ -19,7 +17,7 @@
19
17
  </label>
20
18
  {:else}
21
19
  <label class={prefix}>
22
- <input bind:this={checkbox}
20
+ <input id={domId}
23
21
  bind:checked
24
22
  type="checkbox"
25
23
  {disabled} />
@@ -28,26 +26,30 @@
28
26
  </label>
29
27
  {#if $$slots.default}
30
28
  <label class={`${prefix}-label`}
31
- on:click={toggle}>
29
+ for={domId}>
32
30
  <slot />
33
31
  </label>
34
32
  {/if}
35
33
  {/if}
36
34
 
37
- <script lang="ts">;
35
+ <script lang="ts" context="module">let count = 0;
36
+ </script>
37
+
38
+ <script lang="ts">import { onMount } from "svelte";
39
+ ;
38
40
  export let checked = false;
39
41
  export let disabled = false;
40
42
  export let round = false;
41
43
  export let inline = false;
42
44
  export let tile = null;
43
- let checkbox;
45
+ let id;
46
+ onMount(() => {
47
+ id = count++;
48
+ });
49
+ let domId;
50
+ $: domId = `paper-switch-input-${id}`;
44
51
  let prefix;
45
52
  $: prefix = 'paper-switch' + (inline ? '-2' : '');
46
- function toggle() {
47
- if (disabled)
48
- return;
49
- checkbox.checked = !checkbox.checked;
50
- }
51
53
  function bgClass(color) {
52
54
  if (!color)
53
55
  return;
@@ -4,5 +4,6 @@ import Radio from './Radio.svelte';
4
4
  import Checkbox from './Checkbox.svelte';
5
5
  import Switch from './Switch.svelte';
6
6
  import Slider from './Slider.svelte';
7
+ import Form from './Form.svelte';
7
8
  export declare type InputType = 'text' | 'email' | 'number' | 'password' | 'search' | 'tel' | 'url' | 'time' | 'date' | 'month' | 'week' | 'datetime-local' | 'color' | 'textarea';
8
- export { Input, Select, Radio, Checkbox, Switch, Slider, };
9
+ export { Input, Select, Radio, Checkbox, Switch, Slider, Form, };
@@ -4,4 +4,5 @@ import Radio from './Radio.svelte';
4
4
  import Checkbox from './Checkbox.svelte';
5
5
  import Switch from './Switch.svelte';
6
6
  import Slider from './Slider.svelte';
7
- export { Input, Select, Radio, Checkbox, Switch, Slider, };
7
+ import Form from './Form.svelte';
8
+ export { Input, Select, Radio, Checkbox, Switch, Slider, Form, };
@@ -2,10 +2,7 @@
2
2
 
3
3
  <div class="modal" class:active>
4
4
  <div class="modal-body">
5
- <button class="btn-close"
6
- on:click={close}>
7
- X
8
- </button>
5
+ <CloseButton on:click={close} />
9
6
  {#if title}
10
7
  <h4 class="modal-title">{title}</h4>
11
8
  {/if}
@@ -27,6 +24,7 @@
27
24
  </div>
28
25
 
29
26
  <script lang="ts">import Button from '../Button.svelte';
27
+ import CloseButton from '../CloseButton.svelte';
30
28
  export let active = false;
31
29
  export let title = '';
32
30
  export let subTitle = '';
@@ -40,15 +38,7 @@ function handleKeydown({ key }) {
40
38
  }
41
39
  </script>
42
40
 
43
- <style lang="scss">.btn-close {
44
- border: 0;
45
- }
46
- .btn-close:hover {
47
- box-shadow: none;
48
- transform: none;
49
- }
50
-
51
- .modal.active {
41
+ <style lang="scss">.modal.active {
52
42
  opacity: 1;
53
43
  visibility: visible;
54
44
  }
@@ -1,4 +1,5 @@
1
- <nav class:border class:fixed
1
+ <nav class={`${$$restProps.class ?? ''} paper-navbar`}
2
+ class:border class:fixed
2
3
  class:split-nav={split}>
3
4
  {#if $$slots.brand}
4
5
  <div class="nav-brand">
@@ -31,4 +32,8 @@ function collapse() {
31
32
  max-height: 960px;
32
33
  opacity: 1;
33
34
  padding: 0;
35
+ }
36
+
37
+ :global(.paper-navbar li a.paper-btn) {
38
+ display: initial;
34
39
  }</style>
@@ -1,6 +1,7 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
2
  declare const __propDef: {
3
3
  props: {
4
+ [x: string]: any;
4
5
  border?: boolean;
5
6
  fixed?: boolean;
6
7
  split?: boolean;
@@ -0,0 +1,17 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" fill="currentColor"
2
+ width={dimension} height={dimension} viewBox="0 0 24 24">
3
+ {#if type === 'right'}
4
+ <path d="M5 3l3.057-3 11.943 12-11.943 12-3.057-3 9-9z" />
5
+ {:else}
6
+ <path d="M16.67 0l2.83 2.829-9.339 9.175 9.339 9.167-2.83 2.829-12.17-11.996z" />
7
+ {/if}
8
+ </svg>
9
+
10
+ <script lang="ts">;
11
+ ;
12
+ import arrowDimension from './arrow-dimension';
13
+ export let size;
14
+ export let type;
15
+ let dimension;
16
+ $: dimension = arrowDimension[size];
17
+ </script>
@@ -0,0 +1,19 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { PaperSize } from '../../types';
3
+ import type { Direction } from '.';
4
+ declare const __propDef: {
5
+ props: {
6
+ size: PaperSize;
7
+ type: Direction;
8
+ };
9
+ events: {
10
+ [evt: string]: CustomEvent<any>;
11
+ };
12
+ slots: {};
13
+ };
14
+ export declare type ArrowProps = typeof __propDef.props;
15
+ export declare type ArrowEvents = typeof __propDef.events;
16
+ export declare type ArrowSlots = typeof __propDef.slots;
17
+ export default class Arrow extends SvelteComponentTyped<ArrowProps, ArrowEvents, ArrowSlots> {
18
+ }
19
+ export {};
@@ -0,0 +1,23 @@
1
+ <Button {size} {type}
2
+ isLink {disabled}
3
+ aria-label={ariaLabel}
4
+ on:click={clickHandler}>
5
+ {#if label}
6
+ {label}
7
+ {:else}
8
+ <Arrow {size}
9
+ type={action === 'next' ? 'right' : 'left'} />
10
+ {/if}
11
+ </Button>
12
+
13
+ <script lang="ts">import Button from '../Button.svelte';
14
+ import Arrow from './Arrow.svelte';
15
+ ;
16
+ export let size;
17
+ export let label;
18
+ export let action;
19
+ export let type;
20
+ export let disabled;
21
+ export let clickHandler;
22
+ export let ariaLabel;
23
+ </script>
@@ -0,0 +1,23 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { PaperSize, PaperType } from '../../types';
3
+ declare const __propDef: {
4
+ props: {
5
+ size: PaperSize;
6
+ label: string;
7
+ action: 'previous' | 'next';
8
+ type: PaperType;
9
+ disabled: boolean;
10
+ clickHandler: (e: MouseEvent) => any;
11
+ ariaLabel: string;
12
+ };
13
+ events: {
14
+ [evt: string]: CustomEvent<any>;
15
+ };
16
+ slots: {};
17
+ };
18
+ export declare type NavigationButtonProps = typeof __propDef.props;
19
+ export declare type NavigationButtonEvents = typeof __propDef.events;
20
+ export declare type NavigationButtonSlots = typeof __propDef.slots;
21
+ export default class NavigationButton extends SvelteComponentTyped<NavigationButtonProps, NavigationButtonEvents, NavigationButtonSlots> {
22
+ }
23
+ export {};
@@ -0,0 +1,122 @@
1
+ <section {...$$restProps}>
2
+ {#if navigation}
3
+ <NavigationButton
4
+ type={highlightedStyle}
5
+ {size} action="previous"
6
+ label={previousLabel}
7
+ disabled={current <= 1}
8
+ clickHandler={changePage.bind(null, current-1)}
9
+ ariaLabel={ariaPreviousLabel} />
10
+ {/if}
11
+
12
+ {#if simple}
13
+ {current} / {pageCount}
14
+ {:else}
15
+ <ul class="padding-none">
16
+ {#each pages as {idx, show}}
17
+ <li>
18
+ {#if show}
19
+ <Button {size} isLink
20
+ on:click={changePage.bind(null, idx)}
21
+ type={idx === current ? highlightedStyle : defaultStyle}
22
+ aria-label={ariaPageLabel?.(idx) ?? `Page ${idx}`}
23
+ aria-current={idx === current}>
24
+ {idx}
25
+ </Button>
26
+ {:else if shouldDisplayEllipsis(idx)}
27
+ …
28
+ {/if}
29
+ </li>
30
+ {/each}
31
+ </ul>
32
+ {/if}
33
+
34
+ {#if navigation}
35
+ <NavigationButton
36
+ type={highlightedStyle}
37
+ {size} action="next"
38
+ label={nextLabel}
39
+ disabled={current >= pageCount}
40
+ clickHandler={changePage.bind(null, current+1)}
41
+ ariaLabel={ariaNextLabel} />
42
+ {/if}
43
+
44
+ {#if jumper}
45
+ <span on:keypress={submitJumper}>
46
+ <Input class="paper-pagination-input"
47
+ bind:value={jumperValue}
48
+ type="number" placeholder="Go to"
49
+ min="1" max={pageCount} step="1" />
50
+ </span>
51
+ {/if}
52
+ </section>
53
+
54
+ <script lang="ts">import { createEventDispatcher } from 'svelte';
55
+ import Button from '../Button.svelte';
56
+ import Input from '../Form/Input.svelte';
57
+ ;
58
+ import NavigationButton from './NavigationButton.svelte';
59
+ export let total;
60
+ export let pageSize = 10;
61
+ export let current = 1;
62
+ export let size = 'small';
63
+ export let navigation = true;
64
+ export let simple = false;
65
+ export let previousLabel = null;
66
+ export let nextLabel = null;
67
+ export let highlightedStyle = 'secondary';
68
+ export let defaultStyle = null;
69
+ export let rangeBetween = null;
70
+ export let jumper = false;
71
+ export let ariaPreviousLabel = 'previous page';
72
+ export let ariaNextLabel = 'next page';
73
+ export let ariaPageLabel = null;
74
+ const dispatch = createEventDispatcher();
75
+ let jumperValue;
76
+ let pageCount;
77
+ $: pageCount = Math.ceil(total / pageSize);
78
+ let pages;
79
+ $: if (current) {
80
+ pages = Array.from({ length: pageCount }, (_, i) => ({ idx: ++i, show: shouldDisplayButton(i) }));
81
+ }
82
+ function submitJumper({ code }) {
83
+ const toPage = Number(jumperValue);
84
+ if (code !== 'Enter' || pageInvalid(toPage))
85
+ return;
86
+ changePage(toPage);
87
+ }
88
+ function pageInvalid(idx) {
89
+ return idx < 1 || idx > pageCount || !Number.isInteger(idx);
90
+ }
91
+ function shouldDisplayButton(idx) {
92
+ if (!rangeBetween || [1, pageCount].includes(idx))
93
+ return true;
94
+ return idx >= (current - rangeBetween)
95
+ && idx <= (current + rangeBetween);
96
+ }
97
+ function shouldDisplayEllipsis(idx) {
98
+ return pages[idx - 2].show;
99
+ }
100
+ function changePage(val) {
101
+ if (pageInvalid(val))
102
+ return;
103
+ current = val;
104
+ dispatch('change', current);
105
+ }
106
+ </script>
107
+
108
+ <style lang="scss">ul, li {
109
+ display: inline;
110
+ }
111
+
112
+ ul li {
113
+ text-indent: 0;
114
+ }
115
+ ul li::before {
116
+ content: "";
117
+ }
118
+
119
+ :global(.paper-pagination-input) {
120
+ display: inline;
121
+ width: 4rem;
122
+ }</style>
@@ -0,0 +1,34 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { PaperSize, PaperType } from '../../types';
3
+ declare const __propDef: {
4
+ props: {
5
+ [x: string]: any;
6
+ total: number;
7
+ pageSize?: number;
8
+ current?: number;
9
+ size?: PaperSize;
10
+ navigation?: boolean;
11
+ simple?: boolean;
12
+ previousLabel?: string;
13
+ nextLabel?: string;
14
+ highlightedStyle?: PaperType;
15
+ defaultStyle?: PaperType;
16
+ rangeBetween?: number;
17
+ jumper?: boolean;
18
+ ariaPreviousLabel?: string;
19
+ ariaNextLabel?: string;
20
+ ariaPageLabel?: (idx: number) => string;
21
+ };
22
+ events: {
23
+ change: CustomEvent<any>;
24
+ } & {
25
+ [evt: string]: CustomEvent<any>;
26
+ };
27
+ slots: {};
28
+ };
29
+ export declare type PaginationProps = typeof __propDef.props;
30
+ export declare type PaginationEvents = typeof __propDef.events;
31
+ export declare type PaginationSlots = typeof __propDef.slots;
32
+ export default class Pagination extends SvelteComponentTyped<PaginationProps, PaginationEvents, PaginationSlots> {
33
+ }
34
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { PaperSize } from '../../types';
2
+ declare const arrowDimension: Record<PaperSize, number>;
3
+ export default arrowDimension;
@@ -0,0 +1,6 @@
1
+ const arrowDimension = {
2
+ 'small': 10,
3
+ 'default': 14,
4
+ 'large': 24,
5
+ };
6
+ export default arrowDimension;
@@ -0,0 +1,3 @@
1
+ import Pagination from './Pagination.svelte';
2
+ export declare type Direction = 'left' | 'right';
3
+ export default Pagination;
@@ -0,0 +1,2 @@
1
+ import Pagination from './Pagination.svelte';
2
+ export default Pagination;
@@ -1,10 +1,10 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
- import type { PaperType } from "../types";
2
+ import type { PaperType, Position } from "../types";
3
3
  declare const __propDef: {
4
4
  props: {
5
5
  [x: string]: any;
6
6
  label?: string;
7
- position?: 'top' | 'right' | 'bottom' | 'left';
7
+ position?: Position;
8
8
  inline?: boolean;
9
9
  background?: PaperType;
10
10
  active?: boolean;
@@ -67,4 +67,15 @@ $: activeTab && updateTabsVisility();
67
67
  .tabs-label-header--active {
68
68
  color: var(--primary);
69
69
  border-bottom: 3px solid var(--secondary);
70
+ }
71
+
72
+ :global(.tabs input) {
73
+ display: block;
74
+ }
75
+
76
+ :global(.tabs label) {
77
+ all: inherit;
78
+ }
79
+ :global(.tabs label):hover {
80
+ all: inherit;
70
81
  }</style>
@@ -0,0 +1,78 @@
1
+ {#if active}
2
+ <div class={classes}
3
+ bind:this={toastElement}
4
+ on:mouseenter={pause}
5
+ on:mouseleave={dismiss}
6
+ in:fly={{ y: position.includes('top') ? -100 : 100 }}
7
+ out:fade={{ duration: 300 }}
8
+ role="alert">
9
+ {@html message}
10
+ {#if dismissible||indefinite}
11
+ <CloseButton ariaLabel={closeAriaLabel}
12
+ on:click={close} />
13
+ {/if}
14
+ </div>
15
+ {/if}
16
+
17
+ <script lang="ts">import { onMount } from 'svelte';
18
+ import { fly, fade } from 'svelte/transition';
19
+ ;
20
+ ;
21
+ import { computeClasses } from '../../utils';
22
+ import ToastContainer, { containerClass } from './ToastContainer.svelte';
23
+ import CloseButton from '../CloseButton.svelte';
24
+ export let message;
25
+ export let type = 'primary';
26
+ export let duration = 2000;
27
+ export let position = 'top-right';
28
+ export let pauseOnHover = false;
29
+ export let dismissible = false;
30
+ export let indefinite = false;
31
+ export let closeAriaLabel = 'close';
32
+ export let onClose = null;
33
+ let active = true;
34
+ let toastElement;
35
+ let timeoutId;
36
+ $: containerSelector = `.${containerClass}.${position}`;
37
+ $: classes = `alert margin-small shadow ${computeClasses('alert', { type })}`;
38
+ onMount(() => {
39
+ insert();
40
+ if (!indefinite) {
41
+ timeoutId = window.setTimeout(close, duration);
42
+ }
43
+ if (timeoutId) {
44
+ return () => clearTimeout(timeoutId);
45
+ }
46
+ });
47
+ function pause() {
48
+ if (!pauseOnHover || indefinite)
49
+ return;
50
+ clearTimeout(timeoutId);
51
+ }
52
+ function dismiss() {
53
+ if (!pauseOnHover || indefinite)
54
+ return;
55
+ close();
56
+ }
57
+ function close() {
58
+ active = false;
59
+ onClose === null || onClose === void 0 ? void 0 : onClose();
60
+ }
61
+ function setupContainer() {
62
+ new ToastContainer({
63
+ target: document.body,
64
+ props: { position },
65
+ });
66
+ return document.querySelector(containerSelector);
67
+ }
68
+ function insert() {
69
+ const container = document.querySelector(containerSelector) || setupContainer();
70
+ container.insertAdjacentElement('afterbegin', toastElement);
71
+ }
72
+ </script>
73
+
74
+ <style>
75
+ div {
76
+ width: 250px;
77
+ }
78
+ </style>
@@ -0,0 +1,26 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { PaperType } from '../../types';
3
+ import type { ToastPosition } from './';
4
+ declare const __propDef: {
5
+ props: {
6
+ message: string;
7
+ type?: PaperType;
8
+ duration?: number;
9
+ position?: ToastPosition;
10
+ pauseOnHover?: boolean;
11
+ dismissible?: boolean;
12
+ indefinite?: boolean;
13
+ closeAriaLabel?: string;
14
+ onClose?: Function;
15
+ };
16
+ events: {
17
+ [evt: string]: CustomEvent<any>;
18
+ };
19
+ slots: {};
20
+ };
21
+ export declare type ToastProps = typeof __propDef.props;
22
+ export declare type ToastEvents = typeof __propDef.events;
23
+ export declare type ToastSlots = typeof __propDef.slots;
24
+ export default class Toast extends SvelteComponentTyped<ToastProps, ToastEvents, ToastSlots> {
25
+ }
26
+ export {};
@@ -0,0 +1,37 @@
1
+ <div class="{containerClass} {position}">
2
+ </div>
3
+
4
+ <script lang="ts" context="module">export const containerClass = 'paper-toast-container';
5
+ </script>
6
+
7
+ <script lang="ts">;
8
+ export let position = 'top-right';
9
+ </script>
10
+
11
+ <style lang="scss">:global(.paper-toast-container:is(.top, .bottom) > div) {
12
+ align-self: center;
13
+ }
14
+
15
+ :global(.paper-toast-container:is([class*=right]) > div) {
16
+ align-self: end;
17
+ }
18
+
19
+ div {
20
+ position: fixed;
21
+ display: flex;
22
+ width: 100%;
23
+ padding: 2em;
24
+ overflow: hidden;
25
+ z-index: 9999;
26
+ flex-direction: column;
27
+ }
28
+ div[class*=top] {
29
+ top: 0;
30
+ }
31
+ div[class*=bottom] {
32
+ bottom: 0;
33
+ flex-direction: column-reverse;
34
+ }
35
+ div[class*=left] {
36
+ left: 0;
37
+ }</style>
@@ -0,0 +1,18 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ export declare const containerClass = "paper-toast-container";
3
+ import type { ToastPosition } from './';
4
+ declare const __propDef: {
5
+ props: {
6
+ position?: ToastPosition;
7
+ };
8
+ events: {
9
+ [evt: string]: CustomEvent<any>;
10
+ };
11
+ slots: {};
12
+ };
13
+ export declare type ToastContainerProps = typeof __propDef.props;
14
+ export declare type ToastContainerEvents = typeof __propDef.events;
15
+ export declare type ToastContainerSlots = typeof __propDef.slots;
16
+ export default class ToastContainer extends SvelteComponentTyped<ToastContainerProps, ToastContainerEvents, ToastContainerSlots> {
17
+ }
18
+ export {};
@@ -0,0 +1,32 @@
1
+ import type { PaperType, PositionY } from '../../types';
2
+ export declare type ToastPosition = PositionY | 'top-right' | 'bottom-right' | 'bottom-left' | 'top-left';
3
+ interface ToastProps {
4
+ message: string;
5
+ type?: PaperType;
6
+ duration?: number;
7
+ position?: ToastPosition;
8
+ pauseOnHover?: boolean;
9
+ dismissible?: boolean;
10
+ indefinite?: boolean;
11
+ closeAriaLabel?: string;
12
+ onClose?: Function;
13
+ }
14
+ interface ToastMethods {
15
+ open: (props: ToastProps | string) => void;
16
+ info: (options: OpenWithTypeParams | string) => void;
17
+ success: (options: OpenWithTypeParams | string) => void;
18
+ warning: (options: OpenWithTypeParams | string) => void;
19
+ warn: (options: OpenWithTypeParams | string) => void;
20
+ danger: (options: OpenWithTypeParams | string) => void;
21
+ error: (options: OpenWithTypeParams | string) => void;
22
+ }
23
+ declare type OpenWithTypeParams = Omit<ToastProps, 'type'>;
24
+ export declare function open(props: ToastProps | string): void;
25
+ export declare const info: (options: OpenWithTypeParams | string) => void;
26
+ export declare const success: (options: OpenWithTypeParams | string) => void;
27
+ export declare const warning: (options: OpenWithTypeParams | string) => void;
28
+ export declare const warn: (options: OpenWithTypeParams | string) => void;
29
+ export declare const danger: (options: OpenWithTypeParams | string) => void;
30
+ export declare const error: (options: OpenWithTypeParams | string) => void;
31
+ declare const _default: ToastMethods;
32
+ export default _default;
@@ -0,0 +1,37 @@
1
+ import Toast from './Toast.svelte';
2
+ export function open(props) {
3
+ if (typeof props === 'string')
4
+ props = { message: props };
5
+ new Toast({
6
+ target: document.body,
7
+ props,
8
+ intro: true,
9
+ });
10
+ }
11
+ function openType(type) {
12
+ return (options) => {
13
+ const props = {
14
+ type,
15
+ message: '',
16
+ };
17
+ if (typeof options === 'string')
18
+ props.message = options;
19
+ else
20
+ Object.assign(props, options);
21
+ new Toast({
22
+ target: document.body,
23
+ props,
24
+ intro: true,
25
+ });
26
+ };
27
+ }
28
+ export const info = openType('secondary');
29
+ export const success = openType('success');
30
+ export const warning = openType('warning');
31
+ export const warn = warning;
32
+ export const danger = openType('danger');
33
+ export const error = danger;
34
+ Object.assign(Toast, {
35
+ open, info, success, warning, warn, danger
36
+ });
37
+ export default Toast;
package/index.d.ts CHANGED
@@ -5,11 +5,13 @@ import Breadcrumb from './components/Breadcrumb.svelte';
5
5
  import Navbar from './components/Navbar.svelte';
6
6
  import Modal from './components/Modal';
7
7
  import { Tabs, Tab } from './components/Tabs';
8
- import { Input, Select, Radio, Checkbox, Switch, Slider } from './components/Form';
8
+ import { Input, Select, Radio, Checkbox, Switch, Slider, Form } from './components/Form';
9
9
  import Article from './components/Article.svelte';
10
10
  import Card from './components/Card.svelte';
11
11
  import Collapsible from './components/Collapsible.svelte';
12
12
  import Popover from './components/Popover.svelte';
13
13
  import Progress from './components/Progress.svelte';
14
14
  import Table from './components/Table.svelte';
15
- export { Button, Alert, Badge, Breadcrumb, Navbar, Modal, Tabs, Tab, Input, Select, Radio, Checkbox, Switch, Slider, Article, Card, Collapsible, Popover, Progress, Table, };
15
+ import Pagination from './components/Pagination';
16
+ import Toast from './components/Toast';
17
+ export { Button, Alert, Badge, Breadcrumb, Navbar, Modal, Tabs, Tab, Form, Input, Select, Radio, Checkbox, Switch, Slider, Article, Card, Collapsible, Popover, Progress, Table, Pagination, Toast, };
package/index.js CHANGED
@@ -5,11 +5,13 @@ import Breadcrumb from './components/Breadcrumb.svelte';
5
5
  import Navbar from './components/Navbar.svelte';
6
6
  import Modal from './components/Modal';
7
7
  import { Tabs, Tab } from './components/Tabs';
8
- import { Input, Select, Radio, Checkbox, Switch, Slider } from './components/Form';
8
+ import { Input, Select, Radio, Checkbox, Switch, Slider, Form } from './components/Form';
9
9
  import Article from './components/Article.svelte';
10
10
  import Card from './components/Card.svelte';
11
11
  import Collapsible from './components/Collapsible.svelte';
12
12
  import Popover from './components/Popover.svelte';
13
13
  import Progress from './components/Progress.svelte';
14
14
  import Table from './components/Table.svelte';
15
- export { Button, Alert, Badge, Breadcrumb, Navbar, Modal, Tabs, Tab, Input, Select, Radio, Checkbox, Switch, Slider, Article, Card, Collapsible, Popover, Progress, Table, };
15
+ import Pagination from './components/Pagination';
16
+ import Toast from './components/Toast';
17
+ export { Button, Alert, Badge, Breadcrumb, Navbar, Modal, Tabs, Tab, Form, Input, Select, Radio, Checkbox, Switch, Slider, Article, Card, Collapsible, Popover, Progress, Table, Pagination, Toast, };
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "papercss",
9
9
  "components"
10
10
  ],
11
- "version": "0.1.2",
11
+ "version": "0.2.5",
12
12
  "repository": {
13
13
  "type": "git",
14
14
  "url": "git+https://github.com/Oli8/spaper.git"
@@ -33,8 +33,10 @@
33
33
  "./components/Breadcrumb.svelte": "./components/Breadcrumb.svelte",
34
34
  "./components/Button.svelte": "./components/Button.svelte",
35
35
  "./components/Card.svelte": "./components/Card.svelte",
36
+ "./components/CloseButton.svelte": "./components/CloseButton.svelte",
36
37
  "./components/Collapsible.svelte": "./components/Collapsible.svelte",
37
38
  "./components/Form/Checkbox.svelte": "./components/Form/Checkbox.svelte",
39
+ "./components/Form/Form.svelte": "./components/Form/Form.svelte",
38
40
  "./components/Form/Input.svelte": "./components/Form/Input.svelte",
39
41
  "./components/Form/Radio.svelte": "./components/Form/Radio.svelte",
40
42
  "./components/Form/Select.svelte": "./components/Form/Select.svelte",
@@ -45,12 +47,20 @@
45
47
  "./components/Modal/Modal.svelte": "./components/Modal/Modal.svelte",
46
48
  "./components/Modal": "./components/Modal/index.js",
47
49
  "./components/Navbar.svelte": "./components/Navbar.svelte",
50
+ "./components/Pagination/Arrow.svelte": "./components/Pagination/Arrow.svelte",
51
+ "./components/Pagination/NavigationButton.svelte": "./components/Pagination/NavigationButton.svelte",
52
+ "./components/Pagination/Pagination.svelte": "./components/Pagination/Pagination.svelte",
53
+ "./components/Pagination/arrow-dimension.js": "./components/Pagination/arrow-dimension.js",
54
+ "./components/Pagination": "./components/Pagination/index.js",
48
55
  "./components/Popover.svelte": "./components/Popover.svelte",
49
56
  "./components/Progress.svelte": "./components/Progress.svelte",
50
57
  "./components/Table.svelte": "./components/Table.svelte",
51
58
  "./components/Tabs/Tab.svelte": "./components/Tabs/Tab.svelte",
52
59
  "./components/Tabs/Tabs.svelte": "./components/Tabs/Tabs.svelte",
53
60
  "./components/Tabs": "./components/Tabs/index.js",
61
+ "./components/Toast/Toast.svelte": "./components/Toast/Toast.svelte",
62
+ "./components/Toast/ToastContainer.svelte": "./components/Toast/ToastContainer.svelte",
63
+ "./components/Toast": "./components/Toast/index.js",
54
64
  "./components/style.scss": "./components/style.scss",
55
65
  ".": "./index.js",
56
66
  "./utils.js": "./utils.js"
package/types.d.ts CHANGED
@@ -7,3 +7,7 @@ export type PaperFlexPlacement = 'spaces' | 'edges' | 'right' | 'center' | 'left
7
7
  export type PaperAlign = 'left' | 'center' | 'right';
8
8
 
9
9
  export type Attributes = Record<string, string|boolean>;
10
+
11
+ export type PositionY = 'top' | 'bottom';
12
+ export type PositionX = 'left' | 'right';
13
+ export type Position = PositionX | PositionY;
package/utils.d.ts CHANGED
@@ -1 +1,9 @@
1
+ import type { Attributes } from './types';
2
+ interface getDomAttributesParams {
3
+ props: Attributes;
4
+ classes: string;
5
+ toOmit?: string[];
6
+ }
1
7
  export declare function computeClasses(elPrefix: string, props: Record<string, any>): string;
8
+ export declare function getDomAttributes({ props, classes, toOmit }: getDomAttributesParams): Attributes;
9
+ export {};
package/utils.js CHANGED
@@ -1,3 +1,4 @@
1
+ import omit from 'lodash.omit';
1
2
  const propToClass = {
2
3
  size: (pf, val) => `${pf}-${val}`,
3
4
  block: (pf, _val) => `${pf}-block`,
@@ -11,3 +12,8 @@ export function computeClasses(elPrefix, props) {
11
12
  .join(' ');
12
13
  }
13
14
  ;
15
+ export function getDomAttributes({ props, classes, toOmit = [] }) {
16
+ return {
17
+ ...omit(props, toOmit), class: classes
18
+ };
19
+ }