@onsvisual/svelte-components 0.1.59 → 0.1.61

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.
@@ -7,6 +7,10 @@ export function formatDate(str: any, locale?: string, opts?: {
7
7
  day: string;
8
8
  }): string;
9
9
  export function format(val: any, dp?: any): any;
10
+ export function formatter(dp?: any): {
11
+ (value: number): string;
12
+ (value: number | bigint): string;
13
+ };
10
14
  export function ascending(a: any, b: any): number;
11
15
  export function descending(a: any, b: any): number;
12
16
  export function sleep(ms?: number): Promise<any>;
@@ -15,6 +15,8 @@ export default class Card extends SvelteComponentTyped<{
15
15
  }, {
16
16
  [evt: string]: CustomEvent<any>;
17
17
  }, {
18
+ image: {};
19
+ title: {};
18
20
  default: {};
19
21
  }> {
20
22
  }
@@ -39,6 +41,8 @@ declare const __propDef: {
39
41
  [evt: string]: CustomEvent<any>;
40
42
  };
41
43
  slots: {
44
+ image: {};
45
+ title: {};
42
46
  default: {};
43
47
  };
44
48
  };
@@ -1,5 +1,5 @@
1
1
  <script>
2
- import { format, isNumeric, ascending, descending } from "../../js/utils.js";
2
+ import { formatter, isNumeric, ascending, descending } from "../../js/utils.js";
3
3
 
4
4
  /**
5
5
  * An optional title for the table
@@ -46,6 +46,7 @@
46
46
  let sort = columns.map((c) => "none");
47
47
 
48
48
  $: sortable = columns.map((d) => d.sortable).includes(true);
49
+ $: formatters = columns.map((d) => formatter(d.dp));
49
50
  </script>
50
51
 
51
52
  <div
@@ -121,16 +122,14 @@
121
122
  <tbody class="ons-table__body">
122
123
  {#each _data as row}
123
124
  <tr class="ons-table__row">
124
- {#each columns as col}
125
+ {#each columns as col, i}
125
126
  <td
126
127
  class="ons-table__cell"
127
128
  class:ons-table__cell--numeric="{col.numeric}"
128
129
  data-th="{col.label}"
129
130
  >{@html col.numeric && isNumeric(row[col.key])
130
- ? format(row[col.key], col.dp)
131
- : row[col.key]
132
- ? row[col.key]
133
- : "&ndash;"}</td
131
+ ? formatters[i](row[col.key])
132
+ : row[col.key] || "&ndash;"}</td
134
133
  >
135
134
  {/each}
136
135
  </tr>
package/dist/js/utils.js CHANGED
@@ -46,6 +46,15 @@ export const format = (val, dp = null) => {
46
46
  : val.toLocaleString("en-GB");
47
47
  };
48
48
 
49
+ export const formatter = (dp = null) => {
50
+ return Number.isInteger(dp)
51
+ ? new Intl.NumberFormat("en-GB", {
52
+ minimumFractionDigits: dp,
53
+ maximumFractionDigits: dp,
54
+ }).format
55
+ : new Intl.NumberFormat("en-GB").format;
56
+ };
57
+
49
58
  export const ascending = (a, b) =>
50
59
  a == null || b == null ? NaN : a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
51
60
 
@@ -31,31 +31,41 @@
31
31
  <div id="{id}" class="ons-card" aria-describedBy="{id}_text">
32
32
  {#if href && title}
33
33
  <a href="{href}" class="ons-card__link ons-u-db" class:ons-u-vh="{hideTitle}">
34
- {#if image}
35
- <img
36
- class="ons-card__image ons-u-mb-s"
37
- style:width="100%"
38
- src="{image}"
39
- alt="{imageAlt}"
40
- loading="lazy"
41
- />
42
- {/if}
34
+ <slot name="image">
35
+ {#if image}
36
+ <img
37
+ class="ons-card__image ons-u-mb-s"
38
+ style:width="100%"
39
+ src="{image}"
40
+ alt="{imageAlt}"
41
+ loading="lazy"
42
+ />
43
+ {/if}
44
+ </slot>
45
+ <slot name="title">
46
+ <h3
47
+ class="ons-card__title ons-u-fs-m"
48
+ style:padding="{!noBackground && !image
49
+ ? "12px 16px 0"
50
+ : !noBackground
51
+ ? "0 16px"
52
+ : ""}"
53
+ >
54
+ {title}
55
+ </h3>
56
+ </slot>
57
+ </a>
58
+ {:else if title}
59
+ <slot name="title">
43
60
  <h3
44
61
  class="ons-card__title ons-u-fs-m"
45
- style:padding="{!noBackground && !image ? "12px 16px 0" : !noBackground ? "0 16px" : ""}"
62
+ class:ons-u-vh="{hideTitle}"
63
+ style:padding="{!noBackground ? "8px 16px 0" : ""}"
64
+ style:margin-bottom="5px"
46
65
  >
47
66
  {title}
48
67
  </h3>
49
- </a>
50
- {:else if title}
51
- <h3
52
- class="ons-card__title ons-u-fs-m"
53
- class:ons-u-vh="{hideTitle}"
54
- style:padding="{!noBackground ? "8px 16px 0" : ""}"
55
- style:margin-bottom="5px"
56
- >
57
- {title}
58
- </h3>
68
+ </slot>
59
69
  {/if}
60
70
  <div id="{id}_text" class:tile__body="{!noBackground}">
61
71
  <slot />
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onsvisual/svelte-components",
3
- "version": "0.1.59",
3
+ "version": "0.1.61",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "homepage": "https://onsvisual.github.io/svelte-components",