linaria icon indicating copy to clipboard operation
linaria copied to clipboard

Add support for JS notation styles to styled API

Open badalsaibo opened this issue 1 year ago • 1 comments

Describe the feature

Currently the styled API accepts literal tagged template literals which accepts CSS naming scheme for styles.

I think we could also extend the API to accept valid CSS styles in JavaScript notation too!

Motivation

  1. React Native devs would appreciate it.
  2. Some people like styling in JS way.
  3. More options for people to choose.

Possible implementations

Something similar to how emotion does,

const StyledHeading = styled('h1')(() => ({
  fontSize: '24px'
});

props or theme from a ThemeProvider can be passed to the callback function for easy access.

const StyledHeading = styled('h1')(({ theme, color }) => ({ 
  fontSize: '24px',
  ...( color && { color })
});

Related Issues

badalsaibo avatar Mar 02 '23 12:03 badalsaibo

It's possible, and I even made a PoC in @linaria/griffle, but it's not a priority right now. However, if someone makes a PR, I will be happy to merge it ;)

Anber avatar Apr 25 '23 09:04 Anber