Skip to content

Commit 36d1751

Browse files
committed
make strategy mandatory
1 parent db95add commit 36d1751

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

package.json

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "astro-color-scheme",
3-
"version": "1.1.4",
3+
"version": "1.1.5",
44
"description": "Perfect dark mode for Astro in few lines of code. Theme Toggle for Dark, Light & Auto (system)",
55
"type": "module",
66
"exports": {
@@ -17,7 +17,17 @@
1717
"scripts": {
1818
"test": "echo \"Error: no test specified\" && exit 1"
1919
},
20-
"keywords": ["astro", "astro-component", "themes", "color-scheme", "dark", "dark-mode", "light", "system", "auto"],
20+
"keywords": [
21+
"astro",
22+
"astro-component",
23+
"themes",
24+
"color-scheme",
25+
"dark",
26+
"dark-mode",
27+
"light",
28+
"system",
29+
"auto"
30+
],
2131
"author": "Surjith S M",
2232
"license": "MIT"
2333
}

src/ThemeSwitch.astro

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
2-
type Props = Partial<{
3-
as: "div" | "span";
4-
defaultTheme: "dark" | "light" | "system";
2+
type Props = {
53
strategy: "button" | "checkbox" | "select" | "radio";
6-
}>;
4+
as?: "div" | "span";
5+
defaultTheme?: "dark" | "light" | "system";
6+
};
77
88
const { strategy, defaultTheme, as: Element = "span" }: Props = Astro.props;
99
---
@@ -69,6 +69,12 @@ const { strategy, defaultTheme, as: Element = "span" }: Props = Astro.props;
6969
element.addEventListener(eventType, themeUpdater);
7070
}
7171

72+
if (!strategy) {
73+
throw new Error(
74+
`plugin-astro-color-scheme: Please add a 'strategy' attribute to <ThemeSwitch/>`
75+
);
76+
}
77+
7278
switch (strategy) {
7379
case "button":
7480
setupThemeSwitch("button", "click", (event) => {

0 commit comments

Comments
 (0)