@pushwoosh/dumb-components 1.1.155 → 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.
- package/Tooltip/Tooltip.js +0 -1
- package/Tooltip/helpers.d.ts +4 -5
- package/Tooltip/helpers.js +13 -16
- package/Tooltip/maps.d.ts +0 -1
- package/Tooltip/maps.js +0 -14
- package/Tooltip/types.d.ts +2 -2
- package/Tooltip/useTooltipPosition.d.ts +5 -5
- package/Tooltip/useTooltipPosition.js +6 -6
- package/package.json +1 -1
package/Tooltip/Tooltip.js
CHANGED
package/Tooltip/helpers.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Resolve
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* when unbounded), so both forms used with the old tippy tooltip keep working.
|
|
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.
|
|
6
5
|
*/
|
|
7
|
-
export declare function
|
|
6
|
+
export declare function resolveArrowPadding(arrowOffset: number | string | undefined): number;
|
package/Tooltip/helpers.js
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
import { DEFAULT_ARROW_PADDING
|
|
1
|
+
import { DEFAULT_ARROW_PADDING } from './constants';
|
|
2
2
|
/**
|
|
3
|
-
* Resolve
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* when unbounded), so both forms used with the old tippy tooltip keep working.
|
|
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.
|
|
7
6
|
*/
|
|
8
|
-
export function
|
|
9
|
-
if (
|
|
10
|
-
return
|
|
7
|
+
export function resolveArrowPadding(arrowOffset) {
|
|
8
|
+
if (typeof arrowOffset === 'number') {
|
|
9
|
+
return arrowOffset;
|
|
11
10
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
if (typeof arrowOffset === 'string') {
|
|
12
|
+
const parsed = parseFloat(arrowOffset);
|
|
13
|
+
if (Number.isFinite(parsed)) {
|
|
14
|
+
return parsed;
|
|
15
|
+
}
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
-
const base = typeof maxWidth === 'number' ? maxWidth : DEFAULT_MAX_WIDTH;
|
|
18
|
-
return value / 100 * base;
|
|
19
|
-
}
|
|
20
|
-
return value;
|
|
17
|
+
return DEFAULT_ARROW_PADDING;
|
|
21
18
|
}
|
package/Tooltip/maps.d.ts
CHANGED
|
@@ -5,7 +5,6 @@ import { type TooltipTriggerView } from './TooltipTrigger';
|
|
|
5
5
|
import type { TooltipPosition } from './types';
|
|
6
6
|
export declare const TooltipPositionToFloatingPlacementMap: Record<TooltipPosition, Placement>;
|
|
7
7
|
export declare const TooltipPositionToOffsetMap: Record<TooltipPosition, [number, number]>;
|
|
8
|
-
export declare const TooltipPositionToArrowOffsetMap: Record<TooltipPosition, string>;
|
|
9
8
|
export declare const TooltipTriggerViewMap: Record<TooltipTriggerView, {
|
|
10
9
|
color: Color;
|
|
11
10
|
hoverColor: Color;
|
package/Tooltip/maps.js
CHANGED
|
@@ -28,20 +28,6 @@ export const TooltipPositionToOffsetMap = {
|
|
|
28
28
|
'left-middle': [0, 8],
|
|
29
29
|
'left-end': [6, 8]
|
|
30
30
|
};
|
|
31
|
-
export const TooltipPositionToArrowOffsetMap = {
|
|
32
|
-
'top-start': '24px',
|
|
33
|
-
'top-middle': '50%',
|
|
34
|
-
'top-end': '24px',
|
|
35
|
-
'right-start': '24px',
|
|
36
|
-
'right-middle': '50%',
|
|
37
|
-
'right-end': '24px',
|
|
38
|
-
'bottom-start': '24px',
|
|
39
|
-
'bottom-middle': '50%',
|
|
40
|
-
'bottom-end': '24px',
|
|
41
|
-
'left-start': '24px',
|
|
42
|
-
'left-middle': '50%',
|
|
43
|
-
'left-end': '24px'
|
|
44
|
-
};
|
|
45
31
|
export const TooltipTriggerViewMap = {
|
|
46
32
|
info: {
|
|
47
33
|
color: Color.LOCKED,
|
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
|
|
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. */
|
|
@@ -3,16 +3,16 @@ import type { TooltipPosition } from './types';
|
|
|
3
3
|
type Args = {
|
|
4
4
|
position: TooltipPosition;
|
|
5
5
|
offset?: [number, number] | undefined;
|
|
6
|
-
arrowOffset?: string | undefined;
|
|
7
|
-
maxWidth?: number | 'none' | undefined;
|
|
6
|
+
arrowOffset?: number | string | undefined;
|
|
8
7
|
isOpen: boolean;
|
|
9
8
|
};
|
|
10
9
|
/**
|
|
11
10
|
* Positions the tooltip relative to its anchor via floating-ui: `flip`/`shift` pick a
|
|
12
|
-
* fallback placement when the requested one overflows the viewport, and `arrow` keeps
|
|
13
|
-
*
|
|
11
|
+
* fallback placement when the requested one overflows the viewport, and `arrow` keeps the
|
|
12
|
+
* arrow pointing at the anchor's center. `arrowOffset` only sets the minimum gap (px) the
|
|
13
|
+
* arrow keeps from the tooltip corners. Repositions on scroll/resize while open.
|
|
14
14
|
*/
|
|
15
|
-
export declare function useTooltipPosition({ position, offset: offsetProp, arrowOffset,
|
|
15
|
+
export declare function useTooltipPosition({ position, offset: offsetProp, arrowOffset, isOpen, }: Args): {
|
|
16
16
|
refs: {
|
|
17
17
|
reference: import("react").MutableRefObject<import("@floating-ui/react-dom").ReferenceType | null>;
|
|
18
18
|
floating: React.MutableRefObject<HTMLElement | null>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { arrow, autoUpdate, flip, offset, shift, useFloating } from '@floating-ui/react-dom';
|
|
2
2
|
import { useRef } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { resolveArrowPadding } from './helpers';
|
|
4
|
+
import { TooltipPositionToFloatingPlacementMap, TooltipPositionToOffsetMap } from './maps';
|
|
5
5
|
const ArrowStaticSideMap = {
|
|
6
6
|
top: 'bottom',
|
|
7
7
|
right: 'left',
|
|
@@ -10,19 +10,19 @@ const ArrowStaticSideMap = {
|
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
12
|
* Positions the tooltip relative to its anchor via floating-ui: `flip`/`shift` pick a
|
|
13
|
-
* fallback placement when the requested one overflows the viewport, and `arrow` keeps
|
|
14
|
-
*
|
|
13
|
+
* fallback placement when the requested one overflows the viewport, and `arrow` keeps the
|
|
14
|
+
* arrow pointing at the anchor's center. `arrowOffset` only sets the minimum gap (px) the
|
|
15
|
+
* arrow keeps from the tooltip corners. Repositions on scroll/resize while open.
|
|
15
16
|
*/
|
|
16
17
|
export function useTooltipPosition({
|
|
17
18
|
position,
|
|
18
19
|
offset: offsetProp,
|
|
19
20
|
arrowOffset,
|
|
20
|
-
maxWidth,
|
|
21
21
|
isOpen
|
|
22
22
|
}) {
|
|
23
23
|
const arrowRef = useRef(null);
|
|
24
24
|
const [skidding, distance] = offsetProp ?? TooltipPositionToOffsetMap[position];
|
|
25
|
-
const arrowPadding =
|
|
25
|
+
const arrowPadding = resolveArrowPadding(arrowOffset);
|
|
26
26
|
const {
|
|
27
27
|
refs,
|
|
28
28
|
floatingStyles,
|