Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"babel-loader": "^5.3.2",
"babel-plugin-espower": "^1.0.0",
"babel-runtime": "^5.8.20",
"classnames": "^2.2.5",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it's worth it to introduce a dependency.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your lib your rules) I just have added this for more clear code. All modern JS-world built on dependencies.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah... just not sure if it's worth fixing what ain't broken :-)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Anyway you could use stateless components and const except of let in properties destructuring (this variables are never reassigned).

"css-loader": "^0.18.0",
"eslint": "^1.3.1",
"eslint-plugin-react": "^3.3.2",
Expand Down
82 changes: 40 additions & 42 deletions src/Icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
*/

import React, {PropTypes} from 'react';
import classnames from 'classnames';

export default class Icon extends React.Component {

static propTypes = {
const propTypes = {
name: PropTypes.string.isRequired,
className: PropTypes.string,
size: PropTypes.oneOf(['lg', '2x', '3x', '4x', '5x']),
Expand All @@ -18,48 +17,47 @@ export default class Icon extends React.Component {
stack: PropTypes.oneOf(['1x', '2x']),
inverse: PropTypes.bool,
Component: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
};
};

static defaultProps = {
const defaultProps = {
Component: 'span',
};
className: '',
size: null,
rotate: null,
flip: null,
fixedWidth: false,
spin: false,
pulse: false,
stack: null,
inverse: false,
};

render() {
let {
Component,
name, size, rotate, flip, spin, fixedWidth, stack, inverse,
pulse, className, ...props
} = this.props;
let classNames = `fa fa-${name}`;
if (size) {
classNames = `${classNames} fa-${size}`;
}
if (rotate) {
classNames = `${classNames} fa-rotate-${rotate}`;
}
if (flip) {
classNames = `${classNames} fa-flip-${flip}`;
}
if (fixedWidth) {
classNames = `${classNames} fa-fw`;
}
if (spin) {
classNames = `${classNames} fa-spin`;
}
if (pulse) {
classNames = `${classNames} fa-pulse`;
}
function Icon(props) {
const {
Component,
name, size, rotate, flip, spin, fixedWidth, stack, inverse,
pulse, className, ...restProps
} = props;

if (stack) {
classNames = `${classNames} fa-stack-${stack}`;
}
if (inverse) {
classNames = `${classNames} fa-inverse`;
}
const iconClassNames = classnames(
`fa fa-${name}`,
className,
{
[`fa-${size}`]: size,
[`fa-rotate-${rotate}`]: rotate,
[`fa-flip-${flip}`]: flip,
[`fa-stack-${stack}`]: stack,
'fa-fw': fixedWidth,
'fa-spin': spin,
'fa-pulse': pulse,
'fa-inverse': inverse,
},
);

if (className) {
classNames = `${classNames} ${className}`;
}
return <Component {...props} className={classNames} />;
}
return <Component {...restProps} className={iconClassNames} />;
}

Icon.propTypes = propTypes;
Icon.defaultProps = defaultProps;

export default Icon;
66 changes: 34 additions & 32 deletions src/IconStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,41 @@
*/

import React, {PropTypes} from 'react';
import classnames from 'classnames';

export default class IconStack extends React.Component {

static propTypes = {
const propTypes = {
className: PropTypes.string,
size: PropTypes.oneOf(['lg', '2x', '3x', '4x', '5x']),
children: PropTypes.node.isRequired
};

render() {
let {
className,
size,
children,
...props
} = this.props;

let classNames = ['fa-stack'];

if (size) {
classNames.push(`fa-${size}`);
}

if (className) {
classNames.push(className);
}

const iconStackClassName = classNames.join(' ');

return (
<span {...props} className={iconStackClassName}>
{children}
</span>
);
}
children: PropTypes.node.isRequired,
};

const defaultProps = {
className: '',
size: null,
};

function IconStack(props) {
const {
className,
size,
children,
...restProps
} = props;

const iconStackClassNames = classnames(
'fa-stack',
className,
{ [`fa-${size}`]: size, },
);

return (
<span {...restProps} className={iconStackClassNames}>
{children}
</span>
);
}

IconStack.propTypes = propTypes;
IconStack.defaultProps = defaultProps;

export default IconStack;