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

please consider using css string props like emotion #1141

Open
SteveSuv opened this issue Feb 15, 2023 · 2 comments
Open

please consider using css string props like emotion #1141

SteveSuv opened this issue Feb 15, 2023 · 2 comments

Comments

@SteveSuv
Copy link

Has the official considered using css string props like emotion?

import { css } from '@emotion/react'

const color = 'darkgreen'

render(
  <div
    css={css`
      background-color: hotpink;
      &:hover {
        color: ${color};
      }
    `}
  >
    This has a hotpink background.
  </div>
)

Because users often write code according to the figma inspection when developing projects in the company:

image

If use the css object to write, users also need to convert the figma inspect into the css object.

But if users can directly use the css string, users can directly paste the figma css inspect, which will greatly improve the work efficiency.

@maurer2
Copy link

maurer2 commented Feb 25, 2023

Hello, I believe this isn't supported to keep bundle size in check and runtime performance up, see https://stitches.dev/blog/migrating-from-styled-components-to-stitches#object-syntax-only

@jpmaga
Copy link

jpmaga commented Feb 26, 2023

You can create a function like this one from goober (or copy it): https://github.com/cristianbote/goober/blob/master/src/core/astish.js and then create a simple function for the template tags:

export function css(strings, ...expressions) {
  const evaluated = strings.reduce((result, currentString, i) => (
    `${result}${currentString}${expressions[i] ? expressions[i] : ''}`
  ), '')
  return astish(evaluated)
}

and then use it like in your example.

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

No branches or pull requests

3 participants