question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add variants to jsx source

See original GitHub issue

Thanks for the great library 👍

Is your feature request related to a problem? Please describe. Expose the variant api via custom jsxImport source without having to handle it directly in non-theme-ui components.

Describe the solution you’d like I think the variant api is pretty great. Would you be open to add it into the jsx parser?

That is, for components that are built outside of theme-ui, in addition to sx and css, it would be helpful if the import source would also handle variant. If I had access to the handler from Box

const variant = ({ theme, variant, __themeKey = 'variants' }) =>
  css(get(theme, __themeKey + '.' + variant, get(theme, variant)))

it would allow me to include it for free through my codebase

export interface MyCustomProps extends ExistingProps {
    sx?: SxProp;
    variant?: string;
}

Describe alternatives you’ve considered No alternatives, just an api that makes non-theme-ui components more theme-ui-like

Additional context In my case, I am introducing theme-ui into an existing React codebase, and this would facilitate adoption with a shared api by only adding the requisite comment at the top of the file.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
hasparuscommented, Apr 21, 2021

Hey nrakochy. Thanks for the issue!

I’d like to know what @lachlanjc thinks, but I’d rather not add anything like this to the public API.

  1. There is an alternative: You can use
sx={{ variant: 'my-variant' }}
  1. variant, unlike sx is a pretty common word to appear in React props. I would rather not put my hands on it and proclaim that all variant props will now belong to Theme UI. We don’t have to look far for a problem — a global variant would conflict with components in @theme-ui/components (The behaviour of <Button variant={} /> would be different depending on JSX pragma being set or not.)
0reactions
lachlanjccommented, Apr 25, 2021

Yep, we’re happy to link to other libraries on the https://theme-ui.com/resources page!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create visual variants for React components using ...
Visual variants. In React, a component translates state and props into a visual representation. This usually means into a DOM element.
Read more >
How to use variants on commerceJs ReactJs App? - YouTube
Hello everyone,In this tutorial you will learn how to use variants on commerce.js React.js App.Build E-commerce shop by using commerce.js ...
Read more >
Create Tailwind component variants using React
Learn how to create a Create Tailwind component variants using React. ... The complete source code from an Alert component.
Read more >
adding-products-cart-cjs-react/README.md at master - GitHub
Adding Variants : This step is important when having products with some sort of variance. If you have a product without variances, you...
Read more >
Variant-driven Components - Pedro Duarte
Let's add a color variant to the Box . import { styled } from '@stitches/react';.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found