Skip to content

Commit dbfdaa3

Browse files
committed
Breaking change: use just curried interface
1 parent 531c927 commit dbfdaa3

3 files changed

Lines changed: 11 additions & 18 deletions

File tree

README.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,20 @@ Install peer dependencies `react` and `react-dom` in your project.
2525
```js
2626
import styled from 'styled-jss'
2727

28-
const Button = styled('button', {
29-
fontSize: 12,
30-
color: (props) => props.theme.textColor
31-
})
32-
33-
// Curried interface.
3428
const Button = styled('button')({
3529
fontSize: 12,
3630
color: (props) => props.theme.textColor
3731
})
3832

33+
// You can also use curried interface this way.
3934
const div = styled('div')
4035

4136
const Container = div({
4237
padding: 20
4338
})
4439

4540
// Composition.
46-
const PrimaryButton = styled(Button, {
41+
const PrimaryButton = styled(Button)({
4742
color: 'red'
4843
})
4944
```
@@ -71,14 +66,14 @@ const styled = Styled({
7166
}
7267
})
7368

74-
const NormalButton = styled('button', {
69+
const NormalButton = styled('button')({
7570
composes: '$baseButton',
7671
border: [1, 'solid', 'grey'],
7772
color: 'black'
7873
})
7974

8075
// Composition - same way.
81-
const PrimaryButton = styled(NormalButton, {
76+
const PrimaryButton = styled(NormalButton)({
8277
color: 'red'
8378
})
8479

src/createStyled.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ const getStyledArgs = (
2020
return {tagName, style}
2121
}
2222

23-
const curry1 = (fn: Function) => (a: *, b?: *) => (b !== undefined ? fn(a, b) : b2 => fn(a, b2))
24-
2523
const createStyled = (jss: Function) => (baseStyles: BaseStylesType = {}): StyledType => {
2624
let staticSheet
2725
let dynamicSheet
@@ -41,15 +39,16 @@ const createStyled = (jss: Function) => (baseStyles: BaseStylesType = {}): Style
4139
return {staticSheet, dynamicSheet}
4240
}
4341

44-
return Object.assign(curry1((
45-
tagNameOrStyledElement: TagNameOrStyledElementType,
42+
return Object.assign((
43+
tagNameOrStyledElement: TagNameOrStyledElementType
44+
) => (
4645
ownStyle: ComponentStyleType
4746
): StyledElementType => {
4847
const {tagName, style} = getStyledArgs(tagNameOrStyledElement)
4948
const elementStyle = {...style, ...ownStyle}
5049

5150
return styled({tagName, baseStyles, elementStyle, mountSheets})
52-
}), {mountSheets, styles: baseStyles})
51+
}, {mountSheets, styles: baseStyles})
5352
}
5453

5554
export default createStyled

src/tests/App.jsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react'
22
import type {StyledType} from '../types'
33

44
export default (styled: StyledType) => {
5-
const App = styled('div', {
5+
const App = styled('div')({
66
margin: 50,
77
})
88

@@ -22,16 +22,15 @@ export default (styled: StyledType) => {
2222
color: 'yellow',
2323
})
2424

25-
const Title = styled('h1', {
25+
const Title = styled('h1')({
2626
color: 'red',
2727
})
2828

2929
// function value
30-
const Button = styled('button', {
30+
const Button = styled('button')({
3131
margin: ({margin = 0}) => margin,
3232
})
3333

34-
3534
return () => (
3635
<App>
3736
<Header>

0 commit comments

Comments
 (0)