Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addon-info: allow duplicate displayNames #2269

Merged
merged 4 commits into from Nov 9, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 7 additions & 6 deletions addons/info/src/components/Story.js
Expand Up @@ -14,6 +14,8 @@ import { Pre } from './markdown';
global.STORYBOOK_REACT_CLASSES = global.STORYBOOK_REACT_CLASSES || [];
const { STORYBOOK_REACT_CLASSES } = global;

const getName = type => type.displayName || type.name;

const stylesheet = {
link: {
base: {
Expand Down Expand Up @@ -324,14 +326,13 @@ export default class Story extends React.Component {
extract(this.props.children);

const array = Array.from(types.keys());
array.sort((a, b) => (a.displayName || a.name) > (b.displayName || b.name));
array.sort((a, b) => getName(a) > getName(b));

const { maxPropObjectKeys, maxPropArrayLength, maxPropStringLength } = this.props;
const propTables = array.map(type => (
<div key={type.displayName || type.name}>
<h2 style={this.state.stylesheet.propTableHead}>
"{type.displayName || type.name}" Component
</h2>
const propTables = array.map((type, i) => (
// eslint-disable-next-line react/no-array-index-key
<div key={`${getName(type)}_${i}`}>
Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's OK to use indices in this case

<h2 style={this.state.stylesheet.propTableHead}>"{getName(type)}" Component</h2>
<PropTable
type={type}
maxPropObjectKeys={maxPropObjectKeys}
Expand Down
341 changes: 341 additions & 0 deletions examples/cra-kitchen-sink/src/__snapshots__/storyshots.test.js.snap
Expand Up @@ -6060,6 +6060,347 @@ exports[`Storyshots Button with text 1`] = `
</button>
`;

exports[`Storyshots GitHub issues #1814 1`] = `
<div>
<div
style={
Object {
"position": "relative",
"zIndex": 0,
}
}
>
<div>
<input
type="text"
/>
<textarea />
</div>
</div>
<a
onClick={[Function]}
role="button"
style={
Object {
"background": "#28c",
"borderRadius": "0 0 0 5px",
"color": "#fff",
"cursor": "pointer",
"display": "block",
"fontFamily": "sans-serif",
"fontSize": "12px",
"padding": "5px 15px",
"position": "fixed",
"right": 0,
"textDecoration": "none",
"top": 0,
}
}
tabIndex="0"
>
Show Info
</a>
<div
style={
Object {
"background": "white",
"bottom": 0,
"display": "none",
"left": 0,
"overflow": "auto",
"padding": "0 40px",
"position": "fixed",
"right": 0,
"top": 0,
"zIndex": 99999,
}
}
>
<a
onClick={[Function]}
role="button"
style={
Object {
"background": "#28c",
"borderRadius": "0 0 0 5px",
"color": "#fff",
"cursor": "pointer",
"display": "block",
"fontFamily": "sans-serif",
"fontSize": "12px",
"padding": "5px 15px",
"position": "fixed",
"right": 0,
"textDecoration": "none",
"top": 0,
}
}
tabIndex="0"
>
×
</a>
<div
style={undefined}
>
<div
style={
Object {
"WebkitFontSmoothing": "antialiased",
"backgroundColor": "#fff",
"border": "1px solid #eee",
"borderRadius": "2px",
"boxShadow": "0px 2px 3px rgba(0, 0, 0, 0.05)",
"color": "#444",
"fontFamily": "-apple-system, \\".SFNSText-Regular\\", \\"San Francisco\\", BlinkMacSystemFont, \\"Segoe UI\\", \\"Roboto\\", \\"Oxygen\\", \\"Ubuntu\\", \\"Cantarell\\", \\"Fira Sans\\", \\"Droid Sans\\", \\"Helvetica Neue\\", \\"Lucida Grande\\", \\"Arial\\", sans-serif",
"fontSize": "15px",
"fontWeight": 300,
"lineHeight": 1.45,
"marginTop": "50px",
"padding": "20px 40px 40px",
}
}
>
<div
style={
Object {
"borderBottom": "1px solid #eee",
"marginBottom": 10,
"paddingTop": 10,
}
}
>
<h1
style={
Object {
"fontSize": "35px",
"margin": 0,
"padding": 0,
}
}
>
GitHub issues
</h1>
<h2
style={
Object {
"fontSize": "22px",
"fontWeight": 400,
"margin": "0 0 10px 0",
"padding": 0,
}
}
>
#1814
</h2>
</div>
<div
style={
Object {
"marginBottom": 0,
}
}
>
<p
style={
Object {
"WebkitFontSmoothing": "antialiased",
"color": "#444",
"fontFamily": "-apple-system, \\".SFNSText-Regular\\", \\"San Francisco\\", BlinkMacSystemFont, \\"Segoe UI\\", \\"Roboto\\", \\"Oxygen\\", \\"Ubuntu\\", \\"Cantarell\\", \\"Fira Sans\\", \\"Droid Sans\\", \\"Helvetica Neue\\", \\"Lucida Grande\\", \\"Arial\\", sans-serif",
"fontSize": "15px",
}
}
>
HOC
</p>
</div>
<div>
<h1
style={
Object {
"borderBottom": "1px solid #EEE",
"fontSize": "25px",
"margin": "20px 0 0 0",
"padding": "0 0 5px 0",
}
}
>
Story Source
</h1>
<pre
style={
Object {
"backgroundColor": "#fafafa",
"fontFamily": "Menlo, Monaco, \\"Courier New\\", monospace",
"fontSize": ".88em",
"lineHeight": 1.5,
"overflowX": "scroll",
"padding": ".5rem",
}
}
>
<div>
<div
style={
Object {
"paddingLeft": 18,
"paddingRight": 3,
}
}
>
<span
style={
Object {
"color": "#777",
}
}
>
&lt;
div
</span>
<span />
<span
style={
Object {
"color": "#777",
}
}
>
&gt;
</span>
</div>
<div
style={
Object {
"paddingLeft": 33,
"paddingRight": 3,
}
}
>
<span
style={
Object {
"color": "#777",
}
}
>
&lt;
Unknown
</span>
<span />
<span
style={
Object {
"color": "#777",
}
}
>
/&gt;
</span>
</div>
<div
style={
Object {
"paddingLeft": 33,
"paddingRight": 3,
}
}
>
<span
style={
Object {
"color": "#777",
}
}
>
&lt;
Unknown
</span>
<span />
<span
style={
Object {
"color": "#777",
}
}
>
/&gt;
</span>
</div>
<div
style={
Object {
"paddingLeft": 18,
"paddingRight": 3,
}
}
>
<span
style={
Object {
"color": "#777",
}
}
>
&lt;/
div
&gt;
</span>
</div>
</div>
</pre>
</div>
<div>
<h1
style={
Object {
"borderBottom": "1px solid #EEE",
"fontSize": "25px",
"margin": "20px 0 0 0",
"padding": "0 0 5px 0",
}
}
>
Prop Types
</h1>
<div>
<h2
style={
Object {
"margin": "20px 0 0 0",
}
}
>
"

" Component
</h2>
<small>
No propTypes defined!
</small>
</div>
<div>
<h2
style={
Object {
"margin": "20px 0 0 0",
}
}
>
"

" Component
</h2>
<small>
No propTypes defined!
</small>
</div>
</div>
</div>
</div>
</div>
</div>
`;

exports[`Storyshots Navigation Menu link 1`] = `
<div
className="css-t9df35"
Expand Down
19 changes: 19 additions & 0 deletions examples/cra-kitchen-sink/src/stories/issues.stories.js
@@ -0,0 +1,19 @@
import React from 'react';
import { storiesOf } from '@storybook/react';
import { withInfo } from '@storybook/addon-info';

const hoc = WrapComponent => ({ ...props }) => <WrapComponent {...props} />;

const Input = hoc(() => <input type="text" />);

const TextArea = hoc(({ children }) => <textarea>{children}</textarea>);

storiesOf('GitHub issues', module).add(
Copy link
Member

Choose a reason for hiding this comment

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

Naming it github issues isn't very helpful. Maybe Addon Info.HOC and withInfo('Allow Duplicate DisplayNames for HOC #1814')?

Copy link
Member Author

@Hypnosphi Hypnosphi Nov 9, 2017

Choose a reason for hiding this comment

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

I wanted to introduce a single namespace for reproductions, so that it's easy to find one

Copy link
Member

Choose a reason for hiding this comment

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

I understand, but ultimately, I still think this is a Addon Info thing. If we have 20 different Github issues and I'm making a change to Addon Info, I wouldn't think to check all the Github ones for regressions you know?

Maybe Addon Info.Github Issues and that description I had earlier?

'#1814',
withInfo('HOC')(() => (
<div>
<Input />
<TextArea />
</div>
))
);