Skip to content

Commit 1696cf0

Browse files
committed
Add format() playground
1 parent d1c31c8 commit 1696cf0

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

packages/svelte-ux/src/routes/docs/utils/format/+page.svelte

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
import { format } from '$lib/utils/format';
44
import { PeriodType } from '$lib/utils/date';
55
import Code from '$lib/components/Code.svelte';
6+
import TextField from '$lib/components/TextField.svelte';
7+
import MenuField from '$lib/components/MenuField.svelte';
8+
import type { FormatNumberStyle } from '$lib/utils/number';
9+
10+
let value = 1234.56;
11+
let style: FormatNumberStyle = 'decimal';
12+
let locales: string = 'en'; //
13+
let currency: string = 'USD';
614
715
const date = new Date('1982-03-30T00:00:00');
816
</script>
@@ -13,6 +21,36 @@
1321

1422
<h1>Examples</h1>
1523

24+
<h2>Playground</h2>
25+
26+
<div class="grid grid-cols-xs gap-2 mb-2">
27+
<TextField label="value" bind:value type="decimal" />
28+
29+
<MenuField
30+
label="style"
31+
bind:value={style}
32+
options={['integer', 'decimal', 'currency', 'percent', 'percentRound', 'metric'].map(
33+
(value) => ({ label: value, value })
34+
)}
35+
/>
36+
37+
<MenuField
38+
label="locale"
39+
bind:value={locales}
40+
options={['en', 'de', 'fr', 'jp'].map((value) => ({ label: value, value }))}
41+
/>
42+
43+
<MenuField
44+
label="currency"
45+
bind:value={currency}
46+
options={['USD', 'EUR', 'GBP', 'JPY'].map((value) => ({ label: value, value }))}
47+
/>
48+
</div>
49+
50+
<Preview>
51+
<div>{format(value, style, { locales, currency })}</div>
52+
</Preview>
53+
1654
<h2>number formats (defaut settings)</h2>
1755

1856
<Preview showCode>
@@ -52,4 +90,6 @@
5290
<div>{format(date, PeriodType.Month)}</div>
5391
<div>{format(date, PeriodType.CalendarYear)}</div>
5492
<div>{format(date, PeriodType.Day, 'short')}</div>
93+
<div>{format(date, PeriodType.Month, 'short')}</div>
94+
<div>{format(date, PeriodType.CalendarYear, 'short')}</div>
5595
</Preview>

0 commit comments

Comments
 (0)