Skip to content

Commit 9913312

Browse files
committed
chore: tooltip positions as type, _getAttributeOptions returns TooltipOptions partial
1 parent aee5d8e commit 9913312

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/tooltip.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { Utils } from "./utils";
44
import { Bounding } from "./bounding";
55
import { Component, BaseOptions, InitElements, MElement } from "./component";
66

7+
export type TooltipPosition = 'top' | 'right' | 'bottom' | 'left';
8+
79
export interface TooltipOptions extends BaseOptions {
810
/**
911
* Delay time before tooltip disappears.
@@ -45,7 +47,7 @@ export interface TooltipOptions extends BaseOptions {
4547
* Set the direction of the tooltip.
4648
* @default 'bottom'
4749
*/
48-
position: 'top' | 'right' | 'bottom' | 'left';
50+
position: TooltipPosition;
4951
/**
5052
* Amount in px that the tooltip moves during its transition.
5153
* @default 10
@@ -60,7 +62,7 @@ const _defaults: TooltipOptions = {
6062
margin: 5,
6163
inDuration: 250,
6264
outDuration: 200,
63-
position: 'bottom',
65+
position: 'bottom' as TooltipPosition,
6466
transitionMovement: 10,
6567
opacity: 1
6668
};
@@ -331,15 +333,15 @@ export class Tooltip extends Component<TooltipOptions> {
331333
this.close();
332334
}
333335

334-
_getAttributeOptions() {
335-
const attributeOptions = {};
336+
_getAttributeOptions(): Partial<TooltipOptions> {
337+
let attributeOptions: Partial<TooltipOptions> = { };
336338
const tooltipTextOption = this.el.getAttribute('data-tooltip');
337339
const positionOption = this.el.getAttribute('data-position');
338340
if (tooltipTextOption) {
339-
(attributeOptions as any).text = tooltipTextOption;
341+
attributeOptions.text = tooltipTextOption;
340342
}
341343
if (positionOption) {
342-
(attributeOptions as any).position = positionOption;
344+
attributeOptions.position = positionOption as TooltipPosition;
343345
}
344346
return attributeOptions;
345347
}

0 commit comments

Comments
 (0)