Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vite Storybook - Implement Darkmode natively #305

Closed
paulm17 opened this issue Nov 7, 2024 · 2 comments
Closed

Vite Storybook - Implement Darkmode natively #305

paulm17 opened this issue Nov 7, 2024 · 2 comments
Assignees
Labels

Comments

@paulm17
Copy link

paulm17 commented Nov 7, 2024

Summary

I can get vite, storybook to work fine with the latest version.

My problem is that the only current darkmode switcher employs a class and not a style or a data attribute.

Would be awesome if the team could spend some time to get this working natively.

Image

edit:

this was the only addon that worked somewhat: https://github.com/hipstersmoothie/storybook-dark-mode

Even this article was no good: https://medium.com/design-bootcamp/how-to-toggle-between-dark-and-light-mode-in-storybook-7e9351eb26c1

Examples

No response

Motivation

No response

Search keywords: vite storybook

@paulm17 paulm17 added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Nov 7, 2024
@zannager zannager added the vite label Nov 7, 2024
@paulm17
Copy link
Author

paulm17 commented Nov 9, 2024

Managed to implement this another way. It's good enough so will close:

import React from 'react';
import type { Preview } from '@storybook/react';
import { RaikouProvider } from "@raikou/system";
import { emotionTransform, RaikouEmotionProvider } from "@raikou/emotion";
import "@raikou/system/styles.css";
import "@stylefusion/react/styles.css";
import { useTheme } from 'next-themes';
import { IconMoonFilled, IconSunFilled } from '@tabler/icons-react';
import { ActionIcon } from '@raikou/core';

function ColorSchemeWrapper({ children }: { children: React.ReactNode }) {
  const { theme, setTheme } = useTheme();
  return (
    <>
      <ActionIcon
        size="xl"
        radius="md"
        variant="default"
        pos="fixed"
        bottom={20}
        right={20}
        onClick={theme === "light" ? () => setTheme("dark") : () => setTheme("light")}
        style={{ zIndex: 1000 }}
        aria-label="Toggle theme color direction"
      >
        {theme === 'light' ? <IconSunFilled /> : <IconMoonFilled />}
      </ActionIcon>
      {children}
    </>
  );
}

const preview: Preview = {
  decorators: [
    (Story) => <ColorSchemeWrapper>{Story()}</ColorSchemeWrapper>,
    (Story) => (
      <RaikouProvider stylesTransform={emotionTransform}>
        <RaikouEmotionProvider>
          {Story()}
        </RaikouEmotionProvider>
      </RaikouProvider>
    ),
  ],
  parameters: {
    controls: {
      matchers: {
        color: /(background|color)$/i,
        date: /Date$/i,
      },
    },
  },
};

export default preview;

@paulm17 paulm17 closed this as completed Nov 9, 2024
@github-actions github-actions bot removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Nov 9, 2024
Copy link

github-actions bot commented Nov 9, 2024

This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

Note

@paulm17 How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants