点击后会触发一个操作。
代码演示
类型、尺寸
button
import { Button, Flex, WingBlank } from 'antd-mobile';
/* eslint global-require: 0 */
const ButtonExample = () => (
<WingBlank>
<div className="btn-container">
<div>
<Button className="btn" type="primary">primary button</Button>
<Button className="btn" disabled onClick={e => console.log(e)}>
disabled button
</Button>
<Button className="btn" loading>loading button</Button>
<Button className="btn" icon="check-circle-o">with icon</Button>
<Button className="btn" icon={require('./reload.svg')}>
with local icon
</Button>
<div style={{ height: '0.16rem' }} />
{/* <Button className="btn" activeStyle={false}>无点击反馈</Button> */}
{/* <Button className="btn" activeStyle={{ backgroundColor: 'red' }}>自定义点击反馈 style</Button> */}
<p style={{ margin: '30px 0 18px 0', color: '#999' }}>inline / small</p>
<Flex style={{ marginBottom: '0.16rem' }}>
<Button type="primary" inline style={{ marginRight: '0.08rem' }}>inline</Button>
<Button type="ghost" inline size="small" style={{ marginRight: '0.08rem' }}>inline small</Button>
<Button type="primary" inline size="small">inline small</Button>
</Flex>
</div>
</div>
</WingBlank>
);
ReactDOM.render(<ButtonExample />, mountNode);
.btn-container .btn {
margin: 0.16rem 0;
}
应用场景示例
examples with List / Flex
import { Button, List } from 'antd-mobile';
const ComplexButtonDemo = () => (
<List style={{ margin: '0.1rem 0', backgroundColor: 'white' }}>
<List.Item
extra={<Button type="ghost" size="small" inline>small</Button>}
multipleLine
>
regional manager
<List.Item.Brief>
Can be collected, refund, discount management, view data and other operations
</List.Item.Brief>
</List.Item>
<List.Item
extra={<Button type="primary" size="small" inline>small</Button>}
multipleLine
>
regional manager
<List.Item.Brief>
Can be collected, refund, discount management, view data and other operations
</List.Item.Brief>
</List.Item>
</List>
);
ReactDOM.render(<ComplexButtonDemo />, mountNode);
API
适用平台:WEB、React-Native
属性 | 说明 | 类型 | 默认值 |
---|
type | 按钮类型,可选值为primary /ghost /warning 或者不设 | string | - |
size | 按钮大小,可选值为large 、small | string | large |
activeStyle | 点击反馈的自定义样式 (设为 false 时表示禁止点击反馈) | {}/false | {} |
activeClassName | 点击反馈的自定义类名 | string | |
disabled | 设置禁用 | boolean | false |
onClick | 点击按钮的点击回调函数 | (e: Object): void | 无 |
style | 自定义样式 | Object | 无 |
inline (WEB only ) | 是否设置为行内按钮 | boolean | false |
across (WEB only ) | 是否设置为通栏展示 | boolean | false |
loading (WEB only ) | 设置按钮载入状态 | boolean | false |
icon (WEB only ) | 可以是 Icon 组件里内置的某个 icon 的 type 值,也可以是 require 本地 svg 图标 (注意: loading 设置后此项设置失效) | string /require(./local.svg) | - |
prefixCls (WEB only ) | class前缀 | string | am-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 | 无 |