@better-i18n/use-intl 0.1.18 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/locale-dropdown.d.ts +62 -0
- package/dist/components/locale-dropdown.d.ts.map +1 -0
- package/dist/components/locale-dropdown.js +298 -0
- package/dist/components/locale-dropdown.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { LanguageOption } from "@better-i18n/core";
|
|
3
|
+
import { type ResolvedFlag } from "@better-i18n/core";
|
|
4
|
+
export interface LocaleDropdownRenderContext {
|
|
5
|
+
language: LanguageOption;
|
|
6
|
+
isActive: boolean;
|
|
7
|
+
flag: ResolvedFlag;
|
|
8
|
+
label: string;
|
|
9
|
+
}
|
|
10
|
+
export interface LocaleDropdownProps {
|
|
11
|
+
/** Display variant. "styled" = inline styles + CSS custom properties, "unstyled" = no styles (data attributes only). @default "styled" */
|
|
12
|
+
variant?: "styled" | "unstyled";
|
|
13
|
+
/** Additional className on the root wrapper. */
|
|
14
|
+
className?: string;
|
|
15
|
+
/** Additional className on the trigger button. */
|
|
16
|
+
triggerClassName?: string;
|
|
17
|
+
/** Additional className on the dropdown menu. */
|
|
18
|
+
menuClassName?: string;
|
|
19
|
+
/** Show flag icon/emoji. @default true */
|
|
20
|
+
showFlag?: boolean;
|
|
21
|
+
/** Show native language name. @default true */
|
|
22
|
+
showNativeName?: boolean;
|
|
23
|
+
/** Show locale code (e.g., "EN"). @default true */
|
|
24
|
+
showLocaleCode?: boolean;
|
|
25
|
+
/** Custom render for the trigger button. */
|
|
26
|
+
renderTrigger?: (ctx: {
|
|
27
|
+
language: LanguageOption | undefined;
|
|
28
|
+
isOpen: boolean;
|
|
29
|
+
isLoading: boolean;
|
|
30
|
+
flag: ResolvedFlag | null;
|
|
31
|
+
label: string;
|
|
32
|
+
}) => ReactNode;
|
|
33
|
+
/** Custom render for each menu item. */
|
|
34
|
+
renderItem?: (ctx: LocaleDropdownRenderContext) => ReactNode;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Styled locale dropdown with flag icons, keyboard navigation, and
|
|
38
|
+
* full CSS customization via custom properties or data attributes.
|
|
39
|
+
*
|
|
40
|
+
* Uses `useLocaleRouter()` and `useLanguages()` internally — works
|
|
41
|
+
* out of the box inside `<BetterI18nProvider>` with TanStack Router.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```tsx
|
|
45
|
+
* // Zero config — styled mode
|
|
46
|
+
* <LocaleDropdown />
|
|
47
|
+
*
|
|
48
|
+
* // Headless mode for full custom styling
|
|
49
|
+
* <LocaleDropdown variant="unstyled" className="my-dropdown" />
|
|
50
|
+
*
|
|
51
|
+
* // Custom render
|
|
52
|
+
* <LocaleDropdown
|
|
53
|
+
* renderItem={({ language, isActive, flag, label }) => (
|
|
54
|
+
* <div className={isActive ? "active" : ""}>
|
|
55
|
+
* {flag.type === "emoji" ? flag.emoji : null} {label}
|
|
56
|
+
* </div>
|
|
57
|
+
* )}
|
|
58
|
+
* />
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare function LocaleDropdown({ variant, className, triggerClassName, menuClassName, showFlag, showNativeName, showLocaleCode, renderTrigger, renderItem, }: LocaleDropdownProps): import("react/jsx-runtime").JSX.Element;
|
|
62
|
+
//# sourceMappingURL=locale-dropdown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locale-dropdown.d.ts","sourceRoot":"","sources":["../../src/components/locale-dropdown.tsx"],"names":[],"mappings":"AAEA,OAAO,EAOL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAGL,KA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from "react/jsx-runtime";
|
|
3
|
+
import { useCallback, useEffect, useMemo, useRef, useState, } from "react";
|
|
4
|
+
import { getLanguageLabel, resolveFlag, } from "@better-i18n/core";
|
|
5
|
+
import { useLocaleRouter } from "../hooks/useLocaleRouter.js";
|
|
6
|
+
import { useLanguages } from "../hooks.js";
|
|
7
|
+
// ─── Inline SVG Icons ────────────────────────────────────────────────
|
|
8
|
+
function GlobeIcon() {
|
|
9
|
+
return (_jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "square", "aria-hidden": "true", children: [_jsx("path", { d: "M21 12C21 16.9706 16.9706 21 12 21C7.02944 21 3 16.9706 3 12C3 7.02944 7.02944 3 12 3C16.9706 3 21 7.02944 21 12Z" }), _jsx("path", { d: "M21 12H3" }), _jsx("path", { d: "M12 21C10.067 21 8.5 16.9706 8.5 12C8.5 7.02944 10.067 3 12 3C13.933 3 15.5 7.02944 15.5 12C15.5 16.9706 13.933 21 12 21Z" })] }));
|
|
10
|
+
}
|
|
11
|
+
function ChevronDownIcon({ style }) {
|
|
12
|
+
return (_jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", style: style, children: _jsx("path", { d: "M20 9L13.4142 15.5858C12.6332 16.3668 11.3669 16.3668 10.5858 15.5858L4 9" }) }));
|
|
13
|
+
}
|
|
14
|
+
function CheckIcon() {
|
|
15
|
+
return (_jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: "M6 12l4.243 4.243L18.485 8" }) }));
|
|
16
|
+
}
|
|
17
|
+
// ─── Flag Component ──────────────────────────────────────────────────
|
|
18
|
+
function FlagDisplay({ flag, label, }) {
|
|
19
|
+
const [hasError, setHasError] = useState(false);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
setHasError(false);
|
|
22
|
+
}, [flag.type === "url" ? flag.url : null]);
|
|
23
|
+
if (flag.type === "url" && !hasError) {
|
|
24
|
+
return (_jsx("img", { src: flag.url, alt: label, style: { width: 20, height: 16, borderRadius: 2, objectFit: "cover" }, loading: "lazy", onError: () => setHasError(true) }));
|
|
25
|
+
}
|
|
26
|
+
if (flag.type === "emoji" || (flag.type === "url" && hasError)) {
|
|
27
|
+
const emoji = flag.type === "emoji" ? flag.emoji : null;
|
|
28
|
+
if (emoji) {
|
|
29
|
+
return (_jsx("span", { style: {
|
|
30
|
+
display: "inline-flex",
|
|
31
|
+
alignItems: "center",
|
|
32
|
+
justifyContent: "center",
|
|
33
|
+
width: 20,
|
|
34
|
+
height: 16,
|
|
35
|
+
fontSize: 14,
|
|
36
|
+
lineHeight: 1,
|
|
37
|
+
}, "aria-hidden": "true", children: emoji }));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return (_jsx("span", { style: { color: "var(--better-locale-code-text, #9ca3af)" }, children: _jsx(GlobeIcon, {}) }));
|
|
41
|
+
}
|
|
42
|
+
// ─── Styles ──────────────────────────────────────────────────────────
|
|
43
|
+
const styles = {
|
|
44
|
+
trigger: {
|
|
45
|
+
display: "inline-flex",
|
|
46
|
+
alignItems: "center",
|
|
47
|
+
gap: 8,
|
|
48
|
+
padding: "var(--better-locale-trigger-padding, 6px 10px)",
|
|
49
|
+
borderRadius: "var(--better-locale-trigger-radius, 8px)",
|
|
50
|
+
border: "var(--better-locale-trigger-border, 1px solid transparent)",
|
|
51
|
+
background: "var(--better-locale-trigger-bg, transparent)",
|
|
52
|
+
color: "var(--better-locale-text, #374151)",
|
|
53
|
+
fontSize: 14,
|
|
54
|
+
fontWeight: 500,
|
|
55
|
+
cursor: "pointer",
|
|
56
|
+
transition: "background 0.15s, border-color 0.15s",
|
|
57
|
+
lineHeight: 1,
|
|
58
|
+
fontFamily: "inherit",
|
|
59
|
+
},
|
|
60
|
+
triggerDisabled: {
|
|
61
|
+
opacity: 0.7,
|
|
62
|
+
cursor: "default",
|
|
63
|
+
},
|
|
64
|
+
menu: {
|
|
65
|
+
position: "absolute",
|
|
66
|
+
right: 0,
|
|
67
|
+
top: "calc(100% + 4px)",
|
|
68
|
+
minWidth: 200,
|
|
69
|
+
maxHeight: "70vh",
|
|
70
|
+
overflowY: "auto",
|
|
71
|
+
borderRadius: 12,
|
|
72
|
+
border: "1px solid var(--better-locale-border, #e5e7eb)",
|
|
73
|
+
background: "var(--better-locale-menu-bg, #ffffff)",
|
|
74
|
+
boxShadow: "0 4px 24px rgba(0, 0, 0, 0.12)",
|
|
75
|
+
padding: 0,
|
|
76
|
+
zIndex: 50,
|
|
77
|
+
listStyle: "none",
|
|
78
|
+
margin: 0,
|
|
79
|
+
},
|
|
80
|
+
item: {
|
|
81
|
+
display: "flex",
|
|
82
|
+
alignItems: "center",
|
|
83
|
+
gap: 12,
|
|
84
|
+
width: "100%",
|
|
85
|
+
padding: "8px 14px",
|
|
86
|
+
border: "none",
|
|
87
|
+
background: "transparent",
|
|
88
|
+
color: "var(--better-locale-text, #374151)",
|
|
89
|
+
fontSize: 14,
|
|
90
|
+
cursor: "pointer",
|
|
91
|
+
transition: "background 0.1s",
|
|
92
|
+
textAlign: "left",
|
|
93
|
+
fontFamily: "inherit",
|
|
94
|
+
lineHeight: 1.2,
|
|
95
|
+
},
|
|
96
|
+
itemActive: {
|
|
97
|
+
background: "var(--better-locale-active-bg, #f9fafb)",
|
|
98
|
+
},
|
|
99
|
+
itemHovered: {
|
|
100
|
+
background: "var(--better-locale-hover-bg, #f3f4f6)",
|
|
101
|
+
},
|
|
102
|
+
label: {
|
|
103
|
+
flex: 1,
|
|
104
|
+
textAlign: "left",
|
|
105
|
+
},
|
|
106
|
+
code: {
|
|
107
|
+
fontSize: 10,
|
|
108
|
+
fontFamily: "monospace",
|
|
109
|
+
textTransform: "uppercase",
|
|
110
|
+
color: "var(--better-locale-code-text, #9ca3af)",
|
|
111
|
+
letterSpacing: "0.05em",
|
|
112
|
+
},
|
|
113
|
+
check: {
|
|
114
|
+
color: "var(--better-locale-accent, currentColor)",
|
|
115
|
+
flexShrink: 0,
|
|
116
|
+
},
|
|
117
|
+
skeleton: {
|
|
118
|
+
display: "inline-flex",
|
|
119
|
+
alignItems: "center",
|
|
120
|
+
gap: 8,
|
|
121
|
+
padding: "6px 10px",
|
|
122
|
+
borderRadius: 8,
|
|
123
|
+
border: "1px solid transparent",
|
|
124
|
+
background: "transparent",
|
|
125
|
+
},
|
|
126
|
+
skeletonFlag: {
|
|
127
|
+
width: 20,
|
|
128
|
+
height: 18,
|
|
129
|
+
borderRadius: 3,
|
|
130
|
+
background: "var(--better-locale-border, #e5e7eb)",
|
|
131
|
+
animation: "better-locale-pulse 1.5s ease-in-out infinite",
|
|
132
|
+
flexShrink: 0,
|
|
133
|
+
},
|
|
134
|
+
skeletonText: {
|
|
135
|
+
width: 56,
|
|
136
|
+
height: 18,
|
|
137
|
+
borderRadius: 4,
|
|
138
|
+
background: "var(--better-locale-border, #e5e7eb)",
|
|
139
|
+
animation: "better-locale-pulse 1.5s ease-in-out infinite",
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
// ─── Component ───────────────────────────────────────────────────────
|
|
143
|
+
/**
|
|
144
|
+
* Styled locale dropdown with flag icons, keyboard navigation, and
|
|
145
|
+
* full CSS customization via custom properties or data attributes.
|
|
146
|
+
*
|
|
147
|
+
* Uses `useLocaleRouter()` and `useLanguages()` internally — works
|
|
148
|
+
* out of the box inside `<BetterI18nProvider>` with TanStack Router.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```tsx
|
|
152
|
+
* // Zero config — styled mode
|
|
153
|
+
* <LocaleDropdown />
|
|
154
|
+
*
|
|
155
|
+
* // Headless mode for full custom styling
|
|
156
|
+
* <LocaleDropdown variant="unstyled" className="my-dropdown" />
|
|
157
|
+
*
|
|
158
|
+
* // Custom render
|
|
159
|
+
* <LocaleDropdown
|
|
160
|
+
* renderItem={({ language, isActive, flag, label }) => (
|
|
161
|
+
* <div className={isActive ? "active" : ""}>
|
|
162
|
+
* {flag.type === "emoji" ? flag.emoji : null} {label}
|
|
163
|
+
* </div>
|
|
164
|
+
* )}
|
|
165
|
+
* />
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
export function LocaleDropdown({ variant = "styled", className, triggerClassName, menuClassName, showFlag = true, showNativeName = true, showLocaleCode = true, renderTrigger, renderItem, }) {
|
|
169
|
+
const { locale, navigate, isReady } = useLocaleRouter();
|
|
170
|
+
const { languages, isLoading } = useLanguages();
|
|
171
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
172
|
+
const [focusIndex, setFocusIndex] = useState(-1);
|
|
173
|
+
const containerRef = useRef(null);
|
|
174
|
+
const menuRef = useRef(null);
|
|
175
|
+
const isStyled = variant === "styled";
|
|
176
|
+
const currentLanguage = useMemo(() => languages.find((l) => l.code === locale), [languages, locale]);
|
|
177
|
+
const currentLabel = currentLanguage
|
|
178
|
+
? getLanguageLabel(currentLanguage)
|
|
179
|
+
: locale.toUpperCase();
|
|
180
|
+
const currentFlag = currentLanguage ? resolveFlag(currentLanguage) : null;
|
|
181
|
+
const canToggle = languages.length > 1;
|
|
182
|
+
// Close on outside click
|
|
183
|
+
useEffect(() => {
|
|
184
|
+
if (!isOpen)
|
|
185
|
+
return;
|
|
186
|
+
function handleClick(e) {
|
|
187
|
+
if (containerRef.current &&
|
|
188
|
+
!containerRef.current.contains(e.target)) {
|
|
189
|
+
setIsOpen(false);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
document.addEventListener("mousedown", handleClick);
|
|
193
|
+
return () => document.removeEventListener("mousedown", handleClick);
|
|
194
|
+
}, [isOpen]);
|
|
195
|
+
// Keyboard navigation
|
|
196
|
+
const handleKeyDown = useCallback((e) => {
|
|
197
|
+
if (!isOpen) {
|
|
198
|
+
if (e.key === "ArrowDown" || e.key === "Enter" || e.key === " ") {
|
|
199
|
+
e.preventDefault();
|
|
200
|
+
setIsOpen(true);
|
|
201
|
+
setFocusIndex(0);
|
|
202
|
+
}
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
switch (e.key) {
|
|
206
|
+
case "Escape":
|
|
207
|
+
e.preventDefault();
|
|
208
|
+
setIsOpen(false);
|
|
209
|
+
setFocusIndex(-1);
|
|
210
|
+
break;
|
|
211
|
+
case "ArrowDown":
|
|
212
|
+
e.preventDefault();
|
|
213
|
+
setFocusIndex((prev) => prev < languages.length - 1 ? prev + 1 : 0);
|
|
214
|
+
break;
|
|
215
|
+
case "ArrowUp":
|
|
216
|
+
e.preventDefault();
|
|
217
|
+
setFocusIndex((prev) => prev > 0 ? prev - 1 : languages.length - 1);
|
|
218
|
+
break;
|
|
219
|
+
case "Enter":
|
|
220
|
+
case " ": {
|
|
221
|
+
e.preventDefault();
|
|
222
|
+
const lang = languages[focusIndex];
|
|
223
|
+
if (lang) {
|
|
224
|
+
navigate(lang.code);
|
|
225
|
+
setIsOpen(false);
|
|
226
|
+
setFocusIndex(-1);
|
|
227
|
+
}
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
case "Home":
|
|
231
|
+
e.preventDefault();
|
|
232
|
+
setFocusIndex(0);
|
|
233
|
+
break;
|
|
234
|
+
case "End":
|
|
235
|
+
e.preventDefault();
|
|
236
|
+
setFocusIndex(languages.length - 1);
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
}, [isOpen, focusIndex, languages, navigate]);
|
|
240
|
+
// Scroll focused item into view
|
|
241
|
+
useEffect(() => {
|
|
242
|
+
if (focusIndex >= 0 && menuRef.current) {
|
|
243
|
+
const items = menuRef.current.querySelectorAll("[data-better-locale-item]");
|
|
244
|
+
items[focusIndex]?.scrollIntoView({ block: "nearest" });
|
|
245
|
+
}
|
|
246
|
+
}, [focusIndex]);
|
|
247
|
+
// Loading skeleton
|
|
248
|
+
if (!isReady || isLoading) {
|
|
249
|
+
if (renderTrigger) {
|
|
250
|
+
return (_jsx("div", { "data-better-locale-dropdown": true, className: className, children: renderTrigger({
|
|
251
|
+
language: undefined,
|
|
252
|
+
isOpen: false,
|
|
253
|
+
isLoading: true,
|
|
254
|
+
flag: null,
|
|
255
|
+
label: "",
|
|
256
|
+
}) }));
|
|
257
|
+
}
|
|
258
|
+
return (_jsxs("div", { "data-better-locale-dropdown": true, className: className, children: [_jsxs("div", { "aria-busy": "true", "data-better-locale-trigger": true, className: triggerClassName, style: isStyled ? styles.skeleton : undefined, children: [_jsx("span", { style: isStyled ? styles.skeletonFlag : undefined }), _jsx("span", { style: isStyled ? styles.skeletonText : undefined })] }), isStyled && (_jsx("style", { children: `@keyframes better-locale-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }` }))] }));
|
|
259
|
+
}
|
|
260
|
+
return (_jsxs("div", { ref: containerRef, "data-better-locale-dropdown": true, className: className, style: { position: "relative", display: "inline-block" }, children: [renderTrigger ? (_jsx("div", { onClick: () => canToggle && setIsOpen(!isOpen), onKeyDown: handleKeyDown, role: "button", tabIndex: 0, "aria-haspopup": "listbox", "aria-expanded": isOpen, "data-better-locale-trigger": true, className: triggerClassName, children: renderTrigger({
|
|
261
|
+
language: currentLanguage,
|
|
262
|
+
isOpen,
|
|
263
|
+
isLoading: false,
|
|
264
|
+
flag: currentFlag,
|
|
265
|
+
label: currentLabel,
|
|
266
|
+
}) })) : (_jsxs("button", { type: "button", onClick: () => canToggle && setIsOpen(!isOpen), onKeyDown: handleKeyDown, "aria-haspopup": "listbox", "aria-expanded": isOpen, "aria-label": "Select language", disabled: !canToggle, "data-better-locale-trigger": true, className: triggerClassName, style: isStyled
|
|
267
|
+
? {
|
|
268
|
+
...styles.trigger,
|
|
269
|
+
...(!canToggle ? styles.triggerDisabled : {}),
|
|
270
|
+
}
|
|
271
|
+
: undefined, children: [showFlag && currentFlag && (_jsx(FlagDisplay, { flag: currentFlag, label: currentLabel })), showNativeName && _jsx("span", { children: currentLabel }), canToggle && (_jsx(ChevronDownIcon, { style: {
|
|
272
|
+
transition: "transform 0.2s",
|
|
273
|
+
transform: isOpen ? "rotate(180deg)" : "rotate(0deg)",
|
|
274
|
+
color: "var(--better-locale-code-text, #9ca3af)",
|
|
275
|
+
} }))] })), isOpen && canToggle && (_jsx("ul", { ref: menuRef, role: "listbox", "aria-label": "Available languages", "data-better-locale-menu": true, className: menuClassName, style: isStyled ? styles.menu : undefined, children: languages.map((language, index) => {
|
|
276
|
+
const label = getLanguageLabel(language);
|
|
277
|
+
const isActive = language.code === locale;
|
|
278
|
+
const isFocused = index === focusIndex;
|
|
279
|
+
const flag = resolveFlag(language);
|
|
280
|
+
if (renderItem) {
|
|
281
|
+
return (_jsx("li", { role: "option", "aria-selected": isActive, "data-better-locale-item": true, "data-active": isActive || undefined, "data-focused": isFocused || undefined, onClick: () => {
|
|
282
|
+
navigate(language.code);
|
|
283
|
+
setIsOpen(false);
|
|
284
|
+
}, onMouseEnter: () => setFocusIndex(index), style: { cursor: "pointer" }, children: renderItem({ language, isActive, flag, label }) }, language.code));
|
|
285
|
+
}
|
|
286
|
+
return (_jsxs("li", { role: "option", "aria-selected": isActive, "data-better-locale-item": true, "data-active": isActive || undefined, "data-focused": isFocused || undefined, onClick: () => {
|
|
287
|
+
navigate(language.code);
|
|
288
|
+
setIsOpen(false);
|
|
289
|
+
}, onMouseEnter: () => setFocusIndex(index), style: isStyled
|
|
290
|
+
? {
|
|
291
|
+
...styles.item,
|
|
292
|
+
...(isActive ? styles.itemActive : {}),
|
|
293
|
+
...(isFocused ? styles.itemHovered : {}),
|
|
294
|
+
}
|
|
295
|
+
: undefined, children: [showFlag && _jsx(FlagDisplay, { flag: flag, label: label }), _jsx("span", { style: isStyled ? styles.label : undefined, children: showNativeName ? label : language.code.toUpperCase() }), showLocaleCode && (_jsx("span", { style: isStyled ? styles.code : undefined, children: language.code })), isActive && (_jsx("span", { style: isStyled ? styles.check : undefined, children: _jsx(CheckIcon, {}) }))] }, language.code));
|
|
296
|
+
}) })), isStyled && isOpen && (_jsx("style", { children: `@keyframes better-locale-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }` }))] }));
|
|
297
|
+
}
|
|
298
|
+
//# sourceMappingURL=locale-dropdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locale-dropdown.js","sourceRoot":"","sources":["../../src/components/locale-dropdown.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EACL,WAAW,EACX,SAAS,EACT,OAAO,EACP,MAAM,EACN,QAAQ,GAGT,MAAM,OAAO,CAAC;AAEf,OAAO,EACL,gBAAgB,EAChB,WAAW,GAEZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,wEAAwE;AAExE,SAAS,SAAS;IAChB,OAAO,CACL,eACE,KAAK,EAAC,IAAI,EACV,MAAM,EAAC,IAAI,EACX,OAAO,EAAC,WAAW,EACnB,IAAI,EAAC,MAAM,EACX,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,GAAG,EACf,aAAa,EAAC,QAAQ,iBACV,MAAM,aAElB,eAAM,CAAC,EAAC,mHAAmH,GAAG,EAC9H,eAAM,CAAC,EAAC,UAAU,GAAG,EACrB,eAAM,CAAC,EAAC,2HAA2H,GAAG,IAClI,CACP,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAC,EAAE,KAAK,EAA6B;IAC3D,OAAO,CACL,cACE,KAAK,EAAC,IAAI,EACV,MAAM,EAAC,IAAI,EACX,OAAO,EAAC,WAAW,EACnB,IAAI,EAAC,MAAM,EACX,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,GAAG,EACf,aAAa,EAAC,OAAO,EACrB,cAAc,EAAC,OAAO,iBACV,MAAM,EAClB,KAAK,EAAE,KAAK,YAEZ,eAAM,CAAC,EA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AAC;gCACE,GAAG,MAAM,CAAC,IAAI;gCACd,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;gCACtC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC;6BACzC;4BACH,CAAC,CAAC,SAAS,aAGd,QAAQ,IAAI,KAAC,WAAW,IAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,GAAI,EACtD,eAAM,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,YAC7C,cAAc,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,GAChD,EACN,cAAc,IAAI,CACjB,eAAM,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,YAC5C,QAAQ,CAAC,IAAI,GACT,CACR,EACA,QAAQ,IAAI,CACX,eAAM,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,YAC9C,KAAC,SAAS,KAAG,GACR,CACR,KAlCI,QAAQ,CAAC,IAAI,CAmCf,CACN,CAAC;gBACJ,CAAC,CAAC,GACC,CACN,EAEA,QAAQ,IAAI,MAAM,IAAI,CACrB,0BAAQ,mFAAmF,GAAS,CACrG,IACG,CACP,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export { useLocaleRouter } from "./hooks/useLocaleRouter.js";
|
|
|
6
6
|
export type { UseLocaleRouterReturn } from "./hooks/useLocaleRouter.js";
|
|
7
7
|
export { LanguageSwitcher } from "./components.js";
|
|
8
8
|
export type { LanguageSwitcherProps } from "./components.js";
|
|
9
|
+
export { LocaleDropdown } from "./components/locale-dropdown.js";
|
|
10
|
+
export type { LocaleDropdownProps, LocaleDropdownRenderContext, } from "./components/locale-dropdown.js";
|
|
9
11
|
export type { Messages, BetterI18nProviderConfig, BetterI18nContextValue, } from "./types.js";
|
|
10
12
|
export { extractLocale, getLocaleFromPath, hasLocalePrefix, removeLocalePrefix, addLocalePrefix, replaceLocaleInPath, createLocalePath, type LocaleConfig, } from "@better-i18n/core";
|
|
11
13
|
export { IntlProvider } from "use-intl";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,YAAY,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAG7D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EACL,YAAY,EACZ,SAAS,EAET,eAAe,EACf,YAAY,EACZ,WAAW,EACX,MAAM,EACN,WAAW,GACZ,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,YAAY,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAGxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,YAAY,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,YAAY,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAG7D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EACL,YAAY,EACZ,SAAS,EAET,eAAe,EACf,YAAY,EACZ,WAAW,EACX,MAAM,EACN,WAAW,GACZ,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,YAAY,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAGxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,YAAY,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAE7D,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,YAAY,EACV,mBAAmB,EACnB,2BAA2B,GAC5B,MAAM,iCAAiC,CAAC;AAGzC,YAAY,EACV,QAAQ,EACR,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,KAAK,YAAY,GAClB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,7 @@ useTranslations, useFormatter, useMessages, useNow, useTimeZone, } from "./hooks
|
|
|
9
9
|
export { useLocaleRouter } from "./hooks/useLocaleRouter.js";
|
|
10
10
|
// Components
|
|
11
11
|
export { LanguageSwitcher } from "./components.js";
|
|
12
|
+
export { LocaleDropdown } from "./components/locale-dropdown.js";
|
|
12
13
|
// Re-export locale utilities from core (convenience)
|
|
13
14
|
export { extractLocale, getLocaleFromPath, hasLocalePrefix, removeLocalePrefix, addLocalePrefix, replaceLocaleInPath, createLocalePath, } from "@better-i18n/core";
|
|
14
15
|
// Re-export commonly used use-intl components
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,WAAW;AACX,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAGnD,kBAAkB;AAClB,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EACL,YAAY,EACZ,SAAS;AACT,4BAA4B;AAC5B,eAAe,EACf,YAAY,EACZ,WAAW,EACX,MAAM,EACN,WAAW,GACZ,MAAM,YAAY,CAAC;AAEpB,uCAAuC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAG7D,aAAa;AACb,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,WAAW;AACX,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAGnD,kBAAkB;AAClB,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EACL,YAAY,EACZ,SAAS;AACT,4BAA4B;AAC5B,eAAe,EACf,YAAY,EACZ,WAAW,EACX,MAAM,EACN,WAAW,GACZ,MAAM,YAAY,CAAC;AAEpB,uCAAuC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAG7D,aAAa;AACb,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAGnD,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAajE,qDAAqD;AACrD,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,mBAAmB,EACnB,gBAAgB,GAEjB,MAAM,mBAAmB,CAAC;AAE3B,8CAA8C;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-i18n/use-intl",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Better i18n integration for use-intl (React, TanStack Start)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"prepublishOnly": "bun run build"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@better-i18n/core": "^0.
|
|
60
|
+
"@better-i18n/core": "^0.3.0"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"react": ">=18.0.0",
|