sveltacular 0.0.63 → 0.0.65

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,5 +1,23 @@
1
- <script></script>
1
+ <script>import { getContext } from "svelte";
2
+ import { listContext } from "./list.js";
3
+ const ctx = getContext(listContext);
4
+ const listStyle = ctx.style || "none";
5
+ </script>
2
6
 
3
- <li>
7
+ <li class="{listStyle}">
4
8
  <slot />
5
- </li>
9
+ </li>
10
+
11
+
12
+ <style>
13
+ li.striped {
14
+ background-color: var(--list-row-bg, #fff);
15
+ color: var(--list-row-fg, #000);
16
+ padding: 0.5rem;
17
+
18
+ &:nth-of-type(odd) {
19
+ background-color: var(--list-row-alt-bg, #eee);
20
+ color: var(--list-row-alt-fg, #000);
21
+ }
22
+ }
23
+ </style>
@@ -0,0 +1,5 @@
1
+ export type ListStyle = 'none' | 'disc' | 'circle' | 'square' | 'decimal' | 'decimal-leading-zero' | 'striped';
2
+ export interface ListContext {
3
+ style: ListStyle;
4
+ }
5
+ export declare const listContext = "listContext";
@@ -0,0 +1 @@
1
+ export const listContext = 'listContext';
@@ -1,5 +1,11 @@
1
- <script>export let type = "unordered";
1
+ <script>import { setContext } from "svelte";
2
+ import { listContext } from "./list.js";
3
+ export let type = "unordered";
2
4
  export let style = "none";
5
+ const ctx = {
6
+ style
7
+ };
8
+ setContext(listContext, ctx);
3
9
  </script>
4
10
 
5
11
  {#if type === 'unordered'}
@@ -14,6 +20,12 @@ export let style = "none";
14
20
 
15
21
  <style>.none {
16
22
  list-style-type: none;
23
+ padding-left: 0.5rem;
24
+ }
25
+
26
+ .striped {
27
+ list-style-type: none;
28
+ padding-left: 0;
17
29
  }
18
30
 
19
31
  .disc {
@@ -1,8 +1,9 @@
1
1
  import { SvelteComponent } from "svelte";
2
+ import { type ListStyle } from "./list.js";
2
3
  declare const __propDef: {
3
4
  props: {
4
5
  type?: "unordered" | "ordered" | undefined;
5
- style?: "none" | "circle" | "square" | "disc" | "decimal" | "decimal-leading-zero" | undefined;
6
+ style?: ListStyle | undefined;
6
7
  };
7
8
  events: {
8
9
  [evt: string]: CustomEvent<any>;
@@ -1,8 +1,10 @@
1
1
  <script>export let size = "md";
2
2
  export let style = "standard";
3
+ export let shape = "rounded";
4
+ export let fill = "solid";
3
5
  </script>
4
6
 
5
- <span class="pill {size} {style}">
7
+ <span class="pill {size} {style} {shape} {fill}">
6
8
  <slot />
7
9
  </span>
8
10
 
@@ -33,4 +35,30 @@ export let style = "standard";
33
35
  }
34
36
  .pill.square {
35
37
  border-radius: 0;
38
+ }
39
+ .pill.outline {
40
+ background-color: transparent;
41
+ border: 1px solid #4a5568;
42
+ color: #4a5568;
43
+ }
44
+ .pill.circular {
45
+ border-radius: 50%;
46
+ }
47
+ .pill.positive {
48
+ background-color: #0a5200;
49
+ color: #fff;
50
+ }
51
+ .pill.positive.outline {
52
+ background-color: transparent;
53
+ border: 1px solid #0a5200;
54
+ color: #0a5200;
55
+ }
56
+ .pill.negative {
57
+ background-color: #570000;
58
+ color: #fff;
59
+ }
60
+ .pill.negative.outline {
61
+ background-color: transparent;
62
+ border: 1px solid #570000;
63
+ color: #570000;
36
64
  }</style>
@@ -3,7 +3,9 @@ import type { FormFieldSizeOptions } from '../../types/form.js';
3
3
  declare const __propDef: {
4
4
  props: {
5
5
  size?: FormFieldSizeOptions | undefined;
6
- style?: "standard" | "badge" | "square" | undefined;
6
+ style?: "positive" | "negative" | "standard" | undefined;
7
+ shape?: "circular" | "square" | "rounded" | "badge" | undefined;
8
+ fill?: "outline" | "solid" | undefined;
7
9
  };
8
10
  events: {
9
11
  [evt: string]: CustomEvent<any>;
@@ -1,3 +1,5 @@
1
+
2
+
1
3
  <svg
2
4
  class="w-6 h-6 text-gray-800 dark:text-white"
3
5
  aria-hidden="true"
@@ -8,17 +8,19 @@ import TableHeaderRow from "./table-header-row.svelte";
8
8
  import TableHeader from "./table-header.svelte";
9
9
  import TableRow from "./table-row.svelte";
10
10
  import Table from "./table.svelte";
11
+ import Button from "../forms/button/button.svelte";
11
12
  import Empty from "../generic/empty/empty.svelte";
13
+ import Pill from "../generic/pill/pill.svelte";
12
14
  import FolderOpenIcon from "../icons/folder-open-icon.svelte";
13
15
  import Pagination from "../navigation/pagination/pagination.svelte";
14
16
  import Loading from "../placeholders/loading.svelte";
15
17
  import TableCaption from "./table-caption.svelte";
16
- export let caption = "";
18
+ export let captionSide = "top";
19
+ export let captionAlign = "center";
17
20
  export let rows = void 0;
18
21
  export let cols;
19
22
  export let pagination = void 0;
20
- export let editRow = void 0;
21
- export let deleteRow = void 0;
23
+ export let actions = [];
22
24
  export let onPageChange = null;
23
25
  const getColType = (col) => {
24
26
  if (col.type)
@@ -27,14 +29,6 @@ const getColType = (col) => {
27
29
  return "string";
28
30
  return typeof rows[0][col.key];
29
31
  };
30
- const clickEdit = async (row) => {
31
- if (editRow)
32
- await editRow(row);
33
- };
34
- const clickDelete = async (row) => {
35
- if (deleteRow)
36
- await deleteRow(row);
37
- };
38
32
  const format = (row, key) => {
39
33
  const col = cols.find((col2) => col2.key === key);
40
34
  if (!col)
@@ -71,9 +65,9 @@ const filterRows = () => {
71
65
  return rows.filter((_row, index) => index >= startIndex && index < endIndex);
72
66
  };
73
67
  $:
74
- hasActionRow = editRow || deleteRow;
68
+ hasActionCol = actions.length > 0;
75
69
  $:
76
- colCount = Math.max(1, cols.filter((col) => !col.hide).length) + (hasActionRow ? 1 : 0);
70
+ colCount = Math.max(1, cols.filter((col) => !col.hide).length) + (hasActionCol ? 1 : 0);
77
71
  $:
78
72
  totalPages = pagination && rows ? calculateTotalPages() : 1;
79
73
  $:
@@ -81,8 +75,8 @@ $:
81
75
  </script>
82
76
 
83
77
  <Table>
84
- {#if caption}
85
- <TableCaption>{caption}</TableCaption>
78
+ {#if $$slots.default}
79
+ <TableCaption side={captionSide} align={captionAlign}><slot /></TableCaption>
86
80
  {/if}
87
81
  <TableHeader>
88
82
  <TableHeaderRow>
@@ -91,7 +85,7 @@ $:
91
85
  <TableHeaderCell type={getColType(col)} width={col.width}>{col.label}</TableHeaderCell>
92
86
  {/if}
93
87
  {/each}
94
- {#if hasActionRow}
88
+ {#if hasActionCol}
95
89
  <TableHeaderCell type="string" />
96
90
  {/if}
97
91
  </TableHeaderRow>
@@ -119,20 +113,23 @@ $:
119
113
  <TableCell type={col.type || typeof row[col.key]} width={col.width}>
120
114
  {#if col.link}
121
115
  <a href={col.link(row, col.key)}>{format(row, col.key)}</a>
116
+ {:else if col.type == 'email' && row[col.key]}
117
+ <a href={`mailto:${row[col.key]}`}>{format(row, col.key)}</a>
118
+ {:else if col.type == 'check'}
119
+ {#if row[col.key]}
120
+ <Pill shape="circular" style="positive">✔</Pill>
121
+ {/if}
122
122
  {:else}
123
123
  {format(row, col.key)}
124
124
  {/if}
125
125
  </TableCell>
126
126
  {/if}
127
127
  {/each}
128
- {#if hasActionRow}
128
+ {#if hasActionCol}
129
129
  <TableCell type="actions">
130
- {#if editRow}
131
- <button type="button" on:click={() => clickEdit(row)}>Edit</button>
132
- {/if}
133
- {#if deleteRow}
134
- <button type="button" on:click={() => clickDelete(row)}>Delete</button>
135
- {/if}
130
+ {#each actions as action}
131
+ <Button collapse={true} size="sm" type="button" on:click={() => action.onClick(row)}>{action.text}</Button>
132
+ {/each}
136
133
  </TableCell>
137
134
  {/if}
138
135
  </TableRow>
@@ -164,20 +161,9 @@ $:
164
161
  }
165
162
 
166
163
  a {
167
- color: var(--table-link-fg, #00f);
164
+ color: var(--table-link-fg, rgb(0, 0, 200));
168
165
  text-decoration: none;
169
166
  }
170
167
  a:hover {
171
168
  text-decoration: underline;
172
- }
173
-
174
- button {
175
- background: none;
176
- border: none;
177
- cursor: pointer;
178
- color: var(--table-link-fg, #00f);
179
- text-decoration: none;
180
- }
181
- button:hover {
182
- text-decoration: underline;
183
169
  }</style>
@@ -2,12 +2,15 @@ import { SvelteComponent } from "svelte";
2
2
  import type { DataCol, DataRow, PaginationProperties } from '../types/data.js';
3
3
  declare const __propDef: {
4
4
  props: {
5
- caption?: string | undefined;
5
+ captionSide?: "top" | "bottom" | undefined;
6
+ captionAlign?: "center" | "left" | "right" | undefined;
6
7
  rows?: DataRow[] | undefined;
7
8
  cols: DataCol[];
8
9
  pagination?: PaginationProperties | undefined;
9
- editRow?: ((row: DataRow) => unknown) | undefined;
10
- deleteRow?: ((row: DataRow) => unknown) | undefined;
10
+ actions?: {
11
+ text: string;
12
+ onClick: (row: DataRow) => unknown;
13
+ }[] | undefined;
11
14
  /**
12
15
  * Handle page change, which should return the new filtered/fetched rows.
13
16
  */ onPageChange?: ((pagination: PaginationProperties) => Promise<DataRow[]>) | null | undefined;
@@ -15,7 +18,9 @@ declare const __propDef: {
15
18
  events: {
16
19
  [evt: string]: CustomEvent<any>;
17
20
  };
18
- slots: {};
21
+ slots: {
22
+ default: {};
23
+ };
19
24
  };
20
25
  export type DataGridProps = typeof __propDef.props;
21
26
  export type DataGridEvents = typeof __propDef.events;
@@ -1,4 +1,8 @@
1
- <caption>
1
+ <script>export let side = "top";
2
+ export let align = "center";
3
+ </script>
4
+
5
+ <caption class="{side} {align}">
2
6
  <slot />
3
7
  </caption>
4
8
 
@@ -11,4 +15,15 @@
11
15
  text-transform: uppercase;
12
16
  font-family: sans-serif;
13
17
  text-shadow: 1px 1px 1px black;
18
+ text-align: center;
19
+ caption-side: top;
20
+ }
21
+ caption.bottom {
22
+ caption-side: bottom;
23
+ }
24
+ caption.left {
25
+ text-align: left;
26
+ }
27
+ caption.right {
28
+ text-align: right;
14
29
  }</style>
@@ -1,21 +1,8 @@
1
- /** @typedef {typeof __propDef.props} TableCaptionProps */
2
- /** @typedef {typeof __propDef.events} TableCaptionEvents */
3
- /** @typedef {typeof __propDef.slots} TableCaptionSlots */
4
- export default class TableCaption extends SvelteComponent<{
5
- [x: string]: never;
6
- }, {
7
- [evt: string]: CustomEvent<any>;
8
- }, {
9
- default: {};
10
- }> {
11
- }
12
- export type TableCaptionProps = typeof __propDef.props;
13
- export type TableCaptionEvents = typeof __propDef.events;
14
- export type TableCaptionSlots = typeof __propDef.slots;
15
1
  import { SvelteComponent } from "svelte";
16
2
  declare const __propDef: {
17
3
  props: {
18
- [x: string]: never;
4
+ side?: "top" | "bottom" | undefined;
5
+ align?: "center" | "left" | "right" | undefined;
19
6
  };
20
7
  events: {
21
8
  [evt: string]: CustomEvent<any>;
@@ -24,4 +11,9 @@ declare const __propDef: {
24
11
  default: {};
25
12
  };
26
13
  };
14
+ export type TableCaptionProps = typeof __propDef.props;
15
+ export type TableCaptionEvents = typeof __propDef.events;
16
+ export type TableCaptionSlots = typeof __propDef.slots;
17
+ export default class TableCaption extends SvelteComponent<TableCaptionProps, TableCaptionEvents, TableCaptionSlots> {
18
+ }
27
19
  export {};
@@ -17,7 +17,7 @@ $:
17
17
  td.currency, td.number {
18
18
  text-align: right;
19
19
  }
20
- td.boolean {
20
+ td.check, td.boolean {
21
21
  text-align: center;
22
22
  text-transform: uppercase;
23
23
  }
@@ -3,7 +3,6 @@ export let type = void 0;
3
3
  export let width = void 0;
4
4
  $:
5
5
  styleProperties = [
6
- `text-align: ${type === "currency" || type === "number" ? "right" : type === "boolean" ? "center" : "left"}`,
7
6
  "text-overflow: ellipsis",
8
7
  "overflow: hidden",
9
8
  `width: ${width ? width : "auto"}`
@@ -24,11 +23,12 @@ $:
24
23
  letter-spacing: 0.015em;
25
24
  text-transform: uppercase;
26
25
  text-shadow: 1px 1px 1px black;
26
+ text-align: left;
27
27
  }
28
28
  th.currency, th.number {
29
29
  text-align: right;
30
30
  }
31
- th.boolean {
31
+ th.check, th.boolean {
32
32
  text-align: center;
33
33
  }
34
34
  th:last-child {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sveltacular",
3
- "version": "0.0.63",
3
+ "version": "0.0.65",
4
4
  "description": "A Svelte component library",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",