@fiscozen/composables 0.1.8-beta.1 → 0.1.9

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.
@@ -1,212 +1,260 @@
1
- import { ref as d, reactive as w, onUnmounted as O, nextTick as B, defineComponent as $, useSlots as C, computed as P, toRef as S, watch as y, openBlock as z, createElementBlock as F, createElementVNode as k, renderSlot as R, unref as x, withDirectives as N, vShow as E } from "vue";
2
- const g = (s, n, l, p) => {
3
- let i = "right", e = "right-start";
4
- const r = s.getBoundingClientRect(), c = n.getBoundingClientRect(), h = l.getBoundingClientRect(), m = (h.left - r.left - c.width) / r.width, t = (r.right - h.right - c.width) / r.width, o = (h.top - r.top - c.height) / r.height, f = (r.bottom - h.bottom - c.height) / r.height;
5
- if (i = [
1
+ import { ref as f, reactive as S, onUnmounted as L, nextTick as z, onMounted as E, onBeforeUnmount as M, defineComponent as P, useSlots as N, computed as T, toRef as W, watch as O, openBlock as q, createElementBlock as A, createElementVNode as $, renderSlot as w, unref as F, withDirectives as D, normalizeClass as I, vShow as Q } from "vue";
2
+ const x = (o, t, a, n) => {
3
+ let s = "right", e = "right-start";
4
+ const u = o.getBoundingClientRect(), r = t.getBoundingClientRect(), h = a.getBoundingClientRect(), b = (h.left - u.left - r.width) / u.width, l = (u.right - h.right - r.width) / u.width, i = (h.top - u.top - r.height) / u.height, d = (u.bottom - h.bottom - r.height) / u.height;
5
+ if (s = [
6
6
  {
7
7
  key: "right",
8
- space: t
8
+ space: l
9
9
  },
10
10
  {
11
11
  key: "top",
12
- space: o
12
+ space: i
13
13
  },
14
14
  {
15
15
  key: "bottom",
16
- space: f
16
+ space: d
17
17
  },
18
18
  {
19
19
  key: "left",
20
- space: m
20
+ space: b
21
21
  }
22
- ].sort((a, v) => v.space - a.space)[0].key, !p)
23
- switch (i) {
22
+ ].sort((p, c) => c.space - p.space)[0].key, !n)
23
+ switch (s) {
24
24
  case "right":
25
25
  case "left":
26
- const a = (c.height - h.height) / 2;
27
- r.top > h.top - a && (p = "end"), r.bottom < h.top - a && (p = "start");
26
+ const p = (r.height - h.height) / 2;
27
+ u.top > h.top - p && (n = "end"), u.bottom < h.top - p && (n = "start");
28
28
  break;
29
29
  }
30
- return e = p ? `${i}-${p}` : i, e;
31
- }, q = (s, n, l, p) => ({
32
- x: n.x + s.width * l / 100,
33
- y: n.y + s.height * p / 100
34
- }), D = (s) => {
35
- const n = d(null), l = d(null), p = d(null), i = d(null), e = w({
30
+ return e = n ? `${s}-${n}` : s, e;
31
+ }, U = (o, t, a, n) => ({
32
+ x: t.x + o.width * a / 100,
33
+ y: t.y + o.height * n / 100
34
+ }), X = (o) => {
35
+ const t = f(null), a = f(null), n = f(null), s = f(null), e = S({
36
36
  position: { x: 0, y: 0 }
37
- }), r = {
37
+ }), u = {
38
38
  root: null,
39
39
  rootMargin: "0px",
40
40
  threshold: 1,
41
- ...s.element.intersectionOptions
42
- }, c = (t, o) => {
43
- }, h = d(new IntersectionObserver(c, r)), m = () => B(() => {
44
- var b;
45
- if (n.value = typeof s.element.domRef.value == "string" ? document.querySelector(s.element.domRef.value) : s.element.domRef.value, s.container ? (l.value = typeof s.container.domRef.value == "string" ? document.querySelector(s.container.domRef.value) : s.container.domRef.value, l.value ?? (l.value = document.body)) : l.value = document.body, !n.value)
41
+ ...o.element.intersectionOptions
42
+ }, r = (l, i) => {
43
+ }, h = f(new IntersectionObserver(r, u)), b = () => z(() => {
44
+ var R;
45
+ if (t.value = typeof o.element.domRef.value == "string" ? document.querySelector(o.element.domRef.value) : o.element.domRef.value, o.container ? (a.value = typeof o.container.domRef.value == "string" ? document.querySelector(o.container.domRef.value) : o.container.domRef.value, a.value ?? (a.value = document.body)) : a.value = document.body, !t.value)
46
46
  throw new Error("missing reference element for floating behavior");
47
- s.opener && (p.value = typeof s.opener.domRef.value == "string" ? document.querySelector(s.opener.domRef.value) : s.opener.domRef.value), i.value = n.value.getBoundingClientRect();
48
- const t = (b = p.value) == null ? void 0 : b.getBoundingClientRect(), o = l.value.getBoundingClientRect();
49
- h.value.observe(n.value), h.value.observe(l.value);
50
- let f = s.position ? s.position.value : "auto", u = 0, a = 0;
51
- if (s.opener && p.value && t) {
52
- switch (f) {
47
+ o.opener && (n.value = typeof o.opener.domRef.value == "string" ? document.querySelector(o.opener.domRef.value) : o.opener.domRef.value), s.value = t.value.getBoundingClientRect();
48
+ const l = (R = n.value) == null ? void 0 : R.getBoundingClientRect(), i = a.value.getBoundingClientRect(), d = window.getComputedStyle(t.value);
49
+ h.value.observe(t.value), h.value.observe(a.value);
50
+ let m = o.position ? o.position.value : "auto", p = 0, c = 0;
51
+ if (o.opener && n.value && l) {
52
+ const g = l.left - parseFloat(d.marginLeft) - parseFloat(d.marginRight), B = l.left - parseFloat(d.marginLeft), y = l.top - parseFloat(d.marginTop) - parseFloat(d.marginBottom), C = l.top - parseFloat(d.marginTop);
53
+ switch (m) {
53
54
  case "auto":
54
- f = g(
55
- l.value,
56
- n.value,
57
- p.value
55
+ m = x(
56
+ a.value,
57
+ t.value,
58
+ n.value
58
59
  );
59
60
  break;
60
61
  case "auto-start":
61
- f = g(
62
- l.value,
62
+ m = x(
63
+ a.value,
64
+ t.value,
63
65
  n.value,
64
- p.value,
65
66
  "start"
66
67
  );
67
68
  break;
68
69
  case "auto-end":
69
- f = g(
70
- l.value,
70
+ m = x(
71
+ a.value,
72
+ t.value,
71
73
  n.value,
72
- p.value,
73
74
  "end"
74
75
  );
75
76
  break;
76
77
  }
77
- switch (f) {
78
+ switch (m) {
78
79
  case "bottom":
79
- e.position.y = t.bottom, e.position.x = t.left + t.width / 2, a = -50, u = 0;
80
+ e.position.y = l.bottom, e.position.x = B + l.width / 2, c = -50, p = 0;
80
81
  break;
81
82
  case "bottom-start":
82
- e.position.y = t.bottom, e.position.x = t.left, a = 0, u = 0;
83
+ e.position.y = l.bottom, e.position.x = g, c = 0, p = 0;
83
84
  break;
84
85
  case "bottom-end":
85
- e.position.y = t.bottom, e.position.x = t.right, a = -100, u = 0;
86
+ e.position.y = l.bottom, e.position.x = l.right, c = -100, p = 0;
86
87
  break;
87
88
  case "left-start":
88
- e.position.y = t.top, e.position.x = t.left, a = -100, u = 0;
89
+ e.position.y = y, e.position.x = g, c = -100, p = 0;
89
90
  break;
90
91
  case "left":
91
- e.position.y = t.top + t.height / 2, e.position.x = t.left, u = -50, a = -100;
92
+ e.position.y = C + l.height / 2, e.position.x = g, p = -50, c = -100;
92
93
  break;
93
94
  case "left-end":
94
- e.position.y = t.bottom, e.position.x = t.left, u = -100, a = -100;
95
+ e.position.y = l.bottom, e.position.x = g, p = -100, c = -100;
95
96
  break;
96
97
  case "top-start":
97
- e.position.y = t.top, e.position.x = t.left, u = -100, a = 0;
98
+ e.position.y = y, e.position.x = g, p = -100, c = 0;
98
99
  break;
99
100
  case "top":
100
- e.position.y = t.top, e.position.x = t.left + t.width / 2, a = -50, u = -100;
101
+ e.position.y = y, e.position.x = B + l.width / 2, c = -50, p = -100;
101
102
  break;
102
103
  case "top-end":
103
- e.position.y = t.top, e.position.x = t.right, a = -100, u = -100;
104
+ e.position.y = y, e.position.x = l.right, c = -100, p = -100;
104
105
  break;
105
106
  case "right-start":
106
- e.position.y = t.top, e.position.x = t.right, a = 0, u = 0;
107
+ e.position.y = y, e.position.x = l.right, c = 0, p = 0;
107
108
  break;
108
109
  case "right":
109
- e.position.y = t.top + t.height / 2, e.position.x = t.right, u = -50, a = 0;
110
+ e.position.y = C + l.height / 2, e.position.x = l.right, p = -50, c = 0;
110
111
  break;
111
112
  case "right-end":
112
- e.position.y = t.bottom, e.position.x = t.right, u = -100, a = 0;
113
+ e.position.y = l.bottom, e.position.x = l.right, p = -100, c = 0;
113
114
  break;
114
115
  }
115
116
  } else
116
- switch (f) {
117
+ switch (m) {
117
118
  case "bottom":
118
- e.position.y = o.bottom - i.value.height, e.position.x = o.left + o.width / 2, a = -50;
119
+ e.position.y = i.bottom - s.value.height, e.position.x = i.left + i.width / 2, c = -50;
119
120
  break;
120
121
  case "left-end":
121
122
  case "bottom-start":
122
- e.position.y = o.bottom - i.value.height, e.position.x = o.left;
123
+ e.position.y = i.bottom - s.value.height, e.position.x = i.left;
123
124
  break;
124
125
  case "right-end":
125
126
  case "bottom-end":
126
- e.position.y = o.bottom - i.value.height, e.position.x = o.right - i.value.width;
127
+ e.position.y = i.bottom - s.value.height, e.position.x = i.right - s.value.width;
127
128
  break;
128
129
  case "left":
129
- e.position.y = o.top + (o.height - i.value.height) / 2, e.position.x = o.left;
130
+ e.position.y = i.top + (i.height - s.value.height) / 2, e.position.x = i.left;
130
131
  break;
131
132
  case "top-start":
132
133
  case "left-start":
133
- e.position.y = o.top, e.position.x = o.left;
134
+ e.position.y = i.top, e.position.x = i.left;
134
135
  break;
135
136
  case "top":
136
- e.position.y = o.top, e.position.x = o.left + (o.width - i.value.width) / 2;
137
+ e.position.y = i.top, e.position.x = i.left + (i.width - s.value.width) / 2;
137
138
  break;
138
139
  case "top-end":
139
140
  case "right-start":
140
- e.position.y = o.top, e.position.x = o.right - i.value.width;
141
+ e.position.y = i.top, e.position.x = i.right - s.value.width;
141
142
  case "right":
142
- e.position.y = o.top + (o.height - i.value.height) / 2, e.position.x = o.right - i.value.width;
143
+ e.position.y = i.top + (i.height - s.value.height) / 2, e.position.x = i.right - s.value.width;
143
144
  break;
144
145
  }
145
- const v = q(i.value, e.position, a, u);
146
- v.x < o.left && (e.position.x = o.left, a = 0), v.x + i.value.width > o.right && (e.position.x = o.right - i.value.width, a = 0), v.y < o.top && (e.position.y = o.top, u = 0), v.y + i.value.height > o.bottom && (e.position.y = o.bottom - i.value.height, u = 0), n.value.style.top = `${e.position.y}px`, n.value.style.left = `${e.position.x}px`, n.value.style.transform = `translateY(${u}%) translateX(${a}%)`, n.value.style.position = "absolute", i.value = n.value.getBoundingClientRect();
146
+ const v = U(s.value, e.position, c, p);
147
+ e.position.x = v.x, e.position.y = v.y, v.x < i.left && (e.position.x = i.left, c = 0), v.x + s.value.width > i.right && (e.position.x = i.right - s.value.width, c = 0), v.y < i.top && (e.position.y = i.top, p = 0), v.y + s.value.height > i.bottom && (e.position.y = i.bottom - s.value.height, p = 0), t.value.style.top = `${e.position.y}px`, t.value.style.left = `${e.position.x}px`, t.value.style.position = "fixed", t.value.style.display = "flex", s.value = t.value.getBoundingClientRect();
147
148
  });
148
- return O(() => {
149
+ return L(() => {
149
150
  h.value.disconnect();
150
151
  }), {
151
152
  float: e,
152
- rect: i,
153
+ rect: s,
153
154
  floatObserver: h,
154
- setPosition: m
155
+ setPosition: b
156
+ };
157
+ };
158
+ function k(o) {
159
+ const t = window.matchMedia(o), a = f(t.matches);
160
+ function n(s) {
161
+ a.value = s.matches;
162
+ }
163
+ return E(() => {
164
+ t.addEventListener("change", n);
165
+ }), L(() => {
166
+ t.removeEventListener("change", n);
167
+ }), a;
168
+ }
169
+ function G(o) {
170
+ return {
171
+ isGreater(t) {
172
+ return k(`(min-width: ${o[t]})`);
173
+ },
174
+ isSmaller(t) {
175
+ return k(`(max-width: ${o[t]})`);
176
+ },
177
+ isInBetween(t, a) {
178
+ return k(`(min-width: ${o[t]}) and (max-width: ${o[a]})`);
179
+ }
180
+ };
181
+ }
182
+ function H(o, t) {
183
+ if (!o)
184
+ throw new Error("A target component has to be provided.");
185
+ if (!t)
186
+ throw new Error("A callback has to be provided.");
187
+ const a = (n) => {
188
+ !o.value || n.target === o.value || n.composedPath().includes(o.value) || typeof t == "function" && t();
155
189
  };
156
- }, I = /* @__PURE__ */ $({
190
+ E(() => {
191
+ window.addEventListener("click", a);
192
+ }), M(() => {
193
+ window.removeEventListener("click", a);
194
+ });
195
+ }
196
+ const V = /* @__PURE__ */ P({
157
197
  __name: "FzFloating",
158
198
  props: {
159
199
  isOpen: { type: Boolean, default: !1 },
160
200
  position: { default: "auto" },
161
- container: {}
201
+ container: {},
202
+ contentClass: {},
203
+ openerClass: {}
162
204
  },
163
- setup(s) {
164
- const n = s, l = d(null), p = d(null), i = C(), e = {
165
- position: P(() => n.position),
205
+ setup(o) {
206
+ const t = o, a = f(null), n = f(null), s = N(), e = {
207
+ position: T(() => t.position),
166
208
  element: {
167
- domRef: p
209
+ domRef: n
168
210
  },
169
211
  container: {
170
- domRef: S(n.container || document.body)
212
+ domRef: W(t.container || document.body)
171
213
  }
172
214
  };
173
- i.opener && (e.opener = {
174
- domRef: l
215
+ s.opener && (e.opener = {
216
+ domRef: a
175
217
  });
176
- const r = D(e);
177
- return y(
178
- () => n.position,
179
- () => n.isOpen && r.setPosition()
180
- ), y(
181
- () => n.isOpen,
182
- (c) => c && r.setPosition()
183
- ), (c, h) => (z(), F("div", null, [
184
- k("div", {
218
+ const u = X(e);
219
+ return O(
220
+ () => t.position,
221
+ () => t.isOpen && u.setPosition()
222
+ ), O(
223
+ () => t.isOpen,
224
+ (r) => {
225
+ !r || !n.value || (n.value.style.top = "0px", n.value.style.left = "0px", n.value.style.transform = "none", u.setPosition());
226
+ }
227
+ ), (r, h) => (q(), A("div", null, [
228
+ $("div", {
185
229
  ref_key: "opener",
186
- ref: l,
230
+ ref: a,
187
231
  class: "inline-flex"
188
232
  }, [
189
- R(c.$slots, "opener", {
190
- isOpen: c.isOpen,
191
- floating: x(r)
233
+ w(r.$slots, "opener", {
234
+ isOpen: r.isOpen,
235
+ floating: F(u)
192
236
  })
193
237
  ], 512),
194
- N(k("div", {
238
+ w(r.$slots, "opener-end"),
239
+ D($("div", {
195
240
  ref_key: "content",
196
- ref: p,
197
- class: "bg-core-white absolute p-4"
241
+ ref: n,
242
+ class: I(["bg-core-white fixed p-4 z-10", r.contentClass])
198
243
  }, [
199
- R(c.$slots, "default", {
200
- isOpen: c.isOpen,
201
- floating: x(r)
244
+ w(r.$slots, "default", {
245
+ isOpen: r.isOpen,
246
+ floating: F(u)
202
247
  })
203
- ], 512), [
204
- [E, !c.$slots.opener || c.$slots.opener && c.isOpen]
248
+ ], 2), [
249
+ [Q, r.$slots.default && (!r.$slots.opener || r.$slots.opener && r.isOpen)]
205
250
  ])
206
251
  ]));
207
252
  }
208
253
  });
209
254
  export {
210
- I as FzFloating,
211
- D as useFloating
255
+ V as FzFloating,
256
+ G as useBreakpoints,
257
+ H as useClickOutside,
258
+ X as useFloating,
259
+ k as useMediaQuery
212
260
  };
@@ -1 +1 @@
1
- (function(d,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],i):(d=typeof globalThis<"u"?globalThis:d||self,i(d.FzComposables={},d.Vue))})(this,function(d,i){"use strict";const g=(a,s,r,p)=>{let n="right",e="right-start";const c=a.getBoundingClientRect(),f=s.getBoundingClientRect(),u=r.getBoundingClientRect(),y=(u.left-c.left-f.width)/c.width,t=(c.right-u.right-f.width)/c.width,o=(u.top-c.top-f.height)/c.height,m=(c.bottom-u.bottom-f.height)/c.height;if(n=[{key:"right",space:t},{key:"top",space:o},{key:"bottom",space:m},{key:"left",space:y}].sort((l,b)=>b.space-l.space)[0].key,!p)switch(n){case"right":case"left":const l=(f.height-u.height)/2;c.top>u.top-l&&(p="end"),c.bottom<u.top-l&&(p="start");break}return e=p?`${n}-${p}`:n,e},R=(a,s,r,p)=>({x:s.x+a.width*r/100,y:s.y+a.height*p/100}),v=a=>{const s=i.ref(null),r=i.ref(null),p=i.ref(null),n=i.ref(null),e=i.reactive({position:{x:0,y:0}}),c={root:null,rootMargin:"0px",threshold:1,...a.element.intersectionOptions},f=(t,o)=>{},u=i.ref(new IntersectionObserver(f,c)),y=()=>i.nextTick(()=>{var k;if(s.value=typeof a.element.domRef.value=="string"?document.querySelector(a.element.domRef.value):a.element.domRef.value,a.container?(r.value=typeof a.container.domRef.value=="string"?document.querySelector(a.container.domRef.value):a.container.domRef.value,r.value??(r.value=document.body)):r.value=document.body,!s.value)throw new Error("missing reference element for floating behavior");a.opener&&(p.value=typeof a.opener.domRef.value=="string"?document.querySelector(a.opener.domRef.value):a.opener.domRef.value),n.value=s.value.getBoundingClientRect();const t=(k=p.value)==null?void 0:k.getBoundingClientRect(),o=r.value.getBoundingClientRect();u.value.observe(s.value),u.value.observe(r.value);let m=a.position?a.position.value:"auto",h=0,l=0;if(a.opener&&p.value&&t){switch(m){case"auto":m=g(r.value,s.value,p.value);break;case"auto-start":m=g(r.value,s.value,p.value,"start");break;case"auto-end":m=g(r.value,s.value,p.value,"end");break}switch(m){case"bottom":e.position.y=t.bottom,e.position.x=t.left+t.width/2,l=-50,h=0;break;case"bottom-start":e.position.y=t.bottom,e.position.x=t.left,l=0,h=0;break;case"bottom-end":e.position.y=t.bottom,e.position.x=t.right,l=-100,h=0;break;case"left-start":e.position.y=t.top,e.position.x=t.left,l=-100,h=0;break;case"left":e.position.y=t.top+t.height/2,e.position.x=t.left,h=-50,l=-100;break;case"left-end":e.position.y=t.bottom,e.position.x=t.left,h=-100,l=-100;break;case"top-start":e.position.y=t.top,e.position.x=t.left,h=-100,l=0;break;case"top":e.position.y=t.top,e.position.x=t.left+t.width/2,l=-50,h=-100;break;case"top-end":e.position.y=t.top,e.position.x=t.right,l=-100,h=-100;break;case"right-start":e.position.y=t.top,e.position.x=t.right,l=0,h=0;break;case"right":e.position.y=t.top+t.height/2,e.position.x=t.right,h=-50,l=0;break;case"right-end":e.position.y=t.bottom,e.position.x=t.right,h=-100,l=0;break}}else switch(m){case"bottom":e.position.y=o.bottom-n.value.height,e.position.x=o.left+o.width/2,l=-50;break;case"left-end":case"bottom-start":e.position.y=o.bottom-n.value.height,e.position.x=o.left;break;case"right-end":case"bottom-end":e.position.y=o.bottom-n.value.height,e.position.x=o.right-n.value.width;break;case"left":e.position.y=o.top+(o.height-n.value.height)/2,e.position.x=o.left;break;case"top-start":case"left-start":e.position.y=o.top,e.position.x=o.left;break;case"top":e.position.y=o.top,e.position.x=o.left+(o.width-n.value.width)/2;break;case"top-end":case"right-start":e.position.y=o.top,e.position.x=o.right-n.value.width;case"right":e.position.y=o.top+(o.height-n.value.height)/2,e.position.x=o.right-n.value.width;break}const b=R(n.value,e.position,l,h);b.x<o.left&&(e.position.x=o.left,l=0),b.x+n.value.width>o.right&&(e.position.x=o.right-n.value.width,l=0),b.y<o.top&&(e.position.y=o.top,h=0),b.y+n.value.height>o.bottom&&(e.position.y=o.bottom-n.value.height,h=0),s.value.style.top=`${e.position.y}px`,s.value.style.left=`${e.position.x}px`,s.value.style.transform=`translateY(${h}%) translateX(${l}%)`,s.value.style.position="absolute",n.value=s.value.getBoundingClientRect()});return i.onUnmounted(()=>{u.value.disconnect()}),{float:e,rect:n,floatObserver:u,setPosition:y}},x=i.defineComponent({__name:"FzFloating",props:{isOpen:{type:Boolean,default:!1},position:{default:"auto"},container:{}},setup(a){const s=a,r=i.ref(null),p=i.ref(null),n=i.useSlots(),e={position:i.computed(()=>s.position),element:{domRef:p},container:{domRef:i.toRef(s.container||document.body)}};n.opener&&(e.opener={domRef:r});const c=v(e);return i.watch(()=>s.position,()=>s.isOpen&&c.setPosition()),i.watch(()=>s.isOpen,f=>f&&c.setPosition()),(f,u)=>(i.openBlock(),i.createElementBlock("div",null,[i.createElementVNode("div",{ref_key:"opener",ref:r,class:"inline-flex"},[i.renderSlot(f.$slots,"opener",{isOpen:f.isOpen,floating:i.unref(c)})],512),i.withDirectives(i.createElementVNode("div",{ref_key:"content",ref:p,class:"bg-core-white absolute p-4"},[i.renderSlot(f.$slots,"default",{isOpen:f.isOpen,floating:i.unref(c)})],512),[[i.vShow,!f.$slots.opener||f.$slots.opener&&f.isOpen]])]))}});d.FzFloating=x,d.useFloating=v,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
1
+ (function(f,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],o):(f=typeof globalThis<"u"?globalThis:f||self,o(f.FzComposables={},f.Vue))})(this,function(f,o){"use strict";const k=(i,t,l,s)=>{let a="right",e="right-start";const u=i.getBoundingClientRect(),p=t.getBoundingClientRect(),h=l.getBoundingClientRect(),x=(h.left-u.left-p.width)/u.width,r=(u.right-h.right-p.width)/u.width,n=(h.top-u.top-p.height)/u.height,m=(u.bottom-h.bottom-p.height)/u.height;if(a=[{key:"right",space:r},{key:"top",space:n},{key:"bottom",space:m},{key:"left",space:x}].sort((c,d)=>d.space-c.space)[0].key,!s)switch(a){case"right":case"left":const c=(p.height-h.height)/2;u.top>h.top-c&&(s="end"),u.bottom<h.top-c&&(s="start");break}return e=s?`${a}-${s}`:a,e},F=(i,t,l,s)=>({x:t.x+i.width*l/100,y:t.y+i.height*s/100}),R=i=>{const t=o.ref(null),l=o.ref(null),s=o.ref(null),a=o.ref(null),e=o.reactive({position:{x:0,y:0}}),u={root:null,rootMargin:"0px",threshold:1,...i.element.intersectionOptions},p=(r,n)=>{},h=o.ref(new IntersectionObserver(p,u)),x=()=>o.nextTick(()=>{var B;if(t.value=typeof i.element.domRef.value=="string"?document.querySelector(i.element.domRef.value):i.element.domRef.value,i.container?(l.value=typeof i.container.domRef.value=="string"?document.querySelector(i.container.domRef.value):i.container.domRef.value,l.value??(l.value=document.body)):l.value=document.body,!t.value)throw new Error("missing reference element for floating behavior");i.opener&&(s.value=typeof i.opener.domRef.value=="string"?document.querySelector(i.opener.domRef.value):i.opener.domRef.value),a.value=t.value.getBoundingClientRect();const r=(B=s.value)==null?void 0:B.getBoundingClientRect(),n=l.value.getBoundingClientRect(),m=window.getComputedStyle(t.value);h.value.observe(t.value),h.value.observe(l.value);let g=i.position?i.position.value:"auto",c=0,d=0;if(i.opener&&s.value&&r){const b=r.left-parseFloat(m.marginLeft)-parseFloat(m.marginRight),C=r.left-parseFloat(m.marginLeft),v=r.top-parseFloat(m.marginTop)-parseFloat(m.marginBottom),O=r.top-parseFloat(m.marginTop);switch(g){case"auto":g=k(l.value,t.value,s.value);break;case"auto-start":g=k(l.value,t.value,s.value,"start");break;case"auto-end":g=k(l.value,t.value,s.value,"end");break}switch(g){case"bottom":e.position.y=r.bottom,e.position.x=C+r.width/2,d=-50,c=0;break;case"bottom-start":e.position.y=r.bottom,e.position.x=b,d=0,c=0;break;case"bottom-end":e.position.y=r.bottom,e.position.x=r.right,d=-100,c=0;break;case"left-start":e.position.y=v,e.position.x=b,d=-100,c=0;break;case"left":e.position.y=O+r.height/2,e.position.x=b,c=-50,d=-100;break;case"left-end":e.position.y=r.bottom,e.position.x=b,c=-100,d=-100;break;case"top-start":e.position.y=v,e.position.x=b,c=-100,d=0;break;case"top":e.position.y=v,e.position.x=C+r.width/2,d=-50,c=-100;break;case"top-end":e.position.y=v,e.position.x=r.right,d=-100,c=-100;break;case"right-start":e.position.y=v,e.position.x=r.right,d=0,c=0;break;case"right":e.position.y=O+r.height/2,e.position.x=r.right,c=-50,d=0;break;case"right-end":e.position.y=r.bottom,e.position.x=r.right,c=-100,d=0;break}}else switch(g){case"bottom":e.position.y=n.bottom-a.value.height,e.position.x=n.left+n.width/2,d=-50;break;case"left-end":case"bottom-start":e.position.y=n.bottom-a.value.height,e.position.x=n.left;break;case"right-end":case"bottom-end":e.position.y=n.bottom-a.value.height,e.position.x=n.right-a.value.width;break;case"left":e.position.y=n.top+(n.height-a.value.height)/2,e.position.x=n.left;break;case"top-start":case"left-start":e.position.y=n.top,e.position.x=n.left;break;case"top":e.position.y=n.top,e.position.x=n.left+(n.width-a.value.width)/2;break;case"top-end":case"right-start":e.position.y=n.top,e.position.x=n.right-a.value.width;case"right":e.position.y=n.top+(n.height-a.value.height)/2,e.position.x=n.right-a.value.width;break}const y=F(a.value,e.position,d,c);e.position.x=y.x,e.position.y=y.y,y.x<n.left&&(e.position.x=n.left,d=0),y.x+a.value.width>n.right&&(e.position.x=n.right-a.value.width,d=0),y.y<n.top&&(e.position.y=n.top,c=0),y.y+a.value.height>n.bottom&&(e.position.y=n.bottom-a.value.height,c=0),t.value.style.top=`${e.position.y}px`,t.value.style.left=`${e.position.x}px`,t.value.style.position="fixed",t.value.style.display="flex",a.value=t.value.getBoundingClientRect()});return o.onUnmounted(()=>{h.value.disconnect()}),{float:e,rect:a,floatObserver:h,setPosition:x}};function w(i){const t=window.matchMedia(i),l=o.ref(t.matches);function s(a){l.value=a.matches}return o.onMounted(()=>{t.addEventListener("change",s)}),o.onUnmounted(()=>{t.removeEventListener("change",s)}),l}function S(i){return{isGreater(t){return w(`(min-width: ${i[t]})`)},isSmaller(t){return w(`(max-width: ${i[t]})`)},isInBetween(t,l){return w(`(min-width: ${i[t]}) and (max-width: ${i[l]})`)}}}function $(i,t){if(!i)throw new Error("A target component has to be provided.");if(!t)throw new Error("A callback has to be provided.");const l=s=>{!i.value||s.target===i.value||s.composedPath().includes(i.value)||typeof t=="function"&&t()};o.onMounted(()=>{window.addEventListener("click",l)}),o.onBeforeUnmount(()=>{window.removeEventListener("click",l)})}const E=o.defineComponent({__name:"FzFloating",props:{isOpen:{type:Boolean,default:!1},position:{default:"auto"},container:{},contentClass:{},openerClass:{}},setup(i){const t=i,l=o.ref(null),s=o.ref(null),a=o.useSlots(),e={position:o.computed(()=>t.position),element:{domRef:s},container:{domRef:o.toRef(t.container||document.body)}};a.opener&&(e.opener={domRef:l});const u=R(e);return o.watch(()=>t.position,()=>t.isOpen&&u.setPosition()),o.watch(()=>t.isOpen,p=>{!p||!s.value||(s.value.style.top="0px",s.value.style.left="0px",s.value.style.transform="none",u.setPosition())}),(p,h)=>(o.openBlock(),o.createElementBlock("div",null,[o.createElementVNode("div",{ref_key:"opener",ref:l,class:"inline-flex"},[o.renderSlot(p.$slots,"opener",{isOpen:p.isOpen,floating:o.unref(u)})],512),o.renderSlot(p.$slots,"opener-end"),o.withDirectives(o.createElementVNode("div",{ref_key:"content",ref:s,class:o.normalizeClass(["bg-core-white fixed p-4 z-10",p.contentClass])},[o.renderSlot(p.$slots,"default",{isOpen:p.isOpen,floating:o.unref(u)})],2),[[o.vShow,p.$slots.default&&(!p.$slots.opener||p.$slots.opener&&p.isOpen)]])]))}});f.FzFloating=E,f.useBreakpoints=S,f.useClickOutside=$,f.useFloating=R,f.useMediaQuery=w,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fiscozen/composables",
3
- "version": "0.1.8-beta.1",
3
+ "version": "0.1.9",
4
4
  "description": "Design System utility composables",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
@@ -26,8 +26,8 @@
26
26
  "vitest": "^1.2.0",
27
27
  "vue-tsc": "^1.8.25",
28
28
  "@fiscozen/tsconfig": "^0.1.0",
29
- "@fiscozen/prettier-config": "^0.1.0",
30
- "@fiscozen/eslint-config": "^0.1.0"
29
+ "@fiscozen/eslint-config": "^0.1.0",
30
+ "@fiscozen/prettier-config": "^0.1.0"
31
31
  },
32
32
  "license": "ISC",
33
33
  "scripts": {
@@ -46,6 +46,14 @@ watch(
46
46
  floating.setPosition()
47
47
  }
48
48
  )
49
+
50
+ const contentClass = computed(() => {
51
+ if (props.overrideContentClass) {
52
+ return props.contentClass
53
+ }
54
+
55
+ return ['bg-core-white fixed p-4 z-10', props.contentClass]
56
+ })
49
57
  </script>
50
58
 
51
59
  <template>
@@ -54,16 +62,13 @@ watch(
54
62
  <slot name="opener" :isOpen :floating></slot>
55
63
  </div>
56
64
  <slot name="opener-end"></slot>
57
- <Teleport to="body">
58
- <div
59
- ref="content"
60
- v-show="$slots.default && (!$slots.opener || ($slots.opener && isOpen))"
61
- class="fz__floating__content bg-core-white fixed p-4 z-10"
62
- :class="contentClass"
63
- >
64
- <slot :isOpen :floating></slot>
65
- </div>
66
- </Teleport>
65
+ <div
66
+ ref="content"
67
+ v-show="$slots.default && (!$slots.opener || ($slots.opener && isOpen))"
68
+ :class="contentClass"
69
+ >
70
+ <slot :isOpen :floating></slot>
71
+ </div>
67
72
  </div>
68
73
  </template>
69
74
 
@@ -61,8 +61,8 @@ export const useFloating = (
61
61
  rect.value = safeElementDomRef.value.getBoundingClientRect()
62
62
  const openerRect = safeOpenerDomRef.value?.getBoundingClientRect()
63
63
  const containerRect = safeContainerDomRef.value.getBoundingClientRect()
64
-
65
- const elStyle = window.getComputedStyle(safeElementDomRef.value);
64
+
65
+ const elStyle = window.getComputedStyle(safeElementDomRef.value)
66
66
 
67
67
  // multiple observer calls on same target do not cause multiple registrations
68
68
  floatObserver.value.observe(safeElementDomRef.value)
@@ -74,11 +74,12 @@ export const useFloating = (
74
74
  let translateX = 0
75
75
 
76
76
  if (args.opener && safeOpenerDomRef.value && openerRect) {
77
-
78
- const leftWithoutXMargin = openerRect.left - parseFloat(elStyle.marginLeft) - parseFloat(elStyle.marginRight);
79
- const leftWithoutLeftMargin = openerRect.left - parseFloat(elStyle.marginLeft);
80
- const topWithoutYMargin = openerRect.top - parseFloat(elStyle.marginTop) - parseFloat(elStyle.marginBottom);
81
- const topWithoutTopMargin = openerRect.top - parseFloat(elStyle.marginTop);
77
+ const leftWithoutXMargin =
78
+ openerRect.left - parseFloat(elStyle.marginLeft) - parseFloat(elStyle.marginRight)
79
+ const leftWithoutLeftMargin = openerRect.left - parseFloat(elStyle.marginLeft)
80
+ const topWithoutYMargin =
81
+ openerRect.top - parseFloat(elStyle.marginTop) - parseFloat(elStyle.marginBottom)
82
+ const topWithoutTopMargin = openerRect.top - parseFloat(elStyle.marginTop)
82
83
 
83
84
  switch (position) {
84
85
  case 'auto':
@@ -228,7 +229,7 @@ export const useFloating = (
228
229
 
229
230
  const realPos = calcRealPos(rect.value, float.position, translateX, translateY)
230
231
 
231
- float.position.x = realPos.x
232
+ float.position.x = realPos.x
232
233
  float.position.y = realPos.y
233
234
 
234
235
  if (realPos.x < containerRect.left) {
package/src/types.ts CHANGED
@@ -8,8 +8,17 @@ export interface FzFloatingProps {
8
8
  isOpen: boolean
9
9
  position?: FzFloatingPosition
10
10
  container?: string | null
11
- contentClass?: string | string[] | Record<string, boolean|undefined> | Array<string|Record<string,boolean|undefined>>
12
- openerClass?: string | string[] | Record<string, boolean|undefined> | Array<string|Record<string,boolean|undefined>>
11
+ contentClass?:
12
+ | string
13
+ | string[]
14
+ | Record<string, boolean | undefined>
15
+ | Array<string | Record<string, boolean | undefined>>
16
+ openerClass?:
17
+ | string
18
+ | string[]
19
+ | Record<string, boolean | undefined>
20
+ | Array<string | Record<string, boolean | undefined>>
21
+ overrideContentClass?: boolean
13
22
  }
14
23
 
15
24
  export interface FzAbsolutePosition {