Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ReactTooltip/react-tooltip
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v4.3.1
Choose a base ref
...
head repository: ReactTooltip/react-tooltip
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v4.4.0
Choose a head ref
  • 10 commits
  • 12 files changed
  • 4 contributors

Commits on Mar 10, 2022

  1. feat: add borderClass prop to allow a custom border class

    Allow overriding the default border class name "border" with a custom class name
    danny-does-stuff committed Mar 10, 2022
    Copy the full SHA
    2eec877 View commit details

Commits on Jul 12, 2022

  1. Update react-tooltip.d.ts

    Added useful types and demo comment.
    andrewright authored Jul 12, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    70e40b7 View commit details

Commits on Oct 13, 2022

  1. Copy the full SHA
    0c4cc1b View commit details
  2. Copy the full SHA
    428ca28 View commit details
  3. Copy the full SHA
    71afd00 View commit details
  4. Merge pull request #800 from ReactTooltip/fix/pipeline [skip ci]

    fix: remove github pages deploy from pipeline as we use branch instead [skip ci]
    danielbarion authored Oct 13, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    83293a5 View commit details
  5. Merge pull request #784 from andrewright/patch-1 [skip ci]

    Update react-tooltip.d.ts
    danielbarion authored Oct 13, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    d99b3e8 View commit details
  6. Copy the full SHA
    53792a0 View commit details
  7. feat: add borderClass prop to allow a custom border class [skip-ci]

    feat: add borderClass prop to allow a custom border class
    danielbarion authored Oct 13, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    9844a6c View commit details
  8. chore(release): 4.4.0 [skip ci]

    # [4.4.0](v4.3.1...v4.4.0) (2022-10-13)
    
    ### Features
    
    * add borderClass prop to allow a custom border class ([2eec877](2eec877))
    * add borderClass prop to allow a custom border class [skip-ci] ([9844a6c](9844a6c))
    
    ### Reverts
    
    * revert the upgrade in  uuid as it was breaking the examples page ([71afd00](71afd00))
    semantic-release-bot committed Oct 13, 2022
    Copy the full SHA
    4a7a875 View commit details
Showing with 89 additions and 55 deletions.
  1. +0 −1 .github/workflows/release.yaml
  2. +11 −0 CHANGELOG.md
  3. +1 −0 README.md
  4. +1 −1 example/package.json
  5. +2 −1 example/src/App.js
  6. +2 −2 package.json
  7. +13 −10 react-tooltip.d.ts
  8. +13 −17 src/decorators/bodyMode.js
  9. +7 −1 src/index.js
  10. +16 −17 src/utils/getPosition.js
  11. +19 −1 test/index.spec.js
  12. +4 −4 yarn.lock
1 change: 0 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -28,4 +28,3 @@ jobs:
run: |
yarn build
yarn run semantic-release
yarn gh-pages
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# [4.4.0](https://github.com/ReactTooltip/react-tooltip/compare/v4.3.1...v4.4.0) (2022-10-13)

### Features

