Skip to content

Commit f08e999

Browse files
authored
Merge pull request #603 from pvcresin/add_padding_props
feat(component): adding "padding" property to customize padding style
2 parents 8f22191 + bcbb1c3 commit f08e999

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ Notes:
8181
| globalEventOff | | String | e.g. click | global event to hide tooltip (global only) |
8282
| isCapture | data-iscapture | Bool | true, false | when set to true, custom event's propagation mode will be capture |
8383
| offset | data-offset | Object | top, right, bottom, left | `data-offset="{'top': 10, 'left': 10}"` for specific and `offset={{top: 10, left: 10}}` for global |
84+
| padding | data-padding | String | e.g. `8px 21px` | Popup padding style |
8485
| multiline | data-multiline | Bool | true, false | support `<br>`, `<br />` to make multiline |
8586
| className | data-class | String | | extra custom class, can use !important to overwrite react-tooltip's default class |
8687
| 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. |

src/decorators/defaultStyles.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,5 @@ const defaultColors = {
4343
export function getDefaultPopupColors(type) {
4444
return defaultColors[type] ? { ...defaultColors[type] } : undefined;
4545
}
46+
47+
export const DEFAULT_PADDING = '8px 21px';

src/decorators/styler.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
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(
7+
uuid,
8+
customColors,
9+
type,
10+
hasBorder,
11+
padding
12+
) {
13+
return generateStyle(
14+
uuid,
15+
getPopupColors(customColors, type, hasBorder),
16+
padding
17+
);
818
}
919

1020
/**
1121
* Generates the tooltip style rules based on the element-specified "data-type" property.
1222
*/
13-
function generateStyle(uuid, colors) {
23+
function generateStyle(uuid, colors, padding = DEFAULT_PADDING) {
1424
const textColor = colors.text;
1525
const backgroundColor = colors.background;
1626
const borderColor = colors.border;
@@ -21,6 +31,7 @@ function generateStyle(uuid, colors) {
2131
color: ${textColor};
2232
background: ${backgroundColor};
2333
border: 1px solid ${borderColor};
34+
padding: ${padding};
2435
}
2536
2637
.${uuid}.place-top {

src/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class ReactTooltip extends React.Component {
4141
type: PropTypes.string,
4242
effect: PropTypes.string,
4343
offset: PropTypes.object,
44+
padding: PropTypes.string,
4445
multiline: PropTypes.bool,
4546
border: PropTypes.bool,
4647
textColor: PropTypes.string,
@@ -98,6 +99,7 @@ class ReactTooltip extends React.Component {
9899
border: false,
99100
customColors: {},
100101
offset: {},
102+
padding: props.padding,
101103
extraClass: '',
102104
html: false,
103105
delayHide: 0,
@@ -482,6 +484,7 @@ class ReactTooltip extends React.Component {
482484
},
483485
effect: effect,
484486
offset: offset,
487+
padding: target.getAttribute('data-padding') || self.props.padding,
485488
html:
486489
(target.getAttribute('data-html')
487490
? target.getAttribute('data-html') === 'true'
@@ -760,7 +763,8 @@ class ReactTooltip extends React.Component {
760763
this.state.uuid,
761764
this.state.customColors,
762765
this.state.type,
763-
this.state.border
766+
this.state.border,
767+
this.state.padding
764768
);
765769

766770
const tooltipClass =

src/index.scss

Lines changed: 0 additions & 1 deletion
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)