hipstersmoothie / storybook-dark-mode

A storybook addon that lets your users toggle between dark and light mode.
MIT License
435 stars 56 forks source link

Integration into React Native app #162

Open gHashTag opened 2 years ago

gHashTag commented 2 years ago

It is not clear from the documentation how to add decorators to history. Tell me how to implement it correctly.

const ThemeContext = React.createContext({})

const DarkTheme = {
  dark: true,
  colors: {
    primary: '#FF06F4',
    background: '#1c1c1c',
    card: 'rgb(255, 255, 255)',
    text: '#FFFF',
    border: 'rgb(199, 199, 204)',
    notification: 'rgb(255, 69, 58)'
  }
}

const LightTheme = {
  dark: false,
  colors: {
    primary: '#FF06F4',
    background: '#FFF',
    card: 'rgb(255, 255, 255)',
    text: '#1c1c1c',
    border: 'rgb(199, 199, 204)',
    notification: 'rgb(255, 69, 58)'
  }
}

// create a component that uses the dark mode hook
function ThemeWrapper(props) {
  // render your custom theme provider
  console.log(`useDarkMode()`, useDarkMode())
  return (
    <ThemeContext.Provider value={useDarkMode() ? DarkTheme : LightTheme}>
      {props.children}
    </ThemeContext.Provider>
  );
}

storiesOf('Txt', module
  .addDecorator((renderStory) => <ThemeWrapper>{renderStory()}</ThemeWrapper>)

Simulator Screen Shot - iPhone 12 - 2021-09-21 at 18 23 04 )

hipstersmoothie commented 1 year ago

I personally don't use react native. But if somebody figures this out please submit a PR!