|
5 | 5 | import DateTime from '$lib/components/ui/DateTime.svelte';
|
6 | 6 | import Token from '$lib/components/ui/Highlight/Token.svelte';
|
7 | 7 | import CodeBlock from '$lib/components/ui/CodeBlock.svelte';
|
| 8 | + import Spacing from '$lib/components/ui/Spacing.svelte'; |
| 9 | + import PageLayout from '$lib/components/pages/PageLayout.svelte'; |
| 10 | +
|
8 | 11 | import {
|
9 | 12 | datetimeFormatOptions,
|
10 | 13 | getDateTimeFormatOptions
|
11 | 14 | } from '$lib/format-options/datetime-format.options';
|
12 | 15 | import { copyToClipboard } from '$lib/utils/copy-to-clipboard';
|
13 |
| - import { languageByLocaleAsComboBoxOptions } from '$lib/locale-data/locales'; |
14 | 16 | import type { OptionValues } from '$lib/types/OptionValues.types';
|
15 | 17 | import type { BrowserCompatData } from '$lib/types/BrowserSupport.types';
|
16 |
| - import ComboBoxContext from '$lib/components/ui/ComboBox/ComboBoxContext.svelte'; |
17 |
| - import ComboBox from '$lib/components/ui/ComboBox/ComboBox.svelte'; |
18 |
| - import { selectedLocale } from '$lib/store/selected-locale'; |
19 |
| - import Spacing from '$lib/components/ui/Spacing.svelte'; |
20 | 18 | import { trackEvent } from '$lib/utils/analytics';
|
21 | 19 |
|
| 20 | +
|
22 | 21 | export let locale: string;
|
23 | 22 | export let browserCompatData: BrowserCompatData | null;
|
24 | 23 |
|
|
42 | 41 | };
|
43 | 42 | </script>
|
44 | 43 |
|
45 |
| -<h2>Input values</h2> |
46 |
| -<Spacing /> |
47 |
| - |
48 |
| -<ComboBoxContext> |
49 |
| - <ComboBox |
50 |
| - label="Locale" |
51 |
| - name="locale" |
52 |
| - bind:value={$selectedLocale} |
53 |
| - options={languageByLocaleAsComboBoxOptions} |
54 |
| - /> |
55 |
| -</ComboBoxContext> |
56 |
| -<Spacing size={2} /> |
57 |
| -<DateTime defaultValue={dateTimeString} {onChange} /> |
58 |
| -<Spacing /> |
59 |
| -<h2>Alternative use</h2> |
60 |
| -<Spacing /> |
| 44 | +<PageLayout> |
| 45 | + <DateTime slot="input" defaultValue={dateTimeString} {onChange} /> |
| 46 | + <div slot="alternativeUse"> |
| 47 | + <code>Intl.DateTimeFormat</code> |
| 48 | + can also be used from |
| 49 | + <strong |
| 50 | + ><a |
| 51 | + href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString" |
| 52 | + target="_blank" |
| 53 | + rel="noopener noreferrer">Date.prototype.toLocaleString()</a |
| 54 | + ></strong |
| 55 | + > |
| 56 | + </div> |
| 57 | + <CodeBlock slot="alternativeCode"> |
| 58 | + <Token v="new" t="punctuation" /> <Token v="Date" t="class" />{"("}<Token v="{`"${dateTimeString}"`}" t="string" />{")"} |
| 59 | + .<Token v="toLocaleString" t="function" />{"("}<Token v="{`"${locale}"`}" t="string" />{")"}{"\n"}<Token v="// " ariaHidden noTrim t="comment"/><Token v={`${new Date(dateTimeString).toLocaleString(locale)}`} t="comment" /> |
| 60 | + </CodeBlock> |
| 61 | + <Grid slot="output"> |
| 62 | + {#each Object.entries(datetimeFormatOptions) as [option, values]} |
| 63 | + <OptionSection header={option} {browserCompatData} stackedCompatView> |
| 64 | + {#each values as value} |
| 65 | + {#if value !== undefined} |
| 66 | + <Spacing size={1} /> |
| 67 | + <Highlight |
| 68 | + {onClick} |
| 69 | + values={{ [option]: value }} |
| 70 | + output={new Intl.DateTimeFormat(locale, getDateTimeFormatOptions(option, value)).format( |
| 71 | + new Date(`${dateTimeString}`) |
| 72 | + )} |
| 73 | + /> |
| 74 | + {/if} |
| 75 | + {/each} |
| 76 | + </OptionSection> |
| 77 | + {/each} |
| 78 | + </Grid> |
| 79 | +</PageLayout> |
61 | 80 |
|
62 |
| -<code>Intl.DateTimeFormat</code> |
63 |
| -can also be used from |
64 |
| -<strong |
65 |
| - ><a |
66 |
| - href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString" |
67 |
| - target="_blank" |
68 |
| - rel="noopener noreferrer">Date.prototype.toLocaleString()</a |
69 |
| - ></strong |
70 |
| -> |
71 |
| -<Spacing size={2} /> |
72 |
| -<CodeBlock> |
73 |
| -<Token v="new" t="punctuation" /> <Token v="Date" t="class" />{"("}<Token v="{`"${dateTimeString}"`}" t="string" />{")"} |
74 |
| - .<Token v="toLocaleString" t="function" />{"("}<Token v="{`"${locale}"`}" t="string" />{")"}{"\n"}<Token v="// " ariaHidden noTrim t="comment"/><Token v={`${new Date(dateTimeString).toLocaleString(locale)}`} t="comment" /> |
75 |
| -</CodeBlock> |
76 |
| -<Spacing size={2} /> |
77 |
| -<h2>Output</h2> |
78 |
| -<Spacing /> |
79 |
| -<Grid> |
80 |
| - {#each Object.entries(datetimeFormatOptions) as [option, values]} |
81 |
| - <OptionSection header={option} {browserCompatData} stackedCompatView> |
82 |
| - {#each values as value} |
83 |
| - {#if value !== undefined} |
84 |
| - <Spacing size={1} /> |
85 |
| - <Highlight |
86 |
| - {onClick} |
87 |
| - values={{ [option]: value }} |
88 |
| - output={new Intl.DateTimeFormat(locale, getDateTimeFormatOptions(option, value)).format( |
89 |
| - new Date(`${dateTimeString}`) |
90 |
| - )} |
91 |
| - /> |
92 |
| - {/if} |
93 |
| - {/each} |
94 |
| - </OptionSection> |
95 |
| - {/each} |
96 |
| -</Grid> |
0 commit comments