Skip to content

Commit 9ae765a

Browse files
committed
feat(component): adding "padding" property to customize padding style
1 parent d696fe5 commit 9ae765a

File tree

5 files changed

+18
-6
lines changed

5 files changed

+18
-6
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ Check example: [React-tooltip Test](https://react-tooltip.netlify.com/)
8383
| globalEventOff | | String | e.g. click | global event to hide tooltip (global only) |
8484
| isCapture | data-iscapture | Bool | true, false | when set to true, custom event's propagation mode will be capture |
8585
| offset | data-offset | Object | top, right, bottom, left | `data-offset="{'top': 10, 'left': 10}"` for specific and `offset={{top: 10, left: 10}}` for global |
86+
| padding | data-padding | String | e.g. `8px 21px` | Popup padding style |
8687
| multiline | data-multiline | Bool | true, false | support `<br>`, `<br />` to make multiline |
8788
| className | data-class | String | | extra custom class, can use !important to overwrite react-tooltip's default class |
8889
| html | data-html | Bool | true, false | `<p data-tip="<p>HTML tooltip</p>" data-html={true}></p>` or `<ReactTooltip html={true} />`, but see [Security Note](#security-note) below. |

Diff for: src/decorators/defaultStyles.js

+2
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ const defaultColors = {
1313
export function getDefaultPopupColors (type) {
1414
return defaultColors[type] ? { ...defaultColors[type] } : undefined;
1515
}
16+
17+
export const DEFAULT_PADDING = "8px 21px";

Diff for: src/decorators/styler.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import { getDefaultPopupColors } from "./defaultStyles";
1+
import { getDefaultPopupColors, DEFAULT_PADDING } from "./defaultStyles";
22

33
/**
44
* Generates the specific tooltip style for use on render.
55
*/
6-
export function generateTooltipStyle(uuid, customColors, type, hasBorder) {
7-
return generateStyle(uuid, getPopupColors(customColors, type, hasBorder));
6+
export function generateTooltipStyle(uuid, customColors, type, hasBorder, padding) {
7+
return generateStyle(uuid, getPopupColors(customColors, type, hasBorder), padding);
88
}
99

1010
/**
1111
* Generates the tooltip style rules based on the element-specified "data-type" property.
1212
*/
13-
function generateStyle(uuid, colors) {
13+
function generateStyle(uuid, colors, padding = DEFAULT_PADDING) {
1414
const textColor = colors.text;
1515
const backgroundColor = colors.background;
1616
const borderColor = colors.border;
@@ -21,6 +21,7 @@ function generateStyle(uuid, colors) {
2121
color: ${textColor};
2222
background: ${backgroundColor};
2323
border: 1px solid ${borderColor};
24+
padding: ${padding};
2425
}
2526
2627
.${uuid}.place-top {

Diff for: src/index.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class ReactTooltip extends React.Component {
3838
type: PropTypes.string,
3939
effect: PropTypes.string,
4040
offset: PropTypes.object,
41+
padding: PropTypes.string,
4142
multiline: PropTypes.bool,
4243
border: PropTypes.bool,
4344
textColor: PropTypes.string,
@@ -95,6 +96,7 @@ class ReactTooltip extends React.Component {
9596
border: false,
9697
customColors: {},
9798
offset: {},
99+
padding: props.padding,
98100
extraClass: "",
99101
html: false,
100102
delayHide: 0,
@@ -426,6 +428,7 @@ class ReactTooltip extends React.Component {
426428
},
427429
effect: effect,
428430
offset: offset,
431+
padding: target.getAttribute("data-padding") || self.props.padding,
429432
html: (target.getAttribute("data-html") ? target.getAttribute("data-html") === "true" : self.props.html) ||
430433
false,
431434
delayShow: target.getAttribute("data-delay-show") ||
@@ -674,7 +677,13 @@ class ReactTooltip extends React.Component {
674677
const { extraClass, html, ariaProps, disable } = this.state;
675678
const content = this.getTooltipContent();
676679
const isEmptyTip = this.isEmptyTip(content);
677-
const style = generateTooltipStyle(this.state.uuid, this.state.customColors, this.state.type, this.state.border);
680+
const style = generateTooltipStyle(
681+
this.state.uuid,
682+
this.state.customColors,
683+
this.state.type,
684+
this.state.border,
685+
this.state.padding
686+
);
678687

679688
const tooltipClass =
680689
"__react_component_tooltip" +

Diff for: src/index.scss

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
font-size: 13px;
55
left: -999em;
66
opacity: 0;
7-
padding: 8px 21px;
87
position: fixed;
98
pointer-events: none;
109
transition: opacity 0.3s ease-out;

0 commit comments

Comments
 (0)