4.22.3 • Published 5 months ago

@uiw/react-tooltip v4.22.3

Weekly downloads
285
License
MIT
Repository
github
Last release
5 months ago

Tooltip 文字提示

Buy me a coffee Open in unpkg NPM Downloads npm version

简单的文字提示气泡框。

import { Tooltip } from 'uiw';
// or
import Tooltip from '@uiw/react-tooltip';

基础用法

最简单的用法。

import React from 'react';
import { Tooltip, Button } from 'uiw';

const Demo = () => (
  <div>
    <Tooltip placement="right" content="右边文字提示">
      <Button>右边文字提示(right)</Button>
    </Tooltip>
    <Tooltip placement="top" content="上边文字提示">
      <Button>上边文字提示(top)</Button>
    </Tooltip>
    <Tooltip placement="left" content="左边文字提示">
      <Button>左边文字提示(left)</Button>
    </Tooltip>
    <Tooltip placement="bottom" content="下边文字提示">
      <Button>下边文字提示(bottom)</Button>
    </Tooltip>
    <Tooltip placement="top" content="已被禁用">
      <Button disabled={true}>禁用</Button>
    </Tooltip>
  </div>
)
export default Demo;

位置

位置有 12 个方向,根据 placement 参数来设置。

import React from 'react';
import { Tooltip, Button, Divider } from 'uiw';

const btnStl = {position: 'relative', width: 70 }
const Demo = () => (
  <div>
    <Tooltip placement="left" content={<strong>Hello uiw!</strong>}>
      <Button type="primary">左边文字提示(left)</Button>
    </Tooltip>

    <Tooltip placement="top" content={<strong>Hello uiw!</strong>}>
      <Button type="primary">上边文字提示(top)</Button>
    </Tooltip>

    <Tooltip placement="bottom" content={<strong>Hello uiw!</strong>}>
      <Button type="primary">下边文字提示(bottom)</Button>
    </Tooltip>

    <Tooltip placement="right" content={<strong>Hello uiw!</strong>}>
      <Button type="primary">右边文字提示(right)</Button>
    </Tooltip>

    <Divider />
    <div style={{ position: 'relative' }}>
      <Tooltip placement="topLeft" content={<strong>Hello uiw!</strong>}>
        <Button style={{ ...btnStl, left: 70 }}>TL</Button>
      </Tooltip>
      <Tooltip placement="top" content={<strong>Hello uiw!</strong>}>
        <Button style={{ ...btnStl, left: 70}}>Top</Button>
      </Tooltip>
      <Tooltip placement="topRight" content={<strong>Hello uiw!</strong>}>
        <Button style={{ ...btnStl, left: 70 }}>TR</Button>
      </Tooltip>
    </div>
    <div style={{ position: 'relative', paddingTop: 10 }}>
      <Tooltip placement="leftTop" content={<span><strong>Hello uiw!</strong> 位置有 12 个方向,根据 placement 参数来设置。</span>}>
        <Button style={{ ...btnStl }}>LT</Button>
      </Tooltip>
      <Tooltip placement="rightTop" content={<span><strong>Hello uiw!</strong> 位置有 12 个方向,根据 placement 参数来设置。</span>}>
        <Button style={{ ...btnStl, left: 216 }}>RT</Button>
      </Tooltip>
    </div>
    <div style={{ position: 'relative', paddingTop: 10 }}>
      <Tooltip placement="left" content={<span><strong>Hello uiw!</strong> 位置有 12 个方向,根据 placement 参数来设置。</span>}>
        <Button style={{ ...btnStl }}>Left</Button>
      </Tooltip>
      <Tooltip placement="right" content={<span><strong>Hello uiw!</strong> 位置有 12 个方向,根据 placement 参数来设置。</span>}>
        <Button style={{ ...btnStl, left: 216 }}>Right</Button>
      </Tooltip>
    </div>
    <div style={{ position: 'relative', paddingTop: 10 }}>
      <Tooltip placement="leftBottom" content={<span><strong>Hello uiw!</strong> 位置有 12 个方向,根据 placement 参数来设置。</span>}>
        <Button style={{ ...btnStl }}>LB</Button>
      </Tooltip>
      <Tooltip placement="rightBottom" content={<span><strong>Hello uiw!</strong> 位置有 12 个方向,根据 placement 参数来设置。</span>}>
        <Button style={{ ...btnStl, left: 216 }}>RB</Button>
      </Tooltip>
    </div>
    <div style={{ position: 'relative', paddingTop: 10 }}>
      <Tooltip placement="bottomLeft" content={<span><strong>Hello uiw!</strong> 位置有 12 个方向,根据 placement 参数来设置。</span>}>
        <Button style={{ ...btnStl, left: 70 }}>BL</Button>
      </Tooltip>
      <Tooltip placement="bottom" content={<span><strong>Hello uiw!</strong> 位置有 12 个方向,根据 placement 参数来设置。</span>}>
        <Button style={{ ...btnStl, left: 70 }}>Bottom</Button>
      </Tooltip>
      <Tooltip placement="bottomRight" content={<span><strong>Hello uiw!</strong> 位置有 12 个方向,根据 placement 参数来设置。</span>}>
        <Button style={{ ...btnStl, left: 70 }}>BR</Button>
      </Tooltip>
    </div>

  </div>
)
export default Demo;

