-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
68242f0
commit 6d64dbc
Showing
16 changed files
with
118 additions
and
7 deletions.
There are no files selected for viewing
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
5 changes: 4 additions & 1 deletion
5
packages/svelte/src/lib/components/avatar/examples/basic.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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
<script lang="ts"> | ||
import { Avatar } from '@ark-ui/svelte/avatar' | ||
import { LocaleProvider } from '$lib/providers' | ||
import { Avatar } from '@ark-ui/svelte/avatar' | ||
</script> | ||
|
||
<LocaleProvider locale="de-DE"> | ||
<Avatar.Root> | ||
<Avatar.Fallback>PA</Avatar.Fallback> | ||
<Avatar.Image src="https://i.pravatar.cc/3000" alt="avatar" /> | ||
</Avatar.Root> | ||
</LocaleProvider> |
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
export * from './components' | ||
export * from './providers' | ||
export type { Assign, Optional } from './types' |
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 @@ | ||
export * from './locale' |
8 changes: 8 additions & 0 deletions
8
packages/svelte/src/lib/providers/locale/examples/basic.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,8 @@ | ||
<script lang="ts"> | ||
import { LocaleProvider } from '@ark-ui/svelte/locale' | ||
import Usage from './usage.svelte' | ||
</script> | ||
|
||
<LocaleProvider locale="ar-BH"> | ||
<Usage /> | ||
</LocaleProvider> |
5 changes: 5 additions & 0 deletions
5
packages/svelte/src/lib/providers/locale/examples/setup.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,5 @@ | ||
<script lang="ts"> | ||
import { LocaleProvider } from '@ark-ui/svelte/locale' | ||
</script> | ||
|
||
<LocaleProvider locale="de-DE"> <!-- Your App --></LocaleProvider> |
7 changes: 7 additions & 0 deletions
7
packages/svelte/src/lib/providers/locale/examples/usage.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,7 @@ | ||
<script lang="ts"> | ||
import { useLocaleContext } from '@ark-ui/svelte/locale' | ||
const locale = useLocaleContext() | ||
</script> | ||
|
||
<pre>{JSON.stringify(locale, null, 2)}</pre> |
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,2 @@ | ||
export { default as LocaleProvider, type LocaleProviderProps } from './locale-provider.svelte' | ||
export { DEFAULT_LOCALE, useLocaleContext, type UseLocaleContext } from './use-locale-context' |
32 changes: 32 additions & 0 deletions
32
packages/svelte/src/lib/providers/locale/locale-provider.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,32 @@ | ||
<script module lang="ts"> | ||
import type { Locale } from '@zag-js/i18n-utils' | ||
import type { Snippet } from 'svelte' | ||
export interface LocaleProviderProps { | ||
/** | ||
* The locale to use for the application. | ||
* @default 'en-US' | ||
*/ | ||
locale: string | ||
/** | ||
* The children to render. | ||
*/ | ||
children: Snippet | ||
} | ||
</script> | ||
|
||
<script lang="ts"> | ||
import { isRTL } from '@zag-js/i18n-utils' | ||
import { LocaleContextProvider } from './use-locale-context' | ||
let {locale, children}: LocaleProviderProps = $props() | ||
const context = $state<Locale>({ | ||
locale, | ||
dir: isRTL(locale) ? 'rtl' : 'ltr', | ||
}) | ||
LocaleContextProvider(context) | ||
</script> | ||
|
||
{@render children()} |
21 changes: 21 additions & 0 deletions
21
packages/svelte/src/lib/providers/locale/locale.stories.ts
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,21 @@ | ||
import type { Meta } from '@storybook/svelte' | ||
import BasicExample from './examples/basic.svelte' | ||
import SetupExample from './examples/setup.svelte' | ||
|
||
const meta = { | ||
title: 'Providers / Locale', | ||
} as Meta | ||
|
||
export default meta | ||
|
||
export const Basic = { | ||
render: () => ({ | ||
Component: BasicExample, | ||
}), | ||
} | ||
|
||
export const Setup = { | ||
render: () => ({ | ||
Component: SetupExample, | ||
}), | ||
} |
13 changes: 13 additions & 0 deletions
13
packages/svelte/src/lib/providers/locale/use-locale-context.ts
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,13 @@ | ||
import { createContext } from '$lib/utils/create-context' | ||
import type { Locale } from '@zag-js/i18n-utils' | ||
|
||
export const DEFAULT_LOCALE: Locale = { | ||
dir: 'ltr', | ||
locale: 'en-US', | ||
} | ||
|
||
export interface UseLocaleContext extends Locale {} | ||
|
||
export const [LocaleContextProvider, useLocaleContext] = createContext<UseLocaleContext>({ | ||
key: 'LocaleContext', | ||
}) |
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 |
---|---|---|
@@ -1,11 +1,16 @@ | ||
import { getContext, setContext } from 'svelte' | ||
|
||
interface CreateContextOptions<T> { | ||
key?: string | ||
} | ||
|
||
type CreateContextReturn<T> = [(opts: T) => void, (fallback?: T) => T, symbol] | ||
|
||
export const createContext = <T>(id: string) => { | ||
const contextId = Symbol(id) | ||
export const createContext = <T>(options: CreateContextOptions<T>) => { | ||
const { key } = options | ||
const contextId = Symbol(key) | ||
const provider = (value: T) => setContext(contextId, value) | ||
const consumer = () => getContext(contextId) | ||
const consumer = () => getContext<T>(contextId) | ||
|
||
return [provider, consumer, contextId] as CreateContextReturn<T> | ||
} |
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