@akinon/ui-tooltip 0.3.0 → 0.5.0

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.
@@ -1,5 +1,5 @@
1
- import type { TooltipProps as AntTooltipProps } from 'antd';
2
1
  import * as React from 'react';
3
- export type TooltipProps = AntTooltipProps;
2
+ import type { TooltipProps } from './types';
3
+ export type { TooltipProps } from './types';
4
4
  export declare const Tooltip: ({ children, ...restTooltipProps }: TooltipProps) => React.JSX.Element;
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,IAAI,eAAe,EAAE,MAAM,MAAM,CAAC;AAE5D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,MAAM,MAAM,YAAY,GAAG,eAAe,CAAC;AAE3C,eAAO,MAAM,OAAO,sCAAuC,YAAY,sBAMtE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,eAAO,MAAM,OAAO,sCAAuC,YAAY,sBAgCtE,CAAC"}
package/dist/cjs/index.js CHANGED
@@ -12,10 +12,28 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.Tooltip = void 0;
15
+ const ui_theme_1 = require("@akinon/ui-theme");
16
+ const cssinjs_1 = require("@ant-design/cssinjs");
15
17
  const antd_1 = require("antd");
16
18
  const React = require("react");
17
19
  const Tooltip = (_a) => {
18
20
  var { children } = _a, restTooltipProps = __rest(_a, ["children"]);
19
- return (React.createElement(antd_1.Tooltip, Object.assign({}, restTooltipProps), children));
21
+ const { getPrefixCls, theme } = React.useContext(antd_1.ConfigProvider.ConfigContext);
22
+ const { token, hashId } = (0, ui_theme_1.useToken)();
23
+ const tooltipToken = token.Tooltip;
24
+ const useStyle = (0, cssinjs_1.useStyleRegister)({
25
+ token: token,
26
+ path: ['Tooltip'],
27
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
+ theme: theme
29
+ }, () => {
30
+ const prefixCls = `:where(.${hashId}).${getPrefixCls()}-tooltip`;
31
+ const prefixClsWithoutHash = `.${getPrefixCls()}-tooltip`;
32
+ return {
33
+ [prefixCls]: {},
34
+ [prefixClsWithoutHash]: {}
35
+ };
36
+ });
37
+ return useStyle(React.createElement(antd_1.Tooltip, Object.assign({ color: tooltipToken.bgColor }, restTooltipProps), children));
20
38
  };
21
39
  exports.Tooltip = Tooltip;