事件

文字提示组件 <Tooltip />,通过设置属性 trigger 可以文字提示操作方式。

import React from 'react';
import { Tooltip, Button } from 'uiw';

const Demo = () => (
  <div>
    <Tooltip trigger="hover" placement="top" content="Hello uiw!">
      <Button type="primary">悬浮弹出文字提示(top)</Button>
    </Tooltip>
    <Tooltip trigger="click" placement="top" content="Hello uiw!">
      <Button type="success">点击弹出提示(top)</Button>
    </Tooltip>
  </div>
)
export default Demo;

文字提示框不显示箭头

通过设置属性 visibleArrow 可以文字提示框不显示箭头。

import React from 'react';
import { Tooltip, Button } from 'uiw';

const Demo = () => (
  <div>

    <Tooltip visibleArrow={false} trigger="hover" placement="top" content="Hello uiw!">
      <Button type="primary">悬浮弹出文字提示(top)</Button>
    </Tooltip>
    <Tooltip visibleArrow={false} trigger="click" placement="right" content="Hello uiw!">
      <Button type="success">点击弹出提示(right)</Button>
    </Tooltip>

  </div>
)
export default Demo;

受控组件

import React from 'react';
import { Tooltip, Switch, Divider } from 'uiw';

class Demo extends React.Component {
  constructor() {
    super()
    this.state = {
      isOpen: false,
    }
  }
  onChange(e) {
    this.setState({ isOpen: e.target.checked });
  }
  onVisibleChange(isOpen) {
    this.setState({ isOpen });
  }
  render() {
    return (
      <div>
        <Tooltip
          isOpen={this.state.isOpen}
          onVisibleChange={this.onVisibleChange.bind(this)}
          placement="top"
          content="Hello uiw!"
        >
          <span>鼠标移动到此处,显示和消失触发事件,也可以通过 Switch 组件来控制</span>
        </Tooltip>
        <Divider />
        <Switch checked={this.state.isOpen} onChange={this.onChange.bind(this)} />
      </div>
    )
  }
}
export default Demo;

Props

参数说明类型默认值
content显示的内容String,React.ReactNode-
placement气泡框位置,可现实箭头在不通的方位Enum{top, topLeft, topRight, left, leftTop, leftBottom, right, rightTop, rightBottom, bottom, bottomLeft, bottomRight}top
visibleArrow是否显示 Tooltip 箭头Booleantrue
delay延迟进入和消失,{ show: 2000, hide: 4000 } 或者直接设置 2000,只对 trigger=hover 有效,继承 <OverlayTrigger /> 组件属性Object/Number-
trigger悬停/点击弹出窗口,继承 <OverlayTrigger /> 组件属性Enum{hover, click}hover
disabled是否禁用弹出目标Booleanfalse
isOpen默认是否显示弹窗,继承 <OverlayTrigger /> 组件属性Booleanfalse
autoAdjustOverflow弹出层被遮挡时自动调整位置,继承 <OverlayTrigger /> 组件属性Booleanfalse
onVisibleChange显示隐藏的回调,继承 <OverlayTrigger /> 组件属性Function(isVisible:bool)-

更多属性请参考 OverlayTrigger

4.22.0

8 months ago

4.22.1

6 months ago

4.22.2

6 months ago

4.22.3

5 months ago

4.21.26

1 year ago

4.21.25

1 year ago

4.21.28

1 year ago

4.21.27

1 year ago

5.0.0-bate.2.1

1 year ago

5.0.0-bate.2.0

1 year ago

4.21.24

1 year ago

5.0.0-bate-19

1 year ago

4.21.22

1 year ago

4.21.21

1 year ago

4.21.23

1 year ago

5.0.0-bate-18

1 year ago

5.0.0-bate-14

1 year ago

5.0.0-bate-17

1 year ago

5.0.0-bate-10

1 year ago

5.0.0-bate-11

1 year ago

5.0.0-bate-12

1 year ago

5.0.0-bate-9

1 year ago

5.0.0-bate-7

1 year ago

5.0.0-bate-8

