> {}
export const useAvatar = (props: UseAvatarProps = {}) => {
+ const { dir } = useLocaleContext(DEFAULT_LOCALE)
const context = $derived({
id: createId(),
+ dir,
...props,
})
diff --git a/packages/svelte/src/lib/index.ts b/packages/svelte/src/lib/index.ts
index cb64ac1b52..6d63b651ae 100644
--- a/packages/svelte/src/lib/index.ts
+++ b/packages/svelte/src/lib/index.ts
@@ -1 +1,3 @@
export * from './components'
+export * from './providers'
+export type { Assign, Optional } from './types'
diff --git a/packages/svelte/src/lib/providers/index.ts b/packages/svelte/src/lib/providers/index.ts
new file mode 100644
index 0000000000..1e26053c0c
--- /dev/null
+++ b/packages/svelte/src/lib/providers/index.ts
@@ -0,0 +1 @@
+export * from './locale'
diff --git a/packages/svelte/src/lib/providers/locale/examples/basic.svelte b/packages/svelte/src/lib/providers/locale/examples/basic.svelte
new file mode 100644
index 0000000000..8f545feb39
--- /dev/null
+++ b/packages/svelte/src/lib/providers/locale/examples/basic.svelte
@@ -0,0 +1,8 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/packages/svelte/src/lib/providers/locale/examples/setup.svelte b/packages/svelte/src/lib/providers/locale/examples/setup.svelte
new file mode 100644
index 0000000000..b6730b02b8
--- /dev/null
+++ b/packages/svelte/src/lib/providers/locale/examples/setup.svelte
@@ -0,0 +1,5 @@
+
+
+
\ No newline at end of file
diff --git a/packages/svelte/src/lib/providers/locale/examples/usage.svelte b/packages/svelte/src/lib/providers/locale/examples/usage.svelte
new file mode 100644
index 0000000000..834289c050
--- /dev/null
+++ b/packages/svelte/src/lib/providers/locale/examples/usage.svelte
@@ -0,0 +1,7 @@
+
+
+{JSON.stringify(locale, null, 2)}
\ No newline at end of file
diff --git a/packages/svelte/src/lib/providers/locale/index.ts b/packages/svelte/src/lib/providers/locale/index.ts
new file mode 100644
index 0000000000..074a1a1c15
--- /dev/null
+++ b/packages/svelte/src/lib/providers/locale/index.ts
@@ -0,0 +1,2 @@
+export { default as LocaleProvider, type LocaleProviderProps } from './locale-provider.svelte'
+export { DEFAULT_LOCALE, useLocaleContext, type UseLocaleContext } from './use-locale-context'
diff --git a/packages/svelte/src/lib/providers/locale/locale-provider.svelte b/packages/svelte/src/lib/providers/locale/locale-provider.svelte
new file mode 100644
index 0000000000..461a915a29
--- /dev/null
+++ b/packages/svelte/src/lib/providers/locale/locale-provider.svelte
@@ -0,0 +1,32 @@
+
+
+
+
+{@render children()}
\ No newline at end of file
diff --git a/packages/svelte/src/lib/providers/locale/locale.stories.ts b/packages/svelte/src/lib/providers/locale/locale.stories.ts
new file mode 100644
index 0000000000..d982e4472a
--- /dev/null
+++ b/packages/svelte/src/lib/providers/locale/locale.stories.ts
@@ -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,
+ }),
+}
diff --git a/packages/svelte/src/lib/providers/locale/use-locale-context.ts b/packages/svelte/src/lib/providers/locale/use-locale-context.ts
new file mode 100644
index 0000000000..2adb69a7a5
--- /dev/null
+++ b/packages/svelte/src/lib/providers/locale/use-locale-context.ts
@@ -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({
+ key: 'LocaleContext',
+})
diff --git a/packages/svelte/src/lib/utils/create-context.ts b/packages/svelte/src/lib/utils/create-context.ts
index b22a8928bf..78f0ba0817 100644
--- a/packages/svelte/src/lib/utils/create-context.ts
+++ b/packages/svelte/src/lib/utils/create-context.ts
@@ -1,11 +1,16 @@
import { getContext, setContext } from 'svelte'
+interface CreateContextOptions {
+ key?: string
+}
+
type CreateContextReturn = [(opts: T) => void, (fallback?: T) => T, symbol]
-export const createContext = (id: string) => {
- const contextId = Symbol(id)
+export const createContext = (options: CreateContextOptions) => {
+ const { key } = options
+ const contextId = Symbol(key)
const provider = (value: T) => setContext(contextId, value)
- const consumer = () => getContext(contextId)
+ const consumer = () => getContext(contextId)
return [provider, consumer, contextId] as CreateContextReturn
}
diff --git a/templates/svelte/svelte-kit/src/lib/avatar.svelte b/templates/svelte/svelte-kit/src/lib/avatar.svelte
index f51ddc91bc..088a9c3ec1 100644
--- a/templates/svelte/svelte-kit/src/lib/avatar.svelte
+++ b/templates/svelte/svelte-kit/src/lib/avatar.svelte
@@ -9,7 +9,7 @@ export interface AvatarProps extends AvatarRootProps {
-
+
{getInitials()}