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

Build out a Theme component #9183

Closed
Tracked by #9160
joshblack opened this issue Jul 12, 2021 · 3 comments · Fixed by #9201
Closed
Tracked by #9160

Build out a Theme component #9183

joshblack opened this issue Jul 12, 2021 · 3 comments · Fixed by #9201
Assignees

Comments

@joshblack
Copy link
Contributor

joshblack commented Jul 12, 2021

Build out a component that allows the user to specify the theme with a prop, storing the value in a context. This component will look like:

<Theme theme="white">
  <ChildComponent />
</Theme>

It can also contain a complex object (like a theme object)

import { g90 } from '@carbon/themes';

<Theme theme={g90}>
  <ChildComponent />
</Theme>

This component should provide a way for someone to "zone" a page, or specify what theme a particular component tree should render with (this will involve style updates). This may be through a prop, like zone, or is done automatically and is applied with a CSS selector.

This work should also include initial usage docs for the Theme component

@joshblack joshblack mentioned this issue Jul 12, 2021
8 tasks
@joshblack joshblack changed the title Build out a component which allows the user to specify the theme with a prop, storing the value in a context Build out a Theme component Jul 12, 2021
@janhassel
Copy link
Member

It would be great if the component would also accept a function to which it passes the current/inherited theme. This could help build out high-contrast/inverted zones:

<Theme theme={(currentTheme) => (currentTheme === 'g10' ? 'g100' : 'g10')}>
  <ChildComponent />
</Theme>

Or would this use case be covered by the linked useTheme hook?

@joshblack
Copy link
Contributor Author

Great point @janhassel! I bet you could use the useTheme hook potentially:

function TestComponent() {
  const { theme } = useTheme();

  return (
    <Theme theme={theme === 'g10' ? 'g100' : 'g10'}>
      <ChildComponent />
    </Theme>
  );
}

Definitely let me know though if there is a use-case that the hook can't help out with and we can 100% add this behavior in for the theme prop

@janhassel
Copy link
Member

@joshblack Sounds good! I can't think of anything where this solution wouldn't work 👍

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

Successfully merging a pull request may close this issue.

3 participants