use-wc 1.0.0-pre.57 → 1.0.0-pre.58
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/custom-elements.json +179 -0
- package/dist/design-system.css +16 -0
- package/dist/docs/use-intl-number.md +30 -0
- package/dist/use-wc.d.mts +47 -1
- package/dist/use-wc.mjs +107 -1
- package/package.json +1 -1
- package/vscode.html-custom-data.json +52 -0
package/custom-elements.json
CHANGED
|
@@ -2748,6 +2748,185 @@
|
|
|
2748
2748
|
}
|
|
2749
2749
|
]
|
|
2750
2750
|
},
|
|
2751
|
+
{
|
|
2752
|
+
"kind": "javascript-module",
|
|
2753
|
+
"path": "src/elements/use-intl-number/use-intl-number.ts",
|
|
2754
|
+
"declarations": [
|
|
2755
|
+
{
|
|
2756
|
+
"kind": "class",
|
|
2757
|
+
"description": "Displays a localized, human-readable representation of a number using\n[`Intl.NumberFormat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat).\nRenders a semantic `<data>` element in its shadow root with a machine-readable\n`value` attribute and formatted inner text.\n\nSet `numberstyle` to control what kind of number is formatted (see\n[`style`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#style)):\n- `decimal` (default) → plain number, e.g. `1,234.5`\n- `percent` → percentage, e.g. `42%` (value is the fraction, so `0.42` renders `42%`)\n- `currency` → currency amount, requires `currency`\n- `unit` → measurement, requires `unit`\n\nLocale is resolved from the nearest ancestor `[lang]` attribute, or\n`navigator.language` if none is found. Set `lang` directly on the element to override.",
|
|
2758
|
+
"name": "UseIntlNumber",
|
|
2759
|
+
"members": [
|
|
2760
|
+
{
|
|
2761
|
+
"kind": "field",
|
|
2762
|
+
"name": "value",
|
|
2763
|
+
"type": {
|
|
2764
|
+
"text": "string | undefined"
|
|
2765
|
+
},
|
|
2766
|
+
"attribute": "value"
|
|
2767
|
+
},
|
|
2768
|
+
{
|
|
2769
|
+
"kind": "field",
|
|
2770
|
+
"name": "numberstyle",
|
|
2771
|
+
"type": {
|
|
2772
|
+
"text": "string | undefined"
|
|
2773
|
+
},
|
|
2774
|
+
"attribute": "numberstyle"
|
|
2775
|
+
},
|
|
2776
|
+
{
|
|
2777
|
+
"kind": "field",
|
|
2778
|
+
"name": "currency",
|
|
2779
|
+
"type": {
|
|
2780
|
+
"text": "string | undefined"
|
|
2781
|
+
},
|
|
2782
|
+
"attribute": "currency"
|
|
2783
|
+
},
|
|
2784
|
+
{
|
|
2785
|
+
"kind": "field",
|
|
2786
|
+
"name": "currencydisplay",
|
|
2787
|
+
"type": {
|
|
2788
|
+
"text": "string | undefined"
|
|
2789
|
+
},
|
|
2790
|
+
"attribute": "currencydisplay"
|
|
2791
|
+
},
|
|
2792
|
+
{
|
|
2793
|
+
"kind": "field",
|
|
2794
|
+
"name": "currencysign",
|
|
2795
|
+
"type": {
|
|
2796
|
+
"text": "string | undefined"
|
|
2797
|
+
},
|
|
2798
|
+
"attribute": "currencysign"
|
|
2799
|
+
},
|
|
2800
|
+
{
|
|
2801
|
+
"kind": "field",
|
|
2802
|
+
"name": "unit",
|
|
2803
|
+
"type": {
|
|
2804
|
+
"text": "string | undefined"
|
|
2805
|
+
},
|
|
2806
|
+
"attribute": "unit"
|
|
2807
|
+
},
|
|
2808
|
+
{
|
|
2809
|
+
"kind": "field",
|
|
2810
|
+
"name": "unitdisplay",
|
|
2811
|
+
"type": {
|
|
2812
|
+
"text": "string | undefined"
|
|
2813
|
+
},
|
|
2814
|
+
"attribute": "unitdisplay"
|
|
2815
|
+
},
|
|
2816
|
+
{
|
|
2817
|
+
"kind": "field",
|
|
2818
|
+
"name": "signdisplay",
|
|
2819
|
+
"type": {
|
|
2820
|
+
"text": "string | undefined"
|
|
2821
|
+
},
|
|
2822
|
+
"attribute": "signdisplay"
|
|
2823
|
+
}
|
|
2824
|
+
],
|
|
2825
|
+
"attributes": [
|
|
2826
|
+
{
|
|
2827
|
+
"type": {
|
|
2828
|
+
"text": "string | undefined"
|
|
2829
|
+
},
|
|
2830
|
+
"description": "Numeric amount to format",
|
|
2831
|
+
"name": "value",
|
|
2832
|
+
"fieldName": "value"
|
|
2833
|
+
},
|
|
2834
|
+
{
|
|
2835
|
+
"type": {
|
|
2836
|
+
"text": "string | undefined"
|
|
2837
|
+
},
|
|
2838
|
+
"description": "Format style: `decimal` | `percent` | `currency` | `unit`",
|
|
2839
|
+
"name": "numberstyle",
|
|
2840
|
+
"fieldName": "numberstyle"
|
|
2841
|
+
},
|
|
2842
|
+
{
|
|
2843
|
+
"type": {
|
|
2844
|
+
"text": "string | undefined"
|
|
2845
|
+
},
|
|
2846
|
+
"description": "[ISO 4217 currency code](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currency), e.g. `USD`, `EUR`, `JPY`. Required when numberstyle is `currency`",
|
|
2847
|
+
"name": "currency",
|
|
2848
|
+
"fieldName": "currency"
|
|
2849
|
+
},
|
|
2850
|
+
{
|
|
2851
|
+
"type": {
|
|
2852
|
+
"text": "string | undefined"
|
|
2853
|
+
},
|
|
2854
|
+
"description": "[How the currency is denoted](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currencydisplay): `symbol` | `narrowSymbol` | `code` | `name`",
|
|
2855
|
+
"name": "currencydisplay",
|
|
2856
|
+
"fieldName": "currencydisplay"
|
|
2857
|
+
},
|
|
2858
|
+
{
|
|
2859
|
+
"type": {
|
|
2860
|
+
"text": "string | undefined"
|
|
2861
|
+
},
|
|
2862
|
+
"description": "[Sign convention](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currencysign): `standard` (minus sign) | `accounting` (parenthesized negatives)",
|
|
2863
|
+
"name": "currencysign",
|
|
2864
|
+
"fieldName": "currencysign"
|
|
2865
|
+
},
|
|
2866
|
+
{
|
|
2867
|
+
"type": {
|
|
2868
|
+
"text": "string | undefined"
|
|
2869
|
+
},
|
|
2870
|
+
"description": "[Unit identifier](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#unit), e.g. `kilometer-per-hour`, `liter`. Required when numberstyle is `unit`",
|
|
2871
|
+
"name": "unit",
|
|
2872
|
+
"fieldName": "unit"
|
|
2873
|
+
},
|
|
2874
|
+
{
|
|
2875
|
+
"type": {
|
|
2876
|
+
"text": "string | undefined"
|
|
2877
|
+
},
|
|
2878
|
+
"description": "[How the unit is denoted](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#unitdisplay): `short` | `narrow` | `long`",
|
|
2879
|
+
"name": "unitdisplay",
|
|
2880
|
+
"fieldName": "unitdisplay"
|
|
2881
|
+
},
|
|
2882
|
+
{
|
|
2883
|
+
"type": {
|
|
2884
|
+
"text": "string | undefined"
|
|
2885
|
+
},
|
|
2886
|
+
"description": "[When to show the sign](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#signdisplay): `auto` | `always` | `exceptZero` | `never`",
|
|
2887
|
+
"name": "signdisplay",
|
|
2888
|
+
"fieldName": "signdisplay"
|
|
2889
|
+
},
|
|
2890
|
+
{
|
|
2891
|
+
"name": "lang",
|
|
2892
|
+
"type": {
|
|
2893
|
+
"text": "string"
|
|
2894
|
+
},
|
|
2895
|
+
"fieldName": "lang",
|
|
2896
|
+
"description": "BCP 47 locale tag. Inherits from nearest ancestor `[lang]` if not set.",
|
|
2897
|
+
"inheritedFrom": {
|
|
2898
|
+
"name": "UseLocaleElement",
|
|
2899
|
+
"module": "src/elements/use-locale-element/use-locale-element.ts"
|
|
2900
|
+
}
|
|
2901
|
+
}
|
|
2902
|
+
],
|
|
2903
|
+
"superclass": {
|
|
2904
|
+
"name": "UseLocaleElement",
|
|
2905
|
+
"module": "/src/elements/use-locale-element/use-locale-element"
|
|
2906
|
+
},
|
|
2907
|
+
"tagName": "use-intl-number",
|
|
2908
|
+
"customElement": true
|
|
2909
|
+
}
|
|
2910
|
+
],
|
|
2911
|
+
"exports": [
|
|
2912
|
+
{
|
|
2913
|
+
"kind": "js",
|
|
2914
|
+
"name": "UseIntlNumber",
|
|
2915
|
+
"declaration": {
|
|
2916
|
+
"name": "UseIntlNumber",
|
|
2917
|
+
"module": "src/elements/use-intl-number/use-intl-number.ts"
|
|
2918
|
+
}
|
|
2919
|
+
},
|
|
2920
|
+
{
|
|
2921
|
+
"kind": "custom-element-definition",
|
|
2922
|
+
"name": "use-intl-number",
|
|
2923
|
+
"declaration": {
|
|
2924
|
+
"name": "UseIntlNumber",
|
|
2925
|
+
"module": "src/elements/use-intl-number/use-intl-number.ts"
|
|
2926
|
+
}
|
|
2927
|
+
}
|
|
2928
|
+
]
|
|
2929
|
+
},
|
|
2751
2930
|
{
|
|
2752
2931
|
"kind": "javascript-module",
|
|
2753
2932
|
"path": "src/elements/use-listbox-input/use-listbox-input.ts",
|
package/dist/design-system.css
CHANGED
|
@@ -1241,3 +1241,19 @@
|
|
|
1241
1241
|
}
|
|
1242
1242
|
}
|
|
1243
1243
|
|
|
1244
|
+
/* Grid — a cell holding a use-intl-number reads as tabular data, so it defaults to end-aligned
|
|
1245
|
+
text with tabular-nums, which locks every digit to the same width so values stack and compare
|
|
1246
|
+
cleanly down a column. text-align and font-variant-numeric are both inherited, so setting them
|
|
1247
|
+
on use-gridcell reaches the formatted text inside use-intl-number's shadow root without needing
|
|
1248
|
+
a rule scoped to use-intl-number itself. */
|
|
1249
|
+
@layer use-theme.grid {
|
|
1250
|
+
use-gridcell:has(use-intl-number) {
|
|
1251
|
+
text-align: end;
|
|
1252
|
+
font-variant-numeric: tabular-nums;
|
|
1253
|
+
|
|
1254
|
+
use-theme-escape & {
|
|
1255
|
+
all: revert-layer;
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# `use-intl-number`
|
|
2
|
+
|
|
3
|
+
Displays a localized, human-readable representation of a number using
|
|
4
|
+
[`Intl.NumberFormat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat).
|
|
5
|
+
Renders a semantic `<data>` element in its shadow root with a machine-readable
|
|
6
|
+
`value` attribute and formatted inner text.
|
|
7
|
+
|
|
8
|
+
Set `numberstyle` to control what kind of number is formatted (see
|
|
9
|
+
[`style`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#style)):
|
|
10
|
+
- `decimal` (default) → plain number, e.g. `1,234.5`
|
|
11
|
+
- `percent` → percentage, e.g. `42%` (value is the fraction, so `0.42` renders `42%`)
|
|
12
|
+
- `currency` → currency amount, requires `currency`
|
|
13
|
+
- `unit` → measurement, requires `unit`
|
|
14
|
+
|
|
15
|
+
Locale is resolved from the nearest ancestor `[lang]` attribute, or
|
|
16
|
+
`navigator.language` if none is found. Set `lang` directly on the element to override.
|
|
17
|
+
|
|
18
|
+
## Attributes
|
|
19
|
+
|
|
20
|
+
| Name | Type | Default | Description |
|
|
21
|
+
| --- | --- | --- | --- |
|
|
22
|
+
| value | `string \| undefined` | - | Numeric amount to format |
|
|
23
|
+
| numberstyle | `string \| undefined` | - | Format style: `decimal` \| `percent` \| `currency` \| `unit` |
|
|
24
|
+
| currency | `string \| undefined` | - | [ISO 4217 currency code](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currency), e.g. `USD`, `EUR`, `JPY`. Required when numberstyle is `currency` |
|
|
25
|
+
| currencydisplay | `string \| undefined` | - | [How the currency is denoted](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currencydisplay): `symbol` \| `narrowSymbol` \| `code` \| `name` |
|
|
26
|
+
| currencysign | `string \| undefined` | - | [Sign convention](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currencysign): `standard` (minus sign) \| `accounting` (parenthesized negatives) |
|
|
27
|
+
| unit | `string \| undefined` | - | [Unit identifier](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#unit), e.g. `kilometer-per-hour`, `liter`. Required when numberstyle is `unit` |
|
|
28
|
+
| unitdisplay | `string \| undefined` | - | [How the unit is denoted](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#unitdisplay): `short` \| `narrow` \| `long` |
|
|
29
|
+
| signdisplay | `string \| undefined` | - | [When to show the sign](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#signdisplay): `auto` \| `always` \| `exceptZero` \| `never` |
|
|
30
|
+
| lang | `string` | - | BCP 47 locale tag. Inherits from nearest ancestor `[lang]` if not set. |
|
package/dist/use-wc.d.mts
CHANGED
|
@@ -1406,6 +1406,52 @@ declare global {
|
|
|
1406
1406
|
}
|
|
1407
1407
|
}
|
|
1408
1408
|
//#endregion
|
|
1409
|
+
//#region src/elements/use-intl-number/use-intl-number.d.ts
|
|
1410
|
+
/**
|
|
1411
|
+
* Displays a localized, human-readable representation of a number using
|
|
1412
|
+
* [`Intl.NumberFormat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat).
|
|
1413
|
+
* Renders a semantic `<data>` element in its shadow root with a machine-readable
|
|
1414
|
+
* `value` attribute and formatted inner text.
|
|
1415
|
+
*
|
|
1416
|
+
* Set `numberstyle` to control what kind of number is formatted (see
|
|
1417
|
+
* [`style`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#style)):
|
|
1418
|
+
* - `decimal` (default) → plain number, e.g. `1,234.5`
|
|
1419
|
+
* - `percent` → percentage, e.g. `42%` (value is the fraction, so `0.42` renders `42%`)
|
|
1420
|
+
* - `currency` → currency amount, requires `currency`
|
|
1421
|
+
* - `unit` → measurement, requires `unit`
|
|
1422
|
+
*
|
|
1423
|
+
* Locale is resolved from the nearest ancestor `[lang]` attribute, or
|
|
1424
|
+
* `navigator.language` if none is found. Set `lang` directly on the element to override.
|
|
1425
|
+
*
|
|
1426
|
+
* @attr {string} value - Numeric amount to format
|
|
1427
|
+
* @attr {string} numberstyle - Format style: `decimal` | `percent` | `currency` | `unit`
|
|
1428
|
+
* @attr {string} currency - [ISO 4217 currency code](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currency), e.g. `USD`, `EUR`, `JPY`. Required when numberstyle is `currency`
|
|
1429
|
+
* @attr {string} currencydisplay - [How the currency is denoted](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currencydisplay): `symbol` | `narrowSymbol` | `code` | `name`
|
|
1430
|
+
* @attr {string} currencysign - [Sign convention](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currencysign): `standard` (minus sign) | `accounting` (parenthesized negatives)
|
|
1431
|
+
* @attr {string} unit - [Unit identifier](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#unit), e.g. `kilometer-per-hour`, `liter`. Required when numberstyle is `unit`
|
|
1432
|
+
* @attr {string} unitdisplay - [How the unit is denoted](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#unitdisplay): `short` | `narrow` | `long`
|
|
1433
|
+
* @attr {string} signdisplay - [When to show the sign](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#signdisplay): `auto` | `always` | `exceptZero` | `never`
|
|
1434
|
+
* @attr {string} lang - BCP 47 locale tag. Inherits from nearest ancestor `[lang]` if not set.
|
|
1435
|
+
*/
|
|
1436
|
+
declare class UseIntlNumber extends UseLocaleElement {
|
|
1437
|
+
#private;
|
|
1438
|
+
static styles: import("lit").CSSResult;
|
|
1439
|
+
value?: string;
|
|
1440
|
+
numberstyle?: string;
|
|
1441
|
+
currency?: string;
|
|
1442
|
+
currencydisplay?: string;
|
|
1443
|
+
currencysign?: string;
|
|
1444
|
+
unit?: string;
|
|
1445
|
+
unitdisplay?: string;
|
|
1446
|
+
signdisplay?: string;
|
|
1447
|
+
render(): TemplateResult$1<1>;
|
|
1448
|
+
}
|
|
1449
|
+
declare global {
|
|
1450
|
+
interface HTMLElementTagNameMap {
|
|
1451
|
+
"use-intl-number": UseIntlNumber;
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
//#endregion
|
|
1409
1455
|
//#region src/elements/use-badge/use-badge.d.ts
|
|
1410
1456
|
/**
|
|
1411
1457
|
* `use-badge` renders a small indicator anchored to another element's corner, using
|
|
@@ -1508,4 +1554,4 @@ declare global {
|
|
|
1508
1554
|
}
|
|
1509
1555
|
}
|
|
1510
1556
|
//#endregion
|
|
1511
|
-
export { UseAnchored, UseBadge, UseCalendarBase, UseCalendarRenderDay, UseCaret, UseDateInput, UseDatePicker, UseDatetimeInput, UseDurationInput, UseFocusgroup, UseIntlDatetime, UseListboxInput, UseMenu, UseMonthPicker, UseMonthPickerRenderMonth, UseOption, UseScrollarea, UseTimeInput, UseTree, UseTreeitem, UseWeekPicker, UseWidget };
|
|
1557
|
+
export { UseAnchored, UseBadge, UseCalendarBase, UseCalendarRenderDay, UseCaret, UseDateInput, UseDatePicker, UseDatetimeInput, UseDurationInput, UseFocusgroup, UseIntlDatetime, UseIntlNumber, UseListboxInput, UseMenu, UseMonthPicker, UseMonthPickerRenderMonth, UseOption, UseScrollarea, UseTimeInput, UseTree, UseTreeitem, UseWeekPicker, UseWidget };
|
package/dist/use-wc.mjs
CHANGED
|
@@ -4290,6 +4290,112 @@ __decorate([property({ type: String })], UseIntlDatetime.prototype, "datestyle",
|
|
|
4290
4290
|
__decorate([property({ type: String })], UseIntlDatetime.prototype, "timestyle", void 0);
|
|
4291
4291
|
UseIntlDatetime = __decorate([customElement("use-intl-datetime")], UseIntlDatetime);
|
|
4292
4292
|
//#endregion
|
|
4293
|
+
//#region src/elements/use-intl-number/use-intl-number.ts
|
|
4294
|
+
const NUMBER_STYLES = [
|
|
4295
|
+
"decimal",
|
|
4296
|
+
"percent",
|
|
4297
|
+
"currency",
|
|
4298
|
+
"unit"
|
|
4299
|
+
];
|
|
4300
|
+
const CURRENCY_DISPLAYS = [
|
|
4301
|
+
"symbol",
|
|
4302
|
+
"narrowSymbol",
|
|
4303
|
+
"code",
|
|
4304
|
+
"name"
|
|
4305
|
+
];
|
|
4306
|
+
const CURRENCY_SIGNS = ["standard", "accounting"];
|
|
4307
|
+
const SIGN_DISPLAYS = [
|
|
4308
|
+
"auto",
|
|
4309
|
+
"always",
|
|
4310
|
+
"exceptZero",
|
|
4311
|
+
"never"
|
|
4312
|
+
];
|
|
4313
|
+
const UNIT_DISPLAYS = [
|
|
4314
|
+
"short",
|
|
4315
|
+
"narrow",
|
|
4316
|
+
"long"
|
|
4317
|
+
];
|
|
4318
|
+
let UseIntlNumber = class UseIntlNumber extends UseLocaleElement {
|
|
4319
|
+
static {
|
|
4320
|
+
this.styles = css`
|
|
4321
|
+
:host {
|
|
4322
|
+
display: contents;
|
|
4323
|
+
}
|
|
4324
|
+
`;
|
|
4325
|
+
}
|
|
4326
|
+
#resolveNumberStyle() {
|
|
4327
|
+
return NUMBER_STYLES.includes(this.numberstyle) ? this.numberstyle : "decimal";
|
|
4328
|
+
}
|
|
4329
|
+
#resolveCurrencyDisplay() {
|
|
4330
|
+
return CURRENCY_DISPLAYS.includes(this.currencydisplay) ? this.currencydisplay : "symbol";
|
|
4331
|
+
}
|
|
4332
|
+
#resolveCurrencySign() {
|
|
4333
|
+
return CURRENCY_SIGNS.includes(this.currencysign) ? this.currencysign : "standard";
|
|
4334
|
+
}
|
|
4335
|
+
#resolveUnitDisplay() {
|
|
4336
|
+
return UNIT_DISPLAYS.includes(this.unitdisplay) ? this.unitdisplay : "short";
|
|
4337
|
+
}
|
|
4338
|
+
#resolveSignDisplay() {
|
|
4339
|
+
return SIGN_DISPLAYS.includes(this.signdisplay) ? this.signdisplay : "auto";
|
|
4340
|
+
}
|
|
4341
|
+
#resolveOptions(style) {
|
|
4342
|
+
if (style === "currency") {
|
|
4343
|
+
if (!this.currency) return null;
|
|
4344
|
+
return {
|
|
4345
|
+
style,
|
|
4346
|
+
currency: this.currency,
|
|
4347
|
+
currencyDisplay: this.#resolveCurrencyDisplay(),
|
|
4348
|
+
currencySign: this.#resolveCurrencySign(),
|
|
4349
|
+
signDisplay: this.#resolveSignDisplay()
|
|
4350
|
+
};
|
|
4351
|
+
}
|
|
4352
|
+
if (style === "unit") {
|
|
4353
|
+
if (!this.unit) return null;
|
|
4354
|
+
return {
|
|
4355
|
+
style,
|
|
4356
|
+
unit: this.unit,
|
|
4357
|
+
unitDisplay: this.#resolveUnitDisplay(),
|
|
4358
|
+
signDisplay: this.#resolveSignDisplay()
|
|
4359
|
+
};
|
|
4360
|
+
}
|
|
4361
|
+
return {
|
|
4362
|
+
style,
|
|
4363
|
+
signDisplay: this.#resolveSignDisplay()
|
|
4364
|
+
};
|
|
4365
|
+
}
|
|
4366
|
+
#computeFormatted() {
|
|
4367
|
+
const value = this.value ?? "";
|
|
4368
|
+
const locale = this.lang;
|
|
4369
|
+
if (!value || value.trim() === "") return null;
|
|
4370
|
+
const amount = Number(value);
|
|
4371
|
+
if (isNaN(amount)) return null;
|
|
4372
|
+
const options = this.#resolveOptions(this.#resolveNumberStyle());
|
|
4373
|
+
if (!options) return null;
|
|
4374
|
+
try {
|
|
4375
|
+
return {
|
|
4376
|
+
valueAttr: String(amount),
|
|
4377
|
+
text: new Intl.NumberFormat(locale, options).format(amount)
|
|
4378
|
+
};
|
|
4379
|
+
} catch {
|
|
4380
|
+
return null;
|
|
4381
|
+
}
|
|
4382
|
+
}
|
|
4383
|
+
render() {
|
|
4384
|
+
const result = this.#computeFormatted();
|
|
4385
|
+
if (!result) return html`<data></data>`;
|
|
4386
|
+
return html`<data value=${result.valueAttr}>${result.text}</data>`;
|
|
4387
|
+
}
|
|
4388
|
+
};
|
|
4389
|
+
__decorate([property({ type: String })], UseIntlNumber.prototype, "value", void 0);
|
|
4390
|
+
__decorate([property({ type: String })], UseIntlNumber.prototype, "numberstyle", void 0);
|
|
4391
|
+
__decorate([property({ type: String })], UseIntlNumber.prototype, "currency", void 0);
|
|
4392
|
+
__decorate([property({ type: String })], UseIntlNumber.prototype, "currencydisplay", void 0);
|
|
4393
|
+
__decorate([property({ type: String })], UseIntlNumber.prototype, "currencysign", void 0);
|
|
4394
|
+
__decorate([property({ type: String })], UseIntlNumber.prototype, "unit", void 0);
|
|
4395
|
+
__decorate([property({ type: String })], UseIntlNumber.prototype, "unitdisplay", void 0);
|
|
4396
|
+
__decorate([property({ type: String })], UseIntlNumber.prototype, "signdisplay", void 0);
|
|
4397
|
+
UseIntlNumber = __decorate([customElement("use-intl-number")], UseIntlNumber);
|
|
4398
|
+
//#endregion
|
|
4293
4399
|
//#region src/elements/use-badge/use-badge.ts
|
|
4294
4400
|
let UseBadge = class UseBadge extends LitElement {
|
|
4295
4401
|
#internals;
|
|
@@ -4446,4 +4552,4 @@ __decorate([property({
|
|
|
4446
4552
|
})], UseBadge.prototype, "options", void 0);
|
|
4447
4553
|
UseBadge = __decorate([customElement("use-badge")], UseBadge);
|
|
4448
4554
|
//#endregion
|
|
4449
|
-
export { UseAnchored, UseBadge, UseCalendarBase, UseCaret, UseDateInput, UseDatePicker, UseDatetimeInput, UseDurationInput, UseFocusgroup, UseIntlDatetime, UseListboxInput, UseMenu, UseMonthPicker, UseOption, UseScrollarea, UseTimeInput, UseTree, UseTreeitem, UseWeekPicker, UseWidget };
|
|
4555
|
+
export { UseAnchored, UseBadge, UseCalendarBase, UseCaret, UseDateInput, UseDatePicker, UseDatetimeInput, UseDurationInput, UseFocusgroup, UseIntlDatetime, UseIntlNumber, UseListboxInput, UseMenu, UseMonthPicker, UseOption, UseScrollarea, UseTimeInput, UseTree, UseTreeitem, UseWeekPicker, UseWidget };
|
package/package.json
CHANGED
|
@@ -252,6 +252,58 @@
|
|
|
252
252
|
],
|
|
253
253
|
"references": []
|
|
254
254
|
},
|
|
255
|
+
{
|
|
256
|
+
"name": "use-intl-number",
|
|
257
|
+
"description": "Displays a localized, human-readable representation of a number using\n[`Intl.NumberFormat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat).\nRenders a semantic `<data>` element in its shadow root with a machine-readable\n`value` attribute and formatted inner text.\n\nSet `numberstyle` to control what kind of number is formatted (see\n[`style`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#style)):\n- `decimal` (default) → plain number, e.g. `1,234.5`\n- `percent` → percentage, e.g. `42%` (value is the fraction, so `0.42` renders `42%`)\n- `currency` → currency amount, requires `currency`\n- `unit` → measurement, requires `unit`\n\nLocale is resolved from the nearest ancestor `[lang]` attribute, or\n`navigator.language` if none is found. Set `lang` directly on the element to override.\n---\n",
|
|
258
|
+
"attributes": [
|
|
259
|
+
{
|
|
260
|
+
"name": "value",
|
|
261
|
+
"description": "Numeric amount to format",
|
|
262
|
+
"values": []
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
"name": "numberstyle",
|
|
266
|
+
"description": "Format style: `decimal` | `percent` | `currency` | `unit`",
|
|
267
|
+
"values": []
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
"name": "currency",
|
|
271
|
+
"description": "[ISO 4217 currency code](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currency), e.g. `USD`, `EUR`, `JPY`. Required when numberstyle is `currency`",
|
|
272
|
+
"values": []
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
"name": "currencydisplay",
|
|
276
|
+
"description": "[How the currency is denoted](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currencydisplay): `symbol` | `narrowSymbol` | `code` | `name`",
|
|
277
|
+
"values": []
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
"name": "currencysign",
|
|
281
|
+
"description": "[Sign convention](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currencysign): `standard` (minus sign) | `accounting` (parenthesized negatives)",
|
|
282
|
+
"values": []
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
"name": "unit",
|
|
286
|
+
"description": "[Unit identifier](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#unit), e.g. `kilometer-per-hour`, `liter`. Required when numberstyle is `unit`",
|
|
287
|
+
"values": []
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
"name": "unitdisplay",
|
|
291
|
+
"description": "[How the unit is denoted](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#unitdisplay): `short` | `narrow` | `long`",
|
|
292
|
+
"values": []
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
"name": "signdisplay",
|
|
296
|
+
"description": "[When to show the sign](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#signdisplay): `auto` | `always` | `exceptZero` | `never`",
|
|
297
|
+
"values": []
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
"name": "lang",
|
|
301
|
+
"description": "BCP 47 locale tag. Inherits from nearest ancestor `[lang]` if not set.",
|
|
302
|
+
"values": []
|
|
303
|
+
}
|
|
304
|
+
],
|
|
305
|
+
"references": []
|
|
306
|
+
},
|
|
255
307
|
{
|
|
256
308
|
"name": "use-listbox-input",
|
|
257
309
|
"description": "\n---\n\n\n### **Events:**\n - **use-change**\n\n### **Slots:**\n - **default** - NodeList of `use-option` elements",
|