@windrun-huaiin/base-ui 3.2.1 → 3.2.3
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/index.d.mts +31 -1
- package/dist/components/index.d.ts +31 -1
- package/dist/components/index.js +163 -0
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +160 -0
- package/dist/components/index.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +161 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +158 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/language-detector.tsx +1 -1
- package/src/components/language-switcher.tsx +1 -1
- package/src/components/script/google-analytics-script.tsx +2 -2
- package/src/components/script/microsoft-clarity-script.tsx +2 -2
package/dist/index.mjs
CHANGED
@@ -5507,11 +5507,154 @@ import { useLocale, useTranslations } from "next-intl";
|
|
5507
5507
|
import { useRouter } from "next/navigation";
|
5508
5508
|
import { useEffect as useEffect7, useState as useState7 } from "react";
|
5509
5509
|
import { jsx as jsx81, jsxs as jsxs29 } from "react/jsx-runtime";
|
5510
|
+
function LanguageDetector({ i18nConfig }) {
|
5511
|
+
const [show, setShow] = useState7(false);
|
5512
|
+
const [detectedLocale, setDetectedLocale] = useState7(null);
|
5513
|
+
const currentLocale = useLocale();
|
5514
|
+
const router = useRouter();
|
5515
|
+
const t = useTranslations("languageDetection");
|
5516
|
+
const LANGUAGE_PREFERENCE_KEY = `${i18nConfig.detector.storagePrefix}-${i18nConfig.detector.storageKey}`;
|
5517
|
+
useEffect7(() => {
|
5518
|
+
const browserLang = navigator.language.split("-")[0];
|
5519
|
+
const savedPreference = localStorage.getItem(LANGUAGE_PREFERENCE_KEY);
|
5520
|
+
const preference = savedPreference ? JSON.parse(savedPreference) : null;
|
5521
|
+
const shouldShowDetector = () => {
|
5522
|
+
if (!preference) return true;
|
5523
|
+
if (preference.locale === currentLocale) return false;
|
5524
|
+
if (preference.status === "rejected" && preference.locale === browserLang) return false;
|
5525
|
+
if (preference.status === "accepted" && preference.locale === currentLocale) return false;
|
5526
|
+
const expirationMs = i18nConfig.detector.expirationDays * 24 * 60 * 60 * 1e3;
|
5527
|
+
if (Date.now() - preference.timestamp < expirationMs) return false;
|
5528
|
+
return true;
|
5529
|
+
};
|
5530
|
+
if (i18nConfig.locales.includes(browserLang) && browserLang !== currentLocale && shouldShowDetector()) {
|
5531
|
+
setDetectedLocale(browserLang);
|
5532
|
+
setShow(true);
|
5533
|
+
const timer = setTimeout(() => {
|
5534
|
+
console.log("[LanguageDetector] Auto closing after timeout");
|
5535
|
+
setShow(false);
|
5536
|
+
savePreference(browserLang, "rejected");
|
5537
|
+
}, i18nConfig.detector.autoCloseTimeout);
|
5538
|
+
return () => clearTimeout(timer);
|
5539
|
+
}
|
5540
|
+
}, [currentLocale]);
|
5541
|
+
const savePreference = (locale, status) => {
|
5542
|
+
const preference = {
|
5543
|
+
locale,
|
5544
|
+
status,
|
5545
|
+
timestamp: Date.now()
|
5546
|
+
};
|
5547
|
+
localStorage.setItem(LANGUAGE_PREFERENCE_KEY, JSON.stringify(preference));
|
5548
|
+
};
|
5549
|
+
const handleLanguageChange = () => {
|
5550
|
+
if (detectedLocale) {
|
5551
|
+
savePreference(detectedLocale, "accepted");
|
5552
|
+
const pathname = window.location.pathname;
|
5553
|
+
const newPathname = pathname.replace(`/${currentLocale}`, `/${detectedLocale}`);
|
5554
|
+
router.push(newPathname);
|
5555
|
+
setShow(false);
|
5556
|
+
}
|
5557
|
+
};
|
5558
|
+
const handleClose = () => {
|
5559
|
+
if (detectedLocale) {
|
5560
|
+
savePreference(detectedLocale, "rejected");
|
5561
|
+
}
|
5562
|
+
setShow(false);
|
5563
|
+
};
|
5564
|
+
if (!detectedLocale || !show) return null;
|
5565
|
+
return /* @__PURE__ */ jsx81("div", { className: "fixed top-16 right-4 z-40 w-[420px]", children: /* @__PURE__ */ jsx81("div", { className: `shadow-lg rounded-lg transition-all duration-300 ${show ? "translate-x-0 opacity-100" : "translate-x-full opacity-0"}
|
5566
|
+
bg-linear-to-r from-purple-100/95 via-white/95 to-purple-100/95 backdrop-blur-xs
|
5567
|
+
animate-gradient-x`, children: /* @__PURE__ */ jsxs29("div", { className: "relative px-6 py-4 overflow-hidden", children: [
|
5568
|
+
/* @__PURE__ */ jsxs29("div", { className: "relative z-10 flex flex-col gap-3", children: [
|
5569
|
+
/* @__PURE__ */ jsxs29("div", { className: "flex items-start justify-between gap-4", children: [
|
5570
|
+
/* @__PURE__ */ jsxs29("div", { className: "flex flex-col gap-1.5", children: [
|
5571
|
+
/* @__PURE__ */ jsx81("h3", { className: "text-lg font-semibold text-gray-900", children: t("title") }),
|
5572
|
+
/* @__PURE__ */ jsxs29("p", { className: "text-base text-gray-600", children: [
|
5573
|
+
t("description"),
|
5574
|
+
" ",
|
5575
|
+
/* @__PURE__ */ jsx81("span", { className: "text-purple-500 font-semibold", children: detectedLocale === "zh" ? "\u4E2D\u6587" : "English" }),
|
5576
|
+
"?"
|
5577
|
+
] })
|
5578
|
+
] }),
|
5579
|
+
/* @__PURE__ */ jsx81(
|
5580
|
+
"button",
|
5581
|
+
{
|
5582
|
+
onClick: handleClose,
|
5583
|
+
className: "text-gray-500 hover:text-gray-700",
|
5584
|
+
children: /* @__PURE__ */ jsx81(globalLucideIcons.X, { className: "h-5 w-5" })
|
5585
|
+
}
|
5586
|
+
)
|
5587
|
+
] }),
|
5588
|
+
/* @__PURE__ */ jsxs29("div", { className: "flex items-center gap-3", children: [
|
5589
|
+
/* @__PURE__ */ jsx81(
|
5590
|
+
"button",
|
5591
|
+
{
|
5592
|
+
onClick: handleClose,
|
5593
|
+
className: "flex-1 px-4 py-2 text-base bg-gray-100 text-gray-600 rounded-md hover:bg-gray-200",
|
5594
|
+
children: t("close")
|
5595
|
+
}
|
5596
|
+
),
|
5597
|
+
/* @__PURE__ */ jsx81(
|
5598
|
+
"button",
|
5599
|
+
{
|
5600
|
+
onClick: handleLanguageChange,
|
5601
|
+
className: "flex-1 px-4 py-2 text-base bg-purple-500 text-white rounded-md hover:bg-purple-600",
|
5602
|
+
children: t("changeAction")
|
5603
|
+
}
|
5604
|
+
)
|
5605
|
+
] })
|
5606
|
+
] }),
|
5607
|
+
/* @__PURE__ */ jsx81("div", { className: "absolute inset-0 bg-linear-to-r from-transparent via-purple-200/30 to-transparent animate-shimmer" })
|
5608
|
+
] }) }) });
|
5609
|
+
}
|
5510
5610
|
|
5511
5611
|
// src/components/language-switcher.tsx
|
5512
5612
|
import { usePathname, useRouter as useRouter2 } from "next/navigation";
|
5513
5613
|
import { useLocale as useLocale2 } from "next-intl";
|
5514
5614
|
import { jsx as jsx82, jsxs as jsxs30 } from "react/jsx-runtime";
|
5615
|
+
function LanguageSwitcher({ locales, localeLabels }) {
|
5616
|
+
const locale = useLocale2();
|
5617
|
+
const router = useRouter2();
|
5618
|
+
const pathname = usePathname();
|
5619
|
+
const handleLocaleChange = (newLocale) => {
|
5620
|
+
const newPathname = pathname.replace(`/${locale}`, `/${newLocale}`);
|
5621
|
+
router.push(newPathname);
|
5622
|
+
};
|
5623
|
+
return /* @__PURE__ */ jsxs30(DropdownMenu, { children: [
|
5624
|
+
/* @__PURE__ */ jsx82(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsx82(
|
5625
|
+
LanguageButton,
|
5626
|
+
{
|
5627
|
+
variant: "ghost",
|
5628
|
+
size: "icon",
|
5629
|
+
className: "bg-linear-to-r from-purple-400 to-pink-600 hover:from-purple-500 hover:to-pink-700 text-white transform hover:scale-110 transition-all duration-300",
|
5630
|
+
children: /* @__PURE__ */ jsx82(globalLucideIcons.Globe, { className: "h-5 w-5" })
|
5631
|
+
}
|
5632
|
+
) }),
|
5633
|
+
/* @__PURE__ */ jsx82(
|
5634
|
+
DropdownMenuContent,
|
5635
|
+
{
|
5636
|
+
align: "end",
|
5637
|
+
sideOffset: 5,
|
5638
|
+
className: "bg-white/90 dark:bg-gray-800/90 border-purple-100 dark:border-purple-800 w-[200px] p-2 backdrop-blur-xs translate-x-[50px]",
|
5639
|
+
children: /* @__PURE__ */ jsx82("div", { className: "grid grid-cols-2 gap-1", children: locales.map((loc) => /* @__PURE__ */ jsx82(
|
5640
|
+
DropdownMenuItem,
|
5641
|
+
{
|
5642
|
+
className: `
|
5643
|
+
px-2 py-2 text-sm cursor-pointer text-center justify-center
|
5644
|
+
transition-all duration-300 ease-in-out
|
5645
|
+
hover:scale-105 hover:shadow-md
|
5646
|
+
rounded-md whitespace-nowrap
|
5647
|
+
${locale === loc ? "bg-linear-to-r from-purple-400 to-pink-600 text-white font-medium shadow-lg scale-105" : "hover:bg-linear-to-r hover:from-purple-400/10 hover:to-pink-600/10 hover:text-transparent hover:bg-clip-text"}
|
5648
|
+
`,
|
5649
|
+
onClick: () => handleLocaleChange(loc),
|
5650
|
+
children: localeLabels[loc]
|
5651
|
+
},
|
5652
|
+
loc
|
5653
|
+
)) })
|
5654
|
+
}
|
5655
|
+
)
|
5656
|
+
] });
|
5657
|
+
}
|
5515
5658
|
|
5516
5659
|
// src/components/script/google-analytics-script.tsx
|
5517
5660
|
import Script from "next/script";
|
@@ -5562,6 +5705,18 @@ function useGoogleAnalytics() {
|
|
5562
5705
|
import Script2 from "next/script";
|
5563
5706
|
import { jsx as jsx84 } from "react/jsx-runtime";
|
5564
5707
|
var microsoftClarityId = process.env.NEXT_PUBLIC_MICROSOFT_CLARITY_ID;
|
5708
|
+
function MicrosoftClarityScript() {
|
5709
|
+
if (process.env.NODE_ENV !== "production") {
|
5710
|
+
return null;
|
5711
|
+
}
|
5712
|
+
return /* @__PURE__ */ jsx84(Script2, { id: "microsoft-clarity", strategy: "afterInteractive", children: `
|
5713
|
+
(function(c,l,a,r,i,t,y){
|
5714
|
+
c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
|
5715
|
+
t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
|
5716
|
+
y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
|
5717
|
+
})(window, document, "clarity", "script", "${microsoftClarityId}");
|
5718
|
+
` });
|
5719
|
+
}
|
5565
5720
|
export {
|
5566
5721
|
Accordion,
|
5567
5722
|
AccordionContent,
|
@@ -5695,6 +5850,8 @@ export {
|
|
5695
5850
|
InputOTPSlot,
|
5696
5851
|
Label3 as Label,
|
5697
5852
|
LanguageButton,
|
5853
|
+
LanguageDetector,
|
5854
|
+
LanguageSwitcher,
|
5698
5855
|
Menubar,
|
5699
5856
|
MenubarCheckboxItem,
|
5700
5857
|
MenubarContent,
|
@@ -5711,6 +5868,7 @@ export {
|
|
5711
5868
|
MenubarSubContent,
|
5712
5869
|
MenubarSubTrigger,
|
5713
5870
|
MenubarTrigger,
|
5871
|
+
MicrosoftClarityScript,
|
5714
5872
|
NavigationMenu,
|
5715
5873
|
NavigationMenuContent,
|
5716
5874
|
NavigationMenuIndicator,
|