Skip to content

Commit

Permalink
chore(prettier): Format codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
danez committed Apr 17, 2018
1 parent 0ffa609 commit 9be02f2
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 23 deletions.
12 changes: 10 additions & 2 deletions src/components/Tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,16 @@ export default class Tab extends Component {
};

static propTypes = {
children: PropTypes.oneOfType([PropTypes.array, PropTypes.object, PropTypes.string]),
className: PropTypes.oneOfType([PropTypes.string, PropTypes.array, PropTypes.object]),
children: PropTypes.oneOfType([
PropTypes.array,
PropTypes.object,
PropTypes.string,
]),
className: PropTypes.oneOfType([
PropTypes.string,
PropTypes.array,
PropTypes.object,
]),
disabled: PropTypes.bool,
tabIndex: PropTypes.string,
disabledClassName: PropTypes.string,
Expand Down
6 changes: 5 additions & 1 deletion src/components/TabPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ export default class TabPanel extends Component {

static propTypes = {
children: PropTypes.node,
className: PropTypes.oneOfType([PropTypes.string, PropTypes.array, PropTypes.object]),
className: PropTypes.oneOfType([
PropTypes.string,
PropTypes.array,
PropTypes.object,
]),
forceRender: PropTypes.bool,
id: PropTypes.string, // private
selected: PropTypes.bool, // private
Expand Down
12 changes: 10 additions & 2 deletions src/components/Tabs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { childrenPropType, onSelectPropType, selectedIndexPropType } from '../helpers/propTypes';
import {
childrenPropType,
onSelectPropType,
selectedIndexPropType,
} from '../helpers/propTypes';
import UncontrolledTabs from './UncontrolledTabs';
import { getTabsCount } from '../helpers/count';

Expand All @@ -14,7 +18,11 @@ export default class Tabs extends Component {

static propTypes = {
children: childrenPropType,
className: PropTypes.oneOfType([PropTypes.string, PropTypes.array, PropTypes.object]),
className: PropTypes.oneOfType([
PropTypes.string,
PropTypes.array,
PropTypes.object,
]),
defaultFocus: PropTypes.bool,
defaultIndex: PropTypes.number,
disabledTabClassName: PropTypes.string,
Expand Down
15 changes: 11 additions & 4 deletions src/components/UncontrolledTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ export default class UncontrolledTabs extends Component {

static propTypes = {
children: childrenPropType,
className: PropTypes.oneOfType([PropTypes.string, PropTypes.array, PropTypes.object]),
className: PropTypes.oneOfType([
PropTypes.string,
PropTypes.array,
PropTypes.object,
]),
disabledTabClassName: PropTypes.string,
domRef: PropTypes.func,
focus: PropTypes.bool,
Expand Down Expand Up @@ -172,8 +176,10 @@ export default class UncontrolledTabs extends Component {
focus: selected && (focus || wasTabFocused),
};

if (selectedTabClassName) props.selectedClassName = selectedTabClassName;
if (disabledTabClassName) props.disabledClassName = disabledTabClassName;
if (selectedTabClassName)
props.selectedClassName = selectedTabClassName;
if (disabledTabClassName)
props.disabledClassName = disabledTabClassName;

listIndex++;

Expand All @@ -188,7 +194,8 @@ export default class UncontrolledTabs extends Component {
};

if (forceRenderTabPanel) props.forceRender = forceRenderTabPanel;
if (selectedTabPanelClassName) props.selectedClassName = selectedTabPanelClassName;
if (selectedTabPanelClassName)
props.selectedClassName = selectedTabPanelClassName;

index++;

Expand Down
6 changes: 5 additions & 1 deletion src/components/__tests__/TabList-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ describe('<TabList />', () => {

it('should display the custom classnames for selected and disabled tab specified on tabs', () => {
expectToMatchSnapshot(
<Tabs defaultIndex={0} selectedTabClassName="active" disabledTabClassName="disabled">
<Tabs
defaultIndex={0}
selectedTabClassName="active"
disabledTabClassName="disabled"
>
<TabList>
<Tab>Foo</Tab>
<Tab disabled>Bar</Tab>
Expand Down
41 changes: 34 additions & 7 deletions src/components/__tests__/Tabs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import TabList from '../TabList';
import TabPanel from '../TabPanel';
import Tabs from '../Tabs';
import { reset as resetIdCounter } from '../../helpers/uuid';
import { TabListWrapper, TabWrapper, TabPanelWrapper } from './helpers/higherOrder';
import {
TabListWrapper,
TabWrapper,
TabPanelWrapper,
} from './helpers/higherOrder';

Enzyme.configure({ adapter: new Adapter() });

Expand Down Expand Up @@ -195,7 +199,11 @@ describe('<Tabs />', () => {
);
console.error = oldConsoleError; // eslint-disable-line no-console

const result = Tabs.propTypes.children(wrapper.props(), 'children', 'Tabs');
const result = Tabs.propTypes.children(
wrapper.props(),
'children',
'Tabs',
);
expect(result).toBeInstanceOf(Error);
});

Expand All @@ -214,7 +222,11 @@ describe('<Tabs />', () => {
);
console.error = oldConsoleError; // eslint-disable-line no-console

const result = Tabs.propTypes.children(wrapper.props(), 'children', 'Tabs');
const result = Tabs.propTypes.children(
wrapper.props(),
'children',
'Tabs',
);
expect(result).toBeInstanceOf(Error);
});

Expand All @@ -235,7 +247,11 @@ describe('<Tabs />', () => {
);
console.error = oldConsoleError; // eslint-disable-line no-console

const result = Tabs.propTypes.children(wrapper.props(), 'children', 'Tabs');
const result = Tabs.propTypes.children(
wrapper.props(),
'children',
'Tabs',
);
expect(result).toBeInstanceOf(Error);
});

Expand Down Expand Up @@ -299,7 +315,11 @@ describe('<Tabs />', () => {
);
console.error = oldConsoleError; // eslint-disable-line no-console

const result = Tabs.propTypes.children(wrapper.props(), 'children', 'Tabs');
const result = Tabs.propTypes.children(
wrapper.props(),
'children',
'Tabs',
);
expect(result).toBeInstanceOf(Error);
});

Expand Down Expand Up @@ -327,7 +347,11 @@ describe('<Tabs />', () => {
</Tabs>,
);

const result = Tabs.propTypes.children(wrapper.props(), 'children', 'Tabs');
const result = Tabs.propTypes.children(
wrapper.props(),
'children',
'Tabs',
);
expect(result instanceof Error).toBe(false);
});

Expand Down Expand Up @@ -484,7 +508,10 @@ describe('<Tabs />', () => {
state = {};
handleSelect = () => this.setState({ foo: 'bar' });
render() {
return createTabs({ onSelect: this.handleSelect, className: this.state.foo });
return createTabs({
onSelect: this.handleSelect,
className: this.state.foo,
});
}
}

Expand Down
12 changes: 10 additions & 2 deletions src/helpers/childrenDeepMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ export function deepMap(children, callback) {
return callback(child);
}

if (child.props && child.props.children && typeof child.props.children === 'object') {
if (
child.props &&
child.props.children &&
typeof child.props.children === 'object'
) {
// Clone the child that has children and map them too
return cloneElement(child, {
...child.props,
Expand All @@ -35,7 +39,11 @@ export function deepForEach(children, callback) {

if (isTab(child) || isTabPanel(child)) {
callback(child);
} else if (child.props && child.props.children && typeof child.props.children === 'object') {
} else if (
child.props &&
child.props.children &&
typeof child.props.children === 'object'
) {
if (isTabList(child)) callback(child);
deepForEach(child.props.children, callback);
}
Expand Down
26 changes: 22 additions & 4 deletions src/helpers/propTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ export function childrenPropType(props, propName, componentName) {

deepForEach(children, child => {
if (isTabList(child)) {
if (child.props && child.props.children && typeof child.props.children === 'object') {
deepForEach(child.props.children, listChild => listTabs.push(listChild));
if (
child.props &&
child.props.children &&
typeof child.props.children === 'object'
) {
deepForEach(child.props.children, listChild =>
listTabs.push(listChild),
);
}

if (tabListFound) {
Expand Down Expand Up @@ -45,7 +51,13 @@ export function childrenPropType(props, propName, componentName) {
return error;
}

export function onSelectPropType(props, propName, componentName, location, propFullName) {
export function onSelectPropType(
props,
propName,
componentName,
location,
propFullName,
) {
const prop = props[propName];
const name = propFullName || propName;
let error = null;
Expand All @@ -69,7 +81,13 @@ export function onSelectPropType(props, propName, componentName, location, propF
return error;
}

export function selectedIndexPropType(props, propName, componentName, location, propFullName) {
export function selectedIndexPropType(
props,
propName,
componentName,
location,
propFullName,
) {
const prop = props[propName];
const name = propFullName || propName;
let error = null;
Expand Down

0 comments on commit 9be02f2

Please sign in to comment.