- add borderClass prop to allow a custom border class ([2eec877](https://github.com/ReactTooltip/react-tooltip/commit/2eec8775d30a533e028b3a6b5bca90856f193060))
- add borderClass prop to allow a custom border class [skip-ci] ([9844a6c](https://github.com/ReactTooltip/react-tooltip/commit/9844a6ce5a9ce549b72b4ab0700394adeb009ed2))

### Reverts

- revert the upgrade in uuid as it was breaking the examples page ([71afd00](https://github.com/ReactTooltip/react-tooltip/commit/71afd0045fe3ab4127bd120900a453f17dc4ad4b))

## [4.3.1](https://github.com/ReactTooltip/react-tooltip/compare/v4.3.0...v4.3.1) (2022-10-13)

### Bug Fixes
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -80,6 +80,7 @@ Notes:
| delayUpdate | data-delay-update | Number | | `<p data-tip="tooltip" data-delay-update='1000'></p>` or `<ReactTooltip delayUpdate={1000} />` Sets a delay in calling getContent if the tooltip is already shown and you mouse over another target |
| insecure | null | Bool | true, false | Whether to inject the style header into the page dynamically (violates CSP style-src but is a convenient default) |
| border | data-border | Bool | true, false | Add one pixel white border |
| borderClass | data-border-class | String | e.g. custom-border-class | A custom class name to use for the border - enabled by the `border` prop |
| textColor | data-text-color | String | e.g. red | Popup text color |
| backgroundColor | data-background-color | String | e.g. yellow | Popup background color |
| borderColor | data-border-color | String | e.g. green | Popup border color - enabled by the `border` value |
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-tooltip-example",
"homepage": "https://wwayne.github.io/react-tooltip/",
"homepage": "https://reacttooltip.github.io/react-tooltip/",
"version": "1.0.0",
"license": "MIT",
"dependencies": {
3 changes: 2 additions & 1 deletion example/src/App.js
Original file line number Diff line number Diff line change
@@ -316,7 +316,7 @@ export default class App extends Component {
<div className="side">
<a
data-for="custom-color"
data-tip="That is one weird arrow (and a border)!"
data-tip="That is one weird arrow (and a border with custom class name)!"
>
V(^-^)V
</a>
@@ -325,6 +325,7 @@ export default class App extends Component {
className="custom-color"
place="right"
border
borderClass="custom-border-class"
textColor="#5F4B8BFF"
backgroundColor="#E69A8DFF"
borderColor="darkgreen"
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-tooltip",
"version": "4.3.1",
"version": "4.4.0",
"description": "react tooltip component",
"private": false,
"main": "dist/index.js",
@@ -57,7 +57,7 @@
},
"dependencies": {
"prop-types": "^15.8.1",
"uuid": "9.0.0"
"uuid": "8.3.2"
},
"devDependencies": {
"@babel/cli": "7.19.3",
23 changes: 13 additions & 10 deletions react-tooltip.d.ts
Original file line number Diff line number Diff line change
@@ -30,6 +30,8 @@ export interface TooltipProps {
multiline?: boolean;
// Add 1px white border
border?: boolean;
// A custom class name to use for the border
borderClass?: string;
// Popup text color
textColor?: string;
// Popup background color
@@ -57,15 +59,15 @@ export interface TooltipProps {
// Time delay for showing popup
delayShow?: number;
// Custom event to trigger tooltip
event?: string;
event?: keyof HTMLElementEventMap | string;
// Custom event to hide tooltip
// (this requires the event prop as well)
eventOff?: string;
eventOff?: keyof HTMLElementEventMap | string;
// When set to true, custom event's propagation
// mode will be captue
isCapture?: boolean;
// Global event to hide tooltip
globalEventOff?: string;
globalEventOff?: keyof HTMLElementEventMap | string;
// Function to dynamically generate the tooltip content
getContent?: GetContent;
// Callback after tooltip is shown
@@ -74,7 +76,7 @@ export interface TooltipProps {
afterHide?: VoidFunc;
// Callback to override the tooltip position
overridePosition?: (
position: { left: number; top: number; },
position: { left: number; top: number },
currentEvent: Event,
currentTarget: EventTarget,
// node is the ref argument, and the wrapper
@@ -83,8 +85,8 @@ export interface TooltipProps {
place: Place,
desiredPlace: Place,
effect: Effect,
offset: Offset,
) => ({ left: number; top: number; });
offset: Offset
) => { left: number; top: number };
// Manually disable the tooltip behavior
disable?: boolean;
// Hide the tooltip when scrolling;
@@ -94,7 +96,7 @@ export interface TooltipProps {
// default = true
resizeHide?: boolean;
// The tooltip parent component;
// default = 'div'
// default = 'div'
wrapper?: 'div' | 'span';
// Listen to body events vs. individual events
bodyMode?: boolean;
@@ -109,9 +111,10 @@ export interface TooltipProps {
}

// ReactTooltip component is the default export
// You can overview demo examples here: https://bddeu.csb.app
export default class ReactTooltip extends React.Component<TooltipProps> {
// static methods
static show: (target: Element) => {};
static hide: (target?: Element) => {};
static rebuild: () => {};
static show: (target: Element) => {};
static hide: (target?: Element) => {};
static rebuild: () => {};
}
30 changes: 13 additions & 17 deletions src/decorators/bodyMode.js
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
*/
import { checkStatus } from './customEvent';

const makeProxy = e => {
const makeProxy = (e) => {
const proxy = {};
for (const key in e) {
if (typeof e[key] === 'function') {
@@ -15,7 +15,7 @@ const makeProxy = e => {
return proxy;
};

const bodyListener = function(callback, options, e) {
const bodyListener = function (callback, options, e) {
const { respectEffect = false, customEvent = false } = options;
const { id } = this.props;

@@ -54,28 +54,24 @@ const bodyListener = function(callback, options, e) {

const findCustomEvents = (targetArray, dataAttribute) => {
const events = {};
targetArray.forEach(target => {
targetArray.forEach((target) => {
const event = target.getAttribute(dataAttribute);
if (event) event.split(' ').forEach(event => (events[event] = true));
if (event) event.split(' ').forEach((event) => (events[event] = true));
});

return events;
};

const getBody = () => document.getElementsByTagName('body')[0];

export default function(target) {
target.prototype.isBodyMode = function() {
export default function (target) {
target.prototype.isBodyMode = function () {
return !!this.props.bodyMode;
};

target.prototype.bindBodyListener = function(targetArray) {
const {
event,
eventOff,
possibleCustomEvents,
possibleCustomEventsOff
} = this.state;
target.prototype.bindBodyListener = function (targetArray) {
const { event, eventOff, possibleCustomEvents, possibleCustomEventsOff } =
this.state;
const body = getBody();

const customEvents = findCustomEvents(targetArray, 'data-event');
@@ -85,10 +81,10 @@ export default function(target) {
if (eventOff != null) customEventsOff[eventOff] = true;
possibleCustomEvents
.split(' ')
.forEach(event => (customEvents[event] = true));
.forEach((event) => (customEvents[event] = true));
possibleCustomEventsOff
.split(' ')
.forEach(event => (customEventsOff[event] = true));
.forEach((event) => (customEventsOff[event] = true));

this.unbindBodyListener(body);

@@ -104,7 +100,7 @@ export default function(target) {
for (const event in customEvents) {
listeners[event] = bodyListener.bind(
this,
e => {
(e) => {
const targetEventOff =
e.currentTarget.getAttribute('data-event-off') || eventOff;
checkStatus.call(this, targetEventOff, e);
@@ -122,7 +118,7 @@ export default function(target) {
}
};

target.prototype.unbindBodyListener = function(body) {
target.prototype.unbindBodyListener = function (body) {
body = body || getBody();

const listeners = this.bodyModeListeners;
8 changes: 7 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -44,6 +44,7 @@ class ReactTooltip extends React.Component {
padding: PropTypes.string,
multiline: PropTypes.bool,
border: PropTypes.bool,
borderClass: PropTypes.string,
textColor: PropTypes.string,
backgroundColor: PropTypes.string,
borderColor: PropTypes.string,
@@ -97,6 +98,7 @@ class ReactTooltip extends React.Component {
effect: props.effect || 'float', // float or fixed
show: false,
border: false,
borderClass: 'border',
customColors: {},
offset: {},
padding: props.padding,
@@ -507,6 +509,10 @@ class ReactTooltip extends React.Component {
(target.getAttribute('data-border')
? target.getAttribute('data-border') === 'true'
: self.props.border) || false,
borderClass:
target.getAttribute('data-border-class') ||
self.props.borderClass ||
'border',
extraClass:
target.getAttribute('data-class') ||
self.props.class ||
@@ -791,7 +797,7 @@ class ReactTooltip extends React.Component {
'__react_component_tooltip' +
` ${this.state.uuid}` +
(this.state.show && !disable && !isEmptyTip ? ' show' : '') +
(this.state.border ? ' border' : '') +
(this.state.border ? ' ' + this.state.borderClass : '') +
` place-${this.state.place}` + // top, bottom, left, right
` type-${this.hasCustomColors() ? 'custom' : this.state.type}` + // dark, success, warning, error, info, light, custom
(this.props.delayUpdate ? ' allow_hover' : '') +
33 changes: 16 additions & 17 deletions src/utils/getPosition.js
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
* - `newState` {Object}
* - `position` {Object} {left: {Number}, top: {Number}}
*/
export default function(e, target, node, place, desiredPlace, effect, offset) {
export default function (e, target, node, place, desiredPlace, effect, offset) {
const { width: tipWidth, height: tipHeight } = getDimensions(node);

const { width: targetWidth, height: targetHeight } = getDimensions(target);
@@ -35,19 +35,19 @@ export default function(e, target, node, place, desiredPlace, effect, offset) {
const { parentTop, parentLeft } = getParent(node);

// Get the edge offset of the tooltip
const getTipOffsetLeft = place => {
const getTipOffsetLeft = (place) => {
const offsetX = defaultOffset[place].l;
return mouseX + offsetX + extraOffsetX;
};
const getTipOffsetRight = place => {
const getTipOffsetRight = (place) => {
const offsetX = defaultOffset[place].r;
return mouseX + offsetX + extraOffsetX;
};
const getTipOffsetTop = place => {
const getTipOffsetTop = (place) => {
const offsetY = defaultOffset[place].t;
return mouseY + offsetY + extraOffsetY;
};
const getTipOffsetBottom = place => {
const getTipOffsetBottom = (place) => {
const offsetY = defaultOffset[place].b;
return mouseY + offsetY + extraOffsetY;
};
@@ -66,15 +66,15 @@ export default function(e, target, node, place, desiredPlace, effect, offset) {
// |
// Bottom side
//
const outsideLeft = p => getTipOffsetLeft(p) < 0;
const outsideRight = p => getTipOffsetRight(p) > windowWidth;
const outsideTop = p => getTipOffsetTop(p) < 0;
const outsideBottom = p => getTipOffsetBottom(p) > windowHeight;
const outsideLeft = (p) => getTipOffsetLeft(p) < 0;
const outsideRight = (p) => getTipOffsetRight(p) > windowWidth;
const outsideTop = (p) => getTipOffsetTop(p) < 0;
const outsideBottom = (p) => getTipOffsetBottom(p) > windowHeight;

// Check whether the tooltip with orientation p is completely inside the client window
const outside = p =>
const outside = (p) =>
outsideLeft(p) || outsideRight(p) || outsideTop(p) || outsideBottom(p);
const inside = p => !outside(p);
const inside = (p) => !outside(p);

const placeIsInside = {
top: inside('top'),
@@ -119,7 +119,7 @@ export default function(e, target, node, place, desiredPlace, effect, offset) {
};
}

const getDimensions = node => {
const getDimensions = (node) => {
const { height, width } = node.getBoundingClientRect();
return {
height: parseInt(height, 10),
@@ -132,9 +132,8 @@ const getCurrentOffset = (e, currentTarget, effect) => {
const boundingClientRect = currentTarget.getBoundingClientRect();
const targetTop = boundingClientRect.top;
const targetLeft = boundingClientRect.left;
const { width: targetWidth, height: targetHeight } = getDimensions(
currentTarget
);
const { width: targetWidth, height: targetHeight } =
getDimensions(currentTarget);

if (effect === 'float') {
return {
@@ -221,7 +220,7 @@ const getDefaultPosition = (
};

// Consider additional offset into position calculation
const calculateOffset = offset => {
const calculateOffset = (offset) => {
let extraOffsetX = 0;
let extraOffsetY = 0;

@@ -244,7 +243,7 @@ const calculateOffset = offset => {
};

// Get the offset of the parent elements
const getParent = currentTarget => {
const getParent = (currentTarget) => {
let currentParent = currentTarget;
while (currentParent) {
const computedStyle = window.getComputedStyle(currentParent);
20 changes: 19 additions & 1 deletion test/index.spec.js
Original file line number Diff line number Diff line change
@@ -170,6 +170,21 @@ describe('Tooltip', () => {
arrowColor: '#222',
borderColor: 'blue'
}
],
[
{
border: true,
borderClass: 'custom-border-class',
borderColor: '#414141'
},
{
borderColor: '#414141',
borderClass: 'custom-border-class',
popupType: 'type-custom',
textColor: '#fff',
background: '#222',
arrowColor: '#222'
}
]
]).it('Popup color generation - show', (props, res) => {
render(
@@ -184,10 +199,13 @@ describe('Tooltip', () => {
);

const tooltip = document.getElementById('colorSpec');

const expectedBorderClass = res.borderClass || 'border';

expect(tooltip.className).to.match(
new RegExp(
'__react_component_tooltip [a-zA-Z0-9-]+ show' +
(props.border ? ' border ' : ' ') +
(props.border ? ` ${expectedBorderClass} ` : ' ') +
'place-top ' +
res.popupType,
'i'
Loading