@onsvisual/svelte-components 0.1.28 → 0.1.30

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.
@@ -33,7 +33,7 @@ declare const __propDef: {
33
33
  variant?: "default" | "ghost";
34
34
  disabled?: boolean;
35
35
  checked?: boolean;
36
- group?: any[];
36
+ group?: any[] | null;
37
37
  };
38
38
  events: {
39
39
  change: CustomEvent<any>;
@@ -5,7 +5,7 @@ export function formatDate(str: any, locale?: string, opts?: {
5
5
  month: string;
6
6
  day: string;
7
7
  }): string;
8
- export function commas(num: any): string;
8
+ export function format(val: any, dp?: any): any;
9
9
  export function ascending(a: any, b: any): number;
10
10
  export function descending(a: any, b: any): number;
11
11
  export function sleep(ms?: number): Promise<any>;
@@ -1,5 +1,5 @@
1
1
  <script>
2
- import { commas, ascending, descending } from "../../js/utils.js";
2
+ import { format, ascending, descending } from "../../js/utils.js";
3
3
 
4
4
  /**
5
5
  * An optional title for the table
@@ -37,7 +37,7 @@
37
37
  */
38
38
  export let data = [];
39
39
  /**
40
- * Optional metadata for formatting columns. Array of {key, label, sortable?, numeric?} objects
40
+ * Optional metadata for formatting columns. Array of {key, label, sortable?, numeric?, dp?} objects
41
41
  * @type {array}
42
42
  */
43
43
  export let columns =
@@ -45,7 +45,6 @@
45
45
  let _data = [...data];
46
46
  let sort = columns.map((c) => "none");
47
47
 
48
- const format = (val, numeric) => (numeric ? commas(val) : val);
49
48
  $: sortable = columns.map((d) => d.sortable).includes(true);
50
49
  </script>
51
50
 
@@ -127,7 +126,11 @@
127
126
  class="ons-table__cell"
128
127
  class:ons-table__cell--numeric="{col.numeric}"
129
128
  data-th="{col.label}"
130
- >{@html row[col.key] ? format(row[col.key], col.numeric) : "&ndash;"}</td
129
+ >{@html row[col.key] && col.numeric
130
+ ? format(row[col.key], col.dp)
131
+ : row[col.key]
132
+ ? row[col.key]
133
+ : "&ndash;"}</td
131
134
  >
132
135
  {/each}
133
136
  </tr>
@@ -30,9 +30,9 @@
30
30
  export let checked = false;
31
31
  /**
32
32
  * Binding for checked state of input
33
- * @type {array}
33
+ * @type {array|null}
34
34
  */
35
- export let group = [];
35
+ export let group = null;
36
36
  /**
37
37
  * (Optional) Extended description for element
38
38
  * @type {string}
package/dist/js/utils.js CHANGED
@@ -33,10 +33,13 @@ export const formatDate = (
33
33
  return date.toLocaleDateString(locale, opts);
34
34
  };
35
35
 
36
- export const commas = (num) => {
37
- const parts = String(num).split(".");
38
- parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
39
- return parts.join(".");
36
+ export const format = (val, dp = null) => {
37
+ return dp
38
+ ? val.toLocaleString("en-GB", {
39
+ minimumFractionDigits: dp,
40
+ maximumFractionDigits: dp,
41
+ })
42
+ : val.toLocaleString("en-GB");
40
43
  };
41
44
 
42
45
  export const ascending = (a, b) =>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onsvisual/svelte-components",
3
- "version": "0.1.28",
3
+ "version": "0.1.30",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "homepage": "https://onsvisual.github.io/svelte-components",