Skip to content

Commit

Permalink
Fix dynamic knobs
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypnosphi committed Apr 21, 2018
1 parent 2c73655 commit d2a289e
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 282 deletions.
1 change: 0 additions & 1 deletion addons/knobs/.storybook/addons.js

This file was deleted.

12 changes: 0 additions & 12 deletions addons/knobs/.storybook/config.js

This file was deleted.

4 changes: 0 additions & 4 deletions addons/knobs/.storybook/user/modify_webpack_config.js

This file was deleted.

23 changes: 0 additions & 23 deletions addons/knobs/.storybook/webpack.config.js

This file was deleted.

115 changes: 0 additions & 115 deletions addons/knobs/example/stories/index.js

This file was deleted.

103 changes: 0 additions & 103 deletions addons/knobs/example/typescript/index.tsx

This file was deleted.

6 changes: 1 addition & 5 deletions addons/knobs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,9 @@
"util-deprecate": "^1.0.2"
},
"devDependencies": {
"@storybook/react": "4.0.0-alpha.3",
"raw-loader": "^0.5.1",
"style-loader": "^0.20.3",
"vue": "^2.5.16"
},
"peerDependencies": {
"react": "*",
"react-dom": "*"
"react": "*"
}
}
32 changes: 13 additions & 19 deletions addons/knobs/src/components/Panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,31 +155,25 @@ export default class Panel extends React.Component {
const groups = {};
const groupIds = [];

Object.keys(knobs)
.filter(key => knobs[key].used && knobs[key].groupId)
.forEach(key => {
const knobKeyGroupId = knobs[key].groupId;
groupIds.push(knobKeyGroupId);
groups[knobKeyGroupId] = {
render: () => <div id={knobKeyGroupId}>{knobKeyGroupId}</div>,
title: knobKeyGroupId,
};
});

let knobsArray = Object.keys(knobs);
let knobsArray = Object.keys(knobs).filter(key => knobs[key].used);

knobsArray.filter(key => knobs[key].groupId).forEach(key => {
const knobKeyGroupId = knobs[key].groupId;
groupIds.push(knobKeyGroupId);
groups[knobKeyGroupId] = {
render: () => <div id={knobKeyGroupId}>{knobKeyGroupId}</div>,
title: knobKeyGroupId,
};
});

if (groupIds.length > 0) {
groups[DEFAULT_GROUP_ID] = {
render: () => <div id={DEFAULT_GROUP_ID}>{DEFAULT_GROUP_ID}</div>,
title: DEFAULT_GROUP_ID,
};
knobsArray = knobsArray.filter(key => {
const filter =
groupId === DEFAULT_GROUP_ID
? knobs[key].used
: knobs[key].used && knobs[key].groupId === groupId;
return filter;
});
if (groupId !== DEFAULT_GROUP_ID) {
knobsArray = knobsArray.filter(key => knobs[key].groupId === groupId);
}
}

knobsArray = knobsArray.map(key => knobs[key]);
Expand Down
9 changes: 9 additions & 0 deletions examples/official-storybook/stories/addon-knobs.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ storiesOf('Addons|Knobs.withKnobs', module)
</div>
);
})
.add('dynamic knobs', () => {
const showOptional = select('Show optional', ['yes', 'no'], 'yes');
return (
<div>
<div>{text('compulsary', 'I must be here')}</div>
{showOptional === 'yes' ? <div>{text('optional', 'I can disapear')}</div> : null}
</div>
);
})
.add('triggers actions via button', () => (
<div>
<p>Hit the knob load button and it should trigger an async load after a short delay</p>
Expand Down

0 comments on commit d2a289e

Please sign in to comment.