@nextlyhq/ui 0.0.2-alpha.71 → 0.0.2-alpha.73
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 +3 -1
- package/dist/format.cjs +6 -0
- package/dist/format.cjs.map +1 -1
- package/dist/format.d.cts +14 -1
- package/dist/format.d.ts +14 -1
- package/dist/format.mjs +6 -1
- package/dist/format.mjs.map +1 -1
- package/dist/index.cjs +13 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -3
- package/dist/index.d.ts +10 -3
- package/dist/index.mjs +13 -7
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/styles.scoped.css +1 -1
- package/dist/theme.css +32 -32
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -179,10 +179,12 @@ This does not apply to `styles.css`, where the rules are document-wide and
|
|
|
179
179
|
|
|
180
180
|
| Tool | Version |
|
|
181
181
|
| -------------- | ---------------------------------------------------------------------------------------- |
|
|
182
|
-
| React |
|
|
182
|
+
| React | The supported range in [Requirements][requirements] |
|
|
183
183
|
| Tailwind CSS | 4+ (`@nextlyhq/ui/tailwind-preset` also works as a Tailwind v3 preset, with `theme.css`) |
|
|
184
184
|
| `lucide-react` | 0.400+ |
|
|
185
185
|
|
|
186
|
+
[requirements]: https://nextlyhq.com/docs/getting-started/installation#requirements
|
|
187
|
+
|
|
186
188
|
## Documentation
|
|
187
189
|
|
|
188
190
|
- [**Plugin UI authoring guide**](./docs/plugin-ui-authoring.md): the token contract, dark mode, container queries, and the design lint guard
|
package/dist/format.cjs
CHANGED
|
@@ -71,6 +71,12 @@ function formatChange(delta, options = {}) {
|
|
|
71
71
|
direction: "down"
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
|
+
// src/lib/color/chart.ts
|
|
75
|
+
/** The token a slot is drawn in. */
|
|
76
|
+
function chartColour(slot) {
|
|
77
|
+
return `var(--nx-chart-${slot})`;
|
|
78
|
+
}
|
|
79
|
+
exports.chartColour = chartColour;
|
|
74
80
|
exports.formatChange = formatChange;
|
|
75
81
|
exports.formatCount = formatCount;
|
|
76
82
|
|
package/dist/format.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.cjs","names":[],"sources":["../src/lib/format/number.ts"],"sourcesContent":["/**\n * The one number formatter for dashboard cards.\n *\n * Every figure a card shows -- a count, a chart value, a tooltip, a table cell, a text\n * alternative -- goes through here, so the same number reads the same everywhere it appears.\n * Two figures for one value that disagree (\"1.2k\" in a chart, \"1,248\" in its table, \"1248\" in\n * its description) are what this exists to make impossible.\n *\n * It is pure arithmetic on numbers with `Intl.NumberFormat`: no React, no DOM, so a server can\n * format the same way the admin does.\n *\n * @module lib/format/number\n */\n\n/**\n * @experimental The size a card is drawn at, from its own width. Compact numbers appear only in the small\n * tier, where a full grouped value would not fit; everywhere else the exact value fits and is\n * shown.\n */\nexport type SizeTier = \"small\" | \"medium\" | \"large\";\n\n/** @experimental How a count is formatted: its locale, its card's tier, and whether it is a floor. */\nexport interface FormatCountOptions {\n /** The admin's locale. Defaults to `en-US`, the admin's own default. */\n locale?: string;\n /** The tier the figure is drawn in. Only `small` compacts. */\n tier?: SizeTier;\n /**\n * The value is a lower bound: a source that stops counting at a limit knows only \"at\n * least this many\". Shown as \"N+\" and named \"N or more\".\n */\n floor?: boolean;\n}\n\n/** @experimental What a figure looks like, and what assistive technology hears for it. */\nexport interface FormattedNumber {\n /** Drawn on screen: \"1,248\", \"1.2k\", \"100+\". */\n text: string;\n /**\n * The accessible name: always the full grouped value, so \"1.2k\" is heard as \"1,248\"; a\n * floor is heard as \"100 or more\", never as a bare \"100\".\n */\n label: string;\n}\n\nconst COMPACT_FROM = 1000;\n\n// Intl formatters are costly to build and a dashboard formats hundreds of figures, so one of\n// each kind is kept per locale.\nconst groupedCache = new Map<string, Intl.NumberFormat>();\nconst compactCache = new Map<string, Intl.NumberFormat>();\n\nfunction grouped(locale: string): Intl.NumberFormat {\n let f = groupedCache.get(locale);\n if (!f) {\n f = new Intl.NumberFormat(locale);\n groupedCache.set(locale, f);\n }\n return f;\n}\n\nfunction compact(locale: string): Intl.NumberFormat {\n let f = compactCache.get(locale);\n if (!f) {\n f = new Intl.NumberFormat(locale, {\n notation: \"compact\",\n maximumFractionDigits: 1,\n });\n compactCache.set(locale, f);\n }\n return f;\n}\n\n/**\n * @experimental Format a count, total or chart value.\n *\n * Compact form (\"1.2k\", \"3.4M\") only in the small tier and only from 1,000; the thousands\n * suffix is lowercased and the larger ones keep their capitals, so \"M\" (million) cannot be\n * read as \"m\" (metres, or milli). The accessible name is always the full grouped value.\n *\n * @example\n * formatCount(1248, { tier: \"small\" }) // { text: \"1.2k\", label: \"1,248\" }\n * formatCount(1248, { tier: \"medium\" }) // { text: \"1,248\", label: \"1,248\" }\n * formatCount(100, { floor: true }) // { text: \"100+\", label: \"100 or more\" }\n */\nexport function formatCount(\n value: number,\n options: FormatCountOptions = {}\n): FormattedNumber {\n const locale = options.locale ?? \"en-US\";\n const full = grouped(locale).format(value);\n const shown =\n options.tier === \"small\" && Math.abs(value) >= COMPACT_FROM\n ? compact(locale)\n .format(value)\n // \"1.2K\" -> \"1.2k\"; \"3.4M\" and \"1.2B\" keep their capitals.\n .replace(/K$/, \"k\")\n : full;\n return options.floor\n ? { text: `${shown}+`, label: `${full} or more` }\n : { text: shown, label: full };\n}\n\n/** @experimental Which way a change goes, for styling; never the only signal (the arrow and sign are). */\nexport type ChangeDirection = \"up\" | \"down\" | \"none\";\n\n/** @experimental A formatted change, with its direction. */\nexport interface FormattedChange extends FormattedNumber {\n direction: ChangeDirection;\n}\n\n/**\n * @experimental Format a change against an earlier period.\n *\n * The direction is carried by an arrow AND a sign, so it reads without colour (WCAG 1.4.1):\n * \"↑ +18\", \"↓ −18\", \"→ ±0\". The accessible name says it in words: \"up 18\", \"down 18\",\n * \"no change\". The minus is U+2212, which screen readers and typography both treat as a minus\n * rather than a hyphen.\n */\nexport function formatChange(\n delta: number,\n options: Omit<FormatCountOptions, \"floor\"> = {}\n): FormattedChange {\n const magnitude = formatCount(Math.abs(delta), options);\n if (delta === 0) {\n return { text: \"→ ±0\", label: \"no change\", direction: \"none\" };\n }\n return delta > 0\n ? {\n text: `↑ +${magnitude.text}`,\n label: `up ${magnitude.label}`,\n direction: \"up\",\n }\n : {\n text: `↓ −${magnitude.text}`,\n label: `down ${magnitude.label}`,\n direction: \"down\",\n };\n}\n"],"mappings":";;AA6CA,MAAM,eAAe;AAIrB,MAAM,+BAAe,IAAI,IAA+B;AACxD,MAAM,+BAAe,IAAI,IAA+B;AAExD,SAAS,QAAQ,QAAmC;CAClD,IAAI,IAAI,aAAa,IAAI,MAAM;CAC/B,IAAI,CAAC,GAAG;EACN,IAAI,IAAI,KAAK,aAAa,MAAM;EAChC,aAAa,IAAI,QAAQ,CAAC;CAC5B;CACA,OAAO;AACT;AAEA,SAAS,QAAQ,QAAmC;CAClD,IAAI,IAAI,aAAa,IAAI,MAAM;CAC/B,IAAI,CAAC,GAAG;EACN,IAAI,IAAI,KAAK,aAAa,QAAQ;GAChC,UAAU;GACV,uBAAuB;EACzB,CAAC;EACD,aAAa,IAAI,QAAQ,CAAC;CAC5B;CACA,OAAO;AACT;;;;;;;;;;;;;AAcA,SAAgB,YACd,OACA,UAA8B,CAAC,GACd;CACjB,MAAM,SAAS,QAAQ,UAAU;CACjC,MAAM,OAAO,QAAQ,MAAM,CAAC,CAAC,OAAO,KAAK;CACzC,MAAM,QACJ,QAAQ,SAAS,WAAW,KAAK,IAAI,KAAK,KAAK,eAC3C,QAAQ,MAAM,CAAC,CACZ,OAAO,KAAK,CAAC,CAEb,QAAQ,MAAM,GAAG,IACpB;CACN,OAAO,QAAQ,QACX;EAAE,MAAM,GAAG,MAAM;EAAI,OAAO,GAAG,KAAK;CAAU,IAC9C;EAAE,MAAM;EAAO,OAAO;CAAK;AACjC;;;;;;;;;AAkBA,SAAgB,aACd,OACA,UAA6C,CAAC,GAC7B;CACjB,MAAM,YAAY,YAAY,KAAK,IAAI,KAAK,GAAG,OAAO;CACtD,IAAI,UAAU,GACZ,OAAO;EAAE,MAAM;EAAQ,OAAO;EAAa,WAAW;CAAO;CAE/D,OAAO,QAAQ,IACX;EACE,MAAM,MAAM,UAAU;EACtB,OAAO,MAAM,UAAU;EACvB,WAAW;CACb,IACA;EACE,MAAM,MAAM,UAAU;EACtB,OAAO,QAAQ,UAAU;EACzB,WAAW;CACb;AACN"}
|
|
1
|
+
{"version":3,"file":"format.cjs","names":[],"sources":["../src/lib/format/number.ts","../src/lib/color/chart.ts"],"sourcesContent":["/**\n * The one number formatter for dashboard cards.\n *\n * Every figure a card shows -- a count, a chart value, a tooltip, a table cell, a text\n * alternative -- goes through here, so the same number reads the same everywhere it appears.\n * Two figures for one value that disagree (\"1.2k\" in a chart, \"1,248\" in its table, \"1248\" in\n * its description) are what this exists to make impossible.\n *\n * It is pure arithmetic on numbers with `Intl.NumberFormat`: no React, no DOM, so a server can\n * format the same way the admin does.\n *\n * @module lib/format/number\n */\n\n/**\n * @experimental The size a card is drawn at, from its own width. Compact numbers appear only in the small\n * tier, where a full grouped value would not fit; everywhere else the exact value fits and is\n * shown.\n */\nexport type SizeTier = \"small\" | \"medium\" | \"large\";\n\n/** @experimental How a count is formatted: its locale, its card's tier, and whether it is a floor. */\nexport interface FormatCountOptions {\n /** The admin's locale. Defaults to `en-US`, the admin's own default. */\n locale?: string;\n /** The tier the figure is drawn in. Only `small` compacts. */\n tier?: SizeTier;\n /**\n * The value is a lower bound: a source that stops counting at a limit knows only \"at\n * least this many\". Shown as \"N+\" and named \"N or more\".\n */\n floor?: boolean;\n}\n\n/** @experimental What a figure looks like, and what assistive technology hears for it. */\nexport interface FormattedNumber {\n /** Drawn on screen: \"1,248\", \"1.2k\", \"100+\". */\n text: string;\n /**\n * The accessible name: always the full grouped value, so \"1.2k\" is heard as \"1,248\"; a\n * floor is heard as \"100 or more\", never as a bare \"100\".\n */\n label: string;\n}\n\nconst COMPACT_FROM = 1000;\n\n// Intl formatters are costly to build and a dashboard formats hundreds of figures, so one of\n// each kind is kept per locale.\nconst groupedCache = new Map<string, Intl.NumberFormat>();\nconst compactCache = new Map<string, Intl.NumberFormat>();\n\nfunction grouped(locale: string): Intl.NumberFormat {\n let f = groupedCache.get(locale);\n if (!f) {\n f = new Intl.NumberFormat(locale);\n groupedCache.set(locale, f);\n }\n return f;\n}\n\nfunction compact(locale: string): Intl.NumberFormat {\n let f = compactCache.get(locale);\n if (!f) {\n f = new Intl.NumberFormat(locale, {\n notation: \"compact\",\n maximumFractionDigits: 1,\n });\n compactCache.set(locale, f);\n }\n return f;\n}\n\n/**\n * @experimental Format a count, total or chart value.\n *\n * Compact form (\"1.2k\", \"3.4M\") only in the small tier and only from 1,000; the thousands\n * suffix is lowercased and the larger ones keep their capitals, so \"M\" (million) cannot be\n * read as \"m\" (metres, or milli). The accessible name is always the full grouped value.\n *\n * @example\n * formatCount(1248, { tier: \"small\" }) // { text: \"1.2k\", label: \"1,248\" }\n * formatCount(1248, { tier: \"medium\" }) // { text: \"1,248\", label: \"1,248\" }\n * formatCount(100, { floor: true }) // { text: \"100+\", label: \"100 or more\" }\n */\nexport function formatCount(\n value: number,\n options: FormatCountOptions = {}\n): FormattedNumber {\n const locale = options.locale ?? \"en-US\";\n const full = grouped(locale).format(value);\n const shown =\n options.tier === \"small\" && Math.abs(value) >= COMPACT_FROM\n ? compact(locale)\n .format(value)\n // \"1.2K\" -> \"1.2k\"; \"3.4M\" and \"1.2B\" keep their capitals.\n .replace(/K$/, \"k\")\n : full;\n return options.floor\n ? { text: `${shown}+`, label: `${full} or more` }\n : { text: shown, label: full };\n}\n\n/** @experimental Which way a change goes, for styling; never the only signal (the arrow and sign are). */\nexport type ChangeDirection = \"up\" | \"down\" | \"none\";\n\n/** @experimental A formatted change, with its direction. */\nexport interface FormattedChange extends FormattedNumber {\n direction: ChangeDirection;\n}\n\n/**\n * @experimental Format a change against an earlier period.\n *\n * The direction is carried by an arrow AND a sign, so it reads without colour (WCAG 1.4.1):\n * \"↑ +18\", \"↓ −18\", \"→ ±0\". The accessible name says it in words: \"up 18\", \"down 18\",\n * \"no change\". The minus is U+2212, which screen readers and typography both treat as a minus\n * rather than a hyphen.\n */\nexport function formatChange(\n delta: number,\n options: Omit<FormatCountOptions, \"floor\"> = {}\n): FormattedChange {\n const magnitude = formatCount(Math.abs(delta), options);\n if (delta === 0) {\n return { text: \"→ ±0\", label: \"no change\", direction: \"none\" };\n }\n return delta > 0\n ? {\n text: `↑ +${magnitude.text}`,\n label: `up ${magnitude.label}`,\n direction: \"up\",\n }\n : {\n text: `↓ −${magnitude.text}`,\n label: `down ${magnitude.label}`,\n direction: \"down\",\n };\n}\n","/**\n * The five shared chart colours, as the tokens a chart's marks are drawn in.\n *\n * A token reference rather than a colour, so a mark follows the theme in light\n * and dark and a chart never sets a colour of its own. Server-safe, so a chart a\n * server renders names its colours exactly as the admin's do.\n *\n * @module lib/color/chart\n */\n\n/** One of the five shared chart colours, `--nx-chart-1` to `--nx-chart-5`. */\nexport type ChartSlot = 1 | 2 | 3 | 4 | 5;\n\n/** The token a slot is drawn in. */\nexport function chartColour(slot: ChartSlot): string {\n return `var(--nx-chart-${slot})`;\n}\n"],"mappings":";;AA6CA,MAAM,eAAe;AAIrB,MAAM,+BAAe,IAAI,IAA+B;AACxD,MAAM,+BAAe,IAAI,IAA+B;AAExD,SAAS,QAAQ,QAAmC;CAClD,IAAI,IAAI,aAAa,IAAI,MAAM;CAC/B,IAAI,CAAC,GAAG;EACN,IAAI,IAAI,KAAK,aAAa,MAAM;EAChC,aAAa,IAAI,QAAQ,CAAC;CAC5B;CACA,OAAO;AACT;AAEA,SAAS,QAAQ,QAAmC;CAClD,IAAI,IAAI,aAAa,IAAI,MAAM;CAC/B,IAAI,CAAC,GAAG;EACN,IAAI,IAAI,KAAK,aAAa,QAAQ;GAChC,UAAU;GACV,uBAAuB;EACzB,CAAC;EACD,aAAa,IAAI,QAAQ,CAAC;CAC5B;CACA,OAAO;AACT;;;;;;;;;;;;;AAcA,SAAgB,YACd,OACA,UAA8B,CAAC,GACd;CACjB,MAAM,SAAS,QAAQ,UAAU;CACjC,MAAM,OAAO,QAAQ,MAAM,CAAC,CAAC,OAAO,KAAK;CACzC,MAAM,QACJ,QAAQ,SAAS,WAAW,KAAK,IAAI,KAAK,KAAK,eAC3C,QAAQ,MAAM,CAAC,CACZ,OAAO,KAAK,CAAC,CAEb,QAAQ,MAAM,GAAG,IACpB;CACN,OAAO,QAAQ,QACX;EAAE,MAAM,GAAG,MAAM;EAAI,OAAO,GAAG,KAAK;CAAU,IAC9C;EAAE,MAAM;EAAO,OAAO;CAAK;AACjC;;;;;;;;;AAkBA,SAAgB,aACd,OACA,UAA6C,CAAC,GAC7B;CACjB,MAAM,YAAY,YAAY,KAAK,IAAI,KAAK,GAAG,OAAO;CACtD,IAAI,UAAU,GACZ,OAAO;EAAE,MAAM;EAAQ,OAAO;EAAa,WAAW;CAAO;CAE/D,OAAO,QAAQ,IACX;EACE,MAAM,MAAM,UAAU;EACtB,OAAO,MAAM,UAAU;EACvB,WAAW;CACb,IACA;EACE,MAAM,MAAM,UAAU;EACtB,OAAO,QAAQ,UAAU;EACzB,WAAW;CACb;AACN;;;AC5HA,SAAgB,YAAY,MAAyB;CACnD,OAAO,kBAAkB,KAAK;AAChC"}
|
package/dist/format.d.cts
CHANGED
|
@@ -67,5 +67,18 @@ interface FormattedChange extends FormattedNumber {
|
|
|
67
67
|
* rather than a hyphen.
|
|
68
68
|
*/
|
|
69
69
|
export declare function formatChange(delta: number, options?: Omit<FormatCountOptions, "floor">): FormattedChange;
|
|
70
|
-
|
|
70
|
+
/**
|
|
71
|
+
* The five shared chart colours, as the tokens a chart's marks are drawn in.
|
|
72
|
+
*
|
|
73
|
+
* A token reference rather than a colour, so a mark follows the theme in light
|
|
74
|
+
* and dark and a chart never sets a colour of its own. Server-safe, so a chart a
|
|
75
|
+
* server renders names its colours exactly as the admin's do.
|
|
76
|
+
*
|
|
77
|
+
* @module lib/color/chart
|
|
78
|
+
*/
|
|
79
|
+
/** One of the five shared chart colours, `--nx-chart-1` to `--nx-chart-5`. */
|
|
80
|
+
type ChartSlot = 1 | 2 | 3 | 4 | 5;
|
|
81
|
+
/** The token a slot is drawn in. */
|
|
82
|
+
export declare function chartColour(slot: ChartSlot): string;
|
|
83
|
+
export type { ChangeDirection, ChartSlot, FormatCountOptions, FormattedChange, FormattedNumber, SizeTier };
|
|
71
84
|
//# sourceMappingURL=format.d.cts.map
|
package/dist/format.d.ts
CHANGED
|
@@ -67,5 +67,18 @@ interface FormattedChange extends FormattedNumber {
|
|
|
67
67
|
* rather than a hyphen.
|
|
68
68
|
*/
|
|
69
69
|
export declare function formatChange(delta: number, options?: Omit<FormatCountOptions, "floor">): FormattedChange;
|
|
70
|
-
|
|
70
|
+
/**
|
|
71
|
+
* The five shared chart colours, as the tokens a chart's marks are drawn in.
|
|
72
|
+
*
|
|
73
|
+
* A token reference rather than a colour, so a mark follows the theme in light
|
|
74
|
+
* and dark and a chart never sets a colour of its own. Server-safe, so a chart a
|
|
75
|
+
* server renders names its colours exactly as the admin's do.
|
|
76
|
+
*
|
|
77
|
+
* @module lib/color/chart
|
|
78
|
+
*/
|
|
79
|
+
/** One of the five shared chart colours, `--nx-chart-1` to `--nx-chart-5`. */
|
|
80
|
+
type ChartSlot = 1 | 2 | 3 | 4 | 5;
|
|
81
|
+
/** The token a slot is drawn in. */
|
|
82
|
+
export declare function chartColour(slot: ChartSlot): string;
|
|
83
|
+
export type { ChangeDirection, ChartSlot, FormatCountOptions, FormattedChange, FormattedNumber, SizeTier };
|
|
71
84
|
//# sourceMappingURL=format.d.ts.map
|
package/dist/format.mjs
CHANGED
|
@@ -70,6 +70,11 @@ function formatChange(delta, options = {}) {
|
|
|
70
70
|
direction: "down"
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
|
-
|
|
73
|
+
// src/lib/color/chart.ts
|
|
74
|
+
/** The token a slot is drawn in. */
|
|
75
|
+
function chartColour(slot) {
|
|
76
|
+
return `var(--nx-chart-${slot})`;
|
|
77
|
+
}
|
|
78
|
+
export { chartColour, formatChange, formatCount };
|
|
74
79
|
|
|
75
80
|
//# sourceMappingURL=format.mjs.map
|
package/dist/format.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.mjs","names":[],"sources":["../src/lib/format/number.ts"],"sourcesContent":["/**\n * The one number formatter for dashboard cards.\n *\n * Every figure a card shows -- a count, a chart value, a tooltip, a table cell, a text\n * alternative -- goes through here, so the same number reads the same everywhere it appears.\n * Two figures for one value that disagree (\"1.2k\" in a chart, \"1,248\" in its table, \"1248\" in\n * its description) are what this exists to make impossible.\n *\n * It is pure arithmetic on numbers with `Intl.NumberFormat`: no React, no DOM, so a server can\n * format the same way the admin does.\n *\n * @module lib/format/number\n */\n\n/**\n * @experimental The size a card is drawn at, from its own width. Compact numbers appear only in the small\n * tier, where a full grouped value would not fit; everywhere else the exact value fits and is\n * shown.\n */\nexport type SizeTier = \"small\" | \"medium\" | \"large\";\n\n/** @experimental How a count is formatted: its locale, its card's tier, and whether it is a floor. */\nexport interface FormatCountOptions {\n /** The admin's locale. Defaults to `en-US`, the admin's own default. */\n locale?: string;\n /** The tier the figure is drawn in. Only `small` compacts. */\n tier?: SizeTier;\n /**\n * The value is a lower bound: a source that stops counting at a limit knows only \"at\n * least this many\". Shown as \"N+\" and named \"N or more\".\n */\n floor?: boolean;\n}\n\n/** @experimental What a figure looks like, and what assistive technology hears for it. */\nexport interface FormattedNumber {\n /** Drawn on screen: \"1,248\", \"1.2k\", \"100+\". */\n text: string;\n /**\n * The accessible name: always the full grouped value, so \"1.2k\" is heard as \"1,248\"; a\n * floor is heard as \"100 or more\", never as a bare \"100\".\n */\n label: string;\n}\n\nconst COMPACT_FROM = 1000;\n\n// Intl formatters are costly to build and a dashboard formats hundreds of figures, so one of\n// each kind is kept per locale.\nconst groupedCache = new Map<string, Intl.NumberFormat>();\nconst compactCache = new Map<string, Intl.NumberFormat>();\n\nfunction grouped(locale: string): Intl.NumberFormat {\n let f = groupedCache.get(locale);\n if (!f) {\n f = new Intl.NumberFormat(locale);\n groupedCache.set(locale, f);\n }\n return f;\n}\n\nfunction compact(locale: string): Intl.NumberFormat {\n let f = compactCache.get(locale);\n if (!f) {\n f = new Intl.NumberFormat(locale, {\n notation: \"compact\",\n maximumFractionDigits: 1,\n });\n compactCache.set(locale, f);\n }\n return f;\n}\n\n/**\n * @experimental Format a count, total or chart value.\n *\n * Compact form (\"1.2k\", \"3.4M\") only in the small tier and only from 1,000; the thousands\n * suffix is lowercased and the larger ones keep their capitals, so \"M\" (million) cannot be\n * read as \"m\" (metres, or milli). The accessible name is always the full grouped value.\n *\n * @example\n * formatCount(1248, { tier: \"small\" }) // { text: \"1.2k\", label: \"1,248\" }\n * formatCount(1248, { tier: \"medium\" }) // { text: \"1,248\", label: \"1,248\" }\n * formatCount(100, { floor: true }) // { text: \"100+\", label: \"100 or more\" }\n */\nexport function formatCount(\n value: number,\n options: FormatCountOptions = {}\n): FormattedNumber {\n const locale = options.locale ?? \"en-US\";\n const full = grouped(locale).format(value);\n const shown =\n options.tier === \"small\" && Math.abs(value) >= COMPACT_FROM\n ? compact(locale)\n .format(value)\n // \"1.2K\" -> \"1.2k\"; \"3.4M\" and \"1.2B\" keep their capitals.\n .replace(/K$/, \"k\")\n : full;\n return options.floor\n ? { text: `${shown}+`, label: `${full} or more` }\n : { text: shown, label: full };\n}\n\n/** @experimental Which way a change goes, for styling; never the only signal (the arrow and sign are). */\nexport type ChangeDirection = \"up\" | \"down\" | \"none\";\n\n/** @experimental A formatted change, with its direction. */\nexport interface FormattedChange extends FormattedNumber {\n direction: ChangeDirection;\n}\n\n/**\n * @experimental Format a change against an earlier period.\n *\n * The direction is carried by an arrow AND a sign, so it reads without colour (WCAG 1.4.1):\n * \"↑ +18\", \"↓ −18\", \"→ ±0\". The accessible name says it in words: \"up 18\", \"down 18\",\n * \"no change\". The minus is U+2212, which screen readers and typography both treat as a minus\n * rather than a hyphen.\n */\nexport function formatChange(\n delta: number,\n options: Omit<FormatCountOptions, \"floor\"> = {}\n): FormattedChange {\n const magnitude = formatCount(Math.abs(delta), options);\n if (delta === 0) {\n return { text: \"→ ±0\", label: \"no change\", direction: \"none\" };\n }\n return delta > 0\n ? {\n text: `↑ +${magnitude.text}`,\n label: `up ${magnitude.label}`,\n direction: \"up\",\n }\n : {\n text: `↓ −${magnitude.text}`,\n label: `down ${magnitude.label}`,\n direction: \"down\",\n };\n}\n"],"mappings":";AA6CA,MAAM,eAAe;AAIrB,MAAM,+BAAe,IAAI,IAA+B;AACxD,MAAM,+BAAe,IAAI,IAA+B;AAExD,SAAS,QAAQ,QAAmC;CAClD,IAAI,IAAI,aAAa,IAAI,MAAM;CAC/B,IAAI,CAAC,GAAG;EACN,IAAI,IAAI,KAAK,aAAa,MAAM;EAChC,aAAa,IAAI,QAAQ,CAAC;CAC5B;CACA,OAAO;AACT;AAEA,SAAS,QAAQ,QAAmC;CAClD,IAAI,IAAI,aAAa,IAAI,MAAM;CAC/B,IAAI,CAAC,GAAG;EACN,IAAI,IAAI,KAAK,aAAa,QAAQ;GAChC,UAAU;GACV,uBAAuB;EACzB,CAAC;EACD,aAAa,IAAI,QAAQ,CAAC;CAC5B;CACA,OAAO;AACT;;;;;;;;;;;;;AAcA,SAAgB,YACd,OACA,UAA8B,CAAC,GACd;CACjB,MAAM,SAAS,QAAQ,UAAU;CACjC,MAAM,OAAO,QAAQ,MAAM,CAAC,CAAC,OAAO,KAAK;CACzC,MAAM,QACJ,QAAQ,SAAS,WAAW,KAAK,IAAI,KAAK,KAAK,eAC3C,QAAQ,MAAM,CAAC,CACZ,OAAO,KAAK,CAAC,CAEb,QAAQ,MAAM,GAAG,IACpB;CACN,OAAO,QAAQ,QACX;EAAE,MAAM,GAAG,MAAM;EAAI,OAAO,GAAG,KAAK;CAAU,IAC9C;EAAE,MAAM;EAAO,OAAO;CAAK;AACjC;;;;;;;;;AAkBA,SAAgB,aACd,OACA,UAA6C,CAAC,GAC7B;CACjB,MAAM,YAAY,YAAY,KAAK,IAAI,KAAK,GAAG,OAAO;CACtD,IAAI,UAAU,GACZ,OAAO;EAAE,MAAM;EAAQ,OAAO;EAAa,WAAW;CAAO;CAE/D,OAAO,QAAQ,IACX;EACE,MAAM,MAAM,UAAU;EACtB,OAAO,MAAM,UAAU;EACvB,WAAW;CACb,IACA;EACE,MAAM,MAAM,UAAU;EACtB,OAAO,QAAQ,UAAU;EACzB,WAAW;CACb;AACN"}
|
|
1
|
+
{"version":3,"file":"format.mjs","names":[],"sources":["../src/lib/format/number.ts","../src/lib/color/chart.ts"],"sourcesContent":["/**\n * The one number formatter for dashboard cards.\n *\n * Every figure a card shows -- a count, a chart value, a tooltip, a table cell, a text\n * alternative -- goes through here, so the same number reads the same everywhere it appears.\n * Two figures for one value that disagree (\"1.2k\" in a chart, \"1,248\" in its table, \"1248\" in\n * its description) are what this exists to make impossible.\n *\n * It is pure arithmetic on numbers with `Intl.NumberFormat`: no React, no DOM, so a server can\n * format the same way the admin does.\n *\n * @module lib/format/number\n */\n\n/**\n * @experimental The size a card is drawn at, from its own width. Compact numbers appear only in the small\n * tier, where a full grouped value would not fit; everywhere else the exact value fits and is\n * shown.\n */\nexport type SizeTier = \"small\" | \"medium\" | \"large\";\n\n/** @experimental How a count is formatted: its locale, its card's tier, and whether it is a floor. */\nexport interface FormatCountOptions {\n /** The admin's locale. Defaults to `en-US`, the admin's own default. */\n locale?: string;\n /** The tier the figure is drawn in. Only `small` compacts. */\n tier?: SizeTier;\n /**\n * The value is a lower bound: a source that stops counting at a limit knows only \"at\n * least this many\". Shown as \"N+\" and named \"N or more\".\n */\n floor?: boolean;\n}\n\n/** @experimental What a figure looks like, and what assistive technology hears for it. */\nexport interface FormattedNumber {\n /** Drawn on screen: \"1,248\", \"1.2k\", \"100+\". */\n text: string;\n /**\n * The accessible name: always the full grouped value, so \"1.2k\" is heard as \"1,248\"; a\n * floor is heard as \"100 or more\", never as a bare \"100\".\n */\n label: string;\n}\n\nconst COMPACT_FROM = 1000;\n\n// Intl formatters are costly to build and a dashboard formats hundreds of figures, so one of\n// each kind is kept per locale.\nconst groupedCache = new Map<string, Intl.NumberFormat>();\nconst compactCache = new Map<string, Intl.NumberFormat>();\n\nfunction grouped(locale: string): Intl.NumberFormat {\n let f = groupedCache.get(locale);\n if (!f) {\n f = new Intl.NumberFormat(locale);\n groupedCache.set(locale, f);\n }\n return f;\n}\n\nfunction compact(locale: string): Intl.NumberFormat {\n let f = compactCache.get(locale);\n if (!f) {\n f = new Intl.NumberFormat(locale, {\n notation: \"compact\",\n maximumFractionDigits: 1,\n });\n compactCache.set(locale, f);\n }\n return f;\n}\n\n/**\n * @experimental Format a count, total or chart value.\n *\n * Compact form (\"1.2k\", \"3.4M\") only in the small tier and only from 1,000; the thousands\n * suffix is lowercased and the larger ones keep their capitals, so \"M\" (million) cannot be\n * read as \"m\" (metres, or milli). The accessible name is always the full grouped value.\n *\n * @example\n * formatCount(1248, { tier: \"small\" }) // { text: \"1.2k\", label: \"1,248\" }\n * formatCount(1248, { tier: \"medium\" }) // { text: \"1,248\", label: \"1,248\" }\n * formatCount(100, { floor: true }) // { text: \"100+\", label: \"100 or more\" }\n */\nexport function formatCount(\n value: number,\n options: FormatCountOptions = {}\n): FormattedNumber {\n const locale = options.locale ?? \"en-US\";\n const full = grouped(locale).format(value);\n const shown =\n options.tier === \"small\" && Math.abs(value) >= COMPACT_FROM\n ? compact(locale)\n .format(value)\n // \"1.2K\" -> \"1.2k\"; \"3.4M\" and \"1.2B\" keep their capitals.\n .replace(/K$/, \"k\")\n : full;\n return options.floor\n ? { text: `${shown}+`, label: `${full} or more` }\n : { text: shown, label: full };\n}\n\n/** @experimental Which way a change goes, for styling; never the only signal (the arrow and sign are). */\nexport type ChangeDirection = \"up\" | \"down\" | \"none\";\n\n/** @experimental A formatted change, with its direction. */\nexport interface FormattedChange extends FormattedNumber {\n direction: ChangeDirection;\n}\n\n/**\n * @experimental Format a change against an earlier period.\n *\n * The direction is carried by an arrow AND a sign, so it reads without colour (WCAG 1.4.1):\n * \"↑ +18\", \"↓ −18\", \"→ ±0\". The accessible name says it in words: \"up 18\", \"down 18\",\n * \"no change\". The minus is U+2212, which screen readers and typography both treat as a minus\n * rather than a hyphen.\n */\nexport function formatChange(\n delta: number,\n options: Omit<FormatCountOptions, \"floor\"> = {}\n): FormattedChange {\n const magnitude = formatCount(Math.abs(delta), options);\n if (delta === 0) {\n return { text: \"→ ±0\", label: \"no change\", direction: \"none\" };\n }\n return delta > 0\n ? {\n text: `↑ +${magnitude.text}`,\n label: `up ${magnitude.label}`,\n direction: \"up\",\n }\n : {\n text: `↓ −${magnitude.text}`,\n label: `down ${magnitude.label}`,\n direction: \"down\",\n };\n}\n","/**\n * The five shared chart colours, as the tokens a chart's marks are drawn in.\n *\n * A token reference rather than a colour, so a mark follows the theme in light\n * and dark and a chart never sets a colour of its own. Server-safe, so a chart a\n * server renders names its colours exactly as the admin's do.\n *\n * @module lib/color/chart\n */\n\n/** One of the five shared chart colours, `--nx-chart-1` to `--nx-chart-5`. */\nexport type ChartSlot = 1 | 2 | 3 | 4 | 5;\n\n/** The token a slot is drawn in. */\nexport function chartColour(slot: ChartSlot): string {\n return `var(--nx-chart-${slot})`;\n}\n"],"mappings":";AA6CA,MAAM,eAAe;AAIrB,MAAM,+BAAe,IAAI,IAA+B;AACxD,MAAM,+BAAe,IAAI,IAA+B;AAExD,SAAS,QAAQ,QAAmC;CAClD,IAAI,IAAI,aAAa,IAAI,MAAM;CAC/B,IAAI,CAAC,GAAG;EACN,IAAI,IAAI,KAAK,aAAa,MAAM;EAChC,aAAa,IAAI,QAAQ,CAAC;CAC5B;CACA,OAAO;AACT;AAEA,SAAS,QAAQ,QAAmC;CAClD,IAAI,IAAI,aAAa,IAAI,MAAM;CAC/B,IAAI,CAAC,GAAG;EACN,IAAI,IAAI,KAAK,aAAa,QAAQ;GAChC,UAAU;GACV,uBAAuB;EACzB,CAAC;EACD,aAAa,IAAI,QAAQ,CAAC;CAC5B;CACA,OAAO;AACT;;;;;;;;;;;;;AAcA,SAAgB,YACd,OACA,UAA8B,CAAC,GACd;CACjB,MAAM,SAAS,QAAQ,UAAU;CACjC,MAAM,OAAO,QAAQ,MAAM,CAAC,CAAC,OAAO,KAAK;CACzC,MAAM,QACJ,QAAQ,SAAS,WAAW,KAAK,IAAI,KAAK,KAAK,eAC3C,QAAQ,MAAM,CAAC,CACZ,OAAO,KAAK,CAAC,CAEb,QAAQ,MAAM,GAAG,IACpB;CACN,OAAO,QAAQ,QACX;EAAE,MAAM,GAAG,MAAM;EAAI,OAAO,GAAG,KAAK;CAAU,IAC9C;EAAE,MAAM;EAAO,OAAO;CAAK;AACjC;;;;;;;;;AAkBA,SAAgB,aACd,OACA,UAA6C,CAAC,GAC7B;CACjB,MAAM,YAAY,YAAY,KAAK,IAAI,KAAK,GAAG,OAAO;CACtD,IAAI,UAAU,GACZ,OAAO;EAAE,MAAM;EAAQ,OAAO;EAAa,WAAW;CAAO;CAE/D,OAAO,QAAQ,IACX;EACE,MAAM,MAAM,UAAU;EACtB,OAAO,MAAM,UAAU;EACvB,WAAW;CACb,IACA;EACE,MAAM,MAAM,UAAU;EACtB,OAAO,QAAQ,UAAU;EACzB,WAAW;CACb;AACN;;;AC5HA,SAAgB,YAAY,MAAyB;CACnD,OAAO,kBAAkB,KAAK;AAChC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1672,7 +1672,8 @@ DialogDescription.displayName = _radix_ui_react_dialog.Description.displayName;
|
|
|
1672
1672
|
* AlertDialog Component
|
|
1673
1673
|
*
|
|
1674
1674
|
* A modal dialog for important confirmations that require user acknowledgment.
|
|
1675
|
-
* Built on Radix UI primitives
|
|
1675
|
+
* Built on Radix UI primitives. Its confirming action is primary; pass
|
|
1676
|
+
* `variant="destructive"` only when confirming deletes data.
|
|
1676
1677
|
*
|
|
1677
1678
|
* @example
|
|
1678
1679
|
* ```tsx
|
|
@@ -1689,7 +1690,9 @@ DialogDescription.displayName = _radix_ui_react_dialog.Description.displayName;
|
|
|
1689
1690
|
* </AlertDialogHeader>
|
|
1690
1691
|
* <AlertDialogFooter>
|
|
1691
1692
|
* <AlertDialogCancel>Cancel</AlertDialogCancel>
|
|
1692
|
-
* <AlertDialogAction onClick={handleDelete}>
|
|
1693
|
+
* <AlertDialogAction variant="destructive" onClick={handleDelete}>
|
|
1694
|
+
* Delete
|
|
1695
|
+
* </AlertDialogAction>
|
|
1693
1696
|
* </AlertDialogFooter>
|
|
1694
1697
|
* </AlertDialogContent>
|
|
1695
1698
|
* </AlertDialog>
|
|
@@ -1781,13 +1784,14 @@ const AlertDialogDescription = (0, react.forwardRef)(({ className, ...props }, r
|
|
|
1781
1784
|
}));
|
|
1782
1785
|
AlertDialogDescription.displayName = _radix_ui_react_alert_dialog.Description.displayName;
|
|
1783
1786
|
/**
|
|
1784
|
-
* AlertDialogAction - The
|
|
1785
|
-
*
|
|
1787
|
+
* AlertDialogAction - The confirming action button (e.g., "Save", "Delete").
|
|
1788
|
+
* Primary by default: red is kept for confirming a deletion, so it means one
|
|
1789
|
+
* thing wherever it appears.
|
|
1786
1790
|
* @experimental
|
|
1787
1791
|
*/
|
|
1788
|
-
const AlertDialogAction = (0, react.forwardRef)(({ className, children, ...props }, ref) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_alert_dialog.Action, {
|
|
1792
|
+
const AlertDialogAction = (0, react.forwardRef)(({ className, children, variant = "primary", ...props }, ref) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_alert_dialog.Action, {
|
|
1789
1793
|
ref,
|
|
1790
|
-
className: cn(buttonVariants({ variant
|
|
1794
|
+
className: cn(buttonVariants({ variant }), className),
|
|
1791
1795
|
...props,
|
|
1792
1796
|
children
|
|
1793
1797
|
}));
|
|
@@ -2741,7 +2745,9 @@ function Toaster({ theme = "system", ...props }) {
|
|
|
2741
2745
|
"--normal-bg": "var(--nx-popover)",
|
|
2742
2746
|
"--normal-text": "var(--nx-popover-foreground)",
|
|
2743
2747
|
"--normal-border": "var(--nx-border)",
|
|
2744
|
-
"--border-radius": "0px"
|
|
2748
|
+
"--border-radius": "0px",
|
|
2749
|
+
"--success-bg": "var(--nx-toast-success-bg)",
|
|
2750
|
+
"--success-text": "var(--nx-toast-success-text)"
|
|
2745
2751
|
},
|
|
2746
2752
|
...props
|
|
2747
2753
|
});
|