@pushwoosh/dumb-components 1.1.156 → 1.1.157
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve `arrowOffset` to a px gap. Accepts a number, or a numeric string like `'20px'`
|
|
3
|
+
* (only the leading number is used, the unit is ignored); anything unparseable falls back
|
|
4
|
+
* to the default.
|
|
5
|
+
*/
|
|
6
|
+
export declare function resolveArrowPadding(arrowOffset: number | string | undefined): number;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DEFAULT_ARROW_PADDING } from './constants';
|
|
2
|
+
/**
|
|
3
|
+
* Resolve `arrowOffset` to a px gap. Accepts a number, or a numeric string like `'20px'`
|
|
4
|
+
* (only the leading number is used, the unit is ignored); anything unparseable falls back
|
|
5
|
+
* to the default.
|
|
6
|
+
*/
|
|
7
|
+
export function resolveArrowPadding(arrowOffset) {
|
|
8
|
+
if (typeof arrowOffset === 'number') {
|
|
9
|
+
return arrowOffset;
|
|
10
|
+
}
|
|
11
|
+
if (typeof arrowOffset === 'string') {
|
|
12
|
+
const parsed = parseFloat(arrowOffset);
|
|
13
|
+
if (Number.isFinite(parsed)) {
|
|
14
|
+
return parsed;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return DEFAULT_ARROW_PADDING;
|
|
18
|
+
}
|
package/Tooltip/types.d.ts
CHANGED
|
@@ -9,8 +9,8 @@ export type TooltipProps = {
|
|
|
9
9
|
readonly position?: TooltipPosition;
|
|
10
10
|
/** `[skidding, distance]` offset from the anchor; defaults per position. */
|
|
11
11
|
readonly offset?: [number, number];
|
|
12
|
-
/** Min gap
|
|
13
|
-
readonly arrowOffset?: string;
|
|
12
|
+
/** Min gap the arrow keeps from tooltip corners: a number or numeric string like `'20px'` — unit ignored, treated as px (default `12`). */
|
|
13
|
+
readonly arrowOffset?: number | string;
|
|
14
14
|
/** Max width in pixels, or `'none'` (default `240`). */
|
|
15
15
|
readonly maxWidth?: number | 'none';
|
|
16
16
|
/** Stacking z-index. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { arrow, autoUpdate, flip, offset, shift, useFloating } from '@floating-ui/react-dom';
|
|
2
2
|
import { useRef } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { resolveArrowPadding } from './helpers';
|
|
4
4
|
import { TooltipPositionToFloatingPlacementMap, TooltipPositionToOffsetMap } from './maps';
|
|
5
5
|
const ArrowStaticSideMap = {
|
|
6
6
|
top: 'bottom',
|
|
@@ -22,8 +22,7 @@ export function useTooltipPosition({
|
|
|
22
22
|
}) {
|
|
23
23
|
const arrowRef = useRef(null);
|
|
24
24
|
const [skidding, distance] = offsetProp ?? TooltipPositionToOffsetMap[position];
|
|
25
|
-
const
|
|
26
|
-
const arrowPadding = Number.isFinite(parsedPadding) ? parsedPadding : DEFAULT_ARROW_PADDING;
|
|
25
|
+
const arrowPadding = resolveArrowPadding(arrowOffset);
|
|
27
26
|
const {
|
|
28
27
|
refs,
|
|
29
28
|
floatingStyles,
|