Skip to content

Commit a082285

Browse files
committed
fix(types): improved global typings, closes #601
1 parent eb40315 commit a082285

File tree

5 files changed

+228
-3
lines changed

5 files changed

+228
-3
lines changed

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
"author": "Guillaume Chau <[email protected]>",
66
"scripts": {
77
"build": "NODE_ENV=production npm run build:browser && npm run build:es && npm run build:umd",
8-
"test": "npm run test:unit",
98
"build:browser": "rollup --config build/rollup.config.browser.js",
109
"build:es": "rollup --config build/rollup.config.es.js",
1110
"build:umd": "rollup --config build/rollup.config.umd.js",
1211
"demo:build": "vue-cli-service build",
1312
"demo:serve": "vue-cli-service serve",
1413
"dev": "cross-env NODE_ENV=development rollup --config build/rollup.config.es.js --watch",
1514
"prepublishOnly": "npm run test && npm run build",
16-
"test:unit": "vue-cli-service test:unit"
15+
"test": "npm run test:types && npm run test:unit",
16+
"test:unit": "vue-cli-service test:unit",
17+
"test:types": "cd ./tests/types && tsc --noEmit"
1718
},
1819
"main": "dist/v-tooltip.umd.js",
1920
"module": "dist/v-tooltip.esm.js",
@@ -67,6 +68,7 @@
6768
"sass": "^1.18.0",
6869
"sass-loader": "^7.1.0",
6970
"screenfull": "^3.3.2",
71+
"typescript": "^4.1.3",
7072
"vue": "^2.6.10",
7173
"vue-router": "^3.0.1",
7274
"vue-template-compiler": "^2.6.10"

tests/types/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Vue from 'vue'
2+
import VTooltip from '../..'
3+
4+
Vue.use(VTooltip)
5+
Vue.use(VTooltip, {
6+
disposeTimeout: 4000,
7+
popover: {
8+
defaultAutoHide: false,
9+
},
10+
})
11+
12+
VTooltip.enabled = true
13+
14+
VTooltip.options.defaultClass = '.tooltip'
15+
VTooltip.options.popover.defaultPlacement = 'top'

tests/types/tsconfig.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"files": [
3+
"index.ts"
4+
]
5+
}

types/index.d.ts

Lines changed: 199 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,204 @@
11
import Vue, { VueConstructor, DirectiveOptions, PluginFunction } from 'vue';
22

