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

chore: rm mixin and react-create-class #123

Merged
merged 8 commits into from
Jul 10, 2018
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
46 changes: 45 additions & 1 deletion examples/antd.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import ReactDOM from 'react-dom';
import Tabs, { TabPane } from 'rc-tabs';
import TabContent from 'rc-tabs/lib/TabContent';
import ScrollableInkTabBar from 'rc-tabs/lib/ScrollableInkTabBar';
import ScrollableTabBar from 'rc-tabs/lib/ScrollableTabBar';
import InkTabBar from 'rc-tabs/lib/InkTabBar';
import TabBar from 'rc-tabs/lib/TabBar';

class PanelContent extends React.Component {
constructor(props) {
Expand Down Expand Up @@ -115,7 +117,29 @@ class Demo extends React.Component {

return (
<div style={{ margin: 20 }}>
<h2>Simple Tabs</h2>
<h2>Basic Tabs</h2>
<p>
tabBarPosition:
<select value={this.state.tabBarPosition} onChange={this.changeTabPosition}>
<option value="top">top</option>
<option value="bottom">bottom</option>
<option value="left">left</option>
<option value="right">right</option>
</select>
</p>
<div>
<Tabs
defaultActiveKey="3"
style={style}
tabBarPosition={this.state.tabBarPosition}
renderTabBar={() => <TabBar onTabClick={this.onTabClick}/>}
renderTabContent={() => <TabContent style={contentStyle}/>}
onChange={this.onChange}
>
{ends2}
</Tabs>
</div>
<h2>Basic Tabs With Ink Bar</h2>
<p>
tabBarPosition:
<select value={this.state.tabBarPosition} onChange={this.changeTabPosition}>
Expand All @@ -138,6 +162,26 @@ class Demo extends React.Component {
</Tabs>
</div>
<h2>Scroll Tabs</h2>
<div>
<button onClick={() => this.switchToLast(ends)}>
switch to last tab
</button>
<Tabs
activeKey={this.state.activeKey}
style={style}
tabBarPosition={this.state.tabBarPosition}
renderTabBar={() => <ScrollableTabBar
ref={this.saveBar}
onTabClick={this.onTabClick}
/>}
renderTabContent={() => <TabContent style={contentStyle}/>}
onChange={this.onChange2}
>
{ends}
</Tabs>
</div>
<button onClick={this.tick}>rerender</button>
<h2>Scroll Tabs with inkBar</h2>
<div>
<button onClick={() => this.switchToLast(ends)}>
switch to last tab
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
"dependencies": {
"babel-runtime": "6.x",
"classnames": "2.x",
"create-react-class": "15.x",
"lodash": "^4.17.5",
"prop-types": "15.x",
"rc-hammerjs": "~0.6.0",
Expand Down
39 changes: 26 additions & 13 deletions src/InkTabBar.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
import createReactClass from 'create-react-class';
import InkTabBarMixin from './InkTabBarMixin';
import TabBarMixin from './TabBarMixin';
import RefMixin from './RefMixin';
import React from 'react';
import PropTypes from 'prop-types';
import InkTabBarNode from './InkTabBarNode';
import TabBarTabsNode from './TabBarTabsNode';
import TabBarRootNode from './TabBarRootNode';
import SaveRef from './SaveRef';

const InkTabBar = createReactClass({
displayName: 'InkTabBar',
mixins: [RefMixin, TabBarMixin, InkTabBarMixin],
export default class InkTabBar extends React.Component {
render() {
const inkBarNode = this.getInkBarNode();
const tabs = this.getTabs();
return this.getRootNode([inkBarNode, tabs]);
},
});
return (
<SaveRef>
{(saveRef, getRef) => (
<TabBarRootNode saveRef={saveRef} {...this.props}>
<TabBarTabsNode onTabClick={this.props.onTabClick} saveRef={saveRef} {...this.props} />
<InkTabBarNode saveRef={saveRef} getRef={getRef} {...this.props} />
</TabBarRootNode>
)}
</SaveRef>
);
}
}

export default InkTabBar;
InkTabBar.propTypes = {
onTabClick: PropTypes.func,
};

InkTabBar.defaultProps = {
onTabClick: () => {},
};
51 changes: 30 additions & 21 deletions src/InkTabBarMixin.js → src/InkTabBarNode.js
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { setTransform, isTransformSupported } from './utils';
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { setTransform, isTransformSupported } from './utils';

const isDev = process.env.NODE_ENV !== 'production';

Expand Down Expand Up @@ -41,11 +42,11 @@ function offset(elem) {

function componentDidUpdate(component, init) {
const { styles } = component.props;
const rootNode = component.root;
const wrapNode = component.nav || rootNode;
const rootNode = component.props.getRef('root');
const wrapNode = component.props.getRef('nav') || rootNode;
const containerOffset = offset(wrapNode);
const inkBarNode = component.inkBar;
const activeTab = component.activeTab;
const inkBarNode = component.props.getRef('inkBar');
const activeTab = component.props.getRef('activeTab');
const inkBarNodeStyle = inkBarNode.style;
const tabBarPosition = component.props.tabBarPosition;
if (init) {
Expand Down Expand Up @@ -106,17 +107,7 @@ function componentDidUpdate(component, init) {
inkBarNodeStyle.display = activeTab ? 'block' : 'none';
}

export default {
getDefaultProps() {
return {
inkBarAnimated: true,
};
},

componentDidUpdate() {
componentDidUpdate(this);
},

export default class InkTabBarNode extends React.Component {
componentDidMount() {
if (isDev) {
// https://github.com/ant-design/ant-design/issues/8678
Expand All @@ -126,13 +117,17 @@ export default {
} else {
componentDidUpdate(this, true);
}
},
}

componentDidUpdate() {
componentDidUpdate(this);
}

componentWillUnmount() {
clearTimeout(this.timeout);
},
}

getInkBarNode() {
render() {
const { prefixCls, styles, inkBarAnimated } = this.props;
const className = `${prefixCls}-ink-bar`;
const classes = classnames({
Expand All @@ -148,8 +143,22 @@ export default {
style={styles.inkBar}
className={classes}
key="inkBar"
ref={this.saveRef('inkBar')}
ref={this.props.saveRef('inkBar')}
/>
);
},
}
}

InkTabBarNode.propTypes = {
prefixCls: PropTypes.string,
styles: PropTypes.object,
inkBarAnimated: PropTypes.bool,
saveRef: PropTypes.func,
};

InkTabBarNode.defaultProps = {
prefixCls: '',
inkBarAnimated: true,
styles: {},
saveRef: () => {},
};
7 changes: 0 additions & 7 deletions src/RefMixin.js

This file was deleted.

28 changes: 28 additions & 0 deletions src/SaveRef.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import PropTypes from 'prop-types';

export default class SaveRef extends React.Component {
getRef = (name) => {
return this[name];
}

saveRef = (name) => {
return (node) => {
if (node) {
this[name] = node;
}
};
}

render() {
return this.props.children(this.saveRef, this.getRef);
}
}

SaveRef.propTypes = {
children: PropTypes.func,
};

SaveRef.defaultProps = {
children: () => null,
};
37 changes: 21 additions & 16 deletions src/ScrollableInkTabBar.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import createReactClass from 'create-react-class';
import InkTabBarMixin from './InkTabBarMixin';
import ScrollableTabBarMixin from './ScrollableTabBarMixin';
import TabBarMixin from './TabBarMixin';
import RefMixin from './RefMixin';
import React from 'react';
import InkTabBarNode from './InkTabBarNode';
import TabBarTabsNode from './TabBarTabsNode';
import TabBarRootNode from './TabBarRootNode';
import ScrollableTabBarNode from './ScrollableTabBarNode';
import SaveRef from './SaveRef';

const ScrollableInkTabBar = createReactClass({
displayName: 'ScrollableInkTabBar',
mixins: [RefMixin, TabBarMixin, InkTabBarMixin, ScrollableTabBarMixin],
export default class ScrollableInkTabBar extends React.Component {
render() {
const inkBarNode = this.getInkBarNode();
const tabs = this.getTabs();
const scrollbarNode = this.getScrollBarNode([inkBarNode, tabs]);
return this.getRootNode(scrollbarNode);
},
});

export default ScrollableInkTabBar;
return (
<SaveRef>
{(saveRef, getRef) => (
<TabBarRootNode saveRef={saveRef} {...this.props}>
<ScrollableTabBarNode saveRef={saveRef} getRef={getRef} {...this.props}>
<TabBarTabsNode saveRef={saveRef} {...this.props} />
<InkTabBarNode saveRef={saveRef} getRef={getRef} {...this.props} />
</ScrollableTabBarNode>
</TabBarRootNode>
)}
</SaveRef>
);
}
}
34 changes: 19 additions & 15 deletions src/ScrollableTabBar.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import createReactClass from 'create-react-class';
import ScrollableTabBarMixin from './ScrollableTabBarMixin';
import TabBarMixin from './TabBarMixin';
import RefMixin from './RefMixin';
import React from 'react';
import ScrollableTabBarNode from './ScrollableTabBarNode';
import TabBarRootNode from './TabBarRootNode';
import TabBarTabsNode from './TabBarTabsNode';
import SaveRef from './SaveRef';

const ScrollableTabBar = createReactClass({
displayName: 'ScrollableTabBar',
mixins: [RefMixin, TabBarMixin, ScrollableTabBarMixin],
export default class ScrollableTabBar extends React.Component {
render() {
const inkBarNode = this.getInkBarNode();
const tabs = this.getTabs();
const scrollbarNode = this.getScrollBarNode([inkBarNode, tabs]);
return this.getRootNode(scrollbarNode);
},
});

export default ScrollableTabBar;
return (
<SaveRef>
{(saveRef, getRef) => (
<TabBarRootNode saveRef={saveRef} {...this.props}>
<ScrollableTabBarNode saveRef={saveRef} getRef={getRef} {...this.props}>
<TabBarTabsNode saveRef={saveRef} {...this.props} />
</ScrollableTabBarNode>
</TabBarRootNode>
)}
</SaveRef>
);
}
}
Loading