Skip to content

Commit

Permalink
feat(Tooltip): add arrow props to hide arrow
Browse files Browse the repository at this point in the history
close #207
  • Loading branch information
ZxBing0066 committed Mar 24, 2020
1 parent 8c0c3e7 commit a2d62c7
Show file tree
Hide file tree
Showing 5 changed files with 650 additions and 20 deletions.
13 changes: 9 additions & 4 deletions src/components/Tooltip/Tooltip.jsx
Expand Up @@ -20,21 +20,26 @@ class Tooltip extends Component {
placement: PropTypes.oneOf(Placement),
/** @ignore */
popupClassName: PropTypes.string,
/** 是否显示箭头 */
arrow: PropTypes.bool,
/** 主题风格 */
theme: PropTypes.oneOfType([PropTypes.oneOf(Theme), PropTypes.object])
};
static defaultProps = {
theme: 'light',
arrow: true,
placement: Placement[0]
};
renderPopup(theme) {
const { popup, placement, theme: themeType } = this.props;
const { popup, placement, theme: themeType, arrow } = this.props;
return (
<ThemeProvider theme={theme}>
<TooltipWrap placement={placement} themeType={themeType}>
<Arrow>
<ArrowInner />
</Arrow>
{arrow && (
<Arrow>
<ArrowInner />
</Arrow>
)}
<ContentWrap themeType={themeType}>{popup}</ContentWrap>
</TooltipWrap>
</ThemeProvider>
Expand Down
5 changes: 5 additions & 0 deletions src/components/Tooltip/Tooltip.md
Expand Up @@ -15,6 +15,11 @@
```js {"codepath": "theme.jsx"}
```

* arrow

```js {"codepath": "arrow.jsx"}
```

* placement

```js {"codepath": "placement.jsx"}
Expand Down
23 changes: 23 additions & 0 deletions src/components/Tooltip/__demo__/arrow.jsx
@@ -0,0 +1,23 @@
import React from 'react';

import Tooltip from 'src/components/Tooltip';
import Button from 'src/components/Button';

// demo start
const Demo = () => (
<div>
<div className="demo-wrap">
<Tooltip popup={<p>tooltip message</p>} visible>
<Button>Hover</Button>
</Tooltip>
</div>
<div className="demo-wrap">
<Tooltip popup={<p>tooltip message</p>} arrow={false} visible>
<Button>Hover</Button>
</Tooltip>
</div>
</div>
);
// demo end

export default Demo;
26 changes: 19 additions & 7 deletions src/components/Tooltip/__demo__/tooltip.jsx
@@ -1,9 +1,11 @@
import React from 'react';
import PropTypes from 'prop-types';
import Tooltip from 'components/Tooltip';
import Radio from 'components/Radio';
import Form from 'components/Form';
import Button from 'components/Button';

import Tooltip from 'src/components/Tooltip';
import Radio from 'src/components/Radio';
import Form from 'src/components/Form';
import Button from 'src/components/Button';
import Switch from 'src/components/Switch';

// demo start
const { Placement, Theme } = Tooltip;
Expand All @@ -18,11 +20,12 @@ class Demo extends React.Component {
super(props);
this.state = {
placement: Placement[0],
theme: Theme[0]
theme: Theme[0],
arrow: Tooltip.defaultProps.arrow
};
}
render() {
const { placement, theme } = this.state;
const { placement, theme, arrow } = this.state;
const itemLayout = {
labelCol: {
span: 3
Expand Down Expand Up @@ -52,9 +55,18 @@ class Demo extends React.Component {
}))}
/>
</Form.Item>
<Form.Item label="arrow" {...itemLayout}>
<Switch onChange={arrow => this.setState({ arrow })} checked={arrow} />
</Form.Item>
</Form>
<div className="demo-wrap">
<Tooltip placement={placement} popup={<Popup />} theme={theme}>
<Tooltip
placement={placement}
popup={<Popup />}
theme={theme}
arrow={arrow}
getPopupContainer={() => document.body}
>
<Content>content</Content>
</Tooltip>
</div>
Expand Down

0 comments on commit a2d62c7

Please sign in to comment.