@@ -0,0 +1,466 @@
1
+ export type TooltipProps = Omit<
2
+ AntTooltipProps,
3
+ | 'prefixCls'
4
+ | 'style'
5
+ | 'styles'
6
+ | 'id'
7
+ | 'builtinPlacements'
8
+ | 'showArrow'
9
+ | 'onPopupAlign'
10
+ | 'overlay'
11
+ | 'getTooltipContainer'
12
+ | 'arrowContent'
13
+ | 'motion'
14
+ >;
15
+
16
+ interface AdjustOverflow {
17
+ adjustX?: 0 | 1;
18
+ adjustY?: 0 | 1;
19
+ }
20
+
21
+ interface PlacementsConfig {
22
+ arrowWidth: number;
23
+ arrowPointAtCenter?: boolean;
24
+ autoAdjustOverflow?: boolean | AdjustOverflow;
25
+ offset: number;
26
+ borderRadius: number;
27
+ visibleFirst?: boolean;
28
+ }
29
+
30
+ type LiteralUnion<T extends string> = T | (string & {});
31
+
32
+ type RenderFunction = () => React.ReactNode;
33
+
34
+ interface TooltipPropsWithOverlay extends AbstractTooltipProps {
35
+ /**
36
+ * The text shown in the tooltip
37
+ */
38
+ title?: React.ReactNode | RenderFunction;
39
+ //overlay?: React.ReactNode | RenderFunction;
40
+ }
41
+
42
+ interface TooltipPropsWithTitle extends AbstractTooltipProps {
43
+ /**
44
+ * The text shown in the tooltip
45
+ */
46
+ title: React.ReactNode | RenderFunction;
47
+ //overlay?: React.ReactNode | RenderFunction;
48
+ }
49
+
50
+ export declare type AntTooltipProps =
51
+ | TooltipPropsWithTitle
52
+ | TooltipPropsWithOverlay;
53
+
54
+ type PurePanelProps = Omit<TooltipProps, 'children'>;
55
+
56
+ declare const PurePanel: React.FC<PurePanelProps>;
57
+
58
+ declare const PresetColors: readonly [
59
+ 'blue',
60
+ 'purple',
61
+ 'cyan',
62
+ 'green',
63
+ 'magenta',
64
+ 'pink',
65
+ 'red',
66
+ 'orange',
67
+ 'yellow',
68
+ 'volcano',
69
+ 'geekblue',
70
+ 'lime',
71
+ 'gold'
72
+ ];
73
+
74
+ type PresetColorKey = (typeof PresetColors)[number];
75
+
76
+ type InverseColor = `${PresetColorKey}-inverse`;
77
+
78
+ type PresetColorType = PresetColorKey | InverseColor;
79
+
80
+ export type { AdjustOverflow, PlacementsConfig };
81
+
82
+ export interface TooltipRef {
83
+ forceAlign: VoidFunction;
84
+ }
85
+
86
+ export type TooltipPlacement =
87
+ | 'top'
88
+ | 'left'
89
+ | 'right'
90
+ | 'bottom'
91
+ | 'topLeft'
92
+ | 'topRight'
93
+ | 'bottomLeft'
94
+ | 'bottomRight'
95
+ | 'leftTop'
96
+ | 'leftBottom'
97
+ | 'rightTop'
98
+ | 'rightBottom';
99
+
100
+ export interface TooltipAlignConfig {
101
+ points?: [string, string];
102
+ offset?: [number | string, number | string];
103
+ targetOffset?: [number | string, number | string];
104
+ overflow?: {
105
+ adjustX: boolean;
106
+ adjustY: boolean;
107
+ };
108
+ useCssRight?: boolean;
109
+ useCssBottom?: boolean;
110
+ useCssTransform?: boolean;
111
+ }
112
+
113
+ interface LegacyTooltipProps
114
+ extends Partial<
115
+ Omit<
116
+ RcTooltipProps,
117
+ | 'children'
118
+ | 'visible'
119
+ | 'defaultVisible'
120
+ | 'onVisibleChange'
121
+ | 'afterVisibleChange'
122
+ | 'destroyTooltipOnHide'
123
+ >
124
+ > {
125
+ /**
126
+ * Whether the floating tooltip card is open or not
127
+ */
128
+ open?: RcTooltipProps['visible'];
129
+ /**
130
+ * Whether the floating tooltip card is open by default
131
+ */
132
+ defaultOpen?: boolean;
133
+ /**
134
+ * Callback executed when visibility of the tooltip card is changed
135
+ */
136
+ onOpenChange?: (open: boolean) => void;
137
+ //afterOpenChange?: RcTooltipProps['afterVisibleChange'];
138
+ }
139
+
140
+ export interface AbstractTooltipProps extends LegacyTooltipProps {
141
+ style?: React.CSSProperties;
142
+ /**
143
+ * The additional css class
144
+ */
145
+ className?: string;
146
+ /**
147
+ * ClassName on the root element
148
+ */
149
+ rootClassName?: string;
150
+ /**
151
+ * The background color
152
+ */
153
+ color?: string;
154
+ /**
155
+ * The position of the tooltip relative to the target
156
+ */
157
+ placement?: TooltipPlacement;
158
+ //builtinPlacements?: typeof Placements;
159
+ //openClassName?: string;
160
+ /**
161
+ * Change arrow's visible state and change whether the arrow is pointed at the center of target
162
+ */
163
+ arrow?: boolean;
164
+ /**
165
+ * Whether to adjust popup placement automatically when popup is off screen
166
+ */
167
+ autoAdjustOverflow?: boolean;
168
+ /**
169
+ * The DOM container of the tip, the default behavior is to create a div element in body
170
+ */
171
+ getPopupContainer?: (triggerNode: HTMLElement) => HTMLElement;
172
+ children?: React.ReactNode;
173
+ /**
174
+ * Whether destroy tooltip when hidden
175
+ */
176
+ destroyTooltipOnHide?: boolean;
177
+ }
178
+
179
+ export interface TooltipPropsWithOverlay extends AbstractTooltipProps {
180
+ title?: React.ReactNode | RenderFunction;
181
+ overlay?: React.ReactNode | RenderFunction;
182
+ }
183
+
184
+ export interface TooltipPropsWithTitle extends AbstractTooltipProps {
185
+ title: React.ReactNode | RenderFunction;
186
+ overlay?: React.ReactNode | RenderFunction;
187
+ }
188
+
189
+ export declare type TooltipProps =
190
+ | TooltipPropsWithTitle
191
+ | TooltipPropsWithOverlay;
192
+
193
+ declare const InternalTooltip: React.ForwardRefExoticComponent<
194
+ TooltipProps & React.RefAttributes<TooltipRef>
195
+ >;
196
+
197
+ type ActionType = 'hover' | 'focus' | 'click' | 'contextMenu';
198
+
199
+ interface RcTooltipProps
200
+ extends Pick<
201
+ TriggerProps,
202
+ | 'onPopupAlign'
203
+ | 'builtinPlacements'
204
+ | 'fresh'
205
+ | 'children'
206
+ | 'mouseLeaveDelay'
207
+ | 'mouseEnterDelay'
208
+ | 'prefixCls'
209
+ | 'forceRender'
210
+ > {
211
+ /**
212
+ * Tooltip trigger mode. Could be multiple by passing an array
213
+ */
214
+ trigger?: ActionType | ActionType[];
215
+ defaultVisible?: boolean;
216
+ visible?: boolean;
217
+ placement?: string;
218
+ /** Config popup motion */
219
+ motion?: TriggerProps['popupMotion'];
220
+ onVisibleChange?: (visible: boolean) => void;
221
+ afterVisibleChange?: (visible: boolean) => void;
222
+ overlay: (() => React.ReactNode) | React.ReactNode;
223
+ /**
224
+ * Style of the tooltip card
225
+ */
226
+ overlayStyle?: React.CSSProperties;
227
+ /**
228
+ * Class name of the tooltip card
229
+ */
230
+ overlayClassName?: string;
231
+ getTooltipContainer?: (node: HTMLElement) => HTMLElement;
232
+ destroyTooltipOnHide?: boolean;
233
+ /**
234
+ * This value will be merged into placement's config, please refer to the settings <a href="https://github.com/yiminghe/dom-align" target="_blank">dom-align</a>
235
+ */
236
+ align?: AlignType;
237
+ showArrow?: boolean | ArrowType;
238
+ arrowContent?: React.ReactNode;
239
+ id?: string;
240
+ /**
241
+ * Style of the tooltip inner content
242
+ */
243
+ overlayInnerStyle?: React.CSSProperties;
244
+ /**
245
+ * Config z-index of Tooltip
246
+ */
247
+ zIndex?: number;
248
+ }
249
+
250
+ interface ArrowType {
251
+ className?: string;
252
+ content?: React.ReactNode;
253
+ }
254
+
255
+ interface TooltipRef {
256
+ nativeElement: HTMLElement;
257
+ forceAlign: VoidFunction;
258
+ }
259
+
260
+ type TransitionNameType = string;
261
+
262
+ type AnimationType = string;
263
+
264
+ type BuildInPlacements = Record<string, AlignType>;
265
+
266
+ type StretchType = string;
267
+
268
+ type ActionType = 'hover' | 'focus' | 'click' | 'contextMenu';
269
+
270
+ interface TriggerProps {
271
+ children: React.ReactElement;
272
+ action?: ActionType | ActionType[];
273
+ showAction?: ActionType[];
274
+ hideAction?: ActionType[];
275
+ prefixCls?: string;
276
+ zIndex?: number;
277
+ onPopupAlign?: (element: HTMLElement, align: AlignType) => void;
278
+ stretch?: string;
279
+ popupVisible?: boolean;
280
+ defaultPopupVisible?: boolean;
281
+ onPopupVisibleChange?: (visible: boolean) => void;
282
+ afterPopupVisibleChange?: (visible: boolean) => void;
283
+ getPopupContainer?: (node: HTMLElement) => HTMLElement;
284
+ forceRender?: boolean;
285
+ autoDestroy?: boolean;
286
+ mask?: boolean;
287
+ maskClosable?: boolean;
288
+ /** Set popup motion. You can ref `rc-motion` for more info. */
289
+ popupMotion?: CSSMotionProps;
290
+ /** Set mask motion. You can ref `rc-motion` for more info. */
291
+ maskMotion?: CSSMotionProps;
292
+ /**
293
+ * Delay in seconds, before tooltip is shown on mouse enter
294
+ */
295
+ mouseEnterDelay?: number;
296
+ /**
297
+ * Delay in seconds, before tooltip is hidden on mouse leave
298
+ */
299
+ mouseLeaveDelay?: number;
300
+ focusDelay?: number;
301
+ blurDelay?: number;
302
+ popup: React.ReactNode | (() => React.ReactNode);
303
+ popupPlacement?: string;
304
+ builtinPlacements?: BuildInPlacements;
305
+ popupAlign?: AlignType;
306
+ popupClassName?: string;
307
+ popupStyle?: React.CSSProperties;
308
+ getPopupClassNameFromAlign?: (align: AlignType) => string;
309
+ onPopupClick?: React.MouseEventHandler<HTMLDivElement>;
310
+ alignPoint?: boolean;
311
+ /**
312
+ * Trigger will memo content when close.
313
+ * This may affect the case if want to keep content update.
314
+ * Set `fresh` to `false` will always keep update.
315
+ */
316
+ fresh?: boolean;
317
+ arrow?: boolean | ArrowTypeOuter;
318
+ }
319
+
320
+ interface ArrowTypeOuter {
321
+ className?: string;
322
+ content?: React.ReactNode;
323
+ }
324
+
325
+ type MotionName =
326
+ | string
327
+ | {
328
+ appear?: string;
329
+ enter?: string;
330
+ leave?: string;
331
+ appearActive?: string;
332
+ enterActive?: string;
333
+ leaveActive?: string;
334
+ };
335
+
336
+ interface CSSMotionProps {
337
+ motionName?: MotionName;
338
+ visible?: boolean;
339
+ motionAppear?: boolean;
340
+ motionEnter?: boolean;
341
+ motionLeave?: boolean;
342
+ motionLeaveImmediately?: boolean;
343
+ motionDeadline?: number;
344
+ /**
345
+ * Create element in view even the element is invisible.
346
+ * Will patch `display: none` style on it.
347
+ */
348
+ forceRender?: boolean;
349
+ /**
350
+ * Remove element when motion end. This will not work when `forceRender` is set.
351
+ */
352
+ removeOnLeave?: boolean;
353
+ leavedClassName?: string;
354
+ /** Prepare phase is used for measure element info. It will always trigger even motion is off */
355
+ onAppearPrepare?: MotionPrepareEventHandler;
356
+ /** Prepare phase is used for measure element info. It will always trigger even motion is off */
357
+ onEnterPrepare?: MotionPrepareEventHandler;
358
+ /** Prepare phase is used for measure element info. It will always trigger even motion is off */
359
+ onLeavePrepare?: MotionPrepareEventHandler;
360
+ onAppearStart?: MotionEventHandler;
361
+ onEnterStart?: MotionEventHandler;
362
+ onLeaveStart?: MotionEventHandler;
363
+ onAppearActive?: MotionEventHandler;
364
+ onEnterActive?: MotionEventHandler;
365
+ onLeaveActive?: MotionEventHandler;
366
+ onAppearEnd?: MotionEndEventHandler;
367
+ onEnterEnd?: MotionEndEventHandler;
368
+ onLeaveEnd?: MotionEndEventHandler;
369
+ /** This will always trigger after final visible changed. Even if no motion configured. */
370
+ onVisibleChanged?: (visible: boolean) => void;
371
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
372
+ internalRef?: React.Ref<any>;
373
+ children?: (
374
+ props: {
375
+ visible?: boolean;
376
+ className?: string;
377
+ style?: React.CSSProperties;
378
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
379
+ [key: string]: any;
380
+ },
381
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
382
+ ref: (node: any) => void
383
+ ) => React.ReactElement;
384
+ }
385
+
386
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
387
+ type MotionPrepareEventHandler = (element: HTMLElement) => Promise<any> | void;
388
+
389
+ type MotionEventHandler = (
390
+ element: HTMLElement,
391
+ event: MotionEvent
392
+ ) => React.CSSProperties | void;
393
+
394
+ type MotionEndEventHandler = (
395
+ element: HTMLElement,
396
+ event: MotionEvent
397
+ ) => boolean | void;
398
+
399
+ type OffsetType = number | `${number}%`;
400
+
401
+ type AlignPointTopBottom = 't' | 'b' | 'c';
402
+
403
+ type AlignPointLeftRight = 'l' | 'r' | 'c';
404
+
405
+ type AlignPoint = `${AlignPointTopBottom}${AlignPointLeftRight}`;
406
+
407
+ interface AlignType {
408
+ /**
409
+ * move point of source node to align with point of target node.
410
+ * Such as ['tr','cc'], align top right point of source node with center point of target node.
411
+ * Point can be 't'(top), 'b'(bottom), 'c'(center), 'l'(left), 'r'(right) */
412
+ points?: (string | AlignPoint)[];
413
+ /**
414
+ * offset source node by offset[0] in x and offset[1] in y.
415
+ * If offset contains percentage string value, it is relative to sourceNode region.
416
+ */
417
+ offset?: OffsetType[];
418
+ /**
419
+ * offset target node by offset[0] in x and offset[1] in y.
420
+ * If targetOffset contains percentage string value, it is relative to targetNode region.
421
+ */
422
+ targetOffset?: OffsetType[];
423
+ /**
424
+ * If adjustX field is true, will adjust source node in x direction if source node is invisible.
425
+ * If adjustY field is true, will adjust source node in y direction if source node is invisible.
426
+ */
427
+ overflow?: {
428
+ adjustX?: boolean | number;
429
+ adjustY?: boolean | number;
430
+ shiftX?: boolean | number;
431
+ shiftY?: boolean | number;
432
+ };
433
+ /** Auto adjust arrow position */
434
+ autoArrow?: boolean;
435
+ /**
436
+ * Config visible region check of html node. Default `visible`:
437
+ * - `visible`:
438
+ * The visible region of user browser window.
439
+ * Use `clientHeight` for check.
440
+ * If `visible` region not satisfy, fallback to `scroll`.
441
+ * - `scroll`:
442
+ * The whole region of the html scroll area.
443
+ * Use `scrollHeight` for check.
444
+ * - `visibleFirst`:
445
+ * Similar to `visible`, but if `visible` region not satisfy, fallback to `scroll`.
446
+ */
447
+ htmlRegion?: 'visible' | 'scroll' | 'visibleFirst';
448
+ /**
449
+ * Auto chose position with `top` or `bottom` by the align result
450
+ */
451
+ dynamicInset?: boolean;
452
+ /**
453
+ * Whether use css right instead of left to position
454
+ */
455
+ useCssRight?: boolean;
456
+ /**
457
+ * Whether use css bottom instead of top to position
458
+ */
459
+ useCssBottom?: boolean;
460
+ /**
461
+ * Whether use css transform instead of left/top/right/bottom to position if browser supports.
462
+ * Defaults to false.
463
+ */
464
+ useCssTransform?: boolean;
465
+ ignoreShake?: boolean;
466
+ }
@@ -1,5 +1,5 @@
1
- import type { TooltipProps as AntTooltipProps } from 'antd';
2
1
  import * as React from 'react';
