@eifi1/ui-kit 0.15.3 → 0.15.4

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 (69) hide show
  1. package/README.md +8 -7
  2. package/dist/chart.d.ts +51 -1
  3. package/dist/components/amount-input.d.ts +1 -1
  4. package/dist/components/amount-input.js +5 -10
  5. package/dist/components/amount-input.js.map +1 -1
  6. package/dist/components/button-group.d.ts +1 -1
  7. package/dist/components/calculator.d.ts +1 -1
  8. package/dist/components/chart.d.ts +16 -1
  9. package/dist/components/chart.js +65 -37
  10. package/dist/components/chart.js.map +1 -1
  11. package/dist/components/chip.d.ts +8 -2
  12. package/dist/components/chip.js +12 -3
  13. package/dist/components/chip.js.map +1 -1
  14. package/dist/components/copy-button.d.ts +1 -1
  15. package/dist/components/facing-pair.d.ts +51 -0
  16. package/dist/components/file-button.d.ts +1 -1
  17. package/dist/components/file-dropzone.d.ts +1 -1
  18. package/dist/components/form-actions.d.ts +1 -1
  19. package/dist/components/form-actions.js +9 -1
  20. package/dist/components/form-actions.js.map +1 -1
  21. package/dist/components/money-field.d.ts +1 -1
  22. package/dist/components/number-field.d.ts +1 -1
  23. package/dist/components/number-input.d.ts +1 -1
  24. package/dist/components/number-input.js +17 -3
  25. package/dist/components/number-input.js.map +1 -1
  26. package/dist/components/numpad-sheet.d.ts +1 -1
  27. package/dist/components/series-chart.d.ts +79 -1
  28. package/dist/components/series-chart.js +74 -13
  29. package/dist/components/series-chart.js.map +1 -1
  30. package/dist/components/settings-fields.d.ts +1 -1
  31. package/dist/components/text-link.d.ts +1 -1
  32. package/dist/components/time-input.d.ts +1 -1
  33. package/dist/components/ui.d.ts +1 -1
  34. package/dist/hooks/use-file-drop.d.ts +1 -1
  35. package/dist/i18n/defaults.d.ts +1 -1
  36. package/dist/i18n/kit-labels.d.ts +1 -1
  37. package/dist/i18n/kit-labels.js +8 -2
  38. package/dist/i18n/kit-labels.js.map +1 -1
  39. package/dist/i18n/locales/de-CH-informal.d.ts +1 -1
  40. package/dist/i18n/locales/de-CH.d.ts +1 -1
  41. package/dist/i18n/locales/de-informal.d.ts +1 -1
  42. package/dist/i18n/locales/de.d.ts +1 -1
  43. package/dist/i18n/locales/es.d.ts +1 -1
  44. package/dist/i18n/locales/fr.d.ts +1 -1
  45. package/dist/i18n/locales/hu.d.ts +1 -1
  46. package/dist/i18n/locales/it.d.ts +1 -1
  47. package/dist/i18n/locales/zh.d.ts +1 -1
  48. package/dist/index.d.ts +3 -3
  49. package/dist/{kit-labels-BHfRBbHs.d.ts → kit-labels-CnnBd-2N.d.ts} +13 -2
  50. package/dist/lib/format.d.ts +15 -1
  51. package/dist/lib/format.js +16 -0
  52. package/dist/lib/format.js.map +1 -1
  53. package/dist/rhf/fields.d.ts +1 -1
  54. package/dist/rhf/form.d.ts +1 -1
  55. package/dist/rhf.d.ts +1 -1
  56. package/dist/shell/app-shell.d.ts +1 -1
  57. package/dist/shell/top-bar-brand.d.ts +1 -1
  58. package/dist/shell.d.ts +1 -1
  59. package/dist/wizard/stepper-nav.d.ts +1 -1
  60. package/dist/wizard.d.ts +1 -1
  61. package/package.json +1 -1
  62. package/src/components/amount-input.tsx +8 -13
  63. package/src/components/chart.tsx +102 -41
  64. package/src/components/chip.tsx +29 -4
  65. package/src/components/form-actions.tsx +9 -1
  66. package/src/components/number-input.tsx +22 -2
  67. package/src/components/series-chart.tsx +122 -20
  68. package/src/i18n/kit-labels.tsx +19 -1
  69. package/src/lib/format.ts +30 -0
package/src/lib/format.ts CHANGED
@@ -348,3 +348,33 @@ export function useKitFormat(locale?: string): KitFormat {
348
348
  [kitLocale],
349
349
  );
350
350
  }
351
+
352
+ /* ── Currency minor units ──────────────────────────────────────────────────── */
353
+
354
+ /**
355
+ * The decimals a currency is written with — its minor unit: CHF and EUR 2, JPY 0,
356
+ * KWD 3 — from `Intl`, or `undefined` for a code `Intl` does not accept. The rule
357
+ * AmountInput settles a typed figure by, for a host that needs it outside the field.
358
+ */
359
+ export function currencyMinorDigits(currency: string | null | undefined): number | undefined {
360
+ if (!currency) return undefined;
361
+ try {
362
+ return new Intl.NumberFormat("en", { style: "currency", currency }).resolvedOptions().maximumFractionDigits;
363
+ } catch {
364
+ return undefined;
365
+ }
366
+ }
367
+
368
+ /**
369
+ * `value` rounded to the currency's minor unit (or to `digits`), half away from zero,
370
+ * in decimal arithmetic: 93.4213 CHF → 93.42, 1.005 EUR → 1.01 (`Math.round(1.005 *
371
+ * 100)` is 100, since 1.005 is 1.00499… in binary). A non-finite value, or a currency
372
+ * `Intl` does not know without `digits`, comes back unchanged (keksdose live #356: an
373
+ * FX estimate set into an AmountInput showed four decimals).
374
+ */
375
+ export function roundToCurrency(value: number, currency: string | null | undefined, digits?: number): number {
376
+ const places = digits ?? currencyMinorDigits(currency);
377
+ if (places === undefined || !Number.isFinite(value)) return value;
378
+ const magnitude = Number(`${Math.round(Number(`${Math.abs(value)}e${places}`))}e-${places}`);
379
+ return value < 0 ? -magnitude : magnitude;
380
+ }