Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b5db279
Improve readme styling! 💅🏼
kutyel Dec 9, 2016
13ca512
merge upstream
kutyel Oct 3, 2017
dcbbb8f
Extract getThemeAndGeneratedClassName function from BaseStyledCompone…
Oct 7, 2017
b849f28
Updating changelog
Oct 7, 2017
742fb3b
Make determineTheme helper function for use inside StyledComponent (d…
Oct 8, 2017
197fcc5
use determineTheme in StyledNativeComponent
Oct 8, 2017
7ef8d38
typing determineTheme props parameter for theme attribute
Oct 8, 2017
2af185c
Merge pull request #1214 from lukebelliveau/1130-getThemeandGenerated…
mxstbr Oct 8, 2017
9203f7e
Merge remote-tracking branch 'upstream/master'
kutyel Oct 9, 2017
4125640
Prevent withTheme from breaking when a theme is provided via defaultP…
kutyel Oct 9, 2017
d8af075
remove changes to the readme from a previous PR 😳
kutyel Oct 9, 2017
33de404
Add change to changelog.md
kutyel Oct 9, 2017
dbeac29
Add case with no styledContext but defaultProps
kutyel Oct 9, 2017
eab8f5e
Adjust warning to show up only when needed ⚠️
kutyel Oct 9, 2017
571fce1
Add missing componentWillReceiveProps hook
kutyel Oct 9, 2017
43ab9bd
Added danger-plugin-jest
apoorv-mishra Oct 9, 2017
1080516
Increase test coverage 🐛
kutyel Oct 9, 2017
c9961fd
Fix unit test 🚀
kutyel Oct 9, 2017
6a6b373
Add one more case
kutyel Oct 9, 2017
f51a6f9
Fix unit test... again 😅
kutyel Oct 9, 2017
e945b03
Merge pull request #1223 from apoorv-mishra/fix-#1221
mxstbr Oct 10, 2017
85e566d
Merge branch 'master' into fix-with-theme-hoc
kutyel Oct 11, 2017
b33c00e
Merge pull request #1220 from kutyel/fix-with-theme-hoc
mxstbr Oct 11, 2017
f038dbf
add onReset to valid react props list
iminside Oct 12, 2017
c92f045
Update CHANGELOG
iminside Oct 12, 2017
4c50078
Merge pull request #1234 from 4urbanoff/master
kitten Oct 12, 2017
0e54f82
Add support for ServerStyleSheet in both StyleSheetManager and Styled…
Oct 16, 2017
097dbee
update stylis dependency to 3.x
theshortcut Oct 16, 2017
8aa30c6
Merge pull request #1246 from theshortcut/stylis-3.x
mxstbr Oct 16, 2017
3f96809
Merge branch 'master' into master
kitten Oct 16, 2017
ef05289
including a CHANGELOG entry for the pull request https://github.com/s…
Oct 18, 2017
e4f77e7
Merge remote-tracking branch 'origin/master'
Oct 18, 2017
43daf3b
Merge pull request #1245 from digital-flowers/master
mxstbr Oct 19, 2017
5fe0e38
Fix typo in StyleSheet
nvanselow Oct 20, 2017
a5175ed
Pass options to component style and modify css selector
nvanselow Oct 20, 2017
22a20fe
Pass options to BaseStyledComponent
nvanselow Oct 20, 2017
51d400f
Refactor css selector creation to a util
nvanselow Oct 20, 2017
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ npm-debug.log.*
dist
.DS_Store
bundle-stats.html
.vscode
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ All notable changes to this project will be documented in this file. If a contri

## Unreleased

- N/A
- Prevent `withTheme` HOC from breaking when passing a theme from `defaultProps`, thanks to [@kutyel](https://github.com/kutyel) (see [#1130](https://github.com/styled-components/styled-components/pull/1130))
- Refactor out theme logic in StyledComponent's componentWillMount & componentWillReceiveProps (see [#1130](https://github.com/styled-components/styled-components/issues/1130))
- Add onReset to valid react props list (see [#1234](https://github.com/styled-components/styled-components/pull/1234))
- Add support for ServerStyleSheet PropType in both StyleSheetManager and StyledComponent (see [#1245](https://github.com/styled-components/styled-components/pull/1245))

## [v2.2.1] - 2017-10-04

Expand Down
3 changes: 3 additions & 0 deletions dangerfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import { danger, warn, fail, message } from 'danger'
import fs from 'fs'
import jest from 'danger-plugin-jest'

jest()

const jsModifiedFiles = danger.git.modified_files.filter(path => path.startsWith('src') && path.endsWith('js'))
const vendorModifiedFiles = danger.git.modified_files.filter(path => path.startsWith('src/vendor') && path.endsWith('js'))
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"is-function": "^1.0.1",
"is-plain-object": "^2.0.1",
"prop-types": "^15.5.4",
"stylis": "^3.2.1",
"stylis": "3.x",
"supports-color": "^3.2.3"
},
"devDependencies": {
Expand All @@ -90,6 +90,7 @@
"bundlesize": "^0.13.2",
"chokidar": "^1.6.0",
"danger": "^0.16.0",
"danger-plugin-jest": "^1.0.1",
"enzyme": "^2.8.2",
"eslint": "^3.15.0",
"eslint-config-airbnb": "^13.0.0",
Expand All @@ -102,6 +103,7 @@
"flow-bin": "^0.47.0",
"flow-watch": "^1.1.1",
"jest": "^20.0.4",
"jest-json-reporter": "^1.2.2",
"jsdom": "^9.10.0",
"lint-staged": "^3.3.0",
"node-watch": "^0.4.1",
Expand Down Expand Up @@ -136,7 +138,8 @@
"testPathIgnorePatterns": [
"<rootDir>/src/native",
"<rootDir>/src/primitives"
]
],
"testResultsProcessor": "jest-json-reporter"
},
"lint-staged": {
"*.js": [
Expand All @@ -148,7 +151,7 @@
"bundlesize": [
{
"path": "./dist/styled-components.min.js",
"threshold": "14kB"
"threshold": "14.5kB"
}
]
}
6 changes: 3 additions & 3 deletions src/constructors/test/injectGlobal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { expectCSSMatches, resetStyled } from '../../test/utils'
const injectGlobal = _injectGlobal(stringifyRules, css)

let styled = resetStyled()
const rule1 = 'width: 100%;'
const rule2 = 'padding: 10px;'
const rule3 = 'color: blue;'
const rule1 = 'width:100%;'
const rule2 = 'padding:10px;'
const rule3 = 'color:blue;'

describe('injectGlobal', () => {
beforeEach(() => {
Expand Down
8 changes: 4 additions & 4 deletions src/constructors/test/keyframes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ describe('keyframes', () => {
expectCSSMatches(`
@-webkit-keyframes ${name} {
0% {
opacity: 0;
opacity:0;
}
100% {
opacity: 1;
opacity:1;
}
}

@keyframes ${name} {
0% {
opacity: 0;
opacity:0;
}
100% {
opacity: 1;
opacity:1;
}
}
`)
Expand Down
25 changes: 19 additions & 6 deletions src/hoc/withTheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import PropTypes from 'prop-types'
import hoistStatics from 'hoist-non-react-statics'
import { CHANNEL, CHANNEL_NEXT, CONTEXT_CHANNEL_SHAPE } from '../models/ThemeProvider'
import _isStyledComponent from '../utils/isStyledComponent'
import determineTheme from '../utils/determineTheme'

const wrapWithTheme = (Component: ReactClass<any>) => {
const componentName = (
Expand All @@ -31,17 +32,29 @@ const wrapWithTheme = (Component: ReactClass<any>) => {
unsubscribeId: number = -1

componentWillMount() {
const { defaultProps } = this.constructor
const styledContext = this.context[CHANNEL_NEXT]
if (styledContext === undefined) {
const themeProp = determineTheme(this.props, undefined, defaultProps)
if (styledContext === undefined && themeProp === undefined && process.env.NODE_ENV !== 'production') {
// eslint-disable-next-line no-console
console.error('[withTheme] Please use ThemeProvider to be able to use withTheme')
return
console.warn('[withTheme] You are not using a ThemeProvider nor passing a theme prop or a theme in defaultProps')
} else if (styledContext === undefined && themeProp !== undefined) {
this.setState({ theme: themeProp })
} else {
const { subscribe } = styledContext
this.unsubscribeId = subscribe(nextTheme => {
const theme = determineTheme(this.props, nextTheme, defaultProps)
this.setState({ theme })
})
}
}

componentWillReceiveProps(nextProps: { theme?: ?Object, [key: string]: any }) {
const { defaultProps } = this.constructor
this.setState((oldState) => {
const theme = determineTheme(nextProps, oldState.theme, defaultProps)

const { subscribe } = styledContext
this.unsubscribeId = subscribe(theme => {
this.setState({ theme })
return { theme }
})
}

Expand Down
12 changes: 9 additions & 3 deletions src/models/ComponentStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import hashStr from '../vendor/glamor/hash'
import type { RuleSet, NameGenerator, Flattener, Stringifier } from '../types'
import StyleSheet from './StyleSheet'
import isStyledComponent from '../utils/isStyledComponent'
import getComponentCssSelector from '../utils/getComponentCssSelector'

const isStaticRules = (rules: RuleSet): boolean => {
for (let i = 0; i < rules.length; i += 1) {
Expand Down Expand Up @@ -33,7 +34,6 @@ export default (nameGenerator: NameGenerator, flatten: Flattener, stringifyRules
isStatic: boolean
lastClassName: ?string


constructor(rules: RuleSet, componentId: string) {
this.rules = rules
this.isStatic = isStaticRules(rules)
Expand All @@ -49,7 +49,11 @@ export default (nameGenerator: NameGenerator, flatten: Flattener, stringifyRules
* Hashes it, wraps the whole chunk in a .hash1234 {}
* Returns the hash to be injected on render()
* */
generateAndInjectStyles(executionContext: Object, styleSheet: StyleSheet) {
generateAndInjectStyles(
executionContext: Object,
styleSheet: StyleSheet,
options: Object = {},
) {
const { isStatic, lastClassName } = this
if (isStatic && lastClassName !== undefined) {
return lastClassName
Expand All @@ -74,7 +78,9 @@ export default (nameGenerator: NameGenerator, flatten: Flattener, stringifyRules
return name
}

const css = `\n${stringifyRules(flatCSS, `.${name}`)}`
const selector = getComponentCssSelector(name, options)

const css = `\n${stringifyRules(flatCSS, selector)}`
// NOTE: this can only be set when we inject the class-name.
// For some reason, presumably due to how css is stringifyRules behaves in
// differently between client and server, styles break.
Expand Down
2 changes: 1 addition & 1 deletion src/models/StyleSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default class StyleSheet {
deferredInjections: { [string]: string } = {}
componentTags: { [string]: Tag }
// helper for `ComponentStyle` to know when it cache static styles.
// staticly styled-component can not safely cache styles on the server
// statically styled-component can not safely cache styles on the server
// without all `ComponentStyle` instances saving a reference to the
// the styleSheet instance they last rendered with,
// or listening to creation / reset events. otherwise you might create
Expand Down
11 changes: 9 additions & 2 deletions src/models/StyleSheetManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import StyleSheet, { CONTEXT_KEY } from './StyleSheet'
import ServerStyleSheet from './ServerStyleSheet'

class StyleSheetManager extends Component {
getChildContext() {
Expand All @@ -18,11 +19,17 @@ class StyleSheetManager extends Component {
}

StyleSheetManager.childContextTypes = {
[CONTEXT_KEY]: PropTypes.instanceOf(StyleSheet).isRequired,
[CONTEXT_KEY]: PropTypes.oneOfType([
PropTypes.instanceOf(StyleSheet),
PropTypes.instanceOf(ServerStyleSheet),
]).isRequired,
}

StyleSheetManager.propTypes = {
sheet: PropTypes.instanceOf(StyleSheet).isRequired,
sheet: PropTypes.oneOfType([
PropTypes.instanceOf(StyleSheet),
PropTypes.instanceOf(ServerStyleSheet),
]).isRequired,
}

export default StyleSheetManager
Loading