|
3 | 3 | import { format } from '$lib/utils/format'; |
4 | 4 | import { PeriodType } from '$lib/utils/date'; |
5 | 5 | 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'; |
6 | 14 |
|
7 | 15 | const date = new Date('1982-03-30T00:00:00'); |
8 | 16 | </script> |
|
13 | 21 |
|
14 | 22 | <h1>Examples</h1> |
15 | 23 |
|
| 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 | + |
16 | 54 | <h2>number formats (defaut settings)</h2> |
17 | 55 |
|
18 | 56 | <Preview showCode> |
|
52 | 90 | <div>{format(date, PeriodType.Month)}</div> |
53 | 91 | <div>{format(date, PeriodType.CalendarYear)}</div> |
54 | 92 | <div>{format(date, PeriodType.Day, 'short')}</div> |
| 93 | + <div>{format(date, PeriodType.Month, 'short')}</div> |
| 94 | + <div>{format(date, PeriodType.CalendarYear, 'short')}</div> |
55 | 95 | </Preview> |
0 commit comments