Skip to content

Commit

Permalink
refactor default className propType
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesknelson committed Sep 2, 2015
1 parent 94f90ea commit 9755bb4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/
Empty file added README.md
Empty file.
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "lib/pacomo.js",
"scripts": {
"compile": "babel --stage 0 -d lib/ src/",
"prepublish": "npm run compile",
"prepublish": "npm run test",
"test": "npm run compile && mocha --compilers js:babel/register"
},
"repository": {
Expand All @@ -27,14 +27,17 @@
"url": "https://github.com/jamesknelson/react-pacomo/issues"
},
"homepage": "https://github.com/jamesknelson/react-pacomo#readme",
"peerDependencies": {
"react": "^0.14.0-beta3"
},
"dependencies": {
"classnames": "^2.1.3",
"invariant": "^2.1.0",
"react": "^0.14.0-beta3"
"invariant": "^2.1.0"
},
"devDependencies": {
"babel": "^5.8.23",
"mocha": "^2.3.0",
"react": "^0.14.0-beta3",
"react-addons-test-utils": "^0.14.0-beta3"
}
}
24 changes: 10 additions & 14 deletions src/pacomo.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ export function createDecorator(prefix) {
"pacomo must be applied to a class with no `pacomo` property"
)

const decoratedComponent = class extends component {
return class extends component {
static displayName = componentName

// Add `className` propType, if none exists
static propTypes =
Object.assign(
{className: PropTypes.string},
component.propTypes
)

pacomo(...args) {
return (
classNames(...args)
Expand All @@ -31,18 +40,5 @@ export function createDecorator(prefix) {
)
}
}

// Add `className` propType, if none exists
if (!decoratedComponent.propTypes) {
decoratedComponent.propTypes = {}
}
if (!decoratedComponent.propTypes.className) {
decoratedComponent.propTypes = Object.assign(
{className: PropTypes.string},
decoratedComponent.propTypes
)
}

return decoratedComponent
}
}
4 changes: 2 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ describe('#pacomo', () => {
const pacomo = createDecorator('prefix')(BareComponent).prototype.pacomo

assert.equal(
pacomo('test'),
'prefix-BareComponent-test',
pacomo('test1', 'test2'),
'prefix-BareComponent-test1 prefix-BareComponent-test2',
"`pacomo` produces the correct string when a string is passed in"
)
})
Expand Down

0 comments on commit 9755bb4

Please sign in to comment.