From 63f0d91195bbbd2957064b4a6bff811c334af714 Mon Sep 17 00:00:00 2001 From: Ajay Ghanwat Date: Mon, 8 Dec 2025 14:49:13 +0530 Subject: [PATCH] New Chnages to Switch Theme --- package-lock.json | 11 ++ package.json | 1 + src/components/LanguageSwitcher.astro | 177 ++++++++++++++++++++++++++ src/layouts/Base.astro | 2 +- src/layouts/ComponentLayout.astro | 3 + src/pages/language.astro | 27 ++++ 6 files changed, 220 insertions(+), 1 deletion(-) create mode 100644 src/components/LanguageSwitcher.astro create mode 100644 src/pages/language.astro diff --git a/package-lock.json b/package-lock.json index 001a269..4aa40e6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,6 +24,7 @@ "zod": "^3.25.76" }, "devDependencies": { + "@iconify-json/circle-flags": "^1.2.10", "@iconify-json/lets-icons": "^1.2.1", "@iconify-json/mdi": "^1.2.3", "@iconify-json/solar": "^1.2.5", @@ -841,6 +842,16 @@ "integrity": "sha512-aGTxbpbg8/b5JfU1HXSrbH3wXZuLPJcNEcZQFMxLs3oSzgtVu6nFPkbbGGUvBcUjKV2YyB9Wxxabo+HEH9tcRQ==", "license": "MIT" }, + "node_modules/@iconify-json/circle-flags": { + "version": "1.2.10", + "resolved": "https://registry.npmjs.org/@iconify-json/circle-flags/-/circle-flags-1.2.10.tgz", + "integrity": "sha512-sZRxs689a281RtZvuAiKtV7pQHv8Tk0HkinSM7QvLgdLEK8xgGRCcbDvL09Rq+/KtemmsMzGhS9/qt+r3ca+Ug==", + "dev": true, + "license": "MIT", + "dependencies": { + "@iconify/types": "*" + } + }, "node_modules/@iconify-json/lets-icons": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/@iconify-json/lets-icons/-/lets-icons-1.2.1.tgz", diff --git a/package.json b/package.json index 43e4fbb..1968545 100644 --- a/package.json +++ b/package.json @@ -82,6 +82,7 @@ "zod": "^3.25.76" }, "devDependencies": { + "@iconify-json/circle-flags": "^1.2.10", "@iconify-json/lets-icons": "^1.2.1", "@iconify-json/mdi": "^1.2.3", "@iconify-json/solar": "^1.2.5", diff --git a/src/components/LanguageSwitcher.astro b/src/components/LanguageSwitcher.astro new file mode 100644 index 0000000..b3675e2 --- /dev/null +++ b/src/components/LanguageSwitcher.astro @@ -0,0 +1,177 @@ +--- +import type { HTMLAttributes } from "astro/types"; +import Dropdown from "./Dropdown.astro"; +import { Icon } from "astro-icon/components"; + +interface Language { + code: string; + label: string; + flag?: string; + dir?: "ltr" | "rtl"; +} +interface Props extends HTMLAttributes<"div"> { + languages: Language[]; + storageKey?: string; + rootSelector?: string; + compact?: boolean; + showLabel?: boolean; + rootExtraClass?: string; + class?: string; + onChange?: string; +} + +const { + languages = [{ code: "en", label: "English" }], + storageKey = "wr-lang", + rootSelector = "html", + compact = false, + showLabel = false, + rootExtraClass = "", + class: className, + onChange = "onLanguageChange", + ...rest +}: Props = Astro.props; + +const containerId = `ls-${Math.random().toString(36).slice(2)}`; +const icon = "wr:size-4"; +const item = "wr:flex wr:items-center wr:gap-3 wr:w-full wr:px-3 wr:py-2.5 wr:rounded-lg wr:text-sm wr:hover:bg-muted/70 wr:transition wr:duration-150"; +const checkBase = "wr:size-4 wr:opacity-0 wr:scale-90 wr:transition"; +--- + +
+ + + + + + {showLabel && Language} + + + + + + {languages.map(lang => ( + + ))} + +
+ + + + diff --git a/src/layouts/Base.astro b/src/layouts/Base.astro index 8b691ee..5782861 100644 --- a/src/layouts/Base.astro +++ b/src/layouts/Base.astro @@ -5,7 +5,7 @@ import { cn } from "../utils/cn"; const attributes = Astro.props; --- - + diff --git a/src/layouts/ComponentLayout.astro b/src/layouts/ComponentLayout.astro index 3118d0a..1111392 100644 --- a/src/layouts/ComponentLayout.astro +++ b/src/layouts/ComponentLayout.astro @@ -86,6 +86,9 @@ import Base from "./Base.astro";
  • Table
  • +
  • + Language +
  • diff --git a/src/pages/language.astro b/src/pages/language.astro new file mode 100644 index 0000000..204dc4d --- /dev/null +++ b/src/pages/language.astro @@ -0,0 +1,27 @@ +--- +import LanguageSwitcher from "../components/LanguageSwitcher.astro"; +import ComponentLayout from "../layouts/ComponentLayout.astro"; +--- + + +
    +
    + +
    +
    +

    Test Heading

    +
    +
    +