-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add WeekStartsOn defaults depending on the locale * init a Language Select comp
- Loading branch information
Showing
10 changed files
with
211 additions
and
135 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
packages/svelte-ux/src/lib/components/LanguageSelect.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<script lang="ts"> | ||
import Button from './Button.svelte'; | ||
import Menu from './Menu.svelte'; | ||
import MenuItem from './MenuItem.svelte'; | ||
import { cls } from '../utils/styles'; | ||
import { getSettings } from './settings'; | ||
const { locale } = getSettings(); | ||
let open = false; | ||
type Language = { | ||
name: string; | ||
code: string; | ||
flag: string; | ||
}; | ||
export let languagesDemo: Language[] = [ | ||
{ name: 'English', code: 'en', flag: '🇺🇸' }, | ||
{ name: 'Français', code: 'fr', flag: '🇫🇷' }, | ||
// add more for the demo | ||
]; | ||
$: languageSelected = languagesDemo.find((c) => c.code === $locale)!; | ||
</script> | ||
|
||
<Button on:click={() => (open = !open)}> | ||
{languageSelected.flag} | ||
<Menu bind:open on:close={() => (open = false)} offset={4} explicitClose resize> | ||
<div class="grid gap-2 p-2 border-b border-surface-content/10"> | ||
{#each languagesDemo as language} | ||
<MenuItem | ||
on:click={() => { | ||
languageSelected = language; | ||
locale.set(language.code); | ||
}} | ||
class={cls( | ||
'bg-surface-100 text-surface-content font-semibold border shadow', | ||
languageSelected === language && 'ring-2 ring-surface-content' | ||
)} | ||
> | ||
{language.flag} - {language.name} | ||
</MenuItem> | ||
{/each} | ||
</div> | ||
|
||
<div class="p-2 grid grid-cols-[auto,1fr] gap-2 items-center text-xs"> | ||
<span class="font-medium">Affect dates & numbers formats</span> | ||
</div> | ||
</Menu> | ||
</Button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { DayOfWeek } from './date_types'; | ||
|
||
export function getWeekStartsOnFromIntl(locales?: string): DayOfWeek { | ||
if (!locales) { | ||
return DayOfWeek.Sunday; | ||
} | ||
|
||
const info = new Intl.Locale(locales); | ||
// @ts-ignore | ||
return (info.weekInfo.firstDay ?? 0) % 7; // (in Intl, sunday is 7 not 0, so we need to mod 7) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.