@wishbone-media/spark 0.22.0 → 0.23.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wishbone-media/spark",
3
- "version": "0.22.0",
3
+ "version": "0.23.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -9,14 +9,6 @@
9
9
  --ht-header-highlighted-background-color: transparent;
10
10
  }
11
11
 
12
- .spark-table .handsontable td.current {
13
- @apply relative;
14
-
15
- &::before {
16
- @apply absolute opacity-[0.14] content-[''] inset-0 bg-[var(--ht-cell-selection-background-color,#1a42e8)];
17
- }
18
- }
19
-
20
12
  .spark-table .handsontable tr.ht__row_odd:hover td,
21
13
  .spark-table .handsontable tr.ht__row_even:hover td {
22
14
  @apply !bg-gray-100;
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Spark Currency Renderer
3
+ *
4
+ * Formats numbers as Australian currency with dollar sign and comma separators.
5
+ *
6
+ * Usage:
7
+ * {
8
+ * data: 'total',
9
+ * renderer: 'spark.currency',
10
+ * rendererConfig: {
11
+ * decimals: 2, // Decimal places (default: 2)
12
+ * emptyText: '-', // Text for null/empty values (default: '')
13
+ * }
14
+ * }
15
+ *
16
+ * Examples:
17
+ * - 1234.5 → "$1,234.50"
18
+ * - 1000000 → "$1,000,000.00"
19
+ * - -500 → "-$500.00"
20
+ * - null → ""
21
+ */
22
+
23
+ /**
24
+ * Format a number as Australian currency
25
+ * @param {number} value
26
+ * @param {number} decimals
27
+ * @returns {string}
28
+ */
29
+ const formatCurrency = (value, decimals = 2) => {
30
+ const num = Number(value)
31
+ if (isNaN(num)) return null
32
+
33
+ const isNegative = num < 0
34
+ const absValue = Math.abs(num)
35
+
36
+ // Format with commas and decimals
37
+ const formatted = absValue.toLocaleString('en-AU', {
38
+ minimumFractionDigits: decimals,
39
+ maximumFractionDigits: decimals,
40
+ })
41
+
42
+ // Add dollar sign (after negative sign if negative)
43
+ return isNegative ? `-$${formatted}` : `$${formatted}`
44
+ }
45
+
46
+ export const currencyRenderer = (sparkTable) => {
47
+ return (instance, td, row, col, prop, value, cellProperties) => {
48
+ td.innerHTML = ''
49
+ td.classList.add('spark-table-cell-currency')
50
+
51
+ const config = cellProperties.rendererConfig || {}
52
+ const { decimals = 2, emptyText = '' } = config
53
+
54
+ // Handle null/empty values
55
+ if (value === null || value === undefined || value === '') {
56
+ td.textContent = emptyText
57
+ return
58
+ }
59
+
60
+ const formatted = formatCurrency(value, decimals)
61
+
62
+ if (formatted === null) {
63
+ td.textContent = emptyText
64
+ return
65
+ }
66
+
67
+ const span = document.createElement('span')
68
+ span.textContent = formatted
69
+ td.appendChild(span)
70
+ }
71
+ }
@@ -2,6 +2,7 @@ import { baseRenderer, registerRenderer } from 'handsontable/renderers'
2
2
  import { actionsRenderer } from './actions.js'
3
3
  import { badgeRenderer } from './badge.js'
4
4
  import { booleanRenderer } from './boolean.js'
5
+ import { currencyRenderer } from './currency.js'
5
6
  import { linkRenderer } from './link.js'
6
7
  import { imageRenderer } from './image.js'
7
8
  import { dateRenderer } from './date.js'
@@ -53,9 +54,11 @@ export const getRenderer = (key) => {
53
54
  * - spark.actions: Inline action buttons
54
55
  * - spark.badge: Colored status badges
55
56
  * - spark.boolean: Boolean indicators with check/times icons
57
+ * - spark.currency: Australian currency formatting
56
58
  * - spark.link: Clickable links (email, phone, custom)
57
59
  * - spark.image: Image thumbnails
58
60
  * - spark.date: Formatted dates
61
+ * - spark.datetime: Advanced datetime formatting with timezone support
59
62
  * - style.capitalize: Legacy renderer for text capitalization
60
63
  *
61
64
  * @param {Object} sparkTable - SparkTable instance
@@ -65,6 +68,7 @@ export const registerSparkRenderers = (sparkTable) => {
65
68
  register('spark.actions', actionsRenderer(sparkTable))
66
69
  register('spark.badge', badgeRenderer(sparkTable))
67
70
  register('spark.boolean', booleanRenderer(sparkTable))
71
+ register('spark.currency', currencyRenderer(sparkTable))
68
72
  register('spark.link', linkRenderer(sparkTable))
69
73
  register('spark.image', imageRenderer(sparkTable))
70
74
  register('spark.date', dateRenderer(sparkTable))