Button 按钮

点击后会触发一个操作。

代码演示

类型、尺寸

button

  1. import { Button, WhiteSpace, WingBlank } from 'antd-mobile';
  2. const ButtonExample = () => (
  3. <WingBlank>
  4. <Button>default</Button><WhiteSpace />
  5. <Button disabled>default disabled</Button><WhiteSpace />
  6. <Button type="primary">primary</Button><WhiteSpace />
  7. <Button type="primary" disabled>primary disabled</Button><WhiteSpace />
  8. <Button type="warning">warning</Button><WhiteSpace />
  9. <Button type="warning" disabled>warning disabled</Button><WhiteSpace />
  10. <Button loading>loading button</Button><WhiteSpace />
  11. <Button icon="check-circle-o">with icon</Button><WhiteSpace />
  12. <Button icon={<img src="https://gw.alipayobjects.com/zos/rmsportal/jBfVSpDwPbitsABtDDlB.svg" alt="" />}>with custom icon</Button><WhiteSpace />
  13. <Button icon="check-circle-o" inline size="small" style={{ marginRight: '4px' }}>with icon and inline</Button>
  14. <Button icon="check-circle-o" inline size="small">with icon and inline</Button>
  15. <WhiteSpace />
  16. {/* <Button activeStyle={false}>无点击反馈</Button><WhiteSpace /> */}
  17. {/* <Button activeStyle={{ backgroundColor: 'red' }}>custom feedback style</Button><WhiteSpace /> */}
  18. <WhiteSpace />
  19. <Button type="primary" inline style={{ marginRight: '4px' }}>inline primary</Button>
  20. {/* use `am-button-borderfix`. because Multiple buttons inline arranged, the last one border-right may not display */}
  21. <Button type="ghost" inline style={{ marginRight: '4px' }} className="am-button-borderfix">inline ghost</Button>
  22. <WhiteSpace />
  23. <Button type="primary" inline size="small" style={{ marginRight: '4px' }}>primary</Button>
  24. <Button type="primary" inline size="small" disabled>primary disabled</Button>
  25. <WhiteSpace />
  26. <Button type="ghost" inline size="small" style={{ marginRight: '4px' }}>ghost</Button>
  27. {/* use `am-button-borderfix`. because Multiple buttons inline arranged, the last one border-right may not display */}
  28. <Button type="ghost" inline size="small" className="am-button-borderfix" disabled>ghost disabled</Button>
  29. </WingBlank>
  30. );
  31. ReactDOM.render(<ButtonExample />, mountNode);

应用场景示例

examples with List / Flex

  1. import { Button, List } from 'antd-mobile';
  2. const ComplexButtonDemo = () => (
  3. <List style={{ margin: '5px 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

属性说明类型默认值
type按钮类型,可选值为primary/ghost/warning或者不设string-
size按钮大小,可选值为largesmallstringlarge
activeStyle点击反馈的自定义样式 (设为 false 时表示禁止点击反馈){}/false{}
activeClassName点击反馈的自定义类名string
disabled设置禁用booleanfalse
onClick点击按钮的点击回调函数(e: Object): void
style自定义样式Object
inline是否设置为行内按钮booleanfalse
loading设置按钮载入状态booleanfalse
icon可以是 Icon 组件里内置的某个 icon 的 type 值,也可以是任意合法的 ReactElement (注意: loading设置后此项设置失效)string/React.Element-
prefixClsclass前缀stringam-button
className样式类名string