@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.
- package/README.md +8 -7
- package/dist/chart.d.ts +51 -1
- package/dist/components/amount-input.d.ts +1 -1
- package/dist/components/amount-input.js +5 -10
- package/dist/components/amount-input.js.map +1 -1
- package/dist/components/button-group.d.ts +1 -1
- package/dist/components/calculator.d.ts +1 -1
- package/dist/components/chart.d.ts +16 -1
- package/dist/components/chart.js +103 -39
- package/dist/components/chart.js.map +1 -1
- package/dist/components/chip.d.ts +8 -2
- package/dist/components/chip.js +12 -3
- package/dist/components/chip.js.map +1 -1
- package/dist/components/copy-button.d.ts +1 -1
- package/dist/components/facing-pair.d.ts +51 -0
- package/dist/components/file-button.d.ts +1 -1
- package/dist/components/file-dropzone.d.ts +1 -1
- package/dist/components/form-actions.d.ts +1 -1
- package/dist/components/form-actions.js +9 -1
- package/dist/components/form-actions.js.map +1 -1
- package/dist/components/money-field.d.ts +1 -1
- package/dist/components/number-field.d.ts +1 -1
- package/dist/components/number-input.d.ts +1 -1
- package/dist/components/number-input.js +17 -3
- package/dist/components/number-input.js.map +1 -1
- package/dist/components/numpad-sheet.d.ts +1 -1
- package/dist/components/series-chart.d.ts +79 -1
- package/dist/components/series-chart.js +74 -13
- package/dist/components/series-chart.js.map +1 -1
- package/dist/components/settings-fields.d.ts +1 -1
- package/dist/components/text-link.d.ts +1 -1
- package/dist/components/time-input.d.ts +1 -1
- package/dist/components/ui.d.ts +1 -1
- package/dist/hooks/use-file-drop.d.ts +1 -1
- package/dist/i18n/defaults.d.ts +1 -1
- package/dist/i18n/kit-labels.d.ts +1 -1
- package/dist/i18n/kit-labels.js +8 -2
- package/dist/i18n/kit-labels.js.map +1 -1
- package/dist/i18n/locales/de-CH-informal.d.ts +1 -1
- package/dist/i18n/locales/de-CH.d.ts +1 -1
- package/dist/i18n/locales/de-informal.d.ts +1 -1
- package/dist/i18n/locales/de.d.ts +1 -1
- package/dist/i18n/locales/es.d.ts +1 -1
- package/dist/i18n/locales/fr.d.ts +1 -1
- package/dist/i18n/locales/hu.d.ts +1 -1
- package/dist/i18n/locales/it.d.ts +1 -1
- package/dist/i18n/locales/zh.d.ts +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/{kit-labels-BHfRBbHs.d.ts → kit-labels-CnnBd-2N.d.ts} +13 -2
- package/dist/lib/format.d.ts +15 -1
- package/dist/lib/format.js +16 -0
- package/dist/lib/format.js.map +1 -1
- package/dist/rhf/fields.d.ts +1 -1
- package/dist/rhf/form.d.ts +1 -1
- package/dist/rhf.d.ts +1 -1
- package/dist/shell/app-shell.d.ts +1 -1
- package/dist/shell/top-bar-brand.d.ts +1 -1
- package/dist/shell.d.ts +1 -1
- package/dist/wizard/stepper-nav.d.ts +1 -1
- package/dist/wizard.d.ts +1 -1
- package/package.json +1 -1
- package/src/components/amount-input.tsx +8 -13
- package/src/components/chart.tsx +155 -43
- package/src/components/chip.tsx +29 -4
- package/src/components/form-actions.tsx +9 -1
- package/src/components/number-input.tsx +22 -2
- package/src/components/series-chart.tsx +122 -20
- package/src/i18n/kit-labels.tsx +19 -1
- package/src/lib/format.ts +30 -0
package/src/i18n/kit-labels.tsx
CHANGED
|
@@ -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
|
+
}
|