Skip to content

Commit

Permalink
Merge pull request #27 from onefinestay/replaceable_icon
Browse files Browse the repository at this point in the history
Replaceable icon
  • Loading branch information
jkimbo committed Apr 1, 2015
2 parents 8c27d87 + ee611b9 commit 945ea59
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 12 deletions.
24 changes: 24 additions & 0 deletions dist/icon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"use strict";

var React = require('react/addons');
var cx = React.addons.classSet;

var Icon = React.createClass({displayName: 'Icon',
propTypes: {
focused: React.PropTypes.bool.isRequired
},

render: function() {
var arrowClasses = cx({
'react-choice-icon__arrow': true,
'react-choice-icon__arrow--up': this.props.focused,
'react-choice-icon__arrow--down': !this.props.focused
});

return (
React.createElement("div", {className: arrowClasses})
);
}
});

module.exports = Icon;
11 changes: 5 additions & 6 deletions dist/single.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var _ = require('lodash');
var cx = React.addons.classSet;
var cloneWithProps = React.addons.cloneWithProps;

var Icon = require('./icon');
var OptionWrapper = require('./option-wrapper');

var SearchMixin = require('./search-mixin');
Expand All @@ -25,6 +26,8 @@ var SingleChoice = React.createClass({displayName: 'SingleChoice',

searchField: React.PropTypes.array, // array of search fields

icon: React.PropTypes.func, // icon render

onSelect: React.PropTypes.func, // function called when option is selected
},

Expand Down Expand Up @@ -188,11 +191,7 @@ var SingleChoice = React.createClass({displayName: 'SingleChoice',
'react-choice-single--not-in-focus': !this.state.focus
});

var arrowClasses = cx({
'react-choice-icon__arrow': true,
'react-choice-icon__arrow--up': this.state.focus,
'react-choice-icon__arrow--down': !this.state.focus
});
var IconRenderer = this.props.icon || Icon;

return (
React.createElement("div", {className: "react-choice"},
Expand All @@ -214,7 +213,7 @@ var SingleChoice = React.createClass({displayName: 'SingleChoice',
),

React.createElement("div", {className: "react-choice-icon", onMouseDown: this._handleArrowClick},
React.createElement("div", {className: arrowClasses})
React.createElement(IconRenderer, {focused: this.state.focus})
),

this.state.focus ?
Expand Down
24 changes: 24 additions & 0 deletions src/icon.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"use strict";

var React = require('react/addons');
var cx = React.addons.classSet;

var Icon = React.createClass({
propTypes: {
focused: React.PropTypes.bool.isRequired
},

render: function() {
var arrowClasses = cx({
'react-choice-icon__arrow': true,
'react-choice-icon__arrow--up': this.props.focused,
'react-choice-icon__arrow--down': !this.props.focused
});

return (
<div className={arrowClasses}></div>
);
}
});

module.exports = Icon;
11 changes: 5 additions & 6 deletions src/single.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var _ = require('lodash');
var cx = React.addons.classSet;
var cloneWithProps = React.addons.cloneWithProps;

var Icon = require('./icon');
var OptionWrapper = require('./option-wrapper');

var SearchMixin = require('./search-mixin');
Expand All @@ -25,6 +26,8 @@ var SingleChoice = React.createClass({

searchField: React.PropTypes.array, // array of search fields

icon: React.PropTypes.func, // icon render

onSelect: React.PropTypes.func, // function called when option is selected
},

Expand Down Expand Up @@ -188,11 +191,7 @@ var SingleChoice = React.createClass({
'react-choice-single--not-in-focus': !this.state.focus
});

var arrowClasses = cx({
'react-choice-icon__arrow': true,
'react-choice-icon__arrow--up': this.state.focus,
'react-choice-icon__arrow--down': !this.state.focus
});
var IconRenderer = this.props.icon || Icon;

return (
<div className="react-choice">
Expand All @@ -214,7 +213,7 @@ var SingleChoice = React.createClass({
</div>

<div className="react-choice-icon" onMouseDown={this._handleArrowClick}>
<div className={arrowClasses}></div>
<IconRenderer focused={this.state.focus} />
</div>

{this.state.focus ?
Expand Down

0 comments on commit 945ea59

Please sign in to comment.