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

Make styled-jsx extensible #182

Closed
giuseppeg opened this issue Apr 29, 2017 · 0 comments
Closed

Make styled-jsx extensible #182

giuseppeg opened this issue Apr 29, 2017 · 0 comments

Comments

@giuseppeg
Copy link
Collaborator

I thought of a way to make styled-jsx a bit more flexible and let users manipulate the CSS both at compile and run time (if they want). This for example would make it possible to use SASS with styled-jsx or I could stop supporting styled-jsx-postcss.

The babel plugin could accept an option transformCss that is a module name. Such a module exports an object with two functions for runtime and compile time. Both signatures would be (css: string) => string (by default an identity function).

// my-styled-jsx-transform/index.js
export default {
  compile: (css) => sass.renderSync({ data: css }),
  runtime: (css) => css
}

and in .babelrc:

{
   "plugins": [
      ["styled-jsx/babel", { "transformCss": "my-styled-jsx-transform" }]
   ]
}

Which we will use as follow:

const {compile: _userCompile} = require(state.opts.transformCss)
// set compile to identity function if it is `undefined`

// TBD

const transformedCss = stylis(
   styleJsxId,
   _userCompile(css)
)

// or

const transformedCss = _userCompile(
  stylis(
     styleJsxId,
     css
  )
)

I am not sure about the runtime one (which for now could be postponed) but probably we would need to unshift an import like we do with _JSXStyle. The result would be:

import {runtime as _styledJsxTransformCss} from 'my-styled-jsx-transform'
// ...
<_JSXStyle id={1235435} css={_styledJsxTransformCss(`div { color: red }`)} />

cc @rauchg @nkzawa

This was referenced May 13, 2017
giuseppeg added a commit that referenced this issue Oct 15, 2017
Fixes #182

Details available at #182 This version only works at compile time - I don't think that we should implement any runtime support right now (or ever).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant