bge-ui 1.0.1
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/README.md +18 -0
- package/icons/Coin/HKD.svg +6 -0
- package/icons/Coin/USD.svg +4 -0
- package/icons/Intl/CH.svg +4 -0
- package/icons/Intl/EN.svg +14 -0
- package/icons/Intl/EUR.svg +15 -0
- package/icons/Intl/HKG.svg +8 -0
- package/icons/Intl/JPN.svg +4 -0
- package/icons/Intl/KOR.svg +6 -0
- package/icons/Intl/USA.svg +6 -0
- package/icons/Intl/VNM.svg +4 -0
- package/icons/Media/Facebook.svg +3 -0
- package/icons/Media/Instagram.svg +3 -0
- package/icons/Media/Linked.svg +3 -0
- package/icons/Media/Twitter.svg +3 -0
- package/icons/Mono/International.svg +3 -0
- package/icons/Mono/add-subtract.svg +4 -0
- package/icons/Mono/add.svg +3 -0
- package/icons/Mono/android.svg +3 -0
- package/icons/Mono/api.svg +5 -0
- package/icons/Mono/apple.svg +3 -0
- package/icons/Mono/arrow-down.svg +3 -0
- package/icons/Mono/arrow-up.svg +3 -0
- package/icons/Mono/assets.svg +4 -0
- package/icons/Mono/audit.svg +3 -0
- package/icons/Mono/bank card.svg +4 -0
- package/icons/Mono/building.svg +3 -0
- package/icons/Mono/calendar.svg +3 -0
- package/icons/Mono/check-fill.svg +3 -0
- package/icons/Mono/chevron-left.svg +3 -0
- package/icons/Mono/chevron-right-double.svg +4 -0
- package/icons/Mono/chevron-right.svg +3 -0
- package/icons/Mono/classify01.svg +3 -0
- package/icons/Mono/classify02.svg +6 -0
- package/icons/Mono/close-one.svg +4 -0
- package/icons/Mono/close.svg +3 -0
- package/icons/Mono/complete.svg +3 -0
- package/icons/Mono/copy.svg +4 -0
- package/icons/Mono/docunment.svg +5 -0
- package/icons/Mono/edit.svg +4 -0
- package/icons/Mono/email01.svg +3 -0
- package/icons/Mono/email02.svg +3 -0
- package/icons/Mono/exclamationmark-fill.svg +3 -0
- package/icons/Mono/eye-close.svg +4 -0
- package/icons/Mono/eye.svg +4 -0
- package/icons/Mono/googleplay.svg +6 -0
- package/icons/Mono/help.svg +5 -0
- package/icons/Mono/less.svg +3 -0
- package/icons/Mono/logout.svg +4 -0
- package/icons/Mono/menu.svg +5 -0
- package/icons/Mono/moon.svg +3 -0
- package/icons/Mono/more.svg +5 -0
- package/icons/Mono/notification.svg +3 -0
- package/icons/Mono/other-device.svg +5 -0
- package/icons/Mono/pic-error.svg +5 -0
- package/icons/Mono/pic.svg +4 -0
- package/icons/Mono/remove.svg +4 -0
- package/icons/Mono/route.svg +5 -0
- package/icons/Mono/safety.svg +4 -0
- package/icons/Mono/search.svg +3 -0
- package/icons/Mono/sun.svg +11 -0
- package/icons/Mono/time.svg +4 -0
- package/icons/Mono/toward-fill.svg +3 -0
- package/icons/Mono/transfer.svg +4 -0
- package/icons/Mono/trash.svg +6 -0
- package/icons/Mono/wallet.svg +4 -0
- package/icons/Mono/win.svg +6 -0
- package/icons/color/c2-all.svg +4 -0
- package/icons/color/c2-api.svg +5 -0
- package/icons/color/c2-assets.svg +4 -0
- package/icons/color/c2-bill-1.svg +4 -0
- package/icons/color/c2-bill-2.svg +5 -0
- package/icons/color/c2-card.svg +4 -0
- package/icons/color/c2-complete.svg +4 -0
- package/icons/color/c2-deal.svg +5 -0
- package/icons/color/c2-email.svg +4 -0
- package/icons/color/c2-fee.svg +6 -0
- package/icons/color/c2-google.svg +4 -0
- package/icons/color/c2-home.svg +4 -0
- package/icons/color/c2-kyc.svg +5 -0
- package/icons/color/c2-language.svg +4 -0
- package/icons/color/c2-level.svg +4 -0
- package/icons/color/c2-notification.svg +4 -0
- package/icons/color/c2-pdf.svg +4 -0
- package/icons/color/c2-phone.svg +4 -0
- package/icons/color/c2-register.svg +5 -0
- package/icons/color/c2-right-down.svg +4 -0
- package/icons/color/c2-right-up.svg +4 -0
- package/icons/color/c2-safe-shield.svg +4 -0
- package/icons/color/c2-safe.svg +4 -0
- package/icons/color/c2-traffic-cone.svg +7 -0
- package/icons/color/c2-user-every.svg +9 -0
- package/icons/color/c2-user.svg +5 -0
- package/icons/color/c3-Licensing.svg +5 -0
- package/icons/color/c3-audits.svg +7 -0
- package/icons/color/c3-card.svg +5 -0
- package/icons/color/c3-company.svg +6 -0
- package/icons/color/c3-deposit.svg +6 -0
- package/icons/color/c3-establish.svg +5 -0
- package/icons/color/c3-framework.svg +5 -0
- package/icons/color/c3-kyc.svg +7 -0
- package/icons/color/c3-not-passed.svg +7 -0
- package/icons/color/c3-pass.svg +7 -0
- package/icons/color/c3-safes.svg +8 -0
- package/icons/color/c3-trading.svg +5 -0
- package/icons/color/c3-user-every.svg +11 -0
- package/icons/color/c3-user-follow.svg +6 -0
- package/icons/color/c3-user.svg +6 -0
- package/icons/color/close-fill.svg +4 -0
- package/icons/color/completed-fill.svg +4 -0
- package/icons/color/cookie.svg +16 -0
- package/icons/color/star.svg +4 -0
- package/icons/color/success-fill.svg +11 -0
- package/icons/color/time-fill.svg +4 -0
- package/icons/color/toward-fill.svg +6 -0
- package/icons/generate.ts +152 -0
- package/package.json +37 -0
- package/src/button/index.vue +120 -0
- package/src/button/type.ts +4 -0
- package/src/dropdown/index.vue +10 -0
- package/src/form/form-item.vue +234 -0
- package/src/form/index.vue +122 -0
- package/src/icons/CoinHkd.vue +80 -0
- package/src/icons/CoinUsd.vue +72 -0
- package/src/icons/ColorC2All.vue +75 -0
- package/src/icons/ColorC2Api.vue +71 -0
- package/src/icons/ColorC2Assets.vue +72 -0
- package/src/icons/ColorC2Bill1.vue +70 -0
- package/src/icons/ColorC2Bill2.vue +68 -0
- package/src/icons/ColorC2Card.vue +67 -0
- package/src/icons/ColorC2Complete.vue +72 -0
- package/src/icons/ColorC2Deal.vue +74 -0
- package/src/icons/ColorC2Email.vue +70 -0
- package/src/icons/ColorC2Fee.vue +78 -0
- package/src/icons/ColorC2Google.vue +70 -0
- package/src/icons/ColorC2Home.vue +70 -0
- package/src/icons/ColorC2Kyc.vue +73 -0
- package/src/icons/ColorC2Language.vue +70 -0
- package/src/icons/ColorC2Level.vue +72 -0
- package/src/icons/ColorC2Notification.vue +75 -0
- package/src/icons/ColorC2Pdf.vue +73 -0
- package/src/icons/ColorC2Phone.vue +67 -0
- package/src/icons/ColorC2Register.vue +68 -0
- package/src/icons/ColorC2RightDown.vue +72 -0
- package/src/icons/ColorC2RightUp.vue +72 -0
- package/src/icons/ColorC2Safe.vue +75 -0
- package/src/icons/ColorC2SafeShield.vue +72 -0
- package/src/icons/ColorC2TrafficCone.vue +79 -0
- package/src/icons/ColorC2User.vue +79 -0
- package/src/icons/ColorC2UserEvery.vue +90 -0
- package/src/icons/ColorC3Audits.vue +76 -0
- package/src/icons/ColorC3Card.vue +68 -0
- package/src/icons/ColorC3Company.vue +69 -0
- package/src/icons/ColorC3Deposit.vue +74 -0
- package/src/icons/ColorC3Establish.vue +78 -0
- package/src/icons/ColorC3Framework.vue +71 -0
- package/src/icons/ColorC3Kyc.vue +76 -0
- package/src/icons/ColorC3Licensing.vue +71 -0
- package/src/icons/ColorC3NotPassed.vue +76 -0
- package/src/icons/ColorC3Pass.vue +78 -0
- package/src/icons/ColorC3Safes.vue +83 -0
- package/src/icons/ColorC3Trading.vue +78 -0
- package/src/icons/ColorC3User.vue +78 -0
- package/src/icons/ColorC3UserEvery.vue +98 -0
- package/src/icons/ColorC3UserFollow.vue +83 -0
- package/src/icons/ColorCloseFill.vue +74 -0
- package/src/icons/ColorCompletedFill.vue +71 -0
- package/src/icons/ColorCookie.vue +99 -0
- package/src/icons/ColorStar.vue +72 -0
- package/src/icons/ColorSuccessFill.vue +78 -0
- package/src/icons/ColorTimeFill.vue +66 -0
- package/src/icons/ColorTowardFill.vue +68 -0
- package/src/icons/IntlCh.vue +76 -0
- package/src/icons/IntlEn.vue +112 -0
- package/src/icons/IntlEur.vue +116 -0
- package/src/icons/IntlHkg.vue +98 -0
- package/src/icons/IntlJpn.vue +76 -0
- package/src/icons/IntlKor.vue +88 -0
- package/src/icons/IntlUsa.vue +83 -0
- package/src/icons/IntlVnm.vue +76 -0
- package/src/icons/MediaFacebook.vue +72 -0
- package/src/icons/MediaInstagram.vue +72 -0
- package/src/icons/MediaLinked.vue +72 -0
- package/src/icons/MediaTwitter.vue +70 -0
- package/src/icons/MonoAdd.vue +70 -0
- package/src/icons/MonoAddSubtract.vue +68 -0
- package/src/icons/MonoAndroid.vue +72 -0
- package/src/icons/MonoApi.vue +77 -0
- package/src/icons/MonoApple.vue +70 -0
- package/src/icons/MonoArrowDown.vue +67 -0
- package/src/icons/MonoArrowUp.vue +67 -0
- package/src/icons/MonoAssets.vue +78 -0
- package/src/icons/MonoAudit.vue +72 -0
- package/src/icons/MonoBankCard.vue +73 -0
- package/src/icons/MonoBuilding.vue +72 -0
- package/src/icons/MonoCalendar.vue +72 -0
- package/src/icons/MonoCheckFill.vue +72 -0
- package/src/icons/MonoChevronLeft.vue +72 -0
- package/src/icons/MonoChevronRight.vue +72 -0
- package/src/icons/MonoChevronRightDouble.vue +78 -0
- package/src/icons/MonoClassify01.vue +72 -0
- package/src/icons/MonoClassify02.vue +90 -0
- package/src/icons/MonoClose.vue +70 -0
- package/src/icons/MonoCloseOne.vue +76 -0
- package/src/icons/MonoComplete.vue +72 -0
- package/src/icons/MonoCopy.vue +73 -0
- package/src/icons/MonoDocunment.vue +74 -0
- package/src/icons/MonoEdit.vue +78 -0
- package/src/icons/MonoEmail01.vue +72 -0
- package/src/icons/MonoEmail02.vue +72 -0
- package/src/icons/MonoExclamationmarkFill.vue +72 -0
- package/src/icons/MonoEye.vue +78 -0
- package/src/icons/MonoEyeClose.vue +78 -0
- package/src/icons/MonoGoogleplay.vue +82 -0
- package/src/icons/MonoHelp.vue +77 -0
- package/src/icons/MonoInternational.vue +70 -0
- package/src/icons/MonoLess.vue +67 -0
- package/src/icons/MonoLogout.vue +71 -0
- package/src/icons/MonoMenu.vue +69 -0
- package/src/icons/MonoMoon.vue +72 -0
- package/src/icons/MonoMore.vue +69 -0
- package/src/icons/MonoNotification.vue +72 -0
- package/src/icons/MonoOtherDevice.vue +74 -0
- package/src/icons/MonoPic.vue +76 -0
- package/src/icons/MonoPicError.vue +80 -0
- package/src/icons/MonoRemove.vue +73 -0
- package/src/icons/MonoRoute.vue +69 -0
- package/src/icons/MonoSafety.vue +76 -0
- package/src/icons/MonoSearch.vue +72 -0
- package/src/icons/MonoSun.vue +95 -0
- package/src/icons/MonoTime.vue +78 -0
- package/src/icons/MonoTowardFill.vue +72 -0
- package/src/icons/MonoTransfer.vue +74 -0
- package/src/icons/MonoTrash.vue +75 -0
- package/src/icons/MonoWallet.vue +73 -0
- package/src/icons/MonoWin.vue +70 -0
- package/src/icons/index.ts +231 -0
- package/src/index.ts +50 -0
- package/src/input/index.vue +256 -0
- package/src/link/index.vue +95 -0
- package/src/message/index.vue +205 -0
- package/src/message/method.ts +138 -0
- package/src/tabs/index.vue +126 -0
- package/src/tabs/tab-pane.vue +96 -0
- package/src/tooltip/index.vue +338 -0
- package/src/tooltip/only-child.tsx +70 -0
- package/src/tooltip/usePopper.ts +578 -0
|
@@ -0,0 +1,578 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ref,
|
|
3
|
+
withDirectives,
|
|
4
|
+
vShow,
|
|
5
|
+
onUnmounted,
|
|
6
|
+
h,
|
|
7
|
+
computed,
|
|
8
|
+
watch,
|
|
9
|
+
Transition,
|
|
10
|
+
} from 'vue';
|
|
11
|
+
import type { SetupContext, VNode } from 'vue';
|
|
12
|
+
import { createPopper } from '@popperjs/core';
|
|
13
|
+
import type {
|
|
14
|
+
Instance,
|
|
15
|
+
PositioningStrategy,
|
|
16
|
+
Placement,
|
|
17
|
+
Modifier,
|
|
18
|
+
Options as ModifierOptions
|
|
19
|
+
} from '@popperjs/core';
|
|
20
|
+
import { onClickOutside, useDebounceFn } from '@vueuse/core';
|
|
21
|
+
// import './style.scss';
|
|
22
|
+
import { unrefElement } from '@vueuse/core'
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Set default popper default options
|
|
26
|
+
*/
|
|
27
|
+
const popperDefaultOptions = {
|
|
28
|
+
modifiers: [
|
|
29
|
+
{
|
|
30
|
+
name: 'offset',
|
|
31
|
+
options: { offset: [0, 16] },
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: 'preventOverflow',
|
|
35
|
+
options: { padding: 8 },
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: 'flip',
|
|
39
|
+
options: { fallbackPlacements: ['top', 'bottom', 'left', 'right'] },
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: 'arrow',
|
|
43
|
+
options: { element: ':scope > .popper-content > [data-popper-arrow]' },
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Generate a css text from style object
|
|
50
|
+
*
|
|
51
|
+
* @param {object} style List of style properties
|
|
52
|
+
* @param {object} extra Extra style properties
|
|
53
|
+
* @return {string} Css string
|
|
54
|
+
*/
|
|
55
|
+
const createCssText = function (style: object = {}, extra: object = {}): string {
|
|
56
|
+
const combined = {
|
|
57
|
+
...style,
|
|
58
|
+
...extra,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const cssText = [];
|
|
62
|
+
for (const [key, value] of Object.entries(combined)) {
|
|
63
|
+
cssText.push(`${key}: ${value};`);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return cssText.join(' ');
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* List of transform directions for shift
|
|
71
|
+
* animation
|
|
72
|
+
*/
|
|
73
|
+
const shiftMap = {
|
|
74
|
+
top: 'translateY(-7px)',
|
|
75
|
+
bottom: 'translateY(7px)',
|
|
76
|
+
left: 'translateX(-7px)',
|
|
77
|
+
right: 'translateX(7px)',
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const transformOriginMap = {
|
|
81
|
+
top: 'bottom center',
|
|
82
|
+
bottom: 'top center',
|
|
83
|
+
left: 'center right',
|
|
84
|
+
right: 'center left',
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
type Options = {
|
|
88
|
+
placement?: Placement;
|
|
89
|
+
hover?: boolean;
|
|
90
|
+
disableClickOutside?: boolean;
|
|
91
|
+
openDelay?: number;
|
|
92
|
+
closeDelay?: number;
|
|
93
|
+
showArrow?: boolean;
|
|
94
|
+
strategy?: PositioningStrategy;
|
|
95
|
+
interactive?: boolean;
|
|
96
|
+
animation?: string;
|
|
97
|
+
animationDuration?: number | number[];
|
|
98
|
+
popperOptions?: object;
|
|
99
|
+
modifiers?: Modifier<string, ModifierOptions>[];
|
|
100
|
+
onOpened?: () => void;
|
|
101
|
+
onClosed?: () => void;
|
|
102
|
+
onTransition?: (transition: string, element: HTMLElement) => void;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
type TransitionNames = {
|
|
106
|
+
outer: string;
|
|
107
|
+
inner: string;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// eslint-disable-next-line max-lines-per-function
|
|
111
|
+
const usePopper = function (triggerReference, suppliedOptions: Options = {}) {
|
|
112
|
+
triggerReference = ref(unrefElement(triggerReference.value))
|
|
113
|
+
// if (!triggerReference) {
|
|
114
|
+
// return false
|
|
115
|
+
// }
|
|
116
|
+
const defaults: Options = {
|
|
117
|
+
placement: 'bottom',
|
|
118
|
+
hover: false,
|
|
119
|
+
disableClickOutside: false,
|
|
120
|
+
openDelay: 0,
|
|
121
|
+
closeDelay: 0,
|
|
122
|
+
showArrow: true,
|
|
123
|
+
strategy: 'absolute',
|
|
124
|
+
interactive: false,
|
|
125
|
+
animation: 'shift-in',
|
|
126
|
+
animationDuration: 300,
|
|
127
|
+
popperOptions: {},
|
|
128
|
+
modifiers: [],
|
|
129
|
+
onOpened: () => {
|
|
130
|
+
/**
|
|
131
|
+
* Callback when the tooltip is opened
|
|
132
|
+
*/
|
|
133
|
+
},
|
|
134
|
+
onClosed: () => {
|
|
135
|
+
/**
|
|
136
|
+
* Callback when the tooltip is closed
|
|
137
|
+
*/
|
|
138
|
+
},
|
|
139
|
+
onTransition: () => {
|
|
140
|
+
/**
|
|
141
|
+
* Callback when the tooltip is transitioning
|
|
142
|
+
*
|
|
143
|
+
* @param {string} transition Name of the transition
|
|
144
|
+
* @param {HTMLElement} element Element that is transitioning
|
|
145
|
+
*/
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const options: Options = {
|
|
150
|
+
...defaults,
|
|
151
|
+
...suppliedOptions,
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
// const triggerReference = ref(undefined);
|
|
155
|
+
const tooltipReference = ref(undefined);
|
|
156
|
+
const popperInstance = ref<Instance | undefined>(undefined);
|
|
157
|
+
const isOpened = ref(false);
|
|
158
|
+
const isTargetHovered = ref(false);
|
|
159
|
+
const isTooltipHovered = ref(false);
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Get current placement of the tooltip
|
|
163
|
+
*/
|
|
164
|
+
const placementState = ref(options.placement || 'top');
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Get popper options by merging default options with user-supplied options
|
|
168
|
+
*/
|
|
169
|
+
const getPopperOptions = computed(() => {
|
|
170
|
+
let { modifiers } = popperDefaultOptions;
|
|
171
|
+
if (options.modifiers) {
|
|
172
|
+
modifiers = [...modifiers, ...options.modifiers];
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return {
|
|
176
|
+
...popperDefaultOptions,
|
|
177
|
+
strategy: options.strategy,
|
|
178
|
+
placement: options.placement,
|
|
179
|
+
modifiers,
|
|
180
|
+
...options.popperOptions,
|
|
181
|
+
};
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
// Add a minor delay to the close delay to check if the user is hovering the tooltip
|
|
185
|
+
const getCloseDelay = function () {
|
|
186
|
+
if (options.hover === false || options.interactive === false) {
|
|
187
|
+
return options.closeDelay;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return options.closeDelay === 0 ? 150 : options.closeDelay;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Handle the opening of the tooltip with delay
|
|
195
|
+
*/
|
|
196
|
+
const openWithDelay = useDebounceFn(async () => {
|
|
197
|
+
const updated = await popperInstance.value?.update();
|
|
198
|
+
placementState.value = updated?.placement || options.placement;
|
|
199
|
+
isOpened.value = true;
|
|
200
|
+
}, options.openDelay);
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Handle the closing of the tooltip with delay
|
|
204
|
+
*/
|
|
205
|
+
const closeWithDelay = useDebounceFn(() => {
|
|
206
|
+
if (options.hover === false || options.interactive === false) {
|
|
207
|
+
isOpened.value = false;
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Make sure both elements are not hovered before closing
|
|
212
|
+
if (isTargetHovered.value === false && isTooltipHovered.value === false) {
|
|
213
|
+
isOpened.value = false;
|
|
214
|
+
}
|
|
215
|
+
}, getCloseDelay());
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Toggle tooltip status
|
|
219
|
+
*
|
|
220
|
+
* @param {string} status The status of the tooltip (open|close)
|
|
221
|
+
*/
|
|
222
|
+
const toggleTooltip = (status = '') => {
|
|
223
|
+
let nextStatus = status;
|
|
224
|
+
|
|
225
|
+
if (status === '') {
|
|
226
|
+
nextStatus = isOpened.value ? 'close' : 'open';
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (nextStatus === 'open') {
|
|
230
|
+
openWithDelay();
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
closeWithDelay();
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Toggle tooltip status on hover
|
|
239
|
+
*
|
|
240
|
+
* @param {string} status The status of the tooltip (open|close)
|
|
241
|
+
* @param {string} source The source of the event (trigger|tooltip)
|
|
242
|
+
*/
|
|
243
|
+
const toggleTooltipHover = (status = '', source = '') => {
|
|
244
|
+
if (options.hover === false) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (source === 'trigger') {
|
|
249
|
+
isTargetHovered.value = status === 'open';
|
|
250
|
+
} else {
|
|
251
|
+
isTooltipHovered.value = status === 'open';
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
toggleTooltip(status);
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Build trigger element
|
|
259
|
+
*
|
|
260
|
+
* @param {object} props Props passed to the component
|
|
261
|
+
* @param {SetupContext} context Context passed to the component
|
|
262
|
+
* @return {VNode} Trigger element
|
|
263
|
+
*/
|
|
264
|
+
triggerReference.value && triggerReference.value.addEventListener('mouseenter', () => {
|
|
265
|
+
toggleTooltipHover('open', 'trigger')
|
|
266
|
+
})
|
|
267
|
+
triggerReference.value && triggerReference.value.addEventListener('mouseleave', () => {
|
|
268
|
+
toggleTooltipHover('close', 'trigger')
|
|
269
|
+
})
|
|
270
|
+
triggerReference.value && triggerReference.value.addEventListener('focus', () => {
|
|
271
|
+
toggleTooltipHover('open');
|
|
272
|
+
})
|
|
273
|
+
triggerReference.value && triggerReference.value.addEventListener('click', () => {
|
|
274
|
+
toggleTooltip();
|
|
275
|
+
})
|
|
276
|
+
const triggerElement = ref(triggerReference.value)
|
|
277
|
+
|
|
278
|
+
// const triggerElement = function (props: object, context: SetupContext): VNode {
|
|
279
|
+
// const { slots } = context;
|
|
280
|
+
// // slots.default()[0].ref = triggerReference
|
|
281
|
+
// // slots.default()[0].props.ariaDescribedby = 'tooltip'
|
|
282
|
+
// // console.log(slots.default()[0])
|
|
283
|
+
// // return h('div',
|
|
284
|
+
// return h('div',
|
|
285
|
+
// {
|
|
286
|
+
// class: 'bge-trigger__element',
|
|
287
|
+
// ref: triggerReference,
|
|
288
|
+
// ariaDescribedby: 'tooltip',
|
|
289
|
+
// onMouseenter: () => {
|
|
290
|
+
// return toggleTooltipHover('open', 'trigger');
|
|
291
|
+
// },
|
|
292
|
+
// onMouseleave: () => {
|
|
293
|
+
// return toggleTooltipHover('close', 'trigger');
|
|
294
|
+
// },
|
|
295
|
+
// onFocus: () => {
|
|
296
|
+
// return toggleTooltipHover('open');
|
|
297
|
+
// },
|
|
298
|
+
// onClick: () => {
|
|
299
|
+
// return toggleTooltip();
|
|
300
|
+
// },
|
|
301
|
+
// },
|
|
302
|
+
// slots.default ? slots.default() : '');
|
|
303
|
+
// // return slots.default()[0]
|
|
304
|
+
// };
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Get the animation class
|
|
308
|
+
*/
|
|
309
|
+
const getTransitionNames = computed<TransitionNames>(() => {
|
|
310
|
+
const { animation } = options;
|
|
311
|
+
|
|
312
|
+
if (animation === 'none') {
|
|
313
|
+
return {
|
|
314
|
+
outer: '',
|
|
315
|
+
inner: '',
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
let animationName = animation;
|
|
320
|
+
|
|
321
|
+
// Backward compatibility
|
|
322
|
+
if (animation === 'fade-slide') {
|
|
323
|
+
animationName = 'shift-in';
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
return {
|
|
327
|
+
outer: 'fade',
|
|
328
|
+
inner: animationName,
|
|
329
|
+
};
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Get the animation duration in seconds
|
|
334
|
+
* Animation duration can be a single number
|
|
335
|
+
* or an array of numbers for each direction
|
|
336
|
+
* of the animation
|
|
337
|
+
*/
|
|
338
|
+
const getTransitionDuration = computed(() => {
|
|
339
|
+
const { animationDuration } = options;
|
|
340
|
+
|
|
341
|
+
if (!Array.isArray(animationDuration)) {
|
|
342
|
+
const animationDurationWithDefault: number = animationDuration || 300;
|
|
343
|
+
return {
|
|
344
|
+
enter: `${animationDurationWithDefault / 1000}s`,
|
|
345
|
+
leave: `${animationDurationWithDefault / 1000}s`,
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const [enter, leave] = animationDuration;
|
|
350
|
+
return {
|
|
351
|
+
enter: `${enter / 1000}s`,
|
|
352
|
+
leave: `${leave / 1000}s`,
|
|
353
|
+
};
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Get the transform value of the tooltip for slide animation
|
|
358
|
+
*/
|
|
359
|
+
const getShiftTransform = computed(() => {
|
|
360
|
+
const getTransform = Object.keys(shiftMap).find((key) => {
|
|
361
|
+
return placementState.value.startsWith(key);
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
if (getTransform === undefined) {
|
|
365
|
+
return 'translate(0, 0)';
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
return shiftMap[getTransform];
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
const getScaleOrigin = computed(() => {
|
|
372
|
+
const getScale = Object.keys(transformOriginMap).find((key) => {
|
|
373
|
+
return placementState.value.startsWith(key);
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
if (getScale === undefined) {
|
|
377
|
+
return 'center center';
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
return transformOriginMap[getScale];
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
const createTooltipStyle = computed(() => {
|
|
384
|
+
if (popperInstance.value === undefined) {
|
|
385
|
+
return '';
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
const toggleStyle = {
|
|
389
|
+
'--vue-popper-enter-duration': getTransitionDuration.value.enter,
|
|
390
|
+
'--vue-popper-leave-duration': getTransitionDuration.value.leave,
|
|
391
|
+
'--vue-popper-shift-transform': getShiftTransform.value,
|
|
392
|
+
'--vue-popper-scale-transform-origin': getScaleOrigin.value,
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
const style = popperInstance.value.state.styles.popper;
|
|
396
|
+
const final = createCssText(style, toggleStyle);
|
|
397
|
+
return final;
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
const onTransitionCallback = (type: string, element: HTMLElement) => {
|
|
401
|
+
if (options.onTransition !== undefined) {
|
|
402
|
+
options.onTransition(type, element);
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Build tooltip element
|
|
408
|
+
*
|
|
409
|
+
* @param {object} props Props passed to the component
|
|
410
|
+
* @param {SetupContext} context Context passed to the component
|
|
411
|
+
* @return {VNode} Tooltip element
|
|
412
|
+
*/
|
|
413
|
+
const tooltipElement = function (props: object, context: SetupContext): VNode {
|
|
414
|
+
const { slots } = context;
|
|
415
|
+
return h(Transition,
|
|
416
|
+
{ name: getTransitionNames.value.outer },
|
|
417
|
+
{
|
|
418
|
+
default: () => {
|
|
419
|
+
return withDirectives(
|
|
420
|
+
h(
|
|
421
|
+
'div',
|
|
422
|
+
{
|
|
423
|
+
class: 'bge-popper-wrapper',
|
|
424
|
+
ref: tooltipReference,
|
|
425
|
+
style: createTooltipStyle.value,
|
|
426
|
+
onMouseleave: () => {
|
|
427
|
+
if (options.hover === false || options.interactive === false) {
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
toggleTooltipHover('close', 'tooltip');
|
|
431
|
+
},
|
|
432
|
+
onMouseenter: () => {
|
|
433
|
+
if (options.hover === false || options.interactive === false) {
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
toggleTooltipHover('open', 'tooltip');
|
|
437
|
+
},
|
|
438
|
+
},
|
|
439
|
+
[
|
|
440
|
+
h(Transition,
|
|
441
|
+
{
|
|
442
|
+
'name': getTransitionNames.value.inner,
|
|
443
|
+
'data-placement': placementState.value,
|
|
444
|
+
'data-name': getTransitionNames.value.inner,
|
|
445
|
+
|
|
446
|
+
onBeforeEnter(element: HTMLElement) {
|
|
447
|
+
onTransitionCallback('before-enter', element);
|
|
448
|
+
},
|
|
449
|
+
|
|
450
|
+
onEnter(element: HTMLElement) {
|
|
451
|
+
if (getTransitionNames.value.inner === 'shift-out') {
|
|
452
|
+
element.style.animation = `shift-out ${getTransitionDuration.value.enter}`;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
onTransitionCallback('enter', element);
|
|
456
|
+
},
|
|
457
|
+
|
|
458
|
+
onAfterEnter(element: HTMLElement) {
|
|
459
|
+
if (getTransitionNames.value.inner === 'shift-out') {
|
|
460
|
+
element.style.transform = getShiftTransform.value;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
onTransitionCallback('after-enter', element);
|
|
464
|
+
},
|
|
465
|
+
|
|
466
|
+
onBeforeLeave(element: HTMLElement) {
|
|
467
|
+
if (getTransitionNames.value.inner === 'shift-out') {
|
|
468
|
+
element.style.transform = getShiftTransform.value;
|
|
469
|
+
element.style.animation = '';
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
onTransitionCallback('before-leave', element);
|
|
473
|
+
},
|
|
474
|
+
|
|
475
|
+
onLeave(element: HTMLElement) {
|
|
476
|
+
if (getTransitionNames.value.inner === 'shift-out') {
|
|
477
|
+
element.style.transform = 'translate(0, 0)';
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
onTransitionCallback('leave', element);
|
|
481
|
+
},
|
|
482
|
+
|
|
483
|
+
onAfterLeave(element: HTMLElement) {
|
|
484
|
+
if (getTransitionNames.value.inner === 'shift-out') {
|
|
485
|
+
element.style.transform = 'translate(0, 0)';
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
onTransitionCallback('after-leave', element);
|
|
489
|
+
},
|
|
490
|
+
},
|
|
491
|
+
{
|
|
492
|
+
default: () => {
|
|
493
|
+
return withDirectives(h('div',
|
|
494
|
+
{ class: 'popper-content' },
|
|
495
|
+
[
|
|
496
|
+
slots.default ? slots.default() : '',
|
|
497
|
+
h('div',
|
|
498
|
+
{
|
|
499
|
+
'data-popper-arrow': true,
|
|
500
|
+
'style': options.showArrow === true ? 'display: block' : 'display: none',
|
|
501
|
+
}),
|
|
502
|
+
]), [[vShow, isOpened.value === true]]);
|
|
503
|
+
},
|
|
504
|
+
}),
|
|
505
|
+
]
|
|
506
|
+
),
|
|
507
|
+
[[vShow, isOpened.value === true]]
|
|
508
|
+
);
|
|
509
|
+
},
|
|
510
|
+
});
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Handle click outside to close the tooltip
|
|
515
|
+
*/
|
|
516
|
+
onClickOutside(
|
|
517
|
+
triggerReference.value,
|
|
518
|
+
() => {
|
|
519
|
+
if (options.disableClickOutside !== true) {
|
|
520
|
+
toggleTooltip('close');
|
|
521
|
+
}
|
|
522
|
+
},
|
|
523
|
+
{ ignore: [tooltipReference] }
|
|
524
|
+
);
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* Create popper instance
|
|
528
|
+
*/
|
|
529
|
+
let isInited = false
|
|
530
|
+
const init = () => {
|
|
531
|
+
if (triggerReference.value !== undefined && tooltipReference.value !== undefined) {
|
|
532
|
+
isInited = true
|
|
533
|
+
popperInstance.value = createPopper(
|
|
534
|
+
triggerReference.value,
|
|
535
|
+
tooltipReference.value,
|
|
536
|
+
getPopperOptions.value
|
|
537
|
+
);
|
|
538
|
+
}
|
|
539
|
+
};
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Destroy popper instance
|
|
543
|
+
*/
|
|
544
|
+
onUnmounted(() => {
|
|
545
|
+
popperInstance.value?.destroy();
|
|
546
|
+
popperInstance.value = undefined;
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Watch isOpened value to emit events
|
|
551
|
+
*/
|
|
552
|
+
watch(isOpened, (value) => {
|
|
553
|
+
isInited || init()
|
|
554
|
+
if (value === false) {
|
|
555
|
+
if (options.onClosed !== undefined) {
|
|
556
|
+
options.onClosed();
|
|
557
|
+
}
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
if (options.onOpened !== undefined) {
|
|
562
|
+
options.onOpened();
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
// Update popper instance to reposition tooltip
|
|
566
|
+
popperInstance.value?.update();
|
|
567
|
+
});
|
|
568
|
+
|
|
569
|
+
return {
|
|
570
|
+
triggerElement,
|
|
571
|
+
tooltipElement,
|
|
572
|
+
popperInstance,
|
|
573
|
+
toggleTooltip,
|
|
574
|
+
isOpened: computed(() => { return isOpened.value; }),
|
|
575
|
+
};
|
|
576
|
+
};
|
|
577
|
+
|
|
578
|
+
export { usePopper };
|