classcard-ui 0.2.1494 → 0.2.1495

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": "classcard-ui",
3
- "version": "0.2.1494",
3
+ "version": "0.2.1495",
4
4
  "main": "dist/classcard-ui.umd.min.js",
5
5
  "scripts": {
6
6
  "serve": "vue-cli-service serve",
package/src/.DS_Store ADDED
Binary file
@@ -12,7 +12,7 @@
12
12
  <c-icon v-if="isLoading" class="mr-2 h-4 w-4" name="loader"></c-icon>
13
13
  {{ selectedValue ? selectedValue : label }}
14
14
  </button>
15
- <span class="relative -ml-px block">
15
+ <span class="relative -ml-px block" ref="dropdownTrigger">
16
16
  <button
17
17
  @click="toggleDropdown = !toggleDropdown"
18
18
  @blur="close()"
@@ -30,8 +30,11 @@
30
30
  </button>
31
31
  <div
32
32
  v-if="toggleDropdown"
33
- :class="dropdownPositionClass"
34
- class="absolute right-0 z-10 mt-2 w-56 origin-top-right rounded-md bg-white shadow-lg ring-1 ring-gray-900 ring-opacity-5"
33
+ :class="[
34
+ dropdownPositionClass,
35
+ dropdownMenuClass,
36
+ 'absolute z-10 w-56 rounded-md bg-white shadow-lg ring-1 ring-gray-900 ring-opacity-5',
37
+ ]"
35
38
  >
36
39
  <div
37
40
  class="py-1"
@@ -59,6 +62,7 @@
59
62
  <script>
60
63
  import { getActionID } from "../../helper";
61
64
  import CIcon from "../CIcon/CIcon.vue";
65
+
62
66
  export default {
63
67
  name: "CButtonWithDropdown",
64
68
  components: { CIcon },
@@ -100,11 +104,10 @@ export default {
100
104
  data() {
101
105
  return {
102
106
  toggleDropdown: false,
103
- isSelected: false,
104
107
  selectedValue: this.value,
108
+ dropdownMenuClass: "top-full right-0 mt-2 origin-top-right",
105
109
  };
106
110
  },
107
-
108
111
  computed: {
109
112
  classes() {
110
113
  return {
@@ -128,11 +131,52 @@ export default {
128
131
  getActionIDFn(name) {
129
132
  return getActionID(name, this.id);
130
133
  },
134
+ updateDropdownPlacement() {
135
+ if (this.ticking) return;
136
+
137
+ const trigger = this.$refs.dropdownTrigger;
138
+ if (!trigger) return;
139
+
140
+ this.ticking = true;
141
+ requestAnimationFrame(() => {
142
+ this.ticking = false;
143
+ if (!this.$refs.dropdownTrigger) return;
144
+
145
+ const { top, bottom, left, right } = trigger.getBoundingClientRect();
146
+ const alignRight = right >= window.innerWidth - left;
147
+ const menuHeight = (this.items || []).length * 36 + 8;
148
+ const openAbove =
149
+ window.innerHeight - bottom < menuHeight &&
150
+ top > window.innerHeight - bottom;
151
+ const horizontal = alignRight ? "right-0" : "left-0";
152
+
153
+ if (openAbove) {
154
+ this.dropdownMenuClass = alignRight
155
+ ? `bottom-full ${horizontal} mb-2 origin-bottom-right`
156
+ : `bottom-full ${horizontal} mb-2 origin-bottom-left`;
157
+ } else {
158
+ this.dropdownMenuClass = alignRight
159
+ ? `top-full ${horizontal} mt-2 origin-top-right`
160
+ : `top-full ${horizontal} mt-2 origin-top-left`;
161
+ }
162
+ });
163
+ },
164
+ togglePlacementListeners(active) {
165
+ if (active) {
166
+ window.addEventListener("resize", this.updateDropdownPlacement, {
167
+ passive: true,
168
+ });
169
+ window.addEventListener("scroll", this.updateDropdownPlacement, true);
170
+ return;
171
+ }
172
+
173
+ window.removeEventListener("resize", this.updateDropdownPlacement);
174
+ window.removeEventListener("scroll", this.updateDropdownPlacement, true);
175
+ },
131
176
  selectOption(event, value) {
132
177
  this.selectedValue = event.target.innerText;
133
178
  this.$emit("onSelectOption", value);
134
179
  this.toggleDropdown = false;
135
- this.isSelected = true;
136
180
  },
137
181
  close() {
138
182
  this.toggleDropdown = false;
@@ -145,8 +189,20 @@ export default {
145
189
  value() {
146
190
  this.selectedValue = this.value;
147
191
  },
192
+ toggleDropdown(isOpen) {
193
+ if (isOpen) {
194
+ this.$nextTick(() => {
195
+ if (!this.toggleDropdown || !this.$refs.dropdownTrigger) return;
196
+ this.updateDropdownPlacement();
197
+ this.togglePlacementListeners(true);
198
+ });
199
+ } else {
200
+ this.togglePlacementListeners(false);
201
+ }
202
+ },
203
+ },
204
+ beforeDestroy() {
205
+ this.togglePlacementListeners(false);
148
206
  },
149
207
  };
150
208
  </script>
151
-
152
- <style></style>