Skip to content

Commit

Permalink
Merge pull request #1233 from storybooks/1220-fix-knobs-editing
Browse files Browse the repository at this point in the history
Fixed knobs addon editing bug
  • Loading branch information
shilman authored Jun 9, 2017
2 parents c0dbffd + 6807b5e commit 96e99a3
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 39 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
4 changes: 2 additions & 2 deletions addons/info/src/components/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default function Node(props) {
/>
<span style={tagStyle}>&gt;</span>
</div>
{React.Children.map(children, childElement => (
{React.Children.map(children, childElement =>
<Node
node={childElement}
depth={depth + 1}
Expand All @@ -115,7 +115,7 @@ export default function Node(props) {
maxPropArrayLength={maxPropArrayLength}
maxPropStringLength={maxPropStringLength}
/>
))}
)}
<div style={containerStyleCopy}>
<span style={tagStyle}>&lt;/{name}&gt;</span>
</div>
Expand Down
4 changes: 2 additions & 2 deletions addons/info/src/components/PropTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export default function PropTable(props) {
</tr>
</thead>
<tbody>
{array.map(row => (
{array.map(row =>
<tr key={row.property}>
<td>{row.property}</td>
<td>{row.propType}</td>
Expand All @@ -110,7 +110,7 @@ export default function PropTable(props) {
</td>
<td>{row.description}</td>
</tr>
))}
)}
</tbody>
</table>
);
Expand Down
8 changes: 4 additions & 4 deletions addons/info/src/components/Story.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ export default class Story extends React.Component {
<div>
<h1 style={this.state.stylesheet.source.h1}>Story Source</h1>
<Pre>
{React.Children.map(this.props.children, (root, idx) => (
{React.Children.map(this.props.children, (root, idx) =>
<Node
key={idx}
node={root}
Expand All @@ -274,7 +274,7 @@ export default class Story extends React.Component {
maxPropArrayLength={maxPropArrayLength}
maxPropStringLength={maxPropStringLength}
/>
))}
)}
</Pre>
</div>
);
Expand Down Expand Up @@ -329,7 +329,7 @@ export default class Story extends React.Component {
array.sort((a, b) => (a.displayName || a.name) > (b.displayName || b.name));

const { maxPropObjectKeys, maxPropArrayLength, maxPropStringLength } = this.props;
const propTables = array.map(type => (
const propTables = array.map(type =>
<div key={type.name}>
<h2 style={this.state.stylesheet.propTableHead}>
"{type.displayName || type.name}" Component
Expand All @@ -341,7 +341,7 @@ export default class Story extends React.Component {
maxPropStringLength={maxPropStringLength}
/>
</div>
));
);

if (!propTables || propTables.length === 0) {
return null;
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
4 changes: 2 additions & 2 deletions app/react/src/server/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ export default function(configDir) {
};

router.get('/', (req, res) => {
const headHtml = getManagerHeadHtml(configDir)
const headHtml = getManagerHeadHtml(configDir);
res.send(getIndexHtml({ publicPath, headHtml }));
});

router.get('/iframe.html', (req, res) => {
const headHtml = getHeadHtml(configDir);
res.send(getIframeHtml({ ...data, headHtml, publicPath }));
});
});

if (stats.toJson().errors.length) {
webpackReject(stats);
Expand Down

0 comments on commit 96e99a3

Please sign in to comment.