Popper气泡层 - 图1

Popper 气泡层

基本用法

  1. import { Cell, Button, Popper, Select } from 'zarm';
  2. class Demo extends React.Component {
  3. state = {
  4. visible: false,
  5. direction: 'top',
  6. trigger: 'click',
  7. }
  8. render() {
  9. const { visible, direction, trigger } = this.state;
  10. return (
  11. <>
  12. <Cell className="basic-demo">
  13. <Popper
  14. content="我是气泡层的内容"
  15. destroy={false}
  16. visible={visible}
  17. trigger={trigger}
  18. direction={direction}
  19. className="custom-content"
  20. >
  21. <Button theme="primary" size="xs" onClick={() => trigger === 'manual' && this.setState({ visible: !visible })}>
  22. 点击{visible ? '隐藏' : '显示'}
  23. </Button>
  24. </Popper>
  25. </Cell>
  26. <Cell title="显示方向">
  27. <Select
  28. value={direction}
  29. dataSource={[
  30. { value: 'topLeft', label: 'topLeft' },
  31. { value: 'top', label: 'top' },
  32. { value: 'topRight', label: 'topRight' },
  33. { value: 'rightTop', label: 'rightTop' },
  34. { value: 'right', label: 'right' },
  35. { value: 'rightBottom', label: 'rightBottom' },
  36. { value: 'bottomLeft', label: 'bottomLeft' },
  37. { value: 'bottom', label: 'bottom' },
  38. { value: 'bottomRight', label: 'bottomRight' },
  39. { value: 'leftTop', label: 'leftTop' },
  40. { value: 'left', label: 'left' },
  41. { value: 'leftBottom', label: 'leftBottom' },
  42. ]}
  43. onOk={(selected) => {
  44. this.setState({
  45. direction: selected[0].value,
  46. });
  47. }}
  48. />
  49. </Cell>
  50. <Cell title="触发方式">
  51. <Select
  52. value={trigger}
  53. dataSource={[
  54. { value: 'click', label: 'click(点击状态触发)' },
  55. { value: 'hover', label: 'hover(hover状态触发)' },
  56. { value: 'focus', label: 'focus(聚焦状态触发)' },
  57. { value: 'manual', label: 'manual(受控触发)' },
  58. { value: 'contextMenu', label: 'contextMenu(右键触发)' },
  59. ]}
  60. onOk={(selected) => {
  61. this.setState({
  62. trigger: selected[0].value,
  63. visible: false,
  64. });
  65. }}
  66. />
  67. </Cell>
  68. </>
  69. );
  70. }
  71. }
  72. ReactDOM.render(<Demo />, mountNode);

