@sincpro/web-ui 2.21.0 → 2.23.0
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 +2 -0
- package/dist/components/lines/LineItems.d.ts +13 -1
- package/dist/components/lines/LineItems.js +17 -3
- package/dist/components/lines/index.d.ts +1 -1
- package/dist/foundations/copy.es.d.ts +10 -0
- package/dist/foundations/copy.es.js +53 -0
- package/dist/foundations/index.d.ts +1 -1
- package/dist/foundations/index.js +1 -1
- package/dist/primitives/value/Price.d.ts +4 -2
- package/dist/primitives/value/Price.js +1 -1
- package/dist/primitives/value/format.d.ts +5 -1
- package/dist/primitives/value/format.js +5 -1
- package/dist/primitives/value/priceFormat.d.ts +4 -3
- package/dist/primitives/value/priceFormat.js +9 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -84,6 +84,8 @@ the tokens once — fonts, theme and Tailwind come with it:
|
|
|
84
84
|
import { Field, installCopy, SPANISH_COPY, TextInput } from "@sincpro/web-ui";
|
|
85
85
|
|
|
86
86
|
installCopy(SPANISH_COPY); // optional: the interface in Spanish — once, where the app starts
|
|
87
|
+
// SPANISH_COPY is written in vos («Elegí»); SPANISH_COPY_TU in tú («Elige»). Choose one, the
|
|
88
|
+
// same voice as the framework's and the composer's tables.
|
|
87
89
|
|
|
88
90
|
export function CompanyName({
|
|
89
91
|
value,
|
|
@@ -20,6 +20,11 @@ export type LineItemColumn<T> = Pick<DataColumn<T>, "id" | "header" | "value" |
|
|
|
20
20
|
* with `structure`; without it the section says nothing in this column. */
|
|
21
21
|
subtotal?: (lines: readonly T[]) => ReactNode;
|
|
22
22
|
};
|
|
23
|
+
/** Another way to add lines, beside «Agregar una línea»: its words, and what starts it. */
|
|
24
|
+
export type LineAdd = {
|
|
25
|
+
label: string;
|
|
26
|
+
onAdd: () => void;
|
|
27
|
+
};
|
|
23
28
|
/** Which lines are sections or notes, and how their text is read and written. See
|
|
24
29
|
* «Sections and notes» in the file's header. */
|
|
25
30
|
export type LineStructure<T> = {
|
|
@@ -57,6 +62,13 @@ export type LineItemsProps<T> = {
|
|
|
57
62
|
/** The blank line «Agregar una línea» starts from. Required for adding. It carries its
|
|
58
63
|
* local key from here — `{ key: crypto.randomUUID(), … }` — since it has no server id. */
|
|
59
64
|
newLine?: () => T;
|
|
65
|
+
/**
|
|
66
|
+
* Other ways to add, beside «Agregar una línea» and quieter than it: several at once («Agregar
|
|
67
|
+
* varios…», one line per record chosen), from a catalog. Each starts its own flow; the lines it
|
|
68
|
+
* makes arrive in `lines` as any other. In place they sit in the table's add row, beside a
|
|
69
|
+
* section and a note; with the dialog, beside the add button. None in `read`.
|
|
70
|
+
*/
|
|
71
|
+
moreAdds?: readonly LineAdd[];
|
|
60
72
|
/** A line was removed. It is gone at once; the notice offers to undo it. */
|
|
61
73
|
onRemove?: (id: string) => void;
|
|
62
74
|
/** Put a removed line back where it was. Without it the notice has no «Deshacer». */
|
|
@@ -122,4 +134,4 @@ export type LineItemsProps<T> = {
|
|
|
122
134
|
* removing asked first, what an empty document said. One component, built on
|
|
123
135
|
* `EditableTable` and `Dialog`, makes the one2many the same block everywhere.
|
|
124
136
|
*/
|
|
125
|
-
export declare function LineItems<T>({ lines, columns, getLineId, lineLabel, mode, onChange, onAdd, newLine, onRemove, onRestore, editor, isValid, context, searchText, searchFrom, totals, layout, adding, onOpenLine, flag, cellState, rowState, structure, onReorder, visibleColumnIds, onVisibleColumnIdsChange, }: LineItemsProps<T>): import("react").JSX.Element;
|
|
137
|
+
export declare function LineItems<T>({ lines, columns, getLineId, lineLabel, mode, onChange, onAdd, newLine, moreAdds, onRemove, onRestore, editor, isValid, context, searchText, searchFrom, totals, layout, adding, onOpenLine, flag, cellState, rowState, structure, onReorder, visibleColumnIds, onVisibleColumnIdsChange, }: LineItemsProps<T>): import("react").JSX.Element;
|
|
@@ -38,7 +38,7 @@ function plain(v) {
|
|
|
38
38
|
* removing asked first, what an empty document said. One component, built on
|
|
39
39
|
* `EditableTable` and `Dialog`, makes the one2many the same block everywhere.
|
|
40
40
|
*/
|
|
41
|
-
export function LineItems({ lines, columns, getLineId, lineLabel, mode, onChange, onAdd, newLine, onRemove, onRestore, editor, isValid, context, searchText, searchFrom = 8, totals, layout = "auto", adding, onOpenLine, flag, cellState, rowState, structure, onReorder, visibleColumnIds, onVisibleColumnIdsChange, }) {
|
|
41
|
+
export function LineItems({ lines, columns, getLineId, lineLabel, mode, onChange, onAdd, newLine, moreAdds, onRemove, onRestore, editor, isValid, context, searchText, searchFrom = 8, totals, layout = "auto", adding, onOpenLine, flag, cellState, rowState, structure, onReorder, visibleColumnIds, onVisibleColumnIdsChange, }) {
|
|
42
42
|
const copy = useUiCopy();
|
|
43
43
|
const toast = useOptionalToast();
|
|
44
44
|
const read = useFormMode(mode) === "read";
|
|
@@ -185,6 +185,20 @@ export function LineItems({ lines, columns, getLineId, lineLabel, mode, onChange
|
|
|
185
185
|
: [{ label: copy.lines.addNote, onAdd: () => addInline(structure.newNote) }]),
|
|
186
186
|
];
|
|
187
187
|
const inPlace = inline || bandAdds.length > 0;
|
|
188
|
+
/* The other ways to add: in the table's add row in place, beside the button otherwise. Each
|
|
189
|
+
clears the search first, as adding a line does — what it adds would land out of sight —, and
|
|
190
|
+
answers nothing: its lines arrive through `lines`, never as the table's new draft row (which
|
|
191
|
+
the table would take back, with no «Deshacer», if left untouched). */
|
|
192
|
+
const others = read
|
|
193
|
+
? []
|
|
194
|
+
: (moreAdds ?? []).map((other) => ({
|
|
195
|
+
label: other.label,
|
|
196
|
+
onAdd: () => {
|
|
197
|
+
setQuery("");
|
|
198
|
+
other.onAdd();
|
|
199
|
+
},
|
|
200
|
+
}));
|
|
201
|
+
const tableAdds = inline ? [...bandAdds, ...others] : bandAdds;
|
|
188
202
|
const bands = structure === undefined
|
|
189
203
|
? undefined
|
|
190
204
|
: {
|
|
@@ -271,7 +285,7 @@ export function LineItems({ lines, columns, getLineId, lineLabel, mode, onChange
|
|
|
271
285
|
});
|
|
272
286
|
}
|
|
273
287
|
/* In place, «add» is the table's own row under the grid: where the line will appear. */
|
|
274
|
-
const addButton = canAdd && !inline ? (_jsx(Button, { role: "secondary", size: "sm", icon: Plus, onClick: add, "data-line-add": "", children: copy.lines.add })) : null;
|
|
288
|
+
const addButton = canAdd && !inline ? (_jsxs("span", { className: "flex items-center gap-2", children: [others.map((other) => (_jsx(Button, { role: "ghost", size: "sm", onClick: other.onAdd, children: other.label }, other.label))), _jsx(Button, { role: "secondary", size: "sm", icon: Plus, onClick: add, "data-line-add": "", children: copy.lines.add })] })) : null;
|
|
275
289
|
const count = q === ""
|
|
276
290
|
? fillCopy(lineCount === 1 ? copy.lineItems.one : copy.lineItems.many, {
|
|
277
291
|
count: lineCount.toLocaleString(copy.locale),
|
|
@@ -293,7 +307,7 @@ export function LineItems({ lines, columns, getLineId, lineLabel, mode, onChange
|
|
|
293
307
|
invalid: false,
|
|
294
308
|
}, children: _jsx(SearchField, { value: query, onChange: setQuery, placeholder: copy.lines.search }) })] })) : null, _jsx("span", { className: "text-meta text-muted tabular-nums", "aria-live": "polite", children: count }), columnControl.hasOptional || addButton !== null ? (_jsxs("span", { className: "ml-auto flex items-center gap-2", children: [_jsx(ColumnsMenu, { control: columnControl }), addButton] })) : null] }), _jsx(EditableTable, { rows: shown, columns: tableColumns, getRowId: getLineId, empty: lines.length === 0
|
|
295
309
|
? copy.lines.empty
|
|
296
|
-
: fillCopy(copy.lineItems.noMatch, { query: query.trim() }), layout: layout, ...(inline ? { onAdd: () => addInline(), addLabel: copy.lines.add } : {}), ...(
|
|
310
|
+
: fillCopy(copy.lineItems.noMatch, { query: query.trim() }), layout: layout, ...(inline ? { onAdd: () => addInline(), addLabel: copy.lines.add } : {}), ...(tableAdds.length === 0 ? {} : { adds: tableAdds }), ...(bands === undefined ? {} : { bands }), ...(flag === undefined ? {} : { flag }), ...(cellState === undefined ? {} : { cellState }), ...(rowState === undefined ? {} : { rowState }), ...(onReorder === undefined || read ? {} : { onReorder }), ...(inPlace && onRemove !== undefined
|
|
297
311
|
? /* A blank row nobody wrote in is taken back without a notice: nobody
|
|
298
312
|
removed anything, so there is nothing to undo. */
|
|
299
313
|
{ onDiscard: onRemove }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { type LineEditorState, type LineItemColumn, LineItems, type LineItemsProps, } from "./LineItems.js";
|
|
1
|
+
export { type LineAdd, type LineEditorState, type LineItemColumn, LineItems, type LineItemsProps, } from "./LineItems.js";
|
|
@@ -1,2 +1,12 @@
|
|
|
1
1
|
import type { UiCopyOverride } from "./uiCopy.js";
|
|
2
2
|
export declare const SPANISH_COPY: UiCopyOverride;
|
|
3
|
+
/**
|
|
4
|
+
* The same Spanish, in tú — what most of the region writes (Bolivia, Perú, México, Colombia…);
|
|
5
|
+
* `SPANISH_COPY` is in vos, as Argentina and Uruguay write. An application chooses once, with
|
|
6
|
+
* the framework's and the composer's tables in the same voice: three voices on one screen read
|
|
7
|
+
* as three authors.
|
|
8
|
+
*
|
|
9
|
+
* Only what is said TO the person changes — «Elegí» / «Elige», «podés» / «puedes» —; every other
|
|
10
|
+
* word is the vos table's. A new sentence that tells the person to do something goes in both.
|
|
11
|
+
*/
|
|
12
|
+
export declare const SPANISH_COPY_TU: UiCopyOverride;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { mergeCopyOver } from "./copyStore.js";
|
|
1
2
|
/* ==================================================================== *
|
|
2
3
|
* EL CASTELLANO DEL SISTEMA.
|
|
3
4
|
*
|
|
@@ -882,3 +883,55 @@ export const SPANISH_COPY = {
|
|
|
882
883
|
signature: "Firma",
|
|
883
884
|
},
|
|
884
885
|
};
|
|
886
|
+
/**
|
|
887
|
+
* The same Spanish, in tú — what most of the region writes (Bolivia, Perú, México, Colombia…);
|
|
888
|
+
* `SPANISH_COPY` is in vos, as Argentina and Uruguay write. An application chooses once, with
|
|
889
|
+
* the framework's and the composer's tables in the same voice: three voices on one screen read
|
|
890
|
+
* as three authors.
|
|
891
|
+
*
|
|
892
|
+
* Only what is said TO the person changes — «Elegí» / «Elige», «podés» / «puedes» —; every other
|
|
893
|
+
* word is the vos table's. A new sentence that tells the person to do something goes in both.
|
|
894
|
+
*/
|
|
895
|
+
export const SPANISH_COPY_TU = mergeCopyOver(SPANISH_COPY, {
|
|
896
|
+
field: {
|
|
897
|
+
drop: "Suelta un archivo acá, o elige uno.",
|
|
898
|
+
dropMany: "Suelta archivos acá, o elígelos.",
|
|
899
|
+
tryAnother: "Prueba con otro",
|
|
900
|
+
},
|
|
901
|
+
search: { typeValue: "escribe el valor", askAttribute: "elige un atributo" },
|
|
902
|
+
activity: { messagePlaceholder: "Escribe un mensaje…" },
|
|
903
|
+
richText: {
|
|
904
|
+
badLink: "Escribe una web (empresa.bo), un correo o un teléfono.",
|
|
905
|
+
badVideo: "Pega el enlace de un video de {providers}.",
|
|
906
|
+
},
|
|
907
|
+
editable: { reorderHint: "Arrástrala, o Alt + ↑ / ↓" },
|
|
908
|
+
picker: { placeholder: "elige uno…", refine: "— afina el filtro" },
|
|
909
|
+
chart: { pieNegative: "Una torta no puede mostrar valores negativos: prueba con barras." },
|
|
910
|
+
board: { moveHint: "Arrástrala, o Alt + ← / → para pasarla a otra etapa" },
|
|
911
|
+
kiosk: { start: "Toca para empezar" },
|
|
912
|
+
timeline: {
|
|
913
|
+
moveHint: "Arrástrala para moverla, su borde derecho para estirarla; Alt + flechas con el teclado",
|
|
914
|
+
},
|
|
915
|
+
attachments: {
|
|
916
|
+
emptyAdd: "Todavía no hay archivos adjuntos. Suéltalos acá o elígelos.",
|
|
917
|
+
add: "Suelta más archivos acá o elígelos.",
|
|
918
|
+
},
|
|
919
|
+
fieldPath: {
|
|
920
|
+
failedHint: "Prueba de nuevo en un momento, o copia el error para quien mantiene el modelo.",
|
|
921
|
+
},
|
|
922
|
+
preview: {
|
|
923
|
+
unsupported: "No hay vista previa para este tipo de archivo. Igual lo puedes descargar.",
|
|
924
|
+
officeSentence: "Se ve mejor en su programa. Ábrelo o descárgalo.",
|
|
925
|
+
},
|
|
926
|
+
chat: {
|
|
927
|
+
empty: "Todavía no hay mensajes. Escribe el primero.",
|
|
928
|
+
placeholder: "Escribe un mensaje… Enter lo envía, Shift+Enter hace otro renglón",
|
|
929
|
+
},
|
|
930
|
+
assist: { noneChosen: "Elige al menos un cambio." },
|
|
931
|
+
media: {
|
|
932
|
+
dropImage: "Suelta una imagen acá, pégala o elígela.",
|
|
933
|
+
notImage: "El archivo no es una imagen. Elige un PNG, JPG o WebP.",
|
|
934
|
+
cropHelp: "Arrastra la imagen o muévela con las flechas; + y − acercan y alejan.",
|
|
935
|
+
signatureHelp: "Firma con el mouse o con el dedo sobre la línea.",
|
|
936
|
+
},
|
|
937
|
+
});
|
|
@@ -17,7 +17,7 @@ export { applyTheme, ThemeProvider, type ThemeProviderProps, useTheme, } from ".
|
|
|
17
17
|
export { isTheme, type ResolvedTheme, resolveTheme, type Theme, THEME_ATTRIBUTE, THEMES, } from "./themeChoice.js";
|
|
18
18
|
export type { Density, OpenTarget, Size, Surface, Tone, } from "./types.js";
|
|
19
19
|
/** The system's Spanish, for whoever wants to install it whole. */
|
|
20
|
-
export { SPANISH_COPY } from "./copy.es.js";
|
|
20
|
+
export { SPANISH_COPY, SPANISH_COPY_TU } from "./copy.es.js";
|
|
21
21
|
export { flatten, loose, pick, pickAll, propsOf, slot, slotOf, type Slotted, } from "./slots.js";
|
|
22
22
|
export { dateKey, dateKeysBetween, dateKeyYear, dateLabel, dateTick, grainName, monthName, nextDateKey, } from "./calendar.js";
|
|
23
23
|
export { GRAIN_ORDER, type GroupableField, type GroupGrain, type Grouping, type GroupLevel, itemPath, levelKey, moveLevel, normalizeLevels, pathKey, pathLabels, type Pile, pileCount, type PileFoot, pileFoot, pileIsOpen, pileItems, pileLabel, type PileLabelOf, type PileOf, type PilePage, pilePage, pilesFoot, pilesFrom, pilesOf, type PilesPaging, } from "./grouping.js";
|
|
@@ -34,7 +34,7 @@ export { SurfaceProvider, useSurface } from "./surface.js";
|
|
|
34
34
|
export { applyTheme, ThemeProvider, useTheme, } from "./theme.js";
|
|
35
35
|
export { isTheme, resolveTheme, THEME_ATTRIBUTE, THEMES, } from "./themeChoice.js";
|
|
36
36
|
/** The system's Spanish, for whoever wants to install it whole. */
|
|
37
|
-
export { SPANISH_COPY } from "./copy.es.js";
|
|
37
|
+
export { SPANISH_COPY, SPANISH_COPY_TU } from "./copy.es.js";
|
|
38
38
|
/* THE SLOTS — how an archetype is written as a TREE. It lives here and not inside
|
|
39
39
|
one because all of them speak it: while it was hidden in
|
|
40
40
|
`Record.tsx`, being a tree was a privilege of records. */
|
|
@@ -4,12 +4,14 @@ declare const SIZE: {
|
|
|
4
4
|
readonly lg: "text-display";
|
|
5
5
|
};
|
|
6
6
|
export type PriceProps = {
|
|
7
|
-
|
|
7
|
+
/** A number, or a decimal as its text (`"120.50"`, what a backend sends for money): written as
|
|
8
|
+
* it is, never through a float. */
|
|
9
|
+
value: number | string;
|
|
8
10
|
/** ISO 4217 — `BOB`, `USD`. Without it the number goes with two decimals and no symbol. */
|
|
9
11
|
currency?: string;
|
|
10
12
|
/** The price before: drawn struck through, beside the discount it makes. Not drawn when
|
|
11
13
|
* it is not higher — a «before» that is not more is not a discount. */
|
|
12
|
-
compareAt?: number;
|
|
14
|
+
compareAt?: number | string;
|
|
13
15
|
/** What the price is for — «mes», «kg», «persona» — written after it: «Bs 120,00 / mes». */
|
|
14
16
|
per?: string;
|
|
15
17
|
size?: keyof typeof SIZE;
|
|
@@ -28,5 +28,5 @@ export function Price({ value, currency, compareAt, per, size = "md", format })
|
|
|
28
28
|
const write = (n) => formatPrice(n, { currency, format }, copy.locale);
|
|
29
29
|
const off = discountPercent(value, compareAt);
|
|
30
30
|
const before = off === undefined ? undefined : compareAt;
|
|
31
|
-
return (_jsxs("span", { "data-ui": "price", "data-size": size, className: "inline-flex min-w-0 flex-wrap items-baseline gap-x-2 gap-y-0.5", children: [_jsxs("span", { className: `font-semibold whitespace-nowrap text-ink tabular-nums ${SIZE[size]}`, children: [before === undefined ? null : _jsxs("span", { className: "sr-only", children: [copy.price.now, " "] }), value === 0 ? copy.price.free : write(value), per === undefined ? null : (_jsxs("span", { className: "text-meta font-normal text-muted", children: [_jsx("span", { "aria-hidden": true, children: " / " }), _jsxs("span", { className: "sr-only", children: [" ", copy.price.per, " "] }), per] }))] }), before === undefined || off === undefined ? null : (_jsxs(_Fragment, { children: [_jsxs("del", { className: "text-meta whitespace-nowrap text-muted tabular-nums", "data-ui": "price.before", children: [_jsxs("span", { className: "sr-only", children: [copy.price.before, " "] }), write(before)] }), _jsx(Tag, { tone: "good", title: fillCopy(copy.price.off, { percent: String(off) }), children: formatWith(-off / 100, { style: "percent", signDisplay: "always" }, copy.locale) })] }))] }));
|
|
31
|
+
return (_jsxs("span", { "data-ui": "price", "data-size": size, className: "inline-flex min-w-0 flex-wrap items-baseline gap-x-2 gap-y-0.5", children: [_jsxs("span", { className: `font-semibold whitespace-nowrap text-ink tabular-nums ${SIZE[size]}`, children: [before === undefined ? null : _jsxs("span", { className: "sr-only", children: [copy.price.now, " "] }), Number(value) === 0 ? copy.price.free : write(value), per === undefined ? null : (_jsxs("span", { className: "text-meta font-normal text-muted", children: [_jsx("span", { "aria-hidden": true, children: " / " }), _jsxs("span", { className: "sr-only", children: [" ", copy.price.per, " "] }), per] }))] }), before === undefined || off === undefined ? null : (_jsxs(_Fragment, { children: [_jsxs("del", { className: "text-meta whitespace-nowrap text-muted tabular-nums", "data-ui": "price.before", children: [_jsxs("span", { className: "sr-only", children: [copy.price.before, " "] }), write(before)] }), _jsx(Tag, { tone: "good", title: fillCopy(copy.price.off, { percent: String(off) }), children: formatWith(-off / 100, { style: "percent", signDisplay: "always" }, copy.locale) })] }))] }));
|
|
32
32
|
}
|
|
@@ -5,7 +5,11 @@ export declare const formatDistance: (value: number, locale?: string) => string;
|
|
|
5
5
|
/** A number written with any `Intl.NumberFormatOptions` — a currency, a percentage, fixed
|
|
6
6
|
* decimals — in the session locale. The same options `NumberInput` takes, so a value reads
|
|
7
7
|
* the same in its form and in the cell or the figure that shows it elsewhere. */
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* A number in the locale — or a decimal as its text (`"1299.50"`, what a backend sends for money):
|
|
10
|
+
* `Intl` writes the text as it is, every digit, never through a float.
|
|
11
|
+
*/
|
|
12
|
+
export declare const formatWith: (value: number | string, options: Intl.NumberFormatOptions, locale?: string) => string;
|
|
9
13
|
/** The day alone, in digits and in the locale's order. Exported for `DateValue`'s `date`
|
|
10
14
|
* format; not public. */
|
|
11
15
|
export declare function dateFormat(locale: string): Intl.DateTimeFormat;
|
|
@@ -31,7 +31,11 @@ export const formatDistance = (value, locale = currentCopyLocale()) => distanceF
|
|
|
31
31
|
/** A number written with any `Intl.NumberFormatOptions` — a currency, a percentage, fixed
|
|
32
32
|
* decimals — in the session locale. The same options `NumberInput` takes, so a value reads
|
|
33
33
|
* the same in its form and in the cell or the figure that shows it elsewhere. */
|
|
34
|
-
|
|
34
|
+
/**
|
|
35
|
+
* A number in the locale — or a decimal as its text (`"1299.50"`, what a backend sends for money):
|
|
36
|
+
* `Intl` writes the text as it is, every digit, never through a float.
|
|
37
|
+
*/
|
|
38
|
+
export const formatWith = (value, options, locale = currentCopyLocale()) => new Intl.NumberFormat(locale, options).format(typeof value === "number" ? value : value);
|
|
35
39
|
/* ── Dates — see `DateValue.tsx` for why the relative stops at a week ── */
|
|
36
40
|
function relativeFormat(locale) {
|
|
37
41
|
return new Intl.RelativeTimeFormat(locale, { numeric: "auto" });
|
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Context: rounded DOWN, never to the nearest: 80 for 99 is 19.2 % — «−20 %» would promise
|
|
5
5
|
* more than the shelf gives, and a price is a promise. */
|
|
6
|
-
export declare function discountPercent(
|
|
6
|
+
export declare function discountPercent(amount: number | string, before: number | string | undefined): number | undefined;
|
|
7
7
|
/** A price written in the session's locale: with its currency when there is one («Bs 80,00»),
|
|
8
|
-
* with two decimals when there is none. `format` overrides either.
|
|
9
|
-
|
|
8
|
+
* with two decimals when there is none. `format` overrides either. A decimal's text
|
|
9
|
+
* (`"80.50"`) is written as it is, never through a float. */
|
|
10
|
+
export declare function formatPrice(value: number | string, { currency, format }?: {
|
|
10
11
|
currency?: string;
|
|
11
12
|
format?: Intl.NumberFormatOptions;
|
|
12
13
|
}, locale?: string): string;
|
|
@@ -5,15 +5,20 @@ import { formatWith } from "./format.js";
|
|
|
5
5
|
*
|
|
6
6
|
* Context: rounded DOWN, never to the nearest: 80 for 99 is 19.2 % — «−20 %» would promise
|
|
7
7
|
* more than the shelf gives, and a price is a promise. */
|
|
8
|
-
export function discountPercent(
|
|
9
|
-
if (
|
|
8
|
+
export function discountPercent(amount, before) {
|
|
9
|
+
if (before === undefined)
|
|
10
|
+
return undefined;
|
|
11
|
+
// A ratio to show, never an amount to keep: a float is enough for a whole percentage.
|
|
12
|
+
const value = Number(amount);
|
|
13
|
+
const compareAt = Number(before);
|
|
14
|
+
if (!(compareAt > 0) || !(value < compareAt) || value < 0)
|
|
10
15
|
return undefined;
|
|
11
|
-
}
|
|
12
16
|
const off = Math.floor(((compareAt - value) / compareAt) * 100);
|
|
13
17
|
return off > 0 ? off : undefined;
|
|
14
18
|
}
|
|
15
19
|
/** A price written in the session's locale: with its currency when there is one («Bs 80,00»),
|
|
16
|
-
* with two decimals when there is none. `format` overrides either.
|
|
20
|
+
* with two decimals when there is none. `format` overrides either. A decimal's text
|
|
21
|
+
* (`"80.50"`) is written as it is, never through a float. */
|
|
17
22
|
export function formatPrice(value, { currency, format } = {}, locale = currentCopyLocale()) {
|
|
18
23
|
const options = currency === undefined
|
|
19
24
|
? { minimumFractionDigits: 2, maximumFractionDigits: 2, ...format }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sincpro/web-ui",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.23.0",
|
|
4
4
|
"description": "An enterprise web design system for business software — ERPs, back offices, management tools — in React and Tailwind: tokens, primitives, components and the two views every management screen is made of.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|