Skip to content

Commit

Permalink
Use prop-types
Browse files Browse the repository at this point in the history
  • Loading branch information
Artem Sapegin committed Mar 12, 2018
1 parent 3f9833f commit c7afbd7
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 47 deletions.
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"printWidth": 100,
"singleQuote": true,
"trailingComma": "es5",
"useTabs": true
}
44 changes: 33 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"babel-preset-env": "^1.6.0",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"prop-types": "^15.6.1",
"react": "^15.6.1",
"react-dom": "^15.6.1",
"react-styleguidist": "^6.0.4",
Expand Down
14 changes: 7 additions & 7 deletions src/components/Button.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import React, { PropTypes } from 'react';
import React from 'react';
import PropTypes from 'prop-types';

import s from './Button.css';

/**
* The only true button.
*/
export default function Button({
color,
size,
children,
}) {
export default function Button({ color, size, children }) {
let styles = {
color,
fontSize: Button.sizes[size],
};

return (
<button className={s.root} style={styles}>{children}</button>
<button className={s.root} style={styles}>
{children}
</button>
);
}

Button.propTypes = {
/**
* Button label.
Expand Down
19 changes: 14 additions & 5 deletions src/components/Placeholder.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Component, PropTypes } from 'react';
import React, { Component } from 'react';
import PropTypes from 'prop-types';

import s from './Placeholder.css';

Expand All @@ -7,7 +8,17 @@ import s from './Placeholder.css';
*/
export default class Placeholder extends Component {
static propTypes = {
type: PropTypes.oneOf(['animal', 'bacon', 'beard', 'bear', 'cat', 'food', 'city', 'nature', 'people']),
type: PropTypes.oneOf([
'animal',
'bacon',
'beard',
'bear',
'cat',
'food',
'city',
'nature',
'people',
]),
width: PropTypes.number,
height: PropTypes.number,
};
Expand Down Expand Up @@ -36,8 +47,6 @@ export default class Placeholder extends Component {

render() {
let { width, height } = this.props;
return (
<img className={s.root} src={this.getImageUrl()} width={width} height={height} />
);
return <img className={s.root} src={this.getImageUrl()} width={width} height={height} />;
}
}
14 changes: 7 additions & 7 deletions src/components/PushButton.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import React, { PropTypes } from 'react';
import React from 'react';
import PropTypes from 'prop-types';

import s from './PushButton.css';

/**
* An example-less button.
*/
export default function PushButton({
color,
size,
children,
}) {
export default function PushButton({ color, size, children }) {
let styles = {
color,
fontSize: PushButton.sizes[size],
};

return (
<button className={s.root} style={styles}>{children}</button>
<button className={s.root} style={styles}>
{children}
</button>
);
}

PushButton.propTypes = {
/**
* PushButton label.
Expand Down
34 changes: 17 additions & 17 deletions styleguide.config.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
module.exports = {
title: "React Style Guide Example",
defaultExample: true,
webpackConfig: {
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: "babel-loader"
},
{
test: /\.css$/,
loader: "style-loader!css-loader?modules&importLoaders=1"
}
]
}
}
title: 'React Style Guide Example',
defaultExample: true,
webpackConfig: {
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
{
test: /\.css$/,
loader: 'style-loader!css-loader?modules&importLoaders=1',
},
],
},
},
};

0 comments on commit c7afbd7

Please sign in to comment.