sprintify-ui 0.0.82 → 0.0.83

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sprintify-ui",
3
- "version": "0.0.82",
3
+ "version": "0.0.83",
4
4
  "scripts": {
5
5
  "build": "rimraf dist && vue-tsc && vite build",
6
6
  "build-fast": "rimraf dist && vite build",
@@ -15,7 +15,7 @@
15
15
  leave-from-class="transform scale-100 opacity-100"
16
16
  leave-to-class="transform scale-90 opacity-0"
17
17
  >
18
- <div v-show="showDropdown" class="inline-block">
18
+ <div v-show="showDropdown" class="inline-block" scroll-lock-target>
19
19
  <slot
20
20
  name="dropdown"
21
21
  :close="close"
@@ -31,7 +31,7 @@
31
31
 
32
32
  <script lang="ts" setup>
33
33
  import { PropType, StyleValue } from 'vue';
34
- import { useElementBounding } from '@vueuse/core';
34
+ import { disableScroll, enableScroll } from '../utils';
35
35
 
36
36
  const button = ref<HTMLElement | null>(null);
37
37
  const dropdown = ref<HTMLElement | null>(null);
@@ -57,12 +57,32 @@ const props = defineProps({
57
57
  },
58
58
  });
59
59
 
60
- const { y, x, height, width } = useElementBounding(button);
61
- const { height: dropdownHeight, width: dropdownWidth } =
62
- useElementBounding(dropdown);
60
+ const buttonX = ref(0);
61
+ const buttonY = ref(0);
62
+ const buttonWidth = ref(0);
63
+ const buttonHeight = ref(0);
64
+
65
+ const dropdownWidth = ref(0);
66
+ const dropdownHeight = ref(0);
63
67
 
64
68
  const emit = defineEmits(['close', 'open']);
65
69
 
70
+ function setBoundingBoxes() {
71
+ if (button.value) {
72
+ const { y, x, height, width } = button.value.getBoundingClientRect();
73
+ buttonX.value = x;
74
+ buttonY.value = y;
75
+ buttonWidth.value = width;
76
+ buttonHeight.value = height;
77
+ }
78
+
79
+ if (dropdown.value) {
80
+ const { height, width } = dropdown.value.getBoundingClientRect();
81
+ dropdownWidth.value = width;
82
+ dropdownHeight.value = height;
83
+ }
84
+ }
85
+
66
86
  function toggle() {
67
87
  if (showDropdown.value) {
68
88
  close();
@@ -73,13 +93,16 @@ function toggle() {
73
93
 
74
94
  function open() {
75
95
  activate();
96
+ setBoundingBoxes();
76
97
  showDropdown.value = true;
98
+ disableScroll(dropdown.value);
77
99
  emit('open');
78
100
  }
79
101
 
80
102
  function close() {
81
103
  deactivate();
82
104
  showDropdown.value = false;
105
+ enableScroll();
83
106
  emit('close');
84
107
  }
85
108
 
@@ -129,10 +152,10 @@ function onMouseDown(event: MouseEvent) {
129
152
  }
130
153
 
131
154
  const dropdownStyles = computed((): StyleValue => {
132
- let top = y.value;
155
+ let top = buttonY.value;
133
156
 
134
157
  if (props.placement == 'bottom-start' || props.placement == 'bottom-end') {
135
- top += height.value;
158
+ top += buttonHeight.value;
136
159
  top += props.padding;
137
160
  }
138
161
 
@@ -147,15 +170,18 @@ const dropdownStyles = computed((): StyleValue => {
147
170
  } as any;
148
171
 
149
172
  if (props.placement == 'bottom-end' || props.placement == 'top-end') {
150
- styles.left = `${x.value + width.value - dropdownWidth.value}px`;
173
+ styles.left = `${
174
+ buttonX.value + buttonWidth.value - dropdownWidth.value
175
+ }px`;
151
176
  } else {
152
- styles.left = `${x.value}px`;
177
+ styles.left = `${buttonX.value}px`;
153
178
  }
154
179
 
155
180
  return styles as StyleValue;
156
181
  });
157
182
 
158
183
  onBeforeUnmount(() => {
184
+ close();
159
185
  deactivate();
160
186
  });
161
187
  </script>