Skip to content

Commit 9501dcf

Browse files
committed
small styling adjustments
1 parent 7e7a507 commit 9501dcf

2 files changed

Lines changed: 48 additions & 33 deletions

File tree

package.json

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
"description": "Styled primitives with JSS",
55
"main": "lib/index.js",
66
"scripts": {
7-
"clean": "rm -rf lib/*",
7+
"clean": "rimraf lib/*",
88
"lint": "eslint src",
9+
"lint:staged": "lint-staged",
910
"test": "jest",
1011
"test:watch": "npm test -- --watch",
1112
"test:coverage": "npm test -- --coverage",
@@ -20,18 +21,21 @@
2021
],
2122
"repository": {
2223
"type": "git",
23-
"url": "git+https://github.com/lttb/jss-styled.git"
24+
"url": "git+https://github.com/cssinjs/styled-jss.git"
2425
},
2526
"keywords": [
2627
"jss",
27-
"styled"
28+
"styled",
29+
"react",
30+
"styled-components",
31+
"primitives"
2832
],
2933
"author": "lttb <kenzhaev.artur@gmail.com>",
3034
"license": "MIT",
3135
"bugs": {
32-
"url": "https://github.com/lttb/jss-styled/issues"
36+
"url": "https://github.com/cssinjs/styled-jss/issues"
3337
},
34-
"homepage": "https://github.com/lttb/jss-styled#readme",
38+
"homepage": "https://github.com/cssinjs/styled-jss#readme",
3539
"dependencies": {
3640
"is-react-prop": "^0.0.2",
3741
"jss": "^7.1.0",
@@ -58,6 +62,18 @@
5862
"flow-bin": "^0.44.2",
5963
"flow-typed": "^2.0.0",
6064
"jest": "^18.1.0",
61-
"react-test-renderer": "^15.4.2"
62-
}
65+
"lint-staged": "^3.4.0",
66+
"pre-commit": "^1.2.2",
67+
"react": "^15.5.4",
68+
"react-dom": "^15.5.4",
69+
"react-test-renderer": "^15.4.2",
70+
"rimraf": "^2.6.1"
71+
},
72+
"lint-staged": {
73+
"./src": [
74+
"eslint",
75+
"git add"
76+
]
77+
},
78+
"pre-commit": "lint:staged"
6379
}
Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,44 @@
1-
import React, {PureComponent} from 'react'
2-
1+
import {PureComponent, createElement} from 'react'
32
import {create as createJss, getDynamicStyles} from 'jss'
43
import preset from 'jss-preset-default'
5-
64
import filterProps from './utils/filter-props'
75

8-
96
const jssDefault = createJss(preset())
107

11-
type StyledElementAttrsT = { tag: string, styles: Object }
12-
type StyledElementT = Function & StyledElementAttrsT
13-
type tagOrStyledElementT = string | StyledElementT
14-
type StyledElementPropsT = {
8+
type StyledElementAttrsType = { tag: string, styles: Object }
9+
type StyledElementType = Function & StyledElementAttrsType
10+
type tagOrStyledElementTypeype = string | StyledElementType
11+
type StyledElementPropsType = {
1512
classes: Object,
1613
children: ?any,
1714
className: ?string,
1815
}
1916

20-
2117
export const createStyled = (jss?: Function = jssDefault) => (baseStyles: Object = {}) => {
2218
let sheet
2319
let dynamicSheet
24-
2520
let counter = 0
2621

27-
return (tagOrStyledElement: tagOrStyledElementT, ownStyles: Object): StyledElementT => {
28-
const {tag, styles}: StyledElementAttrsT = typeof tagOrStyledElement === 'string'
22+
return (tagOrStyledElement: tagOrStyledElementTypeype, ownStyles: Object): StyledElementType => {
23+
const {tag, styles}: StyledElementAttrsType = typeof tagOrStyledElement === 'string'
2924
? {tag: tagOrStyledElement, styles: {}}
3025
: tagOrStyledElement
3126

3227
const elementStyles = {...styles, ...ownStyles}
3328
const dynamicStyles = getDynamicStyles(elementStyles)
34-
35-
const StaticTag = `${tag}-${++counter}`
29+
const staticTag = `${tag}-${++counter}`
3630

3731
return class StyledElement extends PureComponent {
38-
props: StyledElementPropsT
39-
4032
static tag = tag
33+
4134
static styles = elementStyles
4235

36+
props: StyledElementPropsType
37+
4338
tagScoped = ''
4439

4540
constructor(props) {
4641
super(props)
47-
4842
this.tagScoped = `${tag}-${++counter}`
4943
}
5044

@@ -61,8 +55,8 @@ export const createStyled = (jss?: Function = jssDefault) => (baseStyles: Object
6155
}).attach()
6256
}
6357

64-
if (!sheet.getRule(StaticTag)) {
65-
sheet.addRule(StaticTag, elementStyles)
58+
if (!sheet.getRule(staticTag)) {
59+
sheet.addRule(staticTag, elementStyles)
6660
}
6761

6862
if (dynamicStyles && !dynamicSheet.getRule(this.tagScoped)) {
@@ -73,7 +67,7 @@ export const createStyled = (jss?: Function = jssDefault) => (baseStyles: Object
7367
}
7468
}
7569

76-
componentWillReceiveProps(nextProps: StyledElementPropsT) {
70+
componentWillReceiveProps(nextProps: StyledElementPropsType) {
7771
if (dynamicStyles) dynamicSheet.update(this.tagScoped, nextProps)
7872
}
7973

@@ -88,25 +82,30 @@ export const createStyled = (jss?: Function = jssDefault) => (baseStyles: Object
8882

8983
const props = filterProps(attrs)
9084
const tagClass = [
91-
sheet.classes[StaticTag],
85+
sheet.classes[staticTag],
9286
dynamicSheet.classes[this.tagScoped],
9387
className,
9488
]
9589
.filter(Boolean)
9690
.join(' ')
9791

98-
return React.createElement(tag, {...props, className: tagClass}, children)
92+
return createElement(tag, {...props, className: tagClass}, children)
9993
}
10094
}
10195
}
10296
}
10397

104-
const defaultStyledBased = createStyled()
105-
const defaultStyled = defaultStyledBased()
98+
const defaultStyledCreator = createStyled()
10699

107-
export {defaultStyled as styled}
100+
const defaultStyled = defaultStyledCreator()
108101

109-
export const createStyledCreator = (styled: Function = defaultStyledBased) =>
102+
const createStyledCreator = (styled: Function = defaultStyledCreator) => (
110103
(baseStyles: Object) => Object.assign(styled(baseStyles), {styles: baseStyles})
104+
)
105+
106+
export {
107+
defaultStyled as styled,
108+
createStyledCreator
109+
}
111110

112111
export default createStyledCreator()

0 commit comments

Comments
 (0)