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

Use prettier #169

Merged
merged 2 commits into from
Apr 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"node": true
},
"rules": {
"arrow-parens": "off",
"no-plusplus": "off",
"react/require-default-props": "off",
"react/jsx-filename-extension": ["error", { "extensions": [".js"] }],
Expand Down
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"build:umd:min": "cross-env MINIFY=1 webpack --config webpack.build.js",
"build": "npm run clean && npm run build:commonjs",
"bundle": "mkdir -p dist && npm run build:umd && npm run build:umd:min",
"format": "prettier --write --single-quote --print-width 100 --trailing-comma all \"src/**/*.js\"",
"lint": "eslint src",
"precommit": "lint-staged",
"preversion": "npm run lint && npm test && npm run build && npm run bundle && git add dist/ && git commit -m 'publish: Distribution'",
"prepublish": "npm run build",
"test": "jest",
Expand Down Expand Up @@ -59,7 +61,10 @@
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^4.0.0",
"eslint-plugin-react": "^6.2.1",
"husky": "^0.13.3",
"jest-cli": "^19.0.2",
"lint-staged": "^3.4.0",
"prettier": "^1.2.2",
"react": "^15.0.0",
"react-addons-test-utils": "^15.0.0",
"react-dom": "^15.0.0",
Expand All @@ -79,5 +84,11 @@
"roots": [
"src"
]
},
"lint-staged": {
"src/**/*.js": [
"prettier --single-quote --print-width 100 --trailing-comma all --write",
"git add"
]
}
}
26 changes: 11 additions & 15 deletions src/components/Tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React, { Component } from 'react';
import cx from 'classnames';

