Button 按钮

点击后会触发一个操作。

代码演示

类型、尺寸

button

  1. import { Button, Flex, WingBlank } from 'antd-mobile';
  2. /* eslint global-require: 0 */
  3. const ButtonExample = () => (
  4. <WingBlank>
  5. <div className="btn-container">
  6. <div>
  7. <Button className="btn" type="primary">primary button</Button>
  8. <Button className="btn" disabled onClick={e => console.log(e)}>
  9. disabled button
  10. </Button>
  11. <Button className="btn" loading>loading button</Button>
  12. <Button className="btn" icon="check-circle-o">with icon</Button>
  13. <Button className="btn" icon={require('./reload.svg')}>
  14. with local icon
  15. </Button>
  16. <div style={{ height: '0.16rem' }} />
  17. {/* <Button className="btn" activeStyle={false}>无点击反馈</Button> */}
  18. {/* <Button className="btn" activeStyle={{ backgroundColor: 'red' }}>自定义点击反馈 style</Button> */}
  19. <p style={{ margin: '30px 0 18px 0', color: '#999' }}>inline / small</p>
  20. <Flex style={{ marginBottom: '0.16rem' }}>
  21. <Button type="primary" inline style={{ marginRight: '0.08rem' }}>inline</Button>
  22. <Button type="ghost" inline size="small" style={{ marginRight: '0.08rem' }}>inline small</Button>
  23. <Button type="primary" inline size="small">inline small</Button>
  24. </Flex>
  25. </div>
  26. </div>
  27. </WingBlank>
  28. );
  29. ReactDOM.render(<ButtonExample />, mountNode);
  1. .btn-container .btn {
  2. margin: 0.16rem 0;
  3. }

应用场景示例

examples with List / Flex

  1. import { Button, List } from 'antd-mobile';
  2. const ComplexButtonDemo = () => (
  3. <List style={{ margin: '0.1rem 0', backgroundColor: 'white' }}>
  4. <List.Item
  5. extra={<Button type="ghost" size="small" inline>small</Button>}
  6. multipleLine
  7. >
  8. regional manager
  9. <List.Item.Brief>
  10. Can be collected, refund, discount management, view data and other operations
  11. </List.Item.Brief>
  12. </List.Item>
  13. <List.Item
  14. extra={<Button type="primary" size="small" inline>small</Button>}
  15. multipleLine
  16. >
  17. regional manager
  18. <List.Item.Brief>
  19. Can be collected, refund, discount management, view data and other operations
  20. </List.Item.Brief>
  21. </List.Item>
  22. </List>
  23. );
  24. ReactDOM.render(<ComplexButtonDemo />, mountNode);

Button按钮 - 图1

API

适用平台:WEB、React-Native
属性说明类型默认值
type按钮类型,可选值为primary/ghost/warning或者不设string-
size按钮大小,可选值为largesmallstringlarge
activeStyle点击反馈的自定义样式 (设为 false 时表示禁止点击反馈){}/false{}
activeClassName点击反馈的自定义类名string
disabled设置禁用booleanfalse
onClick点击按钮的点击回调函数(e: Object): void
style自定义样式Object
inline (WEB only)是否设置为行内按钮booleanfalse
across (WEB only)是否设置为通栏展示booleanfalse
loading (WEB only)设置按钮载入状态booleanfalse
icon (WEB only)可以是 Icon 组件里内置的某个 icon 的 type 值,也可以是 require 本地 svg 图标 (注意: loading设置后此项设置失效)string/require(./local.svg)-
prefixCls (WEB only)class前缀stringam-button
className (WEB only)样式类名string
onPressIn (RN only)同 RN TouchableHighlight onPressIn(e: Object): void
onPressOut (RN only)同 RN TouchableHighlight onPressOut(e: Object): void
onShowUnderlay (RN only)同 RN TouchableHighlight onShowUnderlay(e: Object): void
onHideUnderlay (RN only)同 RN TouchableHighlight onHideUnderlay(e: Object): void