Skip to content

Commit

Permalink
make strategy mandatory
Browse files Browse the repository at this point in the history
  • Loading branch information
surjithctly committed Jun 4, 2024
1 parent db95add commit 36d1751
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
14 changes: 12 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "astro-color-scheme",
"version": "1.1.4",
"version": "1.1.5",
"description": "Perfect dark mode for Astro in few lines of code. Theme Toggle for Dark, Light & Auto (system)",
"type": "module",
"exports": {
Expand All @@ -17,7 +17,17 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": ["astro", "astro-component", "themes", "color-scheme", "dark", "dark-mode", "light", "system", "auto"],
"keywords": [
"astro",
"astro-component",
"themes",
"color-scheme",
"dark",
"dark-mode",
"light",
"system",
"auto"
],
"author": "Surjith S M",
"license": "MIT"
}
14 changes: 10 additions & 4 deletions src/ThemeSwitch.astro
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
type Props = Partial<{
as: "div" | "span";
defaultTheme: "dark" | "light" | "system";
type Props = {
strategy: "button" | "checkbox" | "select" | "radio";
}>;
as?: "div" | "span";
defaultTheme?: "dark" | "light" | "system";
};
const { strategy, defaultTheme, as: Element = "span" }: Props = Astro.props;
---
Expand Down Expand Up @@ -69,6 +69,12 @@ const { strategy, defaultTheme, as: Element = "span" }: Props = Astro.props;
element.addEventListener(eventType, themeUpdater);
}

if (!strategy) {
throw new Error(
`plugin-astro-color-scheme: Please add a 'strategy' attribute to <ThemeSwitch/>`
);
}

switch (strategy) {
case "button":
setupThemeSwitch("button", "click", (event) => {
Expand Down

0 comments on commit 36d1751

Please sign in to comment.