3-
declare const vToolTip: PluginFunction<any>;
3+
interface DelayConfig {
4+
show?: number
5+
hide?: number
6+
}
7+
8+
export interface GlobalVTooltipOptions {
9+
/**
10+
* Default tooltip placement relative to target element
11+
* @default 'top'
12+
*/
13+
defaultPlacement: string
14+
15+
/**
16+
* Default CSS classes applied to the tooltip element
17+
* @default 'vue-tooltip-theme'
18+
*/
19+
defaultClass: string
20+
21+
/**
22+
* Default CSS classes applied to the target element of the tooltip
23+
* @default 'has-tooltip'
24+
*/
25+
defaultTargetClass: string
26+
27+
/**
28+
* Is the content HTML by default?
29+
* @default true
30+
*/
31+
defaultHtml: boolean
32+
33+
/**
34+
* Default HTML template of the tooltip element
35+
* It must include `tooltip-arrow` & `tooltip-inner` CSS classes (can be configured, see below)
36+
* Change if the classes conflict with other libraries (for example bootstrap)
37+
* @default '<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>'
38+
*/
39+
defaultTemplate: string
40+
41+
/**
42+
* Selector used to get the arrow element in the tooltip template
43+
* @default '.tooltip-arrow, .tooltip__arrow'
44+
*/
45+
defaultArrowSelector: string
46+
47+
/**
48+
* Selector used to get the inner content element in the tooltip template
49+
* @default '.tooltip-inner, .tooltip__inner'
50+
*/
51+
defaultInnerSelector: string
52+
53+
/**
54+
* Delay (ms)
55+
* @default 0
56+
*/
57+
defaultDelay: number | DelayConfig
58+
59+
/**
60+
* Default events that trigger the tooltip
61+
* @default 'hover focus'
62+
*/
63+
defaultTrigger: string
64+
65+
/**
66+
* Default position offset (px)
67+
* @default 0
68+
*/
69+
defaultOffset: number | string
70+
71+
/**
72+
* Default container where the tooltip will be appended
73+
* @default 'body'
74+
*/
75+
defaultContainer: string | HTMLElement | false
76+
77+
defaultBoundariesElement: string | HTMLElement
78+
79+
defaultPopperOptions: any
80+
81+
/**
82+
* Class added when content is loading
83+
* @default 'tooltip-loading'
84+
*/
85+
defaultLoadingClass: string
86+
87+
/**
88+
* Displayed when tooltip content is loading
89+
* @default '...'
90+
*/
91+
defaultLoadingContent: string
92+
93+
/**
94+
* Hide on mouseover tooltip
95+
* @default true
96+
*/
97+
autoHide: boolean
98+
99+
/**
100+
* Close tooltip on click on tooltip target?
101+
* @default true
102+
*/
103+
defaultHideOnTargetClick: boolean
104+
105+
/**
106+
* Auto destroy tooltip DOM nodes (ms)
107+
* @default 5000
108+
*/
109+
disposeTimeout: number
110+
111+
/**
112+
* Options for popover
113+
*/
114+
popover: Partial<GlobalVTooltipPopoverOptions>
115+
}
116+
117+
export interface GlobalVTooltipPopoverOptions {
118+
/**
119+
* @default 'bottom'
120+
*/
121+
defaultPlacement: string,
122+
123+
/**
124+
* Use the `popoverClass` prop for theming
125+
* @default 'vue-popover-theme'
126+
*/
127+
defaultClass: string,
128+
129+
/**
130+
* Base class (change if conflicts with other libraries)
131+
* @default 'tooltip popover'
132+
*/
133+
defaultBaseClass: string,
134+
135+
/**
136+
* Wrapper class (contains arrow and inner)
137+
* @default 'wrapper'
138+
*/
139+
defaultWrapperClass: string,
140+
141+
/**
142+
* Inner content class
143+
* @default 'tooltip-inner popover-inner'
144+
*/
145+
defaultInnerClass: string,
146+
147+
/**
148+
* Arrow class
149+
* @default 'tooltip-arrow popover-arrow'
150+
*/
151+
defaultArrowClass: string,
152+
153+
/**
154+
* Class added when popover is open
155+
* @default 'open'
156+
*/
157+
defaultOpenClass: string,
158+
159+
/**
160+
* @default 0
161+
*/
162+
defaultDelay: number | DelayConfig,
163+
164+
/**
165+
* @default 'click'
166+
*/
167+
defaultTrigger: string,
168+
169+
/**
170+
* @default 0
171+
*/
172+
defaultOffset: number | string,
173+
174+
/**
175+
* @default 'body'
176+
*/
177+
defaultContainer: string | HTMLElement | false,
178+
179+
defaultBoundariesElement: string | HTMLElement,
180+
181+
defaultPopperOptions: any,
182+
183+
/**
184+
* Hides if clicked outside of popover
185+
* @default true
186+
*/
187+
defaultAutoHide: boolean,
188+
189+
/**
190+
* Update popper on content resize
191+
* @default true
192+
*/
193+
defaultHandleResize: boolean,
194+
}
195+
196+
export interface GlobalVTooltip {
197+
enabled?: boolean
198+
options?: Partial<GlobalVTooltipOptions>
199+
}
200+
201+
declare const vToolTip: PluginFunction<Partial<GlobalVTooltipOptions>> & GlobalVTooltip;
4202
export default vToolTip;
5203

6204
export const VPopover: VueConstructor<Vue>;

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12267,6 +12267,11 @@ typedarray@^0.0.6:
1226712267
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
1226812268
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=
1226912269

12270+
typescript@^4.1.3:
12271+
version "4.1.3"
12272+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.1.3.tgz#519d582bd94cba0cf8934c7d8e8467e473f53bb7"
12273+
integrity sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg==
12274+
1227012275
1227112276
version "3.4.10"
1227212277
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.4.10.tgz#9ad9563d8eb3acdfb8d38597d2af1d815f6a755f"

0 commit comments

Comments
 (0)