@mekari/pixel3-tooltip 0.0.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.
@@ -0,0 +1,60 @@
1
+ // src/modules/tooltip.props.ts
2
+ var tooltipProps = {
3
+ label: {
4
+ type: String
5
+ },
6
+ placement: {
7
+ type: String,
8
+ default: "top"
9
+ },
10
+ id: {
11
+ type: String
12
+ },
13
+ defaultIsOpen: {
14
+ type: Boolean
15
+ },
16
+ isManual: {
17
+ type: Boolean
18
+ },
19
+ isOpen: {
20
+ type: Boolean
21
+ },
22
+ showDelay: {
23
+ type: Number,
24
+ default: 0
25
+ },
26
+ hideDelay: {
27
+ type: Number,
28
+ default: 0
29
+ },
30
+ usePortal: {
31
+ type: Boolean
32
+ },
33
+ isKeepAlive: {
34
+ type: Boolean,
35
+ default: true
36
+ }
37
+ };
38
+ var singletonTooltipProps = {
39
+ triggerNode: {
40
+ type: [Object],
41
+ default: null
42
+ },
43
+ label: {
44
+ type: String
45
+ },
46
+ placement: {
47
+ type: String,
48
+ default: "right"
49
+ },
50
+ isOpen: {
51
+ type: Boolean
52
+ }
53
+ };
54
+ var tooltipEmits = ["open", "close"];
55
+
56
+ export {
57
+ tooltipProps,
58
+ singletonTooltipProps,
59
+ tooltipEmits
60
+ };
@@ -0,0 +1,40 @@
1
+ import {
2
+ useTooltip
3
+ } from "./chunk-OBETIXOG.mjs";
4
+ import {
5
+ tooltipProps
6
+ } from "./chunk-22GSYROL.mjs";
7
+
8
+ // src/tooltip.tsx
9
+ import { Fragment as _Fragment, createVNode as _createVNode, createTextVNode as _createTextVNode } from "vue";
10
+ import { defineComponent, cloneVNode, Teleport } from "vue";
11
+ var MpTooltip = defineComponent({
12
+ name: "MpTooltip",
13
+ inheritAttrs: false,
14
+ props: tooltipProps,
15
+ emits: ["open", "close"],
16
+ setup(props, {
17
+ slots,
18
+ emit
19
+ }) {
20
+ const {
21
+ triggerAttrs,
22
+ contentAttrs,
23
+ isOpen
24
+ } = useTooltip(props, emit, slots);
25
+ return () => {
26
+ const triggerNode = cloneVNode(slots.default()[0], triggerAttrs.value);
27
+ const contentNode = _createVNode("div", contentAttrs.value, [_createTextVNode(" "), slots.label ? slots.label() : props.label, _createTextVNode(" ")]);
28
+ const renderContentNode = props.usePortal ? _createVNode(Teleport, {
29
+ "to": "body"
30
+ }, {
31
+ default: () => [_createTextVNode(" "), contentNode, _createTextVNode(" ")]
32
+ }) : contentNode;
33
+ return _createVNode(_Fragment, null, [triggerNode, props.isKeepAlive ? renderContentNode : isOpen.value ? renderContentNode : null]);
34
+ };
35
+ }
36
+ });
37
+
38
+ export {
39
+ MpTooltip
40
+ };
@@ -0,0 +1,122 @@
1
+ import {
2
+ MpSingletonTooltip
3
+ } from "./chunk-JHWDKDBR.mjs";
4
+ import {
5
+ __name
6
+ } from "./chunk-QZ7VFGWC.mjs";
7
+
8
+ // src/v-tooltip.ts
9
+ import { createApp, h, ref } from "vue";
10
+ var directiveApp;
11
+ var triggerNode = ref(null);
12
+ var timeoutOpen = ref();
13
+ var timeoutClose = ref();
14
+ var tooltipState = ref({
15
+ isOpen: false,
16
+ label: "",
17
+ placement: "top"
18
+ });
19
+ function initTooltipDirectiveApp() {
20
+ if (directiveApp)
21
+ return;
22
+ directiveApp = createApp({
23
+ devtools: {
24
+ hide: true
25
+ },
26
+ name: "PixelTooltipDirectiveApp",
27
+ render() {
28
+ return h(MpSingletonTooltip, {
29
+ isOpen: tooltipState.value.isOpen,
30
+ triggerNode,
31
+ label: tooltipState.value.label,
32
+ placement: tooltipState.value.placement
33
+ });
34
+ }
35
+ });
36
+ const mountTarget = document.createElement("div");
37
+ mountTarget.id = "PixelTooltipDirectiveApp";
38
+ document.body.appendChild(mountTarget);
39
+ directiveApp.mount(mountTarget);
40
+ }
41
+ __name(initTooltipDirectiveApp, "initTooltipDirectiveApp");
42
+ var PixelTooltipDirective = {
43
+ mounted: (el, binding) => {
44
+ if (window) {
45
+ initTooltipDirectiveApp();
46
+ }
47
+ const value = binding.value;
48
+ const props = {
49
+ label: typeof binding.value === "string" ? binding.value : value.label,
50
+ placement: value.placement,
51
+ showDelay: value.showDelay,
52
+ hideDelay: value.hideDelay
53
+ };
54
+ el.$pixelTooltip = {
55
+ show: async () => {
56
+ clearTimeout(timeoutOpen.value);
57
+ timeoutOpen.value = setTimeout(async () => {
58
+ triggerNode.value = el;
59
+ tooltipState.value.label = props.label;
60
+ tooltipState.value.placement = props.placement || "top";
61
+ tooltipState.value.isOpen = true;
62
+ }, value.showDelay || 0);
63
+ },
64
+ hide: () => {
65
+ clearTimeout(timeoutClose.value);
66
+ timeoutClose.value = setTimeout(async () => {
67
+ tooltipState.value.isOpen = false;
68
+ tooltipState.value.label = "";
69
+ }, value.hideDelay || 0);
70
+ }
71
+ };
72
+ el.addEventListener("mouseover", el.$pixelTooltip.show);
73
+ el.addEventListener("focus", el.$pixelTooltip.show);
74
+ el.addEventListener("mouseleave", el.$pixelTooltip.hide);
75
+ el.addEventListener("blur", el.$pixelTooltip.hide);
76
+ },
77
+ updated: (el, binding) => {
78
+ if (window) {
79
+ initTooltipDirectiveApp();
80
+ }
81
+ const value = binding.value;
82
+ const props = {
83
+ label: typeof binding.value === "string" ? binding.value : value.label,
84
+ placement: value.placement,
85
+ showDelay: value.showDelay,
86
+ hideDelay: value.hideDelay
87
+ };
88
+ el.$pixelTooltip = {
89
+ show: async () => {
90
+ clearTimeout(timeoutOpen.value);
91
+ timeoutOpen.value = setTimeout(async () => {
92
+ triggerNode.value = el;
93
+ tooltipState.value.label = props.label;
94
+ tooltipState.value.placement = props.placement || "top";
95
+ tooltipState.value.isOpen = true;
96
+ }, value.showDelay || 0);
97
+ },
98
+ hide: () => {
99
+ clearTimeout(timeoutClose.value);
100
+ timeoutClose.value = setTimeout(async () => {
101
+ tooltipState.value.isOpen = false;
102
+ tooltipState.value.label = "";
103
+ }, value.hideDelay || 0);
104
+ }
105
+ };
106
+ el.addEventListener("mouseover", el.$pixelTooltip.show);
107
+ el.addEventListener("focus", el.$pixelTooltip.show);
108
+ el.addEventListener("mouseleave", el.$pixelTooltip.hide);
109
+ el.addEventListener("blur", el.$pixelTooltip.hide);
110
+ },
111
+ beforeUnmount(el) {
112
+ el.removeEventListener("mouseover", el.$pixelTooltip.show);
113
+ el.removeEventListener("focus", el.$pixelTooltip.show);
114
+ el.removeEventListener("mouseleave", el.$pixelTooltip.hide);
115
+ el.removeEventListener("blur", el.$pixelTooltip.hide);
116
+ delete el["$pixelTooltip"];
117
+ }
118
+ };
119
+
120
+ export {
121
+ PixelTooltipDirective
122
+ };
@@ -0,0 +1,29 @@
1
+ import {
2
+ useSingletonTooltip
3
+ } from "./chunk-OBETIXOG.mjs";
4
+ import {
5
+ singletonTooltipProps
6
+ } from "./chunk-22GSYROL.mjs";
7
+
8
+ // src/singleton-tooltip.tsx
9
+ import { createVNode as _createVNode, createTextVNode as _createTextVNode } from "vue";
10
+ import { defineComponent } from "vue";
11
+ var MpSingletonTooltip = defineComponent({
12
+ name: "MpSingletonTooltip",
13
+ inheritAttrs: false,
14
+ props: singletonTooltipProps,
15
+ setup(props, {
16
+ slots
17
+ }) {
18
+ const {
19
+ contentAttrs
20
+ } = useSingletonTooltip(props);
21
+ return () => {
22
+ return props.label ? _createVNode("div", contentAttrs.value, [_createTextVNode(" "), slots.default ? slots.default() : props.label, _createTextVNode(" ")]) : null;
23
+ };
24
+ }
25
+ });
26
+
27
+ export {
28
+ MpSingletonTooltip
29
+ };
@@ -0,0 +1,130 @@
1
+ import {
2
+ __name
3
+ } from "./chunk-QZ7VFGWC.mjs";
4
+
5
+ // src/modules/tooltip.hooks.ts
6
+ import { useFloating, autoUpdate, offset, flip, shift } from "@floating-ui/vue";
7
+ import { useId } from "@mekari/pixel3-utils";
8
+ import { ref, computed, watch, toRefs } from "vue";
9
+ import { tooltipRecipe } from "@mekari/pixel3-styled-system/recipes";
10
+ function useTooltip(props, emit, slots) {
11
+ if (slots.default().length > 1) {
12
+ console.error("[Pixel]: The MpTooltip component only expects one child.");
13
+ }
14
+ const getId = computed(() => props.id || `tooltip-${useId(4)}`);
15
+ const isOpen = ref(false);
16
+ const triggerNode = ref(null);
17
+ const contentNode = ref(null);
18
+ const placement = ref(props.placement);
19
+ const middleware = ref([offset(4), flip(), shift()]);
20
+ const {
21
+ floatingStyles
22
+ } = useFloating(triggerNode, contentNode, {
23
+ placement,
24
+ middleware,
25
+ whileElementsMounted: autoUpdate
26
+ });
27
+ function onOpenTooltip() {
28
+ setTimeout(() => {
29
+ isOpen.value = true;
30
+ emit("open");
31
+ }, props.showDelay);
32
+ }
33
+ __name(onOpenTooltip, "onOpenTooltip");
34
+ function onCloseTooltip() {
35
+ setTimeout(() => {
36
+ isOpen.value = false;
37
+ emit("close");
38
+ }, props.hideDelay);
39
+ }
40
+ __name(onCloseTooltip, "onCloseTooltip");
41
+ const triggerAttrs = computed(() => {
42
+ return {
43
+ ref: triggerNode,
44
+ "data-pixel-component": "MpTooltip",
45
+ id: getId.value,
46
+ onMouseover: () => {
47
+ if (props.isManual)
48
+ return;
49
+ onOpenTooltip();
50
+ },
51
+ onMouseleave: () => {
52
+ if (props.isManual)
53
+ return;
54
+ onCloseTooltip();
55
+ },
56
+ onFocus: () => {
57
+ if (props.isManual)
58
+ return;
59
+ onOpenTooltip();
60
+ },
61
+ onBlur: () => {
62
+ if (props.isManual)
63
+ return;
64
+ onCloseTooltip();
65
+ }
66
+ };
67
+ });
68
+ const contentAttrs = computed(() => {
69
+ return {
70
+ ref: contentNode,
71
+ class: tooltipRecipe(),
72
+ style: {
73
+ display: isOpen.value ? "unset" : "none",
74
+ ...floatingStyles.value
75
+ }
76
+ };
77
+ });
78
+ watch(() => props.isOpen, (newValue) => {
79
+ if (props.isManual) {
80
+ isOpen.value = newValue;
81
+ }
82
+ });
83
+ return {
84
+ triggerNode,
85
+ contentNode,
86
+ triggerAttrs,
87
+ contentAttrs,
88
+ isOpen,
89
+ onOpenTooltip,
90
+ onCloseTooltip
91
+ };
92
+ }
93
+ __name(useTooltip, "useTooltip");
94
+ function useSingletonTooltip(props) {
95
+ const {
96
+ triggerNode,
97
+ isOpen,
98
+ placement
99
+ } = toRefs(props);
100
+ const contentNode = ref(null);
101
+ const middleware = ref([offset(4), flip(), shift()]);
102
+ const {
103
+ floatingStyles
104
+ } = useFloating(triggerNode, contentNode, {
105
+ placement,
106
+ middleware,
107
+ whileElementsMounted: autoUpdate
108
+ });
109
+ const contentAttrs = computed(() => {
110
+ return {
111
+ ref: contentNode,
112
+ class: tooltipRecipe(),
113
+ style: {
114
+ display: (isOpen == null ? void 0 : isOpen.value) ? "unset" : "none",
115
+ ...floatingStyles.value
116
+ }
117
+ };
118
+ });
119
+ return {
120
+ triggerNode,
121
+ contentNode,
122
+ contentAttrs
123
+ };
124
+ }
125
+ __name(useSingletonTooltip, "useSingletonTooltip");
126
+
127
+ export {
128
+ useTooltip,
129
+ useSingletonTooltip
130
+ };
@@ -0,0 +1,6 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ export {
5
+ __name
6
+ };
@@ -0,0 +1,4 @@
1
+ export { MpTooltip } from './tooltip.mjs';
2
+ export { PixelTooltipDirective } from './v-tooltip.mjs';
3
+ import '@floating-ui/dom';
4
+ import 'vue';
@@ -0,0 +1,4 @@
1
+ export { MpTooltip } from './tooltip.js';
2
+ export { PixelTooltipDirective } from './v-tooltip.js';
3
+ import '@floating-ui/dom';
4
+ import 'vue';