@korioinc/next-core 2.0.19 → 2.0.21
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/locale-switcher/index.tsx"],"names":[],"mappings":"AAoDA,UAAU,mBAAmB;IAC3B;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,EAAE,SAAS,EAAE,GAAE,mBAAwB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/locale-switcher/index.tsx"],"names":[],"mappings":"AAoDA,UAAU,mBAAmB;IAC3B;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,EAAE,SAAS,EAAE,GAAE,mBAAwB,kDAiF7E"}
|
|
@@ -46,8 +46,13 @@ export default function LocaleSwitcher({ languages } = {}) {
|
|
|
46
46
|
useEffect(() => {
|
|
47
47
|
setMounted(true);
|
|
48
48
|
}, []);
|
|
49
|
-
//
|
|
50
|
-
const
|
|
49
|
+
// Build visible language list, preserving user-provided order.
|
|
50
|
+
const languageMap = new Map(allLanguages.map((language) => [language.code, language]));
|
|
51
|
+
const availableLanguages = languages
|
|
52
|
+
? Array.from(new Set(languages))
|
|
53
|
+
.map((code) => languageMap.get(code))
|
|
54
|
+
.filter((language) => Boolean(language))
|
|
55
|
+
: allLanguages;
|
|
51
56
|
// Get current locale from Lingui
|
|
52
57
|
const currentLocale = i18n.locale;
|
|
53
58
|
// Always provide a fallback to ensure currentLanguage is never undefined
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/theme-switcher/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/theme-switcher/index.tsx"],"names":[],"mappings":"AAuCA,QAAA,MAAM,aAAa,+CA6FlB,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
|
@@ -2,19 +2,39 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { useTheme } from 'next-themes';
|
|
5
|
+
const FALLBACK_THEME_ORDER = ['light', 'dark'];
|
|
6
|
+
const isThemeMode = (value) => value === 'light' || value === 'dark' || value === 'system';
|
|
7
|
+
const getThemeOrder = (themes) => {
|
|
8
|
+
const availableThemes = themes.filter(isThemeMode);
|
|
9
|
+
return availableThemes.length > 0 ? availableThemes : FALLBACK_THEME_ORDER;
|
|
10
|
+
};
|
|
11
|
+
const normalizeTheme = ({ theme, resolvedTheme, themeOrder, }) => {
|
|
12
|
+
if (isThemeMode(theme) && themeOrder.includes(theme)) {
|
|
13
|
+
return theme;
|
|
14
|
+
}
|
|
15
|
+
if (isThemeMode(resolvedTheme) && themeOrder.includes(resolvedTheme)) {
|
|
16
|
+
return resolvedTheme;
|
|
17
|
+
}
|
|
18
|
+
return themeOrder[0] ?? 'light';
|
|
19
|
+
};
|
|
5
20
|
const ThemeSwitcher = () => {
|
|
6
|
-
const { theme, setTheme } = useTheme();
|
|
21
|
+
const { theme, resolvedTheme, setTheme, themes } = useTheme();
|
|
7
22
|
const [mounted, setMounted] = React.useState(false);
|
|
8
23
|
React.useEffect(() => {
|
|
9
24
|
setMounted(true);
|
|
10
25
|
}, []);
|
|
11
|
-
|
|
26
|
+
const themeOrder = getThemeOrder(themes);
|
|
27
|
+
const currentTheme = normalizeTheme({ theme, resolvedTheme, themeOrder });
|
|
28
|
+
const resolvedThemeLabel = resolvedTheme === 'dark' ? 'Dark' : 'Light';
|
|
29
|
+
const currentThemeLabel = currentTheme === 'system' ? `System (${resolvedThemeLabel})` : currentTheme === 'dark' ? 'Dark' : 'Light';
|
|
12
30
|
const toggleTheme = () => {
|
|
13
|
-
|
|
31
|
+
const currentIndex = themeOrder.indexOf(currentTheme);
|
|
32
|
+
const nextTheme = themeOrder[(currentIndex + 1) % themeOrder.length];
|
|
33
|
+
setTheme(nextTheme);
|
|
14
34
|
};
|
|
15
35
|
if (!mounted) {
|
|
16
36
|
return (_jsx("button", { className: 'border-glass-strong bg-glass relative inline-flex h-9 w-9 items-center justify-center rounded-md border opacity-0', "aria-hidden": 'true', children: _jsx("div", { className: 'h-5 w-5' }) }));
|
|
17
37
|
}
|
|
18
|
-
return (_jsxs("button", { onClick: toggleTheme, className: 'border-glass-strong bg-glass hover:bg-glass-tinted relative inline-flex h-9 w-9 items-center justify-center rounded-md border transition-colors', "aria-label": `Switch theme (current: ${
|
|
38
|
+
return (_jsxs("button", { onClick: toggleTheme, className: 'border-glass-strong bg-glass hover:bg-glass-tinted relative inline-flex h-9 w-9 items-center justify-center rounded-md border transition-colors', "aria-label": `Switch theme (current: ${currentThemeLabel})`, title: `Theme: ${currentThemeLabel} (click to change)`, children: [_jsxs("svg", { xmlns: 'http://www.w3.org/2000/svg', viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: '2', strokeLinecap: 'round', strokeLinejoin: 'round', className: `absolute h-5 w-5 transition-all ${currentTheme === 'light' ? 'scale-100 rotate-0 opacity-100' : 'scale-0 rotate-90 opacity-0'}`, children: [_jsx("circle", { cx: '12', cy: '12', r: '5' }), _jsx("line", { x1: '12', y1: '1', x2: '12', y2: '3' }), _jsx("line", { x1: '12', y1: '21', x2: '12', y2: '23' }), _jsx("line", { x1: '4.22', y1: '4.22', x2: '5.64', y2: '5.64' }), _jsx("line", { x1: '18.36', y1: '18.36', x2: '19.78', y2: '19.78' }), _jsx("line", { x1: '1', y1: '12', x2: '3', y2: '12' }), _jsx("line", { x1: '21', y1: '12', x2: '23', y2: '12' }), _jsx("line", { x1: '4.22', y1: '19.78', x2: '5.64', y2: '18.36' }), _jsx("line", { x1: '18.36', y1: '5.64', x2: '19.78', y2: '4.22' })] }), _jsx("svg", { xmlns: 'http://www.w3.org/2000/svg', viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: '2', strokeLinecap: 'round', strokeLinejoin: 'round', className: `absolute h-5 w-5 transition-all ${currentTheme === 'dark' ? 'scale-100 rotate-0 opacity-100' : 'scale-0 -rotate-90 opacity-0'}`, children: _jsx("path", { d: 'M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z' }) }), _jsxs("svg", { xmlns: 'http://www.w3.org/2000/svg', viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: '2', strokeLinecap: 'round', strokeLinejoin: 'round', className: `absolute h-5 w-5 transition-all ${currentTheme === 'system' ? 'scale-100 rotate-0 opacity-100' : 'scale-0 rotate-90 opacity-0'}`, children: [_jsx("rect", { x: '3', y: '4', width: '18', height: '12', rx: '2' }), _jsx("line", { x1: '8', y1: '20', x2: '16', y2: '20' }), _jsx("line", { x1: '12', y1: '16', x2: '12', y2: '20' })] })] }));
|
|
19
39
|
};
|
|
20
40
|
export default ThemeSwitcher;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@korioinc/next-core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.21",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./ads": {
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"tsc-alias": "^1.8.16",
|
|
80
80
|
"tw-animate-css": "^1.4.0",
|
|
81
81
|
"typescript": "^5.9.3",
|
|
82
|
-
"@korioinc/next-configs": "2.0.
|
|
82
|
+
"@korioinc/next-configs": "2.0.21"
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
85
|
"@floating-ui/react": "^0.27.17",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"schema-dts": "^1.1.5",
|
|
95
95
|
"tailwind-merge": "^3.4.0",
|
|
96
96
|
"valtio": "^2.3.0",
|
|
97
|
-
"@korioinc/next-conf": "2.0.
|
|
97
|
+
"@korioinc/next-conf": "2.0.21"
|
|
98
98
|
},
|
|
99
99
|
"publishConfig": {
|
|
100
100
|
"access": "public",
|