primer / react

An implementation of GitHub's Primer Design System using React
https://primer.style/guides/react
MIT License
3.14k stars 535 forks source link

Preview components in different themes #1433

Closed colebemis closed 3 years ago

colebemis commented 3 years ago

Background

Primer React components can be rendered in many different themes. See the Theming for more details.

Light Dark
CleanShot 2021-09-16 at 16 27 32 CleanShot 2021-09-16 at 16 28 17

In fact, one of the criteria for a component to be alpha is that "the component is compatible with color modes and can adapt to different themes."

Problem

We don't have an easy way to preview components in different themes in documentation examples and Storybook.

Tasks

jfuchs commented 3 years ago

Isn't this done for docs with cmd + ctrl + t? Do we want something more obvious like a visible switch in every example?

SferaDev commented 3 years ago

Isn't this done for docs with cmd + ctrl + t? Do we want something more obvious like a visible switch in every example?

I believe something like what ViewComponents documentation has

image image

pksjce commented 3 years ago

Implement a way to preview components in different themes in documentation examples

@colebemis - You mentioned other colormodes? I couldn't find a reference to them. Could you link them for me?

colebemis commented 3 years ago

@pksjce All of the color schemes are listed here: https://github.com/primer/react/blob/main/src/theme-preval.js#L113-L132

You can access the list of color schemes in code with the useTheme hook:

import {useTheme} from '@primer/components'

function Component() {
  const {theme} = useTheme()
  // Object.keys(theme.colorSchemes) -> ['light', 'dark', 'dark_dimmed', 'dark_high_contrast']
}