1+ // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+ // SPDX-License-Identifier: Apache-2.0
3+
4+ import { html } from 'lit' ;
5+ import '@nvidia-elements/core/format-number/define.js' ;
6+
7+ export default {
8+ title : 'Elements/FormatNumber' ,
9+ component : 'nve-format-number'
10+ } ;
11+
12+ /**
13+ * @summary Basic decimal formatting with localized grouping separators. Use for inline counts and metrics.
14+ */
15+ export const Default = {
16+ render : ( ) => html `
17+ < nve-format-number > 1234567.89</ nve-format-number >
18+ `
19+ } ;
20+
21+ /**
22+ * @summary Currency formatting for monetary values with locale-aware symbols and separators. Use for prices, budgets, and financial totals.
23+ */
24+ export const Currency = {
25+ render : ( ) => html `
26+ < div nve-layout ="column gap:sm ">
27+ < nve-format-number format-style ="currency " currency ="USD "> 1234.56</ nve-format-number >
28+ < nve-format-number format-style ="currency " currency ="EUR " currency-display ="code "> 1234.56</ nve-format-number >
29+ < nve-format-number format-style ="currency " currency ="JPY " currency-display ="name "> 1234</ nve-format-number >
30+ </ div >
31+ `
32+ } ;
33+
34+ /**
35+ * @summary Percent formatting for ratios and completion values. Source values should already represent a fraction (such as 0.85 for 85 percent).
36+ */
37+ export const Percent = {
38+ render : ( ) => html `
39+ < div nve-layout ="column gap:sm ">
40+ < nve-format-number format-style ="percent "> 0.85</ nve-format-number >
41+ < nve-format-number format-style ="percent "> 0.126</ nve-format-number >
42+ </ div >
43+ `
44+ } ;
45+
46+ /**
47+ * @summary Unit formatting for measurements and quantities. Use for distances, storage sizes, or other numeric labels that need a localized unit suffix.
48+ */
49+ export const Unit = {
50+ render : ( ) => html `
51+ < div nve-layout ="column gap:sm ">
52+ < nve-format-number format-style ="unit " unit ="kilometer "> 1234.56</ nve-format-number >
53+ < nve-format-number format-style ="unit " unit ="byte " unit-display ="long "> 2048</ nve-format-number >
54+ < nve-format-number format-style ="unit " unit ="celsius " unit-display ="narrow "> 22</ nve-format-number >
55+ </ div >
56+ `
57+ } ;
58+
59+ /**
60+ * @summary Notation presets for scientific, engineering, and compact display. Use compact notation in dashboards or cards where space matters.
61+ */
62+ export const Notation = {
63+ render : ( ) => html `
64+ < div nve-layout ="column gap:sm ">
65+ < nve-format-number notation ="compact " compact-display ="short "> 1234567</ nve-format-number >
66+ < nve-format-number notation ="compact " compact-display ="long "> 1234567</ nve-format-number >
67+ < nve-format-number notation ="scientific "> 1234567</ nve-format-number >
68+ < nve-format-number notation ="engineering "> 1234567</ nve-format-number >
69+ </ div >
70+ `
71+ } ;
72+
73+ /**
74+ * @summary Sign display options for controlling positive and negative indicators. Use 'always' for delta values or 'exceptZero' for change indicators.
75+ */
76+ export const SignDisplay = {
77+ render : ( ) => html `
78+ < div nve-layout ="column gap:sm ">
79+ < nve-format-number sign-display ="always "> 42</ nve-format-number >
80+ < nve-format-number sign-display ="always "> -42</ nve-format-number >
81+ < nve-format-number sign-display ="exceptZero "> 0</ nve-format-number >
82+ < nve-format-number sign-display ="never "> -42</ nve-format-number >
83+ </ div >
84+ `
85+ } ;
86+
87+ /**
88+ * @summary Fraction digit control for tuning decimal precision. Use to enforce fixed decimal places in financial or scientific contexts.
89+ */
90+ export const FractionDigits = {
91+ render : ( ) => html `
92+ < div nve-layout ="column gap:sm ">
93+ < nve-format-number minimum-fraction-digits ="4 "> 1.5</ nve-format-number >
94+ < nve-format-number maximum-fraction-digits ="0 "> 1.567</ nve-format-number >
95+ < nve-format-number minimum-fraction-digits ="2 " maximum-fraction-digits ="2 "> 3</ nve-format-number >
96+ </ div >
97+ `
98+ } ;
99+
100+ /**
101+ * @summary Explicit locale settings for internationalized number output. Use when the target audience locale differs from the document language or browser default.
102+ */
103+ export const Locale = {
104+ render : ( ) => html `
105+ < div nve-layout ="column gap:sm ">
106+ < nve-format-number locale ="de-DE " format-style ="currency " currency ="EUR "> 1234.56</ nve-format-number >
107+ < nve-format-number locale ="ja-JP " format-style ="currency " currency ="JPY "> 1234</ nve-format-number >
108+ < nve-format-number locale ="fr-FR "> 1234567.89</ nve-format-number >
109+ </ div >
110+ `
111+ } ;
112+
113+ /**
114+ * @summary Number attribute input for values supplied by JavaScript or bound data. By default, the component formats text content, which also serves as the SSR fallback, and `number` wins when both are present.
115+ */
116+ export const NumberAttribute = {
117+ render : ( ) => html `
118+ < nve-format-number number ="1234.56 " format-style ="currency " currency ="USD "> </ nve-format-number >
119+ `
120+ } ;
0 commit comments