Skip to content

Commit

Permalink
Match storybook preview with theme
Browse files Browse the repository at this point in the history
  • Loading branch information
iddan committed Apr 27, 2023
1 parent 47b9a5f commit e2ba648
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import type { Preview } from "@storybook/react";

// function to get user dark mode
const getDarkMode = () => {
if (typeof window !== "undefined") {
return window.matchMedia("(prefers-color-scheme: dark)").matches;
}
return false;
};

const preview: Preview = {
parameters: {
backgrounds: {
default: getDarkMode() ? "dark" : "light",
},
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
matchers: {
Expand Down

0 comments on commit e2ba648

Please sign in to comment.