TabBar

页面底部工具栏组件。

组件

TabBar

<TabBar> 组件,工具栏容器。

Props

component
PropType: node

工具栏容器元素,默认为 nav

amStyle
PropType: string

工具栏颜色样式,可选值:

  • 'primary'
  • 'secondary'
  • 'success'
  • 'warning'
  • 'alert'
  • 'dark'
onAction
PropType: func

点击工具栏子项时的处理函数。

TabBar.Item

<TabBar.Item> 组件,工具栏子项。

Props

component
PropType: node

工具栏容器元素,默认为 span

icon
PropType: string

图标名称,可选值参见 Icon 文档。

title
PropType: string

子项标题。

href
PropType: string

子项链接,设置 href 属性以后,子项会渲染为 <a> 元素。

eventKey
PropType: any

事件处理标识符。

badge
PropType: string, number

子项小徽章上显示的文字。

注意:目前只有设置了 icon, 再设置 badge 才有效。

badgeStyle
PropType: string

小徽章颜色样式,默认为 alert

selected
PropType: bool

子项是否被选中。

示例

  1. import React from 'react';
  2. import {
  3. Container,
  4. Group,
  5. TabBar,
  6. Icon,
  7. Badge,
  8. amStyles,
  9. } from 'amazeui-touch';
  10. const TabBarDemo = React.createClass({
  11. getInitialState() {
  12. return {
  13. selected: 'home'
  14. };
  15. },
  16. handleClick(key, e) {
  17. e.preventDefault();
  18. this.setState({
  19. selected: key
  20. }, function() {
  21. console.log('选中了: %s', this.state.selected);
  22. });
  23. },
  24. render() {
  25. return (
  26. <TabBar
  27. amStyle="primary"
  28. onAction={this.handleClick}
  29. >
  30. <TabBar.Item
  31. eventKey="home"
  32. selected={this.state.selected === 'home'}
  33. icon="home"
  34. title="首页"
  35. />
  36. <TabBar.Item
  37. selected={this.state.selected === 'gear'}
  38. eventKey="gear"
  39. icon="gear"
  40. title="设置"
  41. />
  42. <TabBar.Item
  43. selected={this.state.selected === 'info'}
  44. eventKey="info"
  45. icon="info"
  46. badge={5}
  47. title="信息"
  48. />
  49. </TabBar>
  50. )
  51. }
  52. });
  53. const TabBarExample = React.createClass({
  54. renderStyles(amStyle, index) {
  55. return (
  56. <Group
  57. header={amStyle}
  58. noPadded
  59. key={index}
  60. >
  61. <TabBar amStyle={amStyle.toLowerCase()}>
  62. <TabBar.Item selected icon="home" title="首页" />
  63. <TabBar.Item icon="gear" title="设置" />
  64. <TabBar.Item icon="info" badge={5} title="信息" />
  65. </TabBar>
  66. </Group>
  67. )
  68. },
  69. render() {
  70. return (
  71. <Container {...this.props}>
  72. <Group
  73. header="文字"
  74. noPadded
  75. >
  76. <TabBar>
  77. <TabBar.Item selected title="首页" />
  78. <TabBar.Item title="设置" />
  79. <TabBar.Item title="关于" />
  80. </TabBar>
  81. </Group>
  82. <Group
  83. header="图标"
  84. noPadded
  85. >
  86. <TabBar>
  87. <TabBar.Item selected icon="home" />
  88. <TabBar.Item icon="gear" />
  89. <TabBar.Item icon="info" />
  90. </TabBar>
  91. </Group>
  92. <Group
  93. header="图标 + Badge"
  94. noPadded
  95. >
  96. <TabBar>
  97. <TabBar.Item selected icon="home" />
  98. <TabBar.Item icon="gear" />
  99. <TabBar.Item icon="info" badge={5} />
  100. </TabBar>
  101. </Group>
  102. <Group
  103. header="图标 + 文字"
  104. noPadded
  105. >
  106. <TabBar>
  107. <TabBar.Item selected icon="home" title="首页" />
  108. <TabBar.Item icon="gear" title="设置" />
  109. <TabBar.Item icon="info" badge={5} title="信息" />
  110. </TabBar>
  111. </Group>
  112. {amStyles.map(this.renderStyles)}
  113. <Group
  114. header="交互"
  115. noPadded
  116. >
  117. <TabBarDemo />
  118. </Group>
  119. </Container>
  120. );
  121. }
  122. });
  123. // test
  124. export default TabBarExample;

DemoCopy

Version: 1.0.0

原文: http://t.amazeui.org/#/docs/tabbar