自定义箭头

  1. import { Cell, Button, Popper, Radio, Message, Icon } from 'zarm';
  2. class Demo extends React.Component {
  3. state = {
  4. arrow: '0'
  5. }
  6. render() {
  7. const { arrow } = this.state
  8. return (
  9. <>
  10. <Cell description={
  11. <Radio.Group
  12. compact
  13. type="button"
  14. value={this.state.arrow}
  15. onChange={value => {
  16. this.setState({ arrow: value });
  17. }}
  18. >
  19. <Radio value="0">跟随方向</Radio>
  20. <Radio value="1">元素中心</Radio>
  21. </Radio.Group>
  22. }>
  23. 箭头位置
  24. </Cell>
  25. <Cell className="direction-demo">
  26. <div>
  27. <div style={{ marginLeft: 60 }}>
  28. <Popper arrowPointAtCenter={arrow === '1'} className="custom-arrow-content" hasArrow direction="topLeft" content="topLeft text">
  29. <Button block size="xs">TL</Button>
  30. </Popper>
  31. <Popper arrowPointAtCenter={arrow === '1'} className="custom-arrow-content" hasArrow direction="top" content="top text">
  32. <Button block size="xs">Top</Button>
  33. </Popper>
  34. <Popper arrowPointAtCenter={arrow === '1'} className="custom-arrow-content" hasArrow direction="topRight" content="topRight text">
  35. <Button block size="xs">TR</Button>
  36. </Popper>
  37. </div>
  38. <div style={{ width: 60, float: 'left', clear: 'both' }}>
  39. <Popper arrowPointAtCenter={arrow === '1'} className="custom-arrow-content" hasArrow direction="leftTop" content="leftTop text">
  40. <Button block size="xs">LT</Button>
  41. </Popper>
  42. <Popper arrowPointAtCenter={arrow === '1'} className="custom-arrow-content" hasArrow direction="left" content="left text">
  43. <Button block size="xs">Left</Button>
  44. </Popper>
  45. <Popper arrowPointAtCenter={arrow === '1'} className="custom-arrow-content" hasArrow direction="leftBottom" content="leftBottom text">
  46. <Button block size="xs">LB</Button>
  47. </Popper>
  48. </div>
  49. <div style={{ width: 60, marginLeft: 60 * 4 + 20 }}>
  50. <Popper arrowPointAtCenter={arrow === '1'} className="custom-arrow-content" hasArrow direction="rightTop" content="rightTop text">
  51. <Button block size="xs">RT</Button>
  52. </Popper>
  53. <Popper arrowPointAtCenter={arrow === '1'} className="custom-arrow-content" hasArrow direction="right" content="right text">
  54. <Button block size="xs">Right</Button>
  55. </Popper>
  56. <Popper arrowPointAtCenter={arrow === '1'} className="custom-arrow-content" hasArrow direction="rightBottom" content="rightBottom text">
  57. <Button block size="xs">RB</Button>
  58. </Popper>
  59. </div>
  60. <div style={{ marginLeft: 60, clear: 'both' }}>
  61. <Popper arrowPointAtCenter={arrow === '1'} className="custom-arrow-content" hasArrow direction="bottomLeft" content="bottomLeft text">
  62. <Button block size="xs">BL</Button>
  63. </Popper>
  64. <Popper arrowPointAtCenter={arrow === '1'} className="custom-arrow-content" hasArrow direction="bottom" content="bottom text">
  65. <Button block size="xs">Bottom</Button>
  66. </Popper>
  67. <Popper arrowPointAtCenter={arrow === '1'} className="custom-arrow-content" hasArrow direction="bottomRight" content="bottomRight text">
  68. <Button block size="xs">BR</Button>
  69. </Popper>
  70. </div>
  71. <Message theme="warning" icon={<Icon type="warning-round" />}>左右两侧显示位置不足会自动调整为反向显示</Message>
  72. </div>
  73. </Cell>
  74. </>
  75. );
  76. }
  77. }
  78. ReactDOM.render(<Demo />, mountNode);

API

属性类型默认值说明
classNamestring-气泡层类名追加
contentReactNode-显示内容
hasArrowbooleanfalse是否显示箭头节点(注:需要自行定义箭头样式)
destroybooleantrue气泡层关闭后是否移除节点
getContainerHTMLElement | () => HTMLElementdocument.body指定 Popper 挂载的 HTML 节点
animationTypestring'zoom-fade'可选值 fade, door, flip, rotate, zoom,moveUp, moveDown, moveLeft, moveRight,slideUp, slideDown, slideLeft, slideRight
animationDurationnumber200动画执行时间(单位:毫秒)
arrowPointAtCenterbooleanfalse箭头是否指向目标元素中心
mouseEnterDelaynumber100鼠标移入显示气泡层的延时时间(单位:毫秒)
mouseLeaveDelaynumber100鼠标移出隐藏气泡层的延时时间(单位:毫秒)
directionstring'top'显示方向,可选值 topLefttoptopRightrightToprightrightBottombottomLeftbottombottomRightleftTopleftleftBottom
triggerstring移动端为'click' 桌面端为'hover'触发方式,可选值为:click 点击触发状态、hover hover状态触发、focus 聚焦状态触发、manual 受控触发、contextMenu 右键触发
visiblebooleanfalse是否显示,trigger='manual' 时有效
onVisibleChange(visible?: boolean) => voidnoop显示/隐藏 气泡层触发的事件