export default class Tab extends Component {

static defaultProps = {
className: 'ReactTabs__Tab',
disabledClassName: 'ReactTabs__Tab--disabled',
Expand All @@ -15,11 +14,7 @@ export default class Tab extends Component {
};

static propTypes = {
children: PropTypes.oneOfType([
PropTypes.array,
PropTypes.object,
PropTypes.string,
]),
children: PropTypes.oneOfType([PropTypes.array, PropTypes.object, PropTypes.string]),
className: PropTypes.oneOfType([PropTypes.string, PropTypes.array, PropTypes.object]),
disabled: PropTypes.bool,
disabledClassName: PropTypes.string, // private
Expand Down Expand Up @@ -57,19 +52,20 @@ export default class Tab extends Component {
selected,
selectedClassName,
tabRef,
...attributes } = this.props;
...attributes
} = this.props;

return (
<li
{...attributes}
className={cx(
className,
{
[selectedClassName]: selected,
[disabledClassName]: disabled,
},
)}
ref={(node) => { this.node = node; if (tabRef) tabRef(node); }}
className={cx(className, {
[selectedClassName]: selected,
[disabledClassName]: disabled,
})}
ref={node => {
this.node = node;
if (tabRef) tabRef(node);
}}
role="tab"
id={id}
aria-selected={selected ? 'true' : 'false'}
Expand Down
17 changes: 3 additions & 14 deletions src/components/TabList.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,20 @@ import React, { Component } from 'react';
import cx from 'classnames';

export default class TabList extends Component {

static defaultProps = {
className: 'ReactTabs__TabList',
};

static propTypes = {
children: PropTypes.oneOfType([
PropTypes.object,
PropTypes.array,
]),
children: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
className: PropTypes.oneOfType([PropTypes.string, PropTypes.array, PropTypes.object]),
};

render() {
const {
children,
className,
...attributes } = this.props;
const { children, className, ...attributes } = this.props;

return (
<ul
{...attributes}
className={cx(className)}
role="tablist"
>
<ul {...attributes} className={cx(className)} role="tablist">
{children}
</ul>
);
Expand Down
15 changes: 6 additions & 9 deletions src/components/TabPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React, { Component } from 'react';
import cx from 'classnames';

export default class TabPanel extends Component {

static defaultProps = {
className: 'ReactTabs__TabPanel',
forceRender: false,
Expand Down Expand Up @@ -32,22 +31,20 @@ export default class TabPanel extends Component {
selectedClassName,
style,
tabId,
...attributes } = this.props;
...attributes
} = this.props;

return (
<div
{...attributes}
className={cx(
className,
{
[selectedClassName]: selected,
},
)}
className={cx(className, {
[selectedClassName]: selected,
})}
role="tabpanel"
id={id}
aria-labelledby={tabId}
>
{(forceRender || selected) ? children : null}
{forceRender || selected ? children : null}
</div>
);
}
Expand Down
7 changes: 3 additions & 4 deletions src/components/Tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import UncontrolledTabs from './UncontrolledTabs';
import { getTabsCount } from '../helpers/count';

export default class Tabs extends Component {

static defaultProps = {
defaultFocus: false,
forceRenderTabPanel: false,
Expand Down Expand Up @@ -38,9 +37,9 @@ export default class Tabs extends Component {
Tabs.inUncontrolledMode(newProps) !== Tabs.inUncontrolledMode(this.props)
) {
throw new Error(
`Switching between controlled mode (by using \`selectedIndex\`) and uncontrolled mode is not supported in \`Tabs\`.
`Switching between controlled mode (by using \`selectedIndex\`) and uncontrolled mode is not supported in \`Tabs\`.
For more information about controlled and uncontrolled mode of react-tabs see the README.`,
);
);
}
// Use a transactional update to prevent race conditions
// when reading the state in copyPropsToState
Expand Down Expand Up @@ -70,7 +69,7 @@ For more information about controlled and uncontrolled mode of react-tabs see th
}

this.setState(state);
}
};

// preserve the existing selectedIndex from state.
// If the state has not selectedIndex, default to the defaultIndex or 0
Expand Down
43 changes: 24 additions & 19 deletions src/components/UncontrolledTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ function isTabDisabled(node) {
}

export default class UncontrolledTabs extends Component {

static defaultProps = {
className: 'ReactTabs',
focus: false,
Expand Down Expand Up @@ -129,7 +128,7 @@ export default class UncontrolledTabs extends Component {
}

// Map children to dynamically setup refs
return React.Children.map(children, (child) => {
return React.Children.map(children, child => {
// null happens when conditionally rendering TabPanel/Tab
// see https://github.com/reactjs/react-tabs/issues/37
if (child === null) {
Expand All @@ -144,12 +143,13 @@ export default class UncontrolledTabs extends Component {

// Figure out if the current focus in the DOM is set on a Tab
// If it is we should keep the focus on the next selected tab
const wasTabFocused = React.Children.toArray(child.props.children)
const wasTabFocused = React.Children
.toArray(child.props.children)
.filter(tab => tab.type === Tab)
.some((tab, i) => document.activeElement === this.getTab(i));

result = cloneElement(child, {
children: React.Children.map(child.props.children, (tab) => {
children: React.Children.map(child.props.children, tab => {
// null happens when conditionally rendering TabPanel/Tab
// see https://github.com/reactjs/react-tabs/issues/37
if (tab === null) {
Expand All @@ -164,7 +164,9 @@ export default class UncontrolledTabs extends Component {
const selected = selectedIndex === listIndex;

const props = {
tabRef: (node) => { this.tabNodes[key] = node; },
tabRef: node => {
this.tabNodes[key] = node;
},
id: this.tabIds[listIndex],
panelId: this.panelIds[listIndex],
selected,
Expand Down Expand Up @@ -198,7 +200,7 @@ export default class UncontrolledTabs extends Component {
});
}

handleKeyDown = (e) => {
handleKeyDown = e => {
if (this.isTabFromContainer(e.target)) {
let index = this.props.selectedIndex;
let preventDefault = false;
Expand All @@ -222,9 +224,10 @@ export default class UncontrolledTabs extends Component {
}
};

handleClick = (e) => {
handleClick = e => {
let node = e.target;
do { // eslint-disable-line no-cond-assign
// eslint-disable-next-line no-cond-assign
do {
if (this.isTabFromContainer(node)) {
if (isTabDisabled(node)) {
return;
Expand Down Expand Up @@ -263,16 +266,16 @@ export default class UncontrolledTabs extends Component {
render() {
// Delete all known props, so they don't get added to DOM
const {
children,
className,
disabledTabClassName,
focus,
forceRenderTabPanel,
onSelect,
selectedIndex,
selectedTabClassName,
selectedTabPanelClassName,
...attributes
children,
className,
disabledTabClassName,
focus,
forceRenderTabPanel,
onSelect,
selectedIndex,
selectedTabClassName,
selectedTabPanelClassName,
...attributes
} = this.props;

return (
Expand All @@ -281,7 +284,9 @@ export default class UncontrolledTabs extends Component {
className={cx(className)}
onClick={this.handleClick}
onKeyDown={this.handleKeyDown}
ref={(node) => { this.node = node; }}
ref={node => {
this.node = node;
}}
data-tabs
>
{this.getChildren()}
Expand Down
2 changes: 1 addition & 1 deletion src/components/__tests__/Tab-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Tab from '../Tab';
describe('<Tab />', () => {
beforeAll(() => {
// eslint-disable-next-line no-console
console.error = (error) => {
console.error = error => {
throw new Error(error);
};
});
Expand Down
6 changes: 4 additions & 2 deletions src/components/__tests__/TabList-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function hasClassAt(wrapper, index, className) {
describe('<TabList />', () => {
beforeAll(() => {
// eslint-disable-next-line no-console
console.error = (error) => {
console.error = error => {
throw new Error(error);
};
});
Expand Down Expand Up @@ -87,7 +87,9 @@ describe('<TabList />', () => {
<Tabs defaultIndex={0}>
<TabList>
<Tab selectedClassName="active" disabledClassName="disabled">Foo</Tab>
<Tab disabled selectedClassName="active" disabledClassName="disabled">Bar</Tab>
<Tab disabled selectedClassName="active" disabledClassName="disabled">
Bar
</Tab>
</TabList>
<TabPanel>Foo</TabPanel>
<TabPanel>Bar</TabPanel>
Expand Down
9 changes: 6 additions & 3 deletions src/components/__tests__/TabPanel-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import TabPanel from '../TabPanel';
describe('<TabPanel />', () => {
beforeAll(() => {
// eslint-disable-next-line no-console
console.error = (error) => {
console.error = error => {
throw new Error(error);
};
});
Expand Down Expand Up @@ -49,7 +49,11 @@ describe('<TabPanel />', () => {
});

it('should support being selected with custom class name', () => {
const wrapper = shallow(<TabPanel selected id="abcd" tabId="1234" selectedClassName="selected">Hola</TabPanel>);
const wrapper = shallow(
<TabPanel selected id="abcd" tabId="1234" selectedClassName="selected">
Hola
</TabPanel>,
);

expect(wrapper.hasClass('ReactTabs__TabPanel')).toBe(true);
expect(wrapper.hasClass('ReactTabs__TabPanel--selected')).toBe(false);
Expand All @@ -72,4 +76,3 @@ describe('<TabPanel />', () => {
expect(wrapper.prop('role')).toBe('tabpanel');
});
});

Loading