Skip to content

Commit

Permalink
Merge pull request #47 from AndreiCalazans/triangle
Browse files Browse the repository at this point in the history
feat: enable tooltip pointer customization
  • Loading branch information
AndreiCalazans authored Nov 15, 2019
2 parents c1c54cb + 90b50a0 commit 4801f15
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import Tooltip from 'rn-tooltip';
* [`onClose`](#onClose)
* [`onOpen`](#onOpen)
* [`pointerColor`](#pointerColor)
* [`pointerStyle`](#pointerStyle)
* [`popover`](#popover)
* [`actionType`](#actionType)
* [`width`](#width)
Expand Down Expand Up @@ -130,6 +131,14 @@ Color of tooltip pointer, it defaults to the

---

### `pointerStyle`

Passes style object to tooltip pointer view

| Type | Default |
| :------------: | :---------------: |
| object (style) | inherited styling |

### `popover`

Component to be rendered as the display container.
Expand All @@ -145,8 +154,8 @@ Component to be rendered as the display container.
Flag to determine how the tooltip reacts to presses.

| Type | Default |
| :-----: | press |
| Enum | none or press or longPress |
| :-----: | :-----: |
| press or none or longPress | press |

---

Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type Props = {
width?: number | string,
containerStyle?: StyleProp<ViewStyle>;
pointerColor?: string,
pointerStyle?: StyleProp<ViewStyle>,
onClose?: () => void,
onOpen?: () => void,
withOverlay?: boolean,
Expand Down
10 changes: 8 additions & 2 deletions src/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Props = {
width: number | string,
containerStyle: any,
pointerColor: string,
pointerStyle: {},
onClose: () => void,
onOpen: () => void,
withOverlay: boolean,
Expand Down Expand Up @@ -132,7 +133,7 @@ class Tooltip extends React.Component<Props, State> {

renderPointer = tooltipY => {
const { yOffset, xOffset, elementHeight, elementWidth } = this.state;
const { backgroundColor, pointerColor } = this.props;
const { backgroundColor, pointerColor, pointerStyle } = this.props;
const pastMiddleLine = yOffset > tooltipY;

return (
Expand All @@ -144,7 +145,10 @@ class Tooltip extends React.Component<Props, State> {
}}
>
<Triangle
style={{ borderBottomColor: pointerColor || backgroundColor }}
style={{
borderBottomColor: pointerColor || backgroundColor,
...pointerStyle,
}}
isDown={pastMiddleLine}
/>
</View>
Expand Down Expand Up @@ -234,6 +238,7 @@ Tooltip.propTypes = {
width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
containerStyle: ViewPropTypes.style,
pointerColor: PropTypes.string,
pointerStyle: PropTypes.object,
onClose: PropTypes.func,
onOpen: PropTypes.func,
withOverlay: PropTypes.bool,
Expand All @@ -253,6 +258,7 @@ Tooltip.defaultProps = {
height: 40,
width: 150,
containerStyle: {},
pointerStyle: {},
backgroundColor: '#617080',
onClose: () => {},
onOpen: () => {},
Expand Down

0 comments on commit 4801f15

Please sign in to comment.