Skip to content

Commit

Permalink
Cherry-pick knobs fix from #1224
Browse files Browse the repository at this point in the history
  • Loading branch information
ndelangen authored and shilman committed Jun 9, 2017
1 parent c0dbffd commit 244732a
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 29 deletions.
16 changes: 2 additions & 14 deletions addons/actions/src/components/ActionLogger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,14 @@ import Inspector from 'react-inspector';
import style from './style';

class ActionLogger extends Component {
componentDidUpdate() {
const latest = this.ref.latest;
if (latest) {
const borderLeft = style.action.borderLeft;
latest.style.borderLeft = 'solid 5px #aaa';
setTimeout(() => {
latest.style.borderLeft = borderLeft;
}, 300);
}
}

getActionData() {
return this.props.actions.map((action, i) => this.renderAction(action, i));
}

renderAction(action, i) {
const ref = () => (this.ref = i ? '' : 'latest');
renderAction(action) {
const counter = <div style={style.counter}>{action.count}</div>;
return (
<div ref={ref} key={action.id} style={style.action}>
<div key={action.id} style={style.action}>
<div style={style.countwrap}>
{action.count > 1 && counter}
</div>
Expand Down
2 changes: 1 addition & 1 deletion addons/actions/src/components/ActionLogger/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default {
borderLeft: '5px solid white',
borderBottom: '1px solid #fafafa',
transition: 'all 0.1s',
alignItems: 'center',
alignItems: 'start',
},
countwrap: {
paddingBottom: 2,
Expand Down
2 changes: 1 addition & 1 deletion addons/knobs/src/components/PropField.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default class PropField extends React.Component {
PropField.propTypes = {
knob: PropTypes.shape({
name: PropTypes.string,
value: PropTypes.string,
value: PropTypes.any,
}),
onChange: PropTypes.func.isRequired,
};
26 changes: 15 additions & 11 deletions addons/knobs/src/components/PropForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,20 @@ export default class propForm extends React.Component {

return (
<form style={stylesheet.propForm}>
{knobs.map(knob =>
<PropField
key={knob.name}
name={knob.name}
type={knob.type}
value={knob.value}
knob={knob}
onChange={() => this._onFieldChange(knob.name, knob.type)}
/>
)}
{knobs.map(knob => {
// eslint-disable-next-line react/jsx-no-bind
const changeHandler = this.onFieldChange.bind(this, knob.name, knob.type);
return (
<PropField
key={knob.name}
name={knob.name}
type={knob.type}
value={knob.value}
knob={knob}
onChange={changeHandler}
/>
);
})}
</form>
);
}
Expand All @@ -60,7 +64,7 @@ propForm.propTypes = {
knobs: PropTypes.arrayOf(
PropTypes.shape({
name: PropTypes.string,
value: PropTypes.string,
value: PropTypes.any,
})
),
onFieldChange: PropTypes.func.isRequired,
Expand Down
2 changes: 1 addition & 1 deletion addons/knobs/src/components/WrapStory.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ WrapStory.defaultProps = {
WrapStory.propTypes = {
context: PropTypes.object, // eslint-disable-line react/forbid-prop-types
storyFn: PropTypes.func,
channel: React.PropTypes.shape({
channel: PropTypes.shape({
on: PropTypes.func,
removeListener: PropTypes.func,
}).isRequired,
Expand Down
2 changes: 1 addition & 1 deletion addons/knobs/src/components/types/Number.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ NumberType.defaultProps = {
NumberType.propTypes = {
knob: PropTypes.shape({
name: PropTypes.string,
value: PropTypes.string,
value: PropTypes.number,
}),
onChange: PropTypes.func,
};
Expand Down

0 comments on commit 244732a

Please sign in to comment.