Skip to content

Commit

Permalink
Fix: Only show Props & methods tab button if there are props (#488, c…
Browse files Browse the repository at this point in the history
…lose #486)
  • Loading branch information
SaraVieira authored and sapegin committed Jun 12, 2017
1 parent d4dc58f commit 0d0ca5a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/rsg-components/slots/UsageTabButton.js
Expand Up @@ -2,14 +2,23 @@ import React from 'react';
import PropTypes from 'prop-types';
import TabButton from 'rsg-components/TabButton';

const UsageTabButton = props =>
<TabButton {...props}>
Props & methods
</TabButton>;
const UsageTabButton = props => {
const component = props.props;
const showButton = component.props || (component.methods && component.methods.length > 0);
return showButton
? <TabButton {...props}>
Props & methods
</TabButton>
: null;
};

UsageTabButton.propTypes = {
onClick: PropTypes.func.isRequired,
name: PropTypes.string.isRequired,
props: PropTypes.shape({
props: PropTypes.object,
methods: PropTypes.array,
}).isRequired,
active: PropTypes.bool,
};

Expand Down
19 changes: 19 additions & 0 deletions src/rsg-components/slots/UsageTabButton.spec.js
@@ -0,0 +1,19 @@
import React from 'react';
import UsageTabButton from './UsageTabButton';

const props = {
name: 'Pizza',
onClick: () => {},
};

it('should renderer a button', () => {
const actual = shallow(<UsageTabButton {...props} props={{ props: { foo: {} } }} />);

expect(actual).toMatchSnapshot();
});

it('should renderer null if there are not props or methods', () => {
const actual = shallow(<UsageTabButton {...props} props={{}} />);

expect(actual.node).toBeFalsy();
});
17 changes: 17 additions & 0 deletions src/rsg-components/slots/__snapshots__/UsageTabButton.spec.js.snap
@@ -0,0 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`should renderer a button 1`] = `
<Styled(TabButton)
name="Pizza"
onClick={[Function]}
props={
Object {
"props": Object {
"foo": Object {},
},
}
}
>
Props & methods
</Styled(TabButton)>
`;

0 comments on commit 0d0ca5a

Please sign in to comment.