Skip to content

Commit 5d0eb7d

Browse files
committed
feat: add arrow size property
1 parent 9c448c3 commit 5d0eb7d

10 files changed

+26
-14
lines changed

src/components/Tooltip/Tooltip.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ const Tooltip = ({
6868
border,
6969
opacity,
7070
arrowColor,
71+
arrowSize = 8,
7172
role = 'tooltip',
7273
}: ITooltip) => {
7374
const tooltipRef = useRef<HTMLElement>(null)
@@ -345,6 +346,7 @@ const Tooltip = ({
345346
strategy: positionStrategy,
346347
middlewares,
347348
border,
349+
arrowSize,
348350
}).then((computedStylesData) => {
349351
handleComputedPosition(computedStylesData)
350352
})
@@ -437,6 +439,7 @@ const Tooltip = ({
437439
strategy: positionStrategy,
438440
middlewares,
439441
border,
442+
arrowSize,
440443
}).then((computedStylesData) => {
441444
if (!mounted.current) {
442445
// invalidate computed positions after remount
@@ -456,6 +459,7 @@ const Tooltip = ({
456459
position,
457460
imperativeOptions?.position,
458461
float,
462+
arrowSize,
459463
])
460464

461465
useEffect(() => {
@@ -899,6 +903,7 @@ const Tooltip = ({
899903
background: arrowColor
900904
? `linear-gradient(to right bottom, transparent 50%, ${arrowColor} 50%)`
901905
: undefined,
906+
'--rt-arrow-size': `${arrowSize}px`,
902907
}}
903908
ref={tooltipArrowRef}
904909
/>

src/components/Tooltip/TooltipTypes.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,5 +158,6 @@ export interface ITooltip {
158158
border?: CSSProperties['border']
159159
opacity?: CSSProperties['opacity']
160160
arrowColor?: CSSProperties['backgroundColor']
161+
arrowSize?: number
161162
role?: React.AriaRole
162163
}

src/components/Tooltip/core-styles.module.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
.arrow {
1515
position: absolute;
1616
background: inherit;
17+
z-index: -1;
1718
}
1819

1920
.noArrow {

src/components/Tooltip/styles.module.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
}
77

88
.arrow {
9-
width: 8px;
10-
height: 8px;
9+
width: var(--rt-arrow-size);
10+
height: var(--rt-arrow-size);
1111
}
1212

1313
[class*='react-tooltip__place-top'] > .arrow {

src/components/TooltipController/TooltipController.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const TooltipController = React.forwardRef<TooltipRefProps, ITooltipController>(
5858
border,
5959
opacity,
6060
arrowColor,
61+
arrowSize,
6162
setIsOpen,
6263
afterShow,
6364
afterHide,
@@ -368,6 +369,7 @@ const TooltipController = React.forwardRef<TooltipRefProps, ITooltipController>(
368369
border,
369370
opacity,
370371
arrowColor,
372+
arrowSize,
371373
setIsOpen,
372374
afterShow,
373375
afterHide,

src/components/TooltipController/TooltipControllerTypes.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export interface ITooltipController {
9191
border?: CSSProperties['border']
9292
opacity?: CSSProperties['opacity']
9393
arrowColor?: CSSProperties['backgroundColor']
94+
arrowSize?: number
9495
setIsOpen?: (value: boolean) => void
9596
afterShow?: () => void
9697
afterHide?: () => void

src/test/__snapshots__/tooltip-attributes.spec.js.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ exports[`tooltip attributes basic tooltip 1`] = `
1717
Hello World!
1818
<div
1919
class="react-tooltip-arrow"
20-
style="left: -1px; bottom: -4px;"
20+
style="--rt-arrow-size: 8px; left: -1px; bottom: -4px;"
2121
/>
2222
</div>
2323
</div>
@@ -41,7 +41,7 @@ exports[`tooltip attributes tooltip with class name 1`] = `
4141
Hello World!
4242
<div
4343
class="react-tooltip-arrow"
44-
style="left: -1px; bottom: -4px;"
44+
style="--rt-arrow-size: 8px; left: -1px; bottom: -4px;"
4545
/>
4646
</div>
4747
</div>
@@ -65,7 +65,7 @@ exports[`tooltip attributes tooltip with place 1`] = `
6565
Hello World!
6666
<div
6767
class="react-tooltip-arrow"
68-
style="left: -4px; top: -1px;"
68+
style="--rt-arrow-size: 8px; left: -4px; top: -1px;"
6969
/>
7070
</div>
7171
</div>

src/test/__snapshots__/tooltip-props.spec.js.snap

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ exports[`tooltip props basic tooltip 1`] = `
1616
Hello World!
1717
<div
1818
class="react-tooltip-arrow"
19-
style="left: -1px; bottom: -4px;"
19+
style="--rt-arrow-size: 8px; left: -1px; bottom: -4px;"
2020
/>
2121
</div>
2222
</div>
@@ -40,7 +40,7 @@ exports[`tooltip props clickable tooltip 1`] = `
4040
</button>
4141
<div
4242
class="react-tooltip-arrow"
43-
style="left: -1px; bottom: -4px;"
43+
style="--rt-arrow-size: 8px; left: -1px; bottom: -4px;"
4444
/>
4545
</div>
4646
</div>
@@ -62,7 +62,7 @@ exports[`tooltip props tooltip with custom position 1`] = `
6262
Hello World!
6363
<div
6464
class="react-tooltip-arrow"
65-
style="left: -1px; bottom: -4px;"
65+
style="--rt-arrow-size: 8px; left: -1px; bottom: -4px;"
6666
/>
6767
</div>
6868
</div>
@@ -94,7 +94,7 @@ exports[`tooltip props tooltip with delay show 1`] = `
9494
Hello World!
9595
<div
9696
class="react-tooltip-arrow"
97-
style="left: -1px; bottom: -4px;"
97+
style="--rt-arrow-size: 8px; left: -1px; bottom: -4px;"
9898
/>
9999
</div>
100100
</div>
@@ -116,7 +116,7 @@ exports[`tooltip props tooltip with disableTooltip return false 1`] = `
116116
Hello World!
117117
<div
118118
class="react-tooltip-arrow"
119-
style="left: -1px; bottom: -4px;"
119+
style="--rt-arrow-size: 8px; left: -1px; bottom: -4px;"
120120
/>
121121
</div>
122122
</div>
@@ -138,7 +138,7 @@ exports[`tooltip props tooltip with float 1`] = `
138138
Hello World!
139139
<div
140140
class="react-tooltip-arrow"
141-
style="left: -1px; bottom: -4px;"
141+
style="--rt-arrow-size: 8px; left: -1px; bottom: -4px;"
142142
/>
143143
</div>
144144
</div>
@@ -165,7 +165,7 @@ exports[`tooltip props tooltip with html 1`] = `
165165
</span>
166166
<div
167167
class="react-tooltip-arrow"
168-
style="left: -1px; bottom: -4px;"
168+
style="--rt-arrow-size: 8px; left: -1px; bottom: -4px;"
169169
/>
170170
</div>
171171
</div>
@@ -187,7 +187,7 @@ exports[`tooltip props tooltip with place 1`] = `
187187
Hello World!
188188
<div
189189
class="react-tooltip-arrow"
190-
style="left: -4px; top: -1px;"
190+
style="--rt-arrow-size: 8px; left: -4px; top: -1px;"
191191
/>
192192
</div>
193193
</div>

src/utils/compute-tooltip-position-types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface IComputePositionArgs {
1010
strategy?: 'absolute' | 'fixed'
1111
middlewares?: Middleware[]
1212
border?: CSSProperties['border']
13+
arrowSize?: number
1314
}
1415

1516
export interface IComputedPosition {

src/utils/compute-tooltip-position.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const computeTooltipPosition = async ({
1616
shift({ padding: 5 }),
1717
],
1818
border,
19+
arrowSize = 8,
1920
}: IComputePositionArgs) => {
2021
if (!elementReference) {
2122
// elementReference can be null or undefined and we will not compute the position
@@ -78,7 +79,7 @@ const computeTooltipPosition = async ({
7879
right: '',
7980
bottom: '',
8081
...borderSide,
81-
[staticSide]: `-${4 + borderWidth}px`,
82+
[staticSide]: `-${arrowSize / 2 + borderWidth}px`,
8283
}
8384
/* c8 ignore end */
8485

0 commit comments

Comments
 (0)