3
- export type TooltipProps = AntTooltipProps;
2
+ import type { TooltipProps } from './types';
3
+ export type { TooltipProps } from './types';
4
4
  export declare const Tooltip: ({ children, ...restTooltipProps }: TooltipProps) => React.JSX.Element;
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,IAAI,eAAe,EAAE,MAAM,MAAM,CAAC;AAE5D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,MAAM,MAAM,YAAY,GAAG,eAAe,CAAC;AAE3C,eAAO,MAAM,OAAO,sCAAuC,YAAY,sBAMtE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,eAAO,MAAM,OAAO,sCAAuC,YAAY,sBAgCtE,CAAC"}
package/dist/esm/index.js CHANGED
@@ -9,9 +9,27 @@ var __rest = (this && this.__rest) || function (s, e) {
9
9
  }
10
10
  return t;
11
11
  };
12
- import { Tooltip as AntTooltip } from 'antd';
12
+ import { useToken } from '@akinon/ui-theme';
13
+ import { useStyleRegister } from '@ant-design/cssinjs';
14
+ import { ConfigProvider, Tooltip as AntTooltip } from 'antd';
13
15
  import * as React from 'react';
14
16
  export const Tooltip = (_a) => {
15
17
  var { children } = _a, restTooltipProps = __rest(_a, ["children"]);
16
- return (React.createElement(AntTooltip, Object.assign({}, restTooltipProps), children));
18
+ const { getPrefixCls, theme } = React.useContext(ConfigProvider.ConfigContext);
19
+ const { token, hashId } = useToken();
20
+ const tooltipToken = token.Tooltip;
21
+ const useStyle = useStyleRegister({
22
+ token: token,
23
+ path: ['Tooltip'],
24
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
+ theme: theme
26
+ }, () => {
27
+ const prefixCls = `:where(.${hashId}).${getPrefixCls()}-tooltip`;
28
+ const prefixClsWithoutHash = `.${getPrefixCls()}-tooltip`;
29
+ return {
30
+ [prefixCls]: {},
31
+ [prefixClsWithoutHash]: {}
32
+ };
33
+ });
34
+ return useStyle(React.createElement(AntTooltip, Object.assign({ color: tooltipToken.bgColor }, restTooltipProps), children));
17
35
  };
