-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from react-component/feat/swipeableTabBar
feat: add swipeableTabBar for antd-mobile
- Loading branch information
Showing
13 changed files
with
707 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
placeholder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* eslint react/no-multi-comp:0, no-console:0 */ | ||
|
||
import 'rc-tabs/assets/index.less'; | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import Tabs, { TabPane } from 'rc-tabs'; | ||
import TabContent from '../src/SwipeableTabContent'; | ||
import SwipeableInkTabBar from '../src/SwipeableInkTabBar'; | ||
|
||
const contentStyle = { | ||
display: 'flex', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
height: '100px', | ||
backgroundColor: '#fff', | ||
}; | ||
|
||
|
||
const makeTabPane = key => ( | ||
<TabPane tab={`选项${key}`} key={key}> | ||
<div style={contentStyle}> | ||
{`选项${key}内容`} | ||
</div> | ||
</TabPane> | ||
); | ||
|
||
const makeMultiTabPane = (count) => { | ||
const result = []; | ||
for (let i = 0; i < count; i++) { | ||
result.push(makeTabPane(i)); | ||
} | ||
return result; | ||
}; | ||
|
||
const Component = () => ( | ||
<div> | ||
<h1>pageSize = 5, speed = 5</h1> | ||
<div> | ||
<Tabs | ||
renderTabBar={() => | ||
<SwipeableInkTabBar | ||
pageSize={5} | ||
speed={5} | ||
/> | ||
} | ||
renderTabContent={() => <TabContent />} | ||
defaultActiveKey="8" | ||
> | ||
{makeMultiTabPane(11)} | ||
</Tabs> | ||
</div> | ||
<h1>pageSize = 3, speed = 10</h1> | ||
<div> | ||
<Tabs | ||
renderTabBar={() => | ||
<SwipeableInkTabBar | ||
pageSize={3} | ||
speed={10} | ||
/> | ||
} | ||
renderTabContent={() => <TabContent/>} | ||
defaultActiveKey="2" | ||
> | ||
{makeMultiTabPane(7)} | ||
</Tabs> | ||
</div> | ||
<h1>pageSize = 3, speed = 10, tabBarPosition='bottom'</h1> | ||
<div> | ||
<Tabs | ||
tabBarPosition="bottom" | ||
renderTabBar={() => | ||
<SwipeableInkTabBar | ||
pageSize={3} | ||
speed={10} | ||
/> | ||
} | ||
renderTabContent={() => <TabContent/>} | ||
defaultActiveKey="2" | ||
> | ||
{makeMultiTabPane(7)} | ||
</Tabs> | ||
</div> | ||
</div> | ||
); | ||
|
||
ReactDOM.render(<Component />, document.getElementById('__react-content')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import React from 'react'; | ||
import InkTabBarMixin from './InkTabBarMixin'; | ||
import SwipeableTabBarMixin from './SwipeableTabBarMixin'; | ||
import TabBarMixin from './TabBarMixin'; | ||
|
||
const SwipeableInkTabBar = React.createClass({ | ||
mixins: [TabBarMixin, InkTabBarMixin, SwipeableTabBarMixin], | ||
|
||
getSwipeableTabs() { | ||
const props = this.props; | ||
const children = props.panels; | ||
const activeKey = props.activeKey; | ||
const rst = []; | ||
const prefixCls = props.prefixCls; | ||
|
||
const tabStyle = { | ||
display: 'flex', | ||
flex: `0 0 ${1 / props.pageSize * 100}%`, | ||
}; | ||
|
||
React.Children.forEach(children, (child) => { | ||
if (!child) { | ||
return; | ||
} | ||
const key = child.key; | ||
let cls = activeKey === key ? `${prefixCls}-tab-active` : ''; | ||
cls += ` ${prefixCls}-tab`; | ||
let events = {}; | ||
if (child.props.disabled) { | ||
cls += ` ${prefixCls}-tab-disabled`; | ||
} else { | ||
events = { | ||
onClick: this.onTabClick.bind(this, key), | ||
}; | ||
} | ||
const ref = {}; | ||
if (activeKey === key) { | ||
ref.ref = 'activeTab'; | ||
} | ||
rst.push(<div | ||
role="tab" | ||
style={tabStyle} | ||
aria-disabled={child.props.disabled ? 'true' : 'false'} | ||
aria-selected={activeKey === key ? 'true' : 'false'} | ||
{...events} | ||
className={cls} | ||
key={key} | ||
{...ref} | ||
> | ||
{child.props.tab} | ||
</div>); | ||
}); | ||
|
||
return rst; | ||
}, | ||
|
||
render() { | ||
const inkBarNode = this.getInkBarNode(); | ||
const tabs = this.getSwipeableTabs(); | ||
const scrollbarNode = this.getSwipeBarNode([inkBarNode, tabs]); | ||
return this.getRootNode(scrollbarNode); | ||
}, | ||
}); | ||
|
||
export default SwipeableInkTabBar; |
Oops, something went wrong.