@eifi1/ui-kit 0.15.2 → 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 +103 -39
  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 +155 -43
  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
@@ -417,8 +417,12 @@ interface KitI18n {
417
417
  locale?: string;
418
418
  weekStartsOn?: WeekDay;
419
419
  linkComponent?: KitLinkComponent;
420
+ chartTooltipPlacement?: ChartTooltipPlacement;
420
421
  }
421
422
 
423
+ /** Where a chart shows the values under the pointer — see `SeriesChartTooltip.placement`. */
424
+ export type ChartTooltipPlacement = "cursor" | "above" | "below" | "auto";
425
+
422
426
  /**
423
427
  * What every kit link receives: the anchor attributes the kit decided (href, class,
424
428
  * aria-current, handlers, children, ref). An app's router link maps them —
@@ -475,6 +479,13 @@ export interface UiKitProviderProps {
475
479
  * hash-router `#/path` is handed to it like `/path` (see `pickLinkRenderer`).
476
480
  */
477
481
  linkComponent?: KitLinkComponent;
482
+ /**
483
+ * Where every `SeriesChart` below shows its tooltip when it does not say so itself
484
+ * (`tooltip.placement`) — set once so an app's phone charts stop putting the box under
485
+ * the reader's finger (keksdose #359). Default: `"cursor"`, the box that follows the
486
+ * pointer, as before.
487
+ */
488
+ chartTooltipPlacement?: ChartTooltipPlacement;
478
489
  children: ReactNode;
479
490
  }
480
491
 
@@ -491,6 +502,7 @@ export function UiKitProvider({
491
502
  locale,
492
503
  weekStartsOn,
493
504
  linkComponent,
505
+ chartTooltipPlacement,
494
506
  children,
495
507
  }: UiKitProviderProps) {
496
508
  const outer = useContext(KitI18nContext);
@@ -500,8 +512,9 @@ export function UiKitProvider({
500
512
  weekStartsOn: weekStartsOn ?? outer.weekStartsOn,
501
513
  labels: mergeOverrides(outer.labels, labels),
502
514
  linkComponent: linkComponent ?? outer.linkComponent,
515
+ chartTooltipPlacement: chartTooltipPlacement ?? outer.chartTooltipPlacement,
503
516
  }),
504
- [outer, labels, locale, weekStartsOn, linkComponent],
517
+ [outer, labels, locale, weekStartsOn, linkComponent, chartTooltipPlacement],
505
518
  );
506
519
  return <KitI18nContext.Provider value={value}>{children}</KitI18nContext.Provider>;
507
520
  }
@@ -589,6 +602,11 @@ export function useKitWeekStart(): WeekDay | undefined {
589
602
  return useContext(KitI18nContext).weekStartsOn;
590
603
  }
591
604
 
605
+ /** The provider's `chartTooltipPlacement`, or `undefined` — a chart's own prop wins. */
606
+ export function useKitChartTooltipPlacement(): ChartTooltipPlacement | undefined {
607
+ return useContext(KitI18nContext).chartTooltipPlacement;
608
+ }
609
+
592
610
  /** {@link DEFAULT_FILE_LABELS}, but formatting in the provider's locale. */
593
611
  export function useKitFileLabels(prop?: Partial<FileLabels>): FileLabels {
594
612
  const locale = useKitLocale();
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
+ }