@@ -0,0 +1,466 @@
1
+ export type TooltipProps = Omit<
2
+ AntTooltipProps,
3
+ | 'prefixCls'
4
+ | 'style'
5
+ | 'styles'
6
+ | 'id'
7
+ | 'builtinPlacements'
8
+ | 'showArrow'
9
+ | 'onPopupAlign'
10
+ | 'overlay'
11
+ | 'getTooltipContainer'
12
+ | 'arrowContent'
13
+ | 'motion'
14
+ >;
15
+
16
+ interface AdjustOverflow {
17
+ adjustX?: 0 | 1;
18
+ adjustY?: 0 | 1;
19
+ }
20
+
21
+ interface PlacementsConfig {
22
+ arrowWidth: number;
23
+ arrowPointAtCenter?: boolean;
24
+ autoAdjustOverflow?: boolean | AdjustOverflow;
25
+ offset: number;
26
+ borderRadius: number;
27
+ visibleFirst?: boolean;
28
+ }
29
+
30
+ type LiteralUnion<T extends string> = T | (string & {});
31
+
32
+ type RenderFunction = () => React.ReactNode;
33
+
34
+ interface TooltipPropsWithOverlay extends AbstractTooltipProps {
35
+ /**
36
+ * The text shown in the tooltip
37
+ */
38
+ title?: React.ReactNode | RenderFunction;
39
+ //overlay?: React.ReactNode | RenderFunction;
40
+ }
41
+
42
+ interface TooltipPropsWithTitle extends AbstractTooltipProps {
43
+ /**
44
+ * The text shown in the tooltip
45
+ */
46
+ title: React.ReactNode | RenderFunction;
47
+ //overlay?: React.ReactNode | RenderFunction;
48
+ }
49
+
50
+ export declare type AntTooltipProps =
51
+ | TooltipPropsWithTitle
52
+ | TooltipPropsWithOverlay;
53
+
54
+ type PurePanelProps = Omit<TooltipProps, 'children'>;
55
+
56
+ declare const PurePanel: React.FC<PurePanelProps>;
57
+
58
+ declare const PresetColors: readonly [
59
+ 'blue',
60
+ 'purple',
61
+ 'cyan',
62
+ 'green',
63
+ 'magenta',
64
+ 'pink',
65
+ 'red',
66
+ 'orange',
67
+ 'yellow',
68
+ 'volcano',
69
+ 'geekblue',
70
+ 'lime',
71
+ 'gold'
72
+ ];
73
+
74
+ type PresetColorKey = (typeof PresetColors)[number];
75
+
76
+ type InverseColor = `${PresetColorKey}-inverse`;
77
+
78
+ type PresetColorType = PresetColorKey | InverseColor;
79
+
80
+ export type { AdjustOverflow, PlacementsConfig };
81
+
82
+ export interface TooltipRef {
83
+ forceAlign: VoidFunction;
84
+ }
85
+
86
+ export type TooltipPlacement =
87
+ | 'top'
88
+ | 'left'
89
+ | 'right'
90
+ | 'bottom'
91
+ | 'topLeft'
92
+ | 'topRight'
93
+ | 'bottomLeft'
94
+ | 'bottomRight'
95
+ | 'leftTop'
96
+ | 'leftBottom'
97
+ | 'rightTop'
98
+ | 'rightBottom';
99
+
100
+ export interface TooltipAlignConfig {
101
+ points?: [string, string];
102
+ offset?: [number | string, number | string];
103
+ targetOffset?: [number | string, number | string];
104
+ overflow?: {
105
+ adjustX: boolean;
106
+ adjustY: boolean;
107
+ };
108
+ useCssRight?: boolean;
109
+ useCssBottom?: boolean;
110
+ useCssTransform?: boolean;
111
+ }
112
+
113
+ interface LegacyTooltipProps
114
+ extends Partial<
115
+ Omit<
116
+ RcTooltipProps,
117
+ | 'children'
118
+ | 'visible'
119
+ | 'defaultVisible'
120
+ | 'onVisibleChange'
121
+ | 'afterVisibleChange'
122
+ | 'destroyTooltipOnHide'
123
+ >
124
+ > {
125
+ /**
126
+ * Whether the floating tooltip card is open or not
127
+ */
128
+ open?: RcTooltipProps['visible'];
129
+ /**
130
+ * Whether the floating tooltip card is open by default
131
+ */
132
+ defaultOpen?: boolean;
133
+ /**
134
+ * Callback executed when visibility of the tooltip card is changed
135
+ */
136
+ onOpenChange?: (open: boolean) => void;
137
+ //afterOpenChange?: RcTooltipProps['afterVisibleChange'];
138
+ }
139
+
140
+ export interface AbstractTooltipProps extends LegacyTooltipProps {
141
+ style?: React.CSSProperties;
142
+ /**
143
+ * The additional css class
144
+ */
145
+ className?: string;
146
+ /**
147
+ * ClassName on the root element
148
+ */
149
+ rootClassName?: string;
150
+ /**
151
+ * The background color
152
+ */
153
+ color?: string;
154
+ /**
155
+ * The position of the tooltip relative to the target
156
+ */
157
+ placement?: TooltipPlacement;
158
+ //builtinPlacements?: typeof Placements;
159
+ //openClassName?: string;
160
+ /**
161
+ * Change arrow's visible state and change whether the arrow is pointed at the center of target
162
+ */
163
+ arrow?: boolean;
164
+ /**
165
+ * Whether to adjust popup placement automatically when popup is off screen
166
+ */
167
+ autoAdjustOverflow?: boolean;
168
+ /**
169
+ * The DOM container of the tip, the default behavior is to create a div element in body
170
+ */
171
+ getPopupContainer?: (triggerNode: HTMLElement) => HTMLElement;
172
+ children?: React.ReactNode;
173
+ /**
174
+ * Whether destroy tooltip when hidden
175
+ */
176
+ destroyTooltipOnHide?: boolean;
177
+ }
178
+
179
+ export interface TooltipPropsWithOverlay extends AbstractTooltipProps {
180
+ title?: React.ReactNode | RenderFunction;
181
+ overlay?: React.ReactNode | RenderFunction;
182
+ }
183
+
184
+ export interface TooltipPropsWithTitle extends AbstractTooltipProps {
185
+ title: React.ReactNode | RenderFunction;
186
+ overlay?: React.ReactNode | RenderFunction;
187
+ }
188
+
189
+ export declare type TooltipProps =
190
+ | TooltipPropsWithTitle
191
+ | TooltipPropsWithOverlay;
192
+
193
+ declare const InternalTooltip: React.ForwardRefExoticComponent<
194
+ TooltipProps & React.RefAttributes<TooltipRef>
195
+ >;
196
+
197
+ type ActionType = 'hover' | 'focus' | 'click' | 'contextMenu';
198
+
199
+ interface RcTooltipProps
200
+ extends Pick<
201
+ TriggerProps,
202
+ | 'onPopupAlign'
203
+ | 'builtinPlacements'
204
+ | 'fresh'
205
+ | 'children'
206
+ | 'mouseLeaveDelay'
207
+ | 'mouseEnterDelay'
208
+ | 'prefixCls'
209
+ | 'forceRender'
210
+ > {
211
+ /**
212
+ * Tooltip trigger mode. Could be multiple by passing an array
213
+ */
214
+ trigger?: ActionType | ActionType[];
215
+ defaultVisible?: boolean;
216
+ visible?: boolean;
217
+ placement?: string;
218
+ /** Config popup motion */
219
+ motion?: TriggerProps['popupMotion'];
220
+ onVisibleChange?: (visible: boolean) => void;
221
+ afterVisibleChange?: (visible: boolean) => void;
222
+ overlay: (() => React.ReactNode) | React.ReactNode;
223
+ /**
224
+ * Style of the tooltip card
225
+ */
226
+ overlayStyle?: React.CSSProperties;
227
+ /**
228
+ * Class name of the tooltip card
229
+ */
230
+ overlayClassName?: string;
231
+ getTooltipContainer?: (node: HTMLElement) => HTMLElement;
232
+ destroyTooltipOnHide?: boolean;
233
+ /**
234
+ * This value will be merged into placement's config, please refer to the settings <a href="https://github.com/yiminghe/dom-align" target="_blank">dom-align</a>
235
+ */
236
+ align?: AlignType;
237
+ showArrow?: boolean | ArrowType;
238
+ arrowContent?: React.ReactNode;
239
+ id?: string;
240
+ /**
241
+ * Style of the tooltip inner content
242
+ */
243
+ overlayInnerStyle?: React.CSSProperties;
244
+ /**
245
+ * Config z-index of Tooltip
246
+ */
247
+ zIndex?: number;
248
+ }
249
+
250
+ interface ArrowType {
251
+ className?: string;
252
+ content?: React.ReactNode;
253
+ }
254
+
255
+ interface TooltipRef {
256
+ nativeElement: HTMLElement;
257
+ forceAlign: VoidFunction;
258
+ }
259
+
260
+ type TransitionNameType = string;
261
+
262
+ type AnimationType = string;
263
+
264
+ type BuildInPlacements = Record<string, AlignType>;
265
+
266
+ type StretchType = string;
267
+
268
+ type ActionType = 'hover' | 'focus' | 'click' | 'contextMenu';
269
+
270
+ interface TriggerProps {
271
+ children: React.ReactElement;
272
+ action?: ActionType | ActionType[];
273
+ showAction?: ActionType[];
274
+ hideAction?: ActionType[];
275
+ prefixCls?: string;
276
+ zIndex?: number;
277
+ onPopupAlign?: (element: HTMLElement, align: AlignType) => void;
278
+ stretch?: string;
279
+ popupVisible?: boolean;
280
+ defaultPopupVisible?: boolean;
281
+ onPopupVisibleChange?: (visible: boolean) => void;
282
+ afterPopupVisibleChange?: (visible: boolean) => void;
283
+ getPopupContainer?: (node: HTMLElement) => HTMLElement;
284
+ forceRender?: boolean;
285
+ autoDestroy?: boolean;
286
+ mask?: boolean;
287
+ maskClosable?: boolean;
288
+ /** Set popup motion. You can ref `rc-motion` for more info. */
289
+ popupMotion?: CSSMotionProps;
290
+ /** Set mask motion. You can ref `rc-motion` for more info. */
291
+ maskMotion?: CSSMotionProps;
292
+ /**
293
+ * Delay in seconds, before tooltip is shown on mouse enter
294
+ */
295
+ mouseEnterDelay?: number;
296
+ /**
297
+ * Delay in seconds, before tooltip is hidden on mouse leave
298
+ */
299
+ mouseLeaveDelay?: number;
300
+ focusDelay?: number;
301
+ blurDelay?: number;
302
+ popup: React.ReactNode | (() => React.ReactNode);
303
+ popupPlacement?: string;
304
+ builtinPlacements?: BuildInPlacements;
305
+ popupAlign?: AlignType;
306
+ popupClassName?: string;
307
+ popupStyle?: React.CSSProperties;
308
+ getPopupClassNameFromAlign?: (align: AlignType) => string;
309
+ onPopupClick?: React.MouseEventHandler<HTMLDivElement>;
310
+ alignPoint?: boolean;
311
+ /**
312
+ * Trigger will memo content when close.
313
+ * This may affect the case if want to keep content update.
314
+ * Set `fresh` to `false` will always keep update.
315
+ */
316
+ fresh?: boolean;
317
+ arrow?: boolean | ArrowTypeOuter;
318
+ }
319
+
320
+ interface ArrowTypeOuter {
321
+ className?: string;
322
+ content?: React.ReactNode;
323
+ }
324
+
325
+ type MotionName =
326
+ | string
327
+ | {
328
+ appear?: string;
329
+ enter?: string;
330
+ leave?: string;
331
+ appearActive?: string;
332
+ enterActive?: string;
333
+ leaveActive?: string;
334
+ };
335
+
336
+ interface CSSMotionProps {
337
+ motionName?: MotionName;
338
+ visible?: boolean;
339
+ motionAppear?: boolean;
340
+ motionEnter?: boolean;
341
+ motionLeave?: boolean;
342
+ motionLeaveImmediately?: boolean;
343
+ motionDeadline?: number;
344
+ /**
345
+ * Create element in view even the element is invisible.
346
+ * Will patch `display: none` style on it.
347
+ */
348
+ forceRender?: boolean;
349
+ /**
350
+ * Remove element when motion end. This will not work when `forceRender` is set.
351
+ */
352
+ removeOnLeave?: boolean;
353
+ leavedClassName?: string;
354
+ /** Prepare phase is used for measure element info. It will always trigger even motion is off */
355
+ onAppearPrepare?: MotionPrepareEventHandler;
356
+ /** Prepare phase is used for measure element info. It will always trigger even motion is off */
357
+ onEnterPrepare?: MotionPrepareEventHandler;
358
+ /** Prepare phase is used for measure element info. It will always trigger even motion is off */
359
+ onLeavePrepare?: MotionPrepareEventHandler;
360
+ onAppearStart?: MotionEventHandler;
361
+ onEnterStart?: MotionEventHandler;
362
+ onLeaveStart?: MotionEventHandler;
363
+ onAppearActive?: MotionEventHandler;
364
+ onEnterActive?: MotionEventHandler;
365
+ onLeaveActive?: MotionEventHandler;
366
+ onAppearEnd?: MotionEndEventHandler;
367
+ onEnterEnd?: MotionEndEventHandler;
368
+ onLeaveEnd?: MotionEndEventHandler;
369
+ /** This will always trigger after final visible changed. Even if no motion configured. */
370
+ onVisibleChanged?: (visible: boolean) => void;
371
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
372
+ internalRef?: React.Ref<any>;
373
+ children?: (
374
+ props: {
375
+ visible?: boolean;
376
+ className?: string;
377
+ style?: React.CSSProperties;
378
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
379
+ [key: string]: any;
380
+ },
381
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
382
+ ref: (node: any) => void
383
+ ) => React.ReactElement;
384
+ }
385
+
386
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
387
+ type MotionPrepareEventHandler = (element: HTMLElement) => Promise<any> | void;
388
+
389
+ type MotionEventHandler = (
390
+ element: HTMLElement,
391
+ event: MotionEvent
392
+ ) => React.CSSProperties | void;
393
+
394
+ type MotionEndEventHandler = (
395
+ element: HTMLElement,
396
+ event: MotionEvent
397
+ ) => boolean | void;
398
+
399
+ type OffsetType = number | `${number}%`;
400
+
401
+ type AlignPointTopBottom = 't' | 'b' | 'c';
402
+
403
+ type AlignPointLeftRight = 'l' | 'r' | 'c';
404
+
405
+ type AlignPoint = `${AlignPointTopBottom}${AlignPointLeftRight}`;
406
+
407
+ interface AlignType {
408
+ /**
409
+ * move point of source node to align with point of target node.
410
+ * Such as ['tr','cc'], align top right point of source node with center point of target node.
411
+ * Point can be 't'(top), 'b'(bottom), 'c'(center), 'l'(left), 'r'(right) */
412
+ points?: (string | AlignPoint)[];
413
+ /**
414
+ * offset source node by offset[0] in x and offset[1] in y.
415
+ * If offset contains percentage string value, it is relative to sourceNode region.
416
+ */
417
+ offset?: OffsetType[];
418
+ /**
419
+ * offset target node by offset[0] in x and offset[1] in y.
420
+ * If targetOffset contains percentage string value, it is relative to targetNode region.
421
+ */
422
+ targetOffset?: OffsetType[];
423
+ /**
424
+ * If adjustX field is true, will adjust source node in x direction if source node is invisible.
425
+ * If adjustY field is true, will adjust source node in y direction if source node is invisible.
426
+ */
427
+ overflow?: {
428
+ adjustX?: boolean | number;
429
+ adjustY?: boolean | number;
430
+ shiftX?: boolean | number;
431
+ shiftY?: boolean | number;
432
+ };
433
+ /** Auto adjust arrow position */
434
+ autoArrow?: boolean;
435
+ /**
436
+ * Config visible region check of html node. Default `visible`:
437
+ * - `visible`:
438
+ * The visible region of user browser window.
439
+ * Use `clientHeight` for check.
440
+ * If `visible` region not satisfy, fallback to `scroll`.
441
+ * - `scroll`:
442
+ * The whole region of the html scroll area.
443
+ * Use `scrollHeight` for check.
444
+ * - `visibleFirst`:
445
+ * Similar to `visible`, but if `visible` region not satisfy, fallback to `scroll`.
446
+ */
447
+ htmlRegion?: 'visible' | 'scroll' | 'visibleFirst';
448
+ /**
449
+ * Auto chose position with `top` or `bottom` by the align result
450
+ */
451
+ dynamicInset?: boolean;
452
+ /**
453
+ * Whether use css right instead of left to position
454
+ */
455
+ useCssRight?: boolean;
456
+ /**
457
+ * Whether use css bottom instead of top to position
458
+ */
459
+ useCssBottom?: boolean;
460
+ /**
461
+ * Whether use css transform instead of left/top/right/bottom to position if browser supports.
462
+ * Defaults to false.
463
+ */
464
+ useCssTransform?: boolean;
465
+ ignoreShake?: boolean;
466
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akinon/ui-tooltip",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "dist/esm/index.js",
@@ -16,9 +16,8 @@
16
16
  "copyfiles": "^2.4.1",
17
17
  "rimraf": "^5.0.5",
18
18
  "typescript": "^5.2.2",
19
- "@akinon/typescript-config": "0.2.0",
20
- "@akinon/vite-config": "0.4.0",
21
- "@akinon/eslint-config": "0.1.0"
19
+ "@akinon/typescript-config": "0.4.0",
20
+ "@akinon/ui-theme": "0.7.0"
22
21
  },
23
22
  "peerDependencies": {
24
23
  "react": ">=18",
@@ -38,12 +37,8 @@
38
37
  "build": "pnpm run build:esm && pnpm run build:commonjs && pnpm run copy:files",
39
38
  "build:esm": "tsc --outDir dist/esm",
40
39
  "build:commonjs": "tsc --module commonjs --outDir dist/cjs",
41
- "copy:files": "copyfiles -u 1 src/**/*.css dist/esm && copyfiles -u 1 src/**/*.css dist/cjs",
40
+ "copy:files": "copyfiles -u 1 \"src/**/*.!(ts|tsx)\" dist/esm && copyfiles -u 1 \"src/**/*.!(ts|tsx)\" dist/cjs",
42
41
  "clean": "rimraf dist/",
43
- "lint": "eslint *.ts*",
44
- "test": "vitest run",
45
- "test:ui": "vitest --ui",
46
- "test:watch": "vitest watch",
47
42
  "typecheck": "tsc --noEmit"
48
43
  }
49
44
  }