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

[react-jss] Hooks #1089

Merged
merged 61 commits into from
Jun 7, 2019
Merged
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
1b3fade
Revert "Revert "Add dynamic rules to static sheet""
Mar 2, 2019
5dbc7dc
Fix adding dynamic rules to sheet
Mar 2, 2019
0768cae
Fix a few tests
Mar 2, 2019
d017126
Fix tests
Mar 2, 2019
85cec4e
Format code
Mar 2, 2019
91f6882
Add comments
Mar 6, 2019
b507aae
Merge branch 'master' into feat/move-dynamic-rules-into-static-sheet
Mar 10, 2019
61d465e
Merge branch 'master' into feat/move-dynamic-rules-into-static-sheet
Mar 10, 2019
2ca10eb
Update changelog
Mar 10, 2019
45215c6
Update size-snapshot
Mar 10, 2019
48f899d
Initial draft
Mar 10, 2019
b8284c0
Initial version of hook
Mar 15, 2019
7769334
Add missing dependency
Apr 13, 2019
8fed824
Fix some type issues
Apr 14, 2019
11b0fcf
Rename hook folder to create-use-styles and hoc to with-styles
Apr 14, 2019
b20f7ea
Unify some files
Apr 14, 2019
ae88758
Fix imports
Apr 14, 2019
cf23380
Fix some flow issues
Apr 14, 2019
d9b8452
Update size snapshots
Apr 14, 2019
cbef52d
Fix some eslint problems
Apr 14, 2019
9ee1369
Merge branch 'master' into react-jss/feature/hooks
Apr 14, 2019
ad05c90
Update packages/react-jss/src/create-use-styles.js
eps1lon Apr 15, 2019
ae7841a
Update file names and default exports
Apr 15, 2019
800a929
Use type instead of interface
Apr 15, 2019
4967ece
Fix linting
Apr 15, 2019
b49de75
Fixed PR comments
Apr 15, 2019
50725d3
Update size snapshots
Apr 20, 2019
8fcc455
fix linter, make all file names camel cased
kof Apr 23, 2019
01c0f54
Use state instead of relying on memo
May 4, 2019
76fa59a
Merge remote-tracking branch 'origin/react-jss/feature/hooks' into re…
May 4, 2019
02b641c
Use is-in-browser package
May 4, 2019
8a185ab
Fix some type issues and add support for recreating the sheet when th…
May 5, 2019
8b78a2b
Merge branch 'master' into react-jss/feature/hooks
kof May 6, 2019
7e2a92e
upgrade theming
kof May 7, 2019
b08cd37
add sheet to the registry when managing sheets, pass a theme when usi…
kof May 10, 2019
2036cf4
Fixed all tests
May 30, 2019
5aed3f8
Fix linting etc.
May 30, 2019
d4d372a
Use MIN_SAFE_INTEGER
May 30, 2019
965850b
Merge branch 'master' into react-jss/feature/hooks
kof Jun 2, 2019
afa04d8
remove the need for extra eslit rules
kof Jun 2, 2019
f6a9af4
Add tests for hooks and fix some issue
Jun 2, 2019
59e5a2c
Remove check for disableStylesGeneration
Jun 2, 2019
4f17fea
more explicit name for the hook
kof Jun 5, 2019
71b53e6
port class name prefix test
kof Jun 5, 2019
59c2560
reuse tests between hooks and hocs
kof Jun 5, 2019
aef6158
make dynamicStyles tests use hooks
kof Jun 5, 2019
32bb698
generate dynamic styles test using HOC
kof Jun 5, 2019
12b151c
migrate all dynamic styles tests to use createStyledComponent
kof Jun 5, 2019
62252f1
refactor theming tests
kof Jun 5, 2019
73964b6
Rewrite to useReducer
Jun 6, 2019
3dc8d2e
Fix JssProvider
Jun 6, 2019
e46bde6
port theming tests for hooks
kof Jun 6, 2019
af178af
Merge branch 'react-jss/feature/hooks' of github.com:cssinjs/jss into…
kof Jun 6, 2019
76d0964
move reducer to the module scope, since it doesn't need to be recreated
kof Jun 6, 2019
07322b5
Merge branch 'master' into react-jss/feature/hooks
kof Jun 7, 2019
1fd87da
reset module Id
kof Jun 7, 2019
11725ec
rename shallow-equal, add a note
kof Jun 7, 2019
86e5742
hooks docs
kof Jun 7, 2019
5b0af83
better description
kof Jun 7, 2019
95bef20
better wording
kof Jun 7, 2019
68bbae3
fix link
kof Jun 7, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
migrate all dynamic styles tests to use createStyledComponent
  • Loading branch information
kof committed Jun 5, 2019
commit 12b151c6cdbba0dcb87dcf29c4b6521e0740525f
4 changes: 2 additions & 2 deletions packages/react-jss/src/createUseStyles.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable react/prop-types */

import createUseStyles from './createUseStyles'
import createHocAndHooksTests from '../test-utils/createHocAndHooksTests'
import createBasicTests from '../test-utils/createBasicTests'