1 year ago

5.0.0-bate-6

1 year ago

4.21.20

1 year ago

4.21.19

2 years ago

4.21.18

2 years ago

4.21.15

2 years ago

4.21.17

2 years ago

4.21.16

2 years ago

5.0.0-bate-5

2 years ago

5.0.0-bate-3

2 years ago

5.0.0-bate-4

2 years ago

5.0.0-bate-1

2 years ago

5.0.0-bate-2

2 years ago

5.0.0-bate-0

2 years ago

4.21.13

2 years ago

4.21.14

2 years ago

4.21.11

2 years ago

4.21.12

2 years ago

4.21.10

2 years ago

4.21.1

2 years ago

4.21.2

2 years ago

4.21.3

2 years ago

4.21.4

2 years ago

4.21.0

2 years ago

4.20.0

2 years ago

4.21.9

2 years ago

4.21.5

2 years ago

4.21.6

2 years ago

4.21.7

2 years ago

4.21.8

2 years ago

4.18.1

2 years ago

4.18.0

2 years ago

4.17.0

2 years ago

4.16.0

2 years ago

4.16.1

2 years ago

4.16.2

2 years ago

4.19.0

2 years ago

4.15.1

2 years ago

4.14.1

2 years ago

4.14.2

2 years ago

4.14.0

2 years ago

4.13.7

2 years ago

4.13.8

2 years ago

4.13.9

2 years ago

4.13.11

2 years ago

4.13.12

2 years ago

4.13.10

2 years ago

4.15.0

2 years ago

4.10.5

2 years ago

4.10.6

2 years ago

4.10.7

2 years ago

4.9.9

2 years ago

4.10.1

2 years ago

4.10.2

2 years ago

4.10.3

2 years ago

4.10.4

2 years ago

4.10.0

2 years ago

4.13.6

2 years ago

4.13.2

2 years ago

4.13.3

2 years ago

4.13.4

2 years ago

4.13.5

2 years ago

4.13.0

2 years ago

4.13.1

2 years ago

4.12.0

2 years ago

4.12.1

2 years ago

4.12.2

2 years ago

4.11.4

2 years ago

4.11.5

2 years ago

4.11.6

2 years ago

4.9.11

2 years ago

4.9.10

2 years ago

4.11.0

2 years ago

4.11.1

2 years ago

4.11.2

2 years ago

4.11.3

2 years ago

4.9.7

3 years ago

4.9.6

3 years ago

4.9.4

3 years ago

4.9.3

3 years ago

4.9.2

3 years ago

4.9.1

3 years ago

4.9.0

3 years ago

4.8.9

3 years ago

4.8.8

3 years ago

4.7.16

3 years ago

4.8.5

3 years ago

4.8.4

3 years ago

4.8.7

3 years ago

4.8.6

3 years ago

4.8.1

3 years ago

4.8.0

3 years ago

4.8.3

3 years ago

4.8.2

3 years ago

4.7.13

3 years ago

4.7.14

3 years ago

4.7.15

3 years ago

4.7.12

3 years ago

4.7.10

3 years ago

4.7.11

3 years ago

4.7.9

3 years ago

4.7.8

3 years ago

4.7.7

3 years ago

4.7.6

3 years ago

4.7.5

3 years ago

4.7.4

3 years ago

4.7.3

3 years ago

4.7.2

3 years ago

4.7.0

3 years ago

4.6.19

3 years ago

4.6.15

3 years ago

4.6.16

3 years ago

4.6.17

3 years ago

4.6.18

3 years ago

4.6.14

4 years ago

4.6.13

4 years ago

4.6.12

4 years ago

4.6.11

4 years ago

4.6.10

4 years ago

4.6.9

4 years ago

4.6.8

4 years ago

4.6.7

4 years ago

4.6.6

4 years ago

4.6.3

4 years ago

4.6.4

4 years ago

4.6.2

4 years ago

4.6.1

4 years ago

4.6.0

4 years ago

4.5.0

4 years ago

4.4.1

4 years ago

4.4.0

4 years ago

4.3.1

4 years ago

4.2.3

4 years ago

4.2.5

4 years ago

4.3.0

4 years ago

4.2.14

4 years ago

4.2.1

4 years ago

4.2.0

4 years ago

4.1.2

4 years ago

4.1.1

4 years ago

4.1.0

4 years ago

4.0.0

4 years ago

4.0.0-alpha.7

4 years ago

4.0.0-alpha.8

4 years ago

4.0.0-alpha.6

4 years ago

4.0.0-alpha.3

4 years ago

4.0.0-alpha.2

4 years ago

4.0.0-alpha.1

4 years ago

4.0.0-alpha.0

4 years ago