@toife/vue 3.2.7 → 3.3.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/package.json
CHANGED
package/src/components/index.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Tooltip } from "./tooltip.vue";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<div ref="rootRef" v-bind="wrapperAttrs">
|
|
2
|
+
<div
|
|
3
|
+
ref="triggerRef"
|
|
4
|
+
v-bind="triggerAttrs"
|
|
5
|
+
@pointerenter="show"
|
|
6
|
+
@pointerleave="hide"
|
|
7
|
+
@focusin="show"
|
|
8
|
+
@focusout="onFocusOut"
|
|
9
|
+
>
|
|
10
|
+
<slot />
|
|
11
|
+
</div>
|
|
12
|
+
<div v-show="visible" v-bind="contentAttrs">
|
|
13
|
+
<slot name="content" />
|
|
14
|
+
</div>
|
|
15
|
+
</div>
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
<style lang="scss" src="@toife/core/features/tooltip/tooltip.scss" scoped></style>
|
|
2
|
+
<template src="./tooltip.html"></template>
|
|
3
|
+
<script lang="ts" setup>
|
|
4
|
+
import { unref, computed, inject, ref } from "vue";
|
|
5
|
+
import {
|
|
6
|
+
TOOLTIP_DEFAULT_PROPS,
|
|
7
|
+
APP_PROVIDER_STATE_KEY,
|
|
8
|
+
getTooltipAttrs,
|
|
9
|
+
getTooltipContentAttrs,
|
|
10
|
+
getTooltipTriggerAttrs,
|
|
11
|
+
type AppProviderState,
|
|
12
|
+
type TooltipProps,
|
|
13
|
+
} from "@toife/core";
|
|
14
|
+
import type { ProviderStateRefs } from "../../shared/provider-state";
|
|
15
|
+
|
|
16
|
+
// Component setup (props, emits, injects)
|
|
17
|
+
// ----------------------------------------------------------------------------
|
|
18
|
+
const props = withDefaults(defineProps<TooltipProps>(), {
|
|
19
|
+
...TOOLTIP_DEFAULT_PROPS,
|
|
20
|
+
});
|
|
21
|
+
const appState = inject<ProviderStateRefs<AppProviderState>>(APP_PROVIDER_STATE_KEY);
|
|
22
|
+
|
|
23
|
+
// Reactive state
|
|
24
|
+
// ----------------------------------------------------------------------------
|
|
25
|
+
const rootRef = ref<HTMLElement | null>(null);
|
|
26
|
+
const triggerRef = ref<HTMLElement | null>(null);
|
|
27
|
+
const visible = ref(false);
|
|
28
|
+
|
|
29
|
+
// Computed properties
|
|
30
|
+
// ----------------------------------------------------------------------------
|
|
31
|
+
const wrapperAttrs = computed(() => {
|
|
32
|
+
const role = props.role ?? unref(appState?.role) ?? "";
|
|
33
|
+
const shape = props.shape ?? unref(appState?.shape) ?? "";
|
|
34
|
+
|
|
35
|
+
return getTooltipAttrs({
|
|
36
|
+
role,
|
|
37
|
+
shape,
|
|
38
|
+
size: props.size,
|
|
39
|
+
disabled: props.disabled,
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const contentAttrs = computed(() => getTooltipContentAttrs({ placement: props.placement }));
|
|
44
|
+
const triggerAttrs = getTooltipTriggerAttrs();
|
|
45
|
+
|
|
46
|
+
// Methods
|
|
47
|
+
// ----------------------------------------------------------------------------
|
|
48
|
+
const show = () => {
|
|
49
|
+
if (props.disabled) return;
|
|
50
|
+
visible.value = true;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const hide = () => {
|
|
54
|
+
visible.value = false;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const onFocusOut = (event: FocusEvent) => {
|
|
58
|
+
const root = rootRef.value;
|
|
59
|
+
const next = event.relatedTarget as Node | null;
|
|
60
|
+
if (root && next && root.contains(next)) return;
|
|
61
|
+
hide();
|
|
62
|
+
};
|
|
63
|
+
</script>
|
package/src/factory.ts
CHANGED
|
@@ -40,6 +40,7 @@ import {
|
|
|
40
40
|
Tag,
|
|
41
41
|
Tab,
|
|
42
42
|
Tabs,
|
|
43
|
+
Tooltip,
|
|
43
44
|
Toast,
|
|
44
45
|
ToastContent,
|
|
45
46
|
Toolbar,
|
|
@@ -116,6 +117,7 @@ class Toife {
|
|
|
116
117
|
this.app.component(prefix + "tag", Tag);
|
|
117
118
|
this.app.component(prefix + "tab", Tab);
|
|
118
119
|
this.app.component(prefix + "tabs", Tabs);
|
|
120
|
+
this.app.component(prefix + "tooltip", Tooltip);
|
|
119
121
|
this.app.component(prefix + "toast", Toast);
|
|
120
122
|
this.app.component(prefix + "toast-content", ToastContent);
|
|
121
123
|
this.app.component(prefix + "toolbar", Toolbar);
|