Popover 气泡

在点击控件或者某个区域后,浮出一个气泡菜单来做更多的操作。如果设置了遮罩层,建议通过点击遮罩层的任一位置,进行退出。

代码演示

气泡

  1. import { Popover, NavBar, Icon } from 'antd-mobile';
  2. const Item = Popover.Item;
  3. const myImg = src => <img src={`https://gw.alipayobjects.com/zos/rmsportal/${src}.svg`} className="am-icon am-icon-xs" alt="" />;
  4. class App extends React.Component {
  5. state = {
  6. visible: true,
  7. selected: '',
  8. };
  9. onSelect = (opt) => {
  10. // console.log(opt.props.value);
  11. this.setState({
  12. visible: false,
  13. selected: opt.props.value,
  14. });
  15. };
  16. handleVisibleChange = (visible) => {
  17. this.setState({
  18. visible,
  19. });
  20. };
  21. render() {
  22. return (<div>
  23. <NavBar
  24. mode="light"
  25. rightContent={
  26. <Popover mask
  27. overlayClassName="fortest"
  28. overlayStyle={{ color: 'currentColor' }}
  29. visible={this.state.visible}
  30. overlay={[
  31. (<Item key="4" value="scan" icon={myImg('tOtXhkIWzwotgGSeptou')} data-seed="logId">Scan</Item>),
  32. (<Item key="5" value="special" icon={myImg('PKAgAqZWJVNwKsAJSmXd')} style={{ whiteSpace: 'nowrap' }}>My Qrcode</Item>),
  33. (<Item key="6" value="button ct" icon={myImg('uQIYTFeRrjPELImDRrPt')}>
  34. <span style={{ marginRight: 5 }}>Help</span>
  35. </Item>),
  36. ]}
  37. align={{
  38. overflow: { adjustY: 0, adjustX: 0 },
  39. offset: [-10, 0],
  40. }}
  41. onVisibleChange={this.handleVisibleChange}
  42. onSelect={this.onSelect}
  43. >
  44. <div style={{
  45. height: '100%',
  46. padding: '0 15px',
  47. marginRight: '-15px',
  48. display: 'flex',
  49. alignItems: 'center',
  50. }}
  51. >
  52. <Icon type="ellipsis" />
  53. </div>
  54. </Popover>
  55. }
  56. >
  57. NavBar
  58. </NavBar>
  59. </div>);
  60. }
  61. }
  62. ReactDOM.render(<App />, mountNode);

Popover气泡 - 图1

API

Popover

属性说明类型默认值
visible当前显隐状态Booleanfalse
onVisibleChange当显隐状态变化时回调函数(visible: bool): void-
placementenum{'left','right','top','bottom', 'topLeft', 'topRight', 'bottomLeft', 'bottomRight'}String'bottomRight'
mask是否显示遮罩背景层Booleanfalse
overlay弹出层内容ReactNode-
onSelect选中某选项时的回调函数(node: any, index?: number): void-
更多 API 可查看 rmc-tooltip### Popover.Item#
属性说明类型默认值
disabled是否禁用Booleanfalse
styleitem 样式Object-
iconiconReactNode-