Skip to content

Share styles in a performant way with good dx #594

Answered by peduarte
rafgraph asked this question in Ideas
Discussion options

You must be logged in to vote

Hey!

This is currently possible. The styled function accepts infinite arguments. The first argument decides which node tag to render the element with. The other arguments will just pull out its styles and variants. The powerful thing here is that you can pass in css() or styled() instances.

This means you can do something like:

const sharedStyles = css({ margin: "50px" });

const BaseComp = styled("button", { border: "2px solid", padding: 15 });

const MyComp = styled(BaseComp, sharedStyles, {
  color: "green"
});

Demo: https://codesandbox.io/s/quizzical-kepler-2ipcj?file=/src/App.tsx:47-239

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@btz530
Comment options

Answer selected by rafgraph
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
3 participants