Popover 气泡

在点击控件或者某个区域后,浮出一个气泡区域来放置更多的操作或者信息。

规则

  • 通过点击背景的任一位置,进行退出。

代码演示

Popover

  1. import { Popover, NavBar, Icon } from 'antd-mobile';
  2. const Item = Popover.Item;
  3. const App = React.createClass({
  4. getInitialState() {
  5. return {
  6. visible: true,
  7. selected: '',
  8. };
  9. },
  10. onSelect(opt) {
  11. // console.log(opt.props.value);
  12. this.setState({
  13. visible: false,
  14. selected: opt.props.value,
  15. });
  16. },
  17. handleVisibleChange(visible) {
  18. this.setState({
  19. visible,
  20. });
  21. },
  22. render() {
  23. let offsetX = -10; // just for pc demo
  24. if (/(iPhone|iPad|iPod|iOS|Android)/i.test(navigator.userAgent)) {
  25. offsetX = -30;
  26. }
  27. return (<div>
  28. <NavBar iconName={false} rightContent={
  29. <Popover mask
  30. visible={this.state.visible}
  31. overlay={[
  32. (<Item key="4" value="scan" iconName="scan" data-seed="logId">扫一扫</Item>),
  33. (<Item key="5" value="special" iconName="qrcode" style={{ whiteSpace: 'nowrap' }}>我的二维码</Item>),
  34. (<Item key="6" value="button ct" iconName="question-circle-o">
  35. <span style={{ marginRight: 5 }}>帮助</span>
  36. </Item>),
  37. ]}
  38. popupAlign={{
  39. overflow: { adjustY: 0, adjustX: 0 },
  40. offset: [offsetX, 15],
  41. }}
  42. onVisibleChange={this.handleVisibleChange}
  43. onSelect={this.onSelect}
  44. >
  45. <div style={{
  46. height: '100%',
  47. padding: '0 0.3rem',
  48. marginRight: '-0.3rem',
  49. display: 'flex',
  50. alignItems: 'center',
  51. }}
  52. >
  53. <Icon type="ellipsis" />
  54. </div>
  55. </Popover>
  56. }
  57. >
  58. NavBar
  59. </NavBar>
  60. </div>);
  61. },
  62. });
  63. 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'
popupAlign (web only)用于设置偏移量等、会被合并到 placement 的设置中,可选值为 dom-alignalignConfig配置( points 设置用 placement 代替)Object{ overflow: { adjustY: 0, adjustX: 0 } } 禁掉位置自动适应
mask (web only)是否显示遮罩背景层Booleanfalse
overlay弹出层内容React.node-
onSelect选中某选项时的回调函数(node: any, index?: number): void-
stylemenu 样式Object-
triggerStyle (rn only)触发元素外围容器样式Object-
overlayStyle (rn only)弹出层外围容器样式Object-
contextStyle (rn only)最外围容器样式Object-
renderOverlayComponent (rn only)自定义弹出层的外围组件,默认是ScrollView,示例(opts) => <Cus>{opts}</Cus>Function(opts)-
name (rn only)menu 名字,用于手动触发开关 menuString-
openMenu / closeMenu / toggleMenu(rn only)用于手动开关 menu,参数为上边 menu 的 name. 使用示例见 demoFunction(name)-

Popover.Item

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