Button 按钮
定义/Definition
按钮用于标记一个(或封装一组)操作命令,触发相应的业务逻辑命令。规则 / Rule
在移动端中,同个页面只有一个主按钮;
当页面中有两个及以上按钮时,需要区分主次关系,将主按钮放置于次按钮的右侧;
按钮内容为两个字的时候,中间加空格;
当按钮有组合出现,以文字的居中对齐
代码演示
主按钮和次按钮可独立使用,需要强引导用主按钮。 在有多个操作同时出现时,需要区分主次优先级,主按钮在同一个操作区域建议最多出现一次。
当操作并不需要太过强调/明显时,可以启动幽灵变量。 该变量是在原有按钮类型上的变形,主次等级遵循原有按钮的规则。
// 此处用作demo展示,不要用在生产环境this.customNavFlag = true;import { Button, NavBar } from 'antd-mobile';const ButtonExample = React.createClass({getInitialState() {return {dark: false,};},switchDark() {this.setState({ dark: !this.state.dark });},render() {return (<div className="button-container"style={{ backgroundColor: this.state.dark ? 'black' : 'white', height: '100%' }}><NavBar iconName={false} rightContent={(<spanstyle={{ cursor: 'pointer' }}onClick={this.switchDark}>{this.state.dark ? '白天' : '夜间'}</span>)}>类型/type</NavBar><div style={{ margin: '0 8px' }}><div style={{ margin: '32px 0' }}><p className="demo-p">type="primary" - 用于主要操作或必须点击才能完成流程的操作</p><div style={{ height: 8 }} /><Button type="primary" onClick={e => console.log(e)}>primary按钮</Button></div><div style={{ margin: '32px 0' }}><p className="demo-p">默认type - 用于较轻或不希望引导用户使用的操作</p><div style={{ height: 8 }} /><Button>default 按钮</Button></div><div style={{ margin: '32px 0' }}><p className="demo-p">提醒按钮</p><div style={{ height: 8 }} /><Button type="warning">warning 按钮</Button></div><div style={{ margin: '32px 0' }}><p className="demo-p">添加 loading 属性即可让按钮处于加载状态</p><div style={{ height: 8 }} /><Button loading>loading 按钮</Button></div></div></div>);},});ReactDOM.render(<ButtonExample />, mountNode);
添加 disabled 属性即可让按钮处于不可用状态,同时按钮样式也会改变。
// 此处用作demo展示,不要用在生产环境this.customNavFlag = true;import { Button, NavBar } from 'antd-mobile';const ButtonExample = React.createClass({getInitialState() {return {dark: false,};},switchDark() {this.setState({ dark: !this.state.dark });},render() {return (<div className="button-container"style={{ backgroundColor: this.state.dark ? 'black' : 'white', height: '100%' }}><NavBar iconName={false} rightContent={<spanstyle={{ cursor: 'pointer' }}onClick={this.switchDark}>{this.state.dark ? '白天' : '夜间'}</span>}>幽灵模式/ghost</NavBar><div style={{ margin: '0 8px' }}><div style={{ margin: '32px 0' }}><p className="demo-p">主按钮的幽灵模式,用于较轻量级或希望引导用户使用的操作</p><div style={{ height: 8 }} /><Button type="primary" ghost>primary ghost 按钮</Button></div><div style={{ margin: '32px 0' }}><p className="demo-p">次按钮的幽灵模式,用于较轻量级或不希望引导用户使用的操作</p><div style={{ height: 8 }} /><Button ghost>default ghost 按钮</Button></div></div></div>);},});ReactDOM.render(<ButtonExample />, mountNode);
支持大小两种尺寸。 支持是否是行内按钮。
// 此处用作demo展示,不要用在生产环境this.customNavFlag = true;import { Button, NavBar } from 'antd-mobile';const ButtonExample = React.createClass({getInitialState() {return {dark: false,};},switchDark() {this.setState({ dark: !this.state.dark });},render() {return (<div className="button-container"style={{ backgroundColor: this.state.dark ? 'black' : 'white', height: '100%' }}><NavBar iconName={false} rightContent={<spanstyle={{ cursor: 'pointer' }}onClick={this.switchDark}>{this.state.dark ? '白天' : '夜间'}</span>}>失效状态</NavBar><div style={{ margin: '0 8px' }}><div style={{ margin: '32px 0' }}><p className="demo-p">主按钮失效</p><div style={{ height: 8 }} /><Button type="primary" disabled>primary 按钮</Button><div style={{ height: 8 }} /><Button type="primary" ghost disabled>primary ghost 按钮</Button></div><div style={{ margin: '32px 0' }}><p className="demo-p">次按钮失效</p><div style={{ height: 8 }} /><Button disabled>default disabled 按钮</Button><div style={{ height: 8 }} /><Button ghost disabled>default ghost disabled 按钮</Button></div></div></div>);},});ReactDOM.render(<ButtonExample />, mountNode);
和 List / Flex 结合使用示例
// 此处用作demo展示,不要用在生产环境this.customNavFlag = true;import { Button, NavBar } from 'antd-mobile';const ButtonExample = React.createClass({getInitialState() {return {dark: false,};},switchDark() {this.setState({ dark: !this.state.dark });},render() {return (<div className="button-container"style={{ backgroundColor: this.state.dark ? 'black' : 'white', height: '100%' }}><NavBar iconName={false} rightContent={<spanstyle={{ cursor: 'pointer' }}onClick={this.switchDark}>{this.state.dark ? '白天' : '夜间'}</span>}>尺寸/行内</NavBar><div style={{ margin: '0 8px' }}><div style={{ margin: '32px 0' }}><p className="demo-p">主按钮</p><div style={{ height: 8 }} /><Button type="primary">primary 按钮</Button><div style={{ height: 8 }} /><Button type="primary" inline>inline</Button> <Button type="primary" size="small" inline>inline</Button></div><div style={{ margin: '32px 0' }}><p className="demo-p">次按钮</p><div style={{ height: 8 }} /><Button>default 按钮</Button><div style={{ height: 8 }} /><Button inline>inline</Button> <Button size="small" inline>inline</Button></div></div></div>);},});ReactDOM.render(<ButtonExample />, mountNode);
import { Button, Flex, List } from 'antd-mobile';ReactDOM.render(<div className="button-container"><div style={{ margin: '32px 8px 8px' }}><Flex><Flex.Item><Button type="primary" size="small">primary按钮</Button></Flex.Item><Flex.Item><Button type="primary" ghost size="small">primary ghost 按钮</Button></Flex.Item></Flex><div style={{ height: 8 }} /><Flex><Flex.Item><Button size="small" inline>small</Button></Flex.Item></Flex></div><List ><List.Body><List.Item line={2}extra={<Button type="primary" size="small" inline>small</Button>}><div className="am-list-title">区域经理</div><div className="am-list-brief">可进行收款、退款、折扣管理、查看数据等操作</div></List.Item><List.Item line={2}extra={<Button size="small" inline>small</Button>}><div className="am-list-title">区域经理</div><div className="am-list-brief">可进行收款、退款、折扣管理、查看数据等操作</div></List.Item></List.Body></List></div>, mountNode);

API
| 成员 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| type | 按钮类型,可选值为primary/warning或者不设 | string | - |
| htmlType(web) | 设置button原生的type值,可选值请参考 HTML标准 | string | button |
| ghost | 是否是幽灵按钮 | boolean | false |
| size | 设置按钮大小,可选值为large、small | string | large |
| loading(web) | 设置按钮载入状态 | boolean | false |
| inline(web) | 是否是行内按钮 | boolean | false |
| disabled | 是否不可用 | boolean | false |
| onClick | 点击按钮的回调函数 | Function | 无 |
