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

Rule proposal: css argument types #4

Open
lencioni opened this issue Aug 31, 2016 · 1 comment
Open

Rule proposal: css argument types #4

lencioni opened this issue Aug 31, 2016 · 1 comment

Comments

@lencioni
Copy link
Collaborator

The css() function can only take arguments that are properties of the styles prop object, plain JavaScript objects, falsey values, or arrays of those types.

Bad:

function MyComponent({ styles }) {
  return (
    <div {...css(styles)} />
  );
}
function MyComponent({ styles }) {
  return (
    <div {...css('foo')} />
  );
}
function MyComponent({ styles }) {
  return (
    <div {...css(1)} />
  );
}
function MyComponent({ styles }) {
  return (
    <div {...css(true)} />
  );
}
function MyComponent({ styles, foo }) {
  return (
    <div {...css(foo)} />
  );
}
function MyComponent({ styles, foo }) {
  return (
    <div {...css(foo.bar)} />
  );
}

Good:

function MyComponent({ styles }) {
  return (
    <div {...css(styles.foo, styles.bar, { color: 'red' })} />
  );
}

It might also make sense for this rule to validate the shape of the JavaScript objects passed to css() to ensure that they are flat objects appropriate for inline styles.

@ljharb
Copy link
Collaborator

ljharb commented Aug 31, 2016

Good:

function MyComponent({ styles: { foo, bar } }) {
  return (
    <div {...css(foo, bar, { color: 'red' })} />
  );
}

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

2 participants