const createStyledComponent = (styles, options) => {
const useStyles = createUseStyles(styles, options)
@@ -13,5 +13,5 @@ const createStyledComponent = (styles, options) => {
}

describe('React-JSS: createUseStyles', () => {
createHocAndHooksTests({createStyledComponent})
createBasicTests({createStyledComponent})
})
4 changes: 2 additions & 2 deletions packages/react-jss/src/withStyles.test.js
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import {spy} from 'sinon'
import TestRenderer from 'react-test-renderer'

import {withStyles, JssProvider} from '.'
import createHocAndHooksTests from '../test-utils/createHocAndHooksTests'
import createBasicTests from '../test-utils/createBasicTests'

const createGenerateId = () => {
let counter = 0
@@ -20,7 +20,7 @@ const createStyledComponent = (styles, options = {}) => {
}

describe('React-JSS: withStyles', () => {
createHocAndHooksTests({createStyledComponent})
createBasicTests({createStyledComponent})

describe('should merge the classes', () => {
const styles = {
59 changes: 33 additions & 26 deletions packages/react-jss/test-utils/createDynamicStylesTests.js
Original file line number Diff line number Diff line change
@@ -5,16 +5,14 @@ import React from 'react'
import TestRenderer from 'react-test-renderer'
import {stripIndent} from 'common-tags'

import injectSheet, {JssProvider, SheetsRegistry} from '../src'
import {JssProvider, SheetsRegistry} from '../src'

const createGenerateId = () => {
let counter = 0
return rule => `${rule.key}-${counter++}`
}

export default ({createStyledComponent}) => {
const NoRenderer = () => null
NoRenderer.displayName = 'NoRenderer'
let registry

beforeEach(() => {
@@ -151,12 +149,14 @@ export default ({createStyledComponent}) => {

it('should unset values when null is returned from fn value', () => {
const generateId = createGenerateId()
MyComponent = injectSheet({

MyComponent = createStyledComponent({
button: {
width: 10,
height: ({height}) => height
}
})(NoRenderer)
})

const Container = ({height}) => (
<JssProvider registry={registry} generateId={generateId}>
<MyComponent height={height} />
@@ -186,14 +186,15 @@ export default ({createStyledComponent}) => {

it('should unset values when null is returned from fn rule', () => {
const generateId = createGenerateId()
MyComponent = injectSheet({
MyComponent = createStyledComponent({
button0: {
width: 10
},
button1: ({height}) => ({
height
})
})(NoRenderer)
})

const Container = ({height}) => (
<JssProvider registry={registry} generateId={generateId}>
<MyComponent height={height} />
@@ -234,13 +235,13 @@ export default ({createStyledComponent}) => {
}
}
}
const InnerComponent = () => null
InnerComponent.defaultProps = {

MyComponent = createStyledComponent(styles)
MyComponent.defaultProps = {
color: 'rgb(255, 0, 0)'
}
const StyledComponent = injectSheet(styles)(InnerComponent)

TestRenderer.create(<StyledComponent height={20} />)
TestRenderer.create(<MyComponent height={20} />)

expect(passedProps.color).to.equal('rgb(255, 0, 0)')
expect(passedProps.height).to.equal(20)
@@ -249,14 +250,23 @@ export default ({createStyledComponent}) => {

describe('function rules', () => {
let MyComponent
let classes

beforeEach(() => {
MyComponent = injectSheet({
button: ({height = 1}) => ({
color: 'rgb(255, 255, 255)',
height: `${height}px`
})
})(NoRenderer)
MyComponent = createStyledComponent(
{
button: ({height = 1}) => ({
color: 'rgb(255, 255, 255)',
height: `${height}px`
})
},
{name: 'NoRenderer'}
)
MyComponent.defaultProps = {
getClasses: cls => {
classes = cls
}
}
})

it('should attach and detach a sheet', () => {
@@ -296,14 +306,12 @@ export default ({createStyledComponent}) => {
})

it('should have dynamic and static styles', () => {
const renderer = TestRenderer.create(
TestRenderer.create(
<JssProvider generateId={createGenerateId()}>
<MyComponent />
</JssProvider>
)
const props = renderer.root.findByType(NoRenderer).props

expect(props.classes.button).to.equal('button-0 button-0-1')
expect(classes.button).to.equal('button-0 button-0-1')
})

it('should generate different dynamic values', () => {
@@ -375,13 +383,12 @@ export default ({createStyledComponent}) => {
return {color: 'rgb(255, 255, 255)'}
}
}
const InnerComponent = () => null
InnerComponent.defaultProps = {

MyComponent = createStyledComponent(styles)
MyComponent.defaultProps = {
color: 'rgb(255, 0, 0)'
}
const StyledComponent = injectSheet(styles)(InnerComponent)

TestRenderer.create(<StyledComponent height={20} />)
TestRenderer.create(<MyComponent height={20} />)

expect(passedProps.color).to.equal('rgb(255, 0, 0)')
expect(passedProps.height).to.equal(20)
6 changes: 3 additions & 3 deletions packages/react-jss/tests/dynamicStyles.js
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ describe('React-JSS: dynamic styles', () => {
const useStyles = createUseStyles(styles, options)
const Comp = props => {
const classes = useStyles(props)
props.getClasses(classes)
if (props.getClasses) props.getClasses(classes)
return null
}
Comp.displayName = options.name
@@ -21,8 +21,8 @@ describe('React-JSS: dynamic styles', () => {

describe('using withStyles', () => {
const createStyledComponent = (styles, options = {}) => {
const Comp = props => {
props.getClasses(props.classes)
const Comp = ({getClasses, classes}) => {
if (getClasses) getClasses(classes)
return null
}
Comp.displayName = options.name