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

Overriding component style #51

Open
kserjey opened this issue Oct 18, 2017 · 2 comments
Open

Overriding component style #51

kserjey opened this issue Oct 18, 2017 · 2 comments

Comments

@kserjey
Copy link

kserjey commented Oct 18, 2017

Can u add something like 'css' prop in glamorous? I think it might be useful when u want specify just a margin.

<MyStyledComponent css={{ marginBottom: 8 }}/>
@lttb
Copy link
Member

lttb commented Oct 19, 2017

Hi @kserjey!

That's a nice point, thanks.

But it looks like it may have the same problems as described here #41 (comment), because it causes the styles recalculation on each mount/rerender.

As a workaround, you can use style attribute for inline styles in such cases.

You can also pass the className with class, created by the jss, for example:

// css.js

const sheet = jss.createStyleSheet().attach();
const cache = new Map()

export default styles => {
  if (cache.has(styles)) return cache.get(styles)

  const rule = sheet.addRule(styles)
  cache.set(styles, rule)

  return rule
}
import css from './css'

const {className} = css({marginBottom: 8})

<MyStyledComponent className={className} />

Maybe it will be valuable to make a function like this css as a helper in this library.

But I hope to find an effective implementation for the suggested behavior, and, of course, we're open for PRs :)

@kof
Copy link
Member

kof commented Oct 19, 2017

I am also thinknig to have such a function in the core JSS.

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

3 participants