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

Add a basic cx api so that users can merge emotion and custom classes #397

Merged
merged 14 commits into from
Oct 16, 2017

Conversation

tkh44
Copy link
Member

@tkh44 tkh44 commented Oct 12, 2017

Add a basic cx api so that users can merge emotion and custom classes similar to the classnames library without the quirks of selectivity.

test('all types', () => {
  const cls1 = css`
    font-size: 20px;
    background: green;
  `
  const cls2 = css`
    font-size: 20px;
    background: blue;
  `

  const cls3 = css`
    font-size: 20px;
    background: darkorange;
  `

  const cls4 = css`
    font-size: 20px;
    background: darkgreen;
  `

  const foo = true
  const bar = false

  const tree = renderer
    .create(
      <div
        className={cx(
          { [cls1]: foo },
          { [cls2]: bar },
          () => 'modal',
          'XxX420_no_scopeXxX',
          [cls3, cls4]
        )}
      />
    )
    .toJSON()
  expect(tree).toMatchSnapshot()
})
.glamor-0 {
  font-size: 20px;
  background: green;
  font-size: 20px;
  background: darkorange;
  font-size: 20px;
  background: darkgreen;
}

<div
  className=" modal XxX420_no_scopeXxX glamor-0"
/>

Checklist:

  • Documentation
  • Tests
  • Code complete

@tkh44
Copy link
Member Author

tkh44 commented Oct 13, 2017

This is a nice little bonus

test('fun fun functions', () => {
  const cls1 = css`
    font-size: 20px;
    background: green;
  `
  const cls2 = css`
    font-size: 20px;
    background: blue;
  `

  const cls3 = css`
    font-size: 20px;
    background: darkorange;
  `

  const cls4 = css`
    font-size: 20px;
    background: darkgreen;
  `

  const tree = renderer
    .create(
      <div
        className={cx(() => () => [
          () => [cls1, false && cls2, 'modal'],
          () => [() => [cls3, () => ({ [cls4]: true }), 'profile']]
        ])}
      />
    )
    .toJSON()
})

@codecov
Copy link

codecov bot commented Oct 13, 2017

Codecov Report

Merging #397 into master will increase coverage by 0.07%.
The diff coverage is 100%.

Impacted Files Coverage Δ
packages/emotion/src/index.js 100% <100%> (ø) ⬆️

@tkh44 tkh44 merged commit 118bc8d into master Oct 16, 2017
@tkh44 tkh44 deleted the add-cx branch October 16, 2017 20:54
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

Successfully merging this pull request may close these issues.

None yet

2 participants