Popover 气泡

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

代码演示

气泡

  1. /* eslint global-require: 0 */
  2. import { Popover, NavBar, Icon } from 'antd-mobile';
  3. const Item = Popover.Item;
  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. let offsetX = -10; // just for pc demo
  23. if (/(iPhone|iPad|iPod|iOS|Android)/i.test(navigator.userAgent)) {
  24. offsetX = -26;
  25. }
  26. return (<div>
  27. <NavBar iconName={false}
  28. mode="light"
  29. rightContent={
  30. <Popover mask
  31. overlayClassName="fortest"
  32. overlayStyle={{ color: 'currentColor' }}
  33. visible={this.state.visible}
  34. overlay={[
  35. (<Item key="4" value="scan" icon={<Icon type={require('./scan.svg')} size="xs" />} data-seed="logId">扫一扫</Item>),
  36. (<Item key="5" value="special" icon={<Icon type={require('./qrcode.svg')} size="xs" />} style={{ whiteSpace: 'nowrap' }}>我的二维码</Item>),
  37. (<Item key="6" value="button ct" icon={<Icon type={require('./help.svg')} size="xs" />}>
  38. <span style={{ marginRight: 5 }}>帮助</span>
  39. </Item>),
  40. ]}
  41. align={{
  42. overflow: { adjustY: 0, adjustX: 0 },
  43. offset: [offsetX, 15],
  44. }}
  45. onVisibleChange={this.handleVisibleChange}
  46. onSelect={this.onSelect}
  47. >
  48. <div style={{
  49. height: '100%',
  50. padding: '0 0.3rem',
  51. marginRight: '-0.3rem',
  52. display: 'flex',
  53. alignItems: 'center',
  54. }}
  55. >
  56. <Icon type="ellipsis" />
  57. </div>
  58. </Popover>
  59. }
  60. >
  61. NavBar
  62. </NavBar>
  63. </div>);
  64. }
  65. }
  66. ReactDOM.render(<App />, mountNode);

Popover气泡 - 图1

API

适用平台:WEB、React-Native

Popover

属性说明类型默认值
visible (web only)当前显隐状态Booleanfalse
onVisibleChange (web only)当显隐状态变化时回调函数(visible: bool): void-
placement (web only)enum{'left','right','top','bottom', 'topLeft', 'topRight', 'bottomLeft', 'bottomRight'}String'bottomRight'
mask (web only)是否显示遮罩背景层Booleanfalse
overlay弹出层内容React.node-
onSelect选中某选项时的回调函数(node: any, index?: number): void-
style (rn only)设置样式Object-
triggerStyle (rn only)触发元素外围容器样式Object-
overlayStyle (rn only)弹出层外围容器样式Object-
contextStyle (rn only)最外围容器样式Object-
renderOverlayComponent (rn only)自定义弹出层的外围组件,默认是ScrollView,示例(opts) => <Cus>{opts}</Cus>(opts: any): React.Node-
name (rn only)menu 名字,用于手动触发开关 menuString-
openMenu / closeMenu / toggleMenu(rn only)用于手动开关 menu,参数为上边 menu 的 name. 使用示例见 demoFunction(name)-
更多 API 可查看 rc-tooltip (web only)

Popover.Item

属性说明类型默认值
children节点内容String/React.node-
disabled是否禁用Booleanfalse
styleitem 样式Object-
icon (web only)iconReact.Node-
value (rn only)可作为选中的条目IDstring/number-