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

Introduce React Storybook #699

Closed
Rokt33r opened this issue Nov 28, 2020 · 0 comments
Closed

Introduce React Storybook #699

Rokt33r opened this issue Nov 28, 2020 · 0 comments
Assignees
Labels
documentation 📚 Issue concerns documentation and homepage of Boost Note
Projects

Comments

@Rokt33r
Copy link
Member

Rokt33r commented Nov 28, 2020

FYI: how to apply theme

import styled from '../lib/styled'
import React, { FC, PropsWithChildren, ComponentType } from 'react'
import { ThemeProvider } from 'styled-components'
import { lightTheme, darkTheme } from '../lib/styled/themes'
import { Story } from '@storybook/react/types-6-0'

interface ThemedWrapperProps {
  theme?: 'light' | 'dark'
}

export const ThemedWrapper: FC<ThemedWrapperProps> = ({
  theme = 'light',
  children,
}) => {
  return (
    <ThemeProvider theme={theme === 'light' ? lightTheme : darkTheme}>
      <StyledBackground>{children}</StyledBackground>
    </ThemeProvider>
  )
}

const StyledBackground = styled.div`
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px;
  background-color: ${({ theme }) => theme.baseBackgroundColor};
  box-sizing: border-box;
`

export type ThemedStory<P> = Story<
  { theme: 'dark' | 'light' } & PropsWithChildren<P>
>

export function createThemedTemplate<P = {}>(
  Component: ComponentType<P>
): {
  Template: ThemedStory<P>
  themeArgType: {}
} {
  return {
    Template: ({ theme, ...args }: any) => {
      return (
        <ThemedWrapper theme={theme}>
          <Component {...args} />
        </ThemedWrapper>
      )
    },
    themeArgType: {
      defaultValue: 'light',
      control: {
        type: 'inline-radio',
        options: ['light', 'dark'],
      },
    },
  }
}
@Rokt33r Rokt33r added this to This sprint(Nov 28th - Dec 11th) in Dev kanban Nov 28, 2020
@Flexo013 Flexo013 added the documentation 📚 Issue concerns documentation and homepage of Boost Note label Dec 10, 2020
@Rokt33r Rokt33r moved this from This sprint(Nov 28th - Dec 11th) to Done in Dev kanban Dec 12, 2020
@Rokt33r Rokt33r closed this as completed Dec 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation 📚 Issue concerns documentation and homepage of Boost Note
Projects
No open projects
Dev kanban
  
Done
Development

No branches or pull requests

3 participants