sprintify-ui 0.0.107 → 0.0.109

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.
@@ -67,16 +67,18 @@ const props = defineProps({
67
67
  },
68
68
  });
69
69
 
70
+ const emit = defineEmits(['close', 'open']);
71
+
70
72
  const buttonX = ref(0);
71
73
  const buttonY = ref(0);
72
74
  const buttonWidth = ref(0);
73
75
  const buttonHeight = ref(0);
74
76
 
77
+ const dropdownX = ref(0);
78
+ const dropdownY = ref(0);
75
79
  const dropdownWidth = ref(0);
76
80
  const dropdownHeight = ref(0);
77
81
 
78
- const emit = defineEmits(['close', 'open']);
79
-
80
82
  function setBoundingBoxes() {
81
83
  if (button.value) {
82
84
  const { y, x, height, width } = button.value.getBoundingClientRect();
@@ -87,7 +89,9 @@ function setBoundingBoxes() {
87
89
  }
88
90
 
89
91
  if (dropdown.value) {
90
- const { height, width } = dropdown.value.getBoundingClientRect();
92
+ const { y, x, height, width } = dropdown.value.getBoundingClientRect();
93
+ dropdownX.value = x;
94
+ dropdownY.value = y;
91
95
  dropdownWidth.value = width;
92
96
  dropdownHeight.value = height;
93
97
  }
@@ -163,25 +167,50 @@ useClickOutside(
163
167
  );
164
168
 
165
169
  const placementInternal = computed(() => {
166
- const tooTallForTop =
167
- buttonY.value - dropdownHeight.value - props.padding < 0;
168
- const tooTallForBottom =
169
- window.innerHeight - buttonY.value - buttonHeight.value - props.padding <
170
- dropdownHeight.value;
171
-
172
- if (props.placement == 'top-start' && tooTallForTop) {
173
- return 'bottom-start';
174
- }
175
- if (props.placement == 'top-end' && tooTallForTop) {
176
- return 'bottom-end';
177
- }
178
- if (props.placement == 'bottom-start' && tooTallForBottom) {
179
- return 'top-start';
170
+ // vertical
171
+ const spaceTop = buttonY.value - props.padding;
172
+ const spaceBottom =
173
+ window.innerHeight - buttonY.value - buttonHeight.value - props.padding;
174
+
175
+ const tooTallForTop = spaceTop < dropdownHeight.value;
176
+ const tooTallForBottom = spaceBottom < dropdownHeight.value;
177
+
178
+ let verticalPreference = props.placement.split('-')[0];
179
+
180
+ if (tooTallForTop && !tooTallForBottom) {
181
+ verticalPreference = 'bottom';
182
+ } else if (!tooTallForTop && tooTallForBottom) {
183
+ verticalPreference = 'top';
184
+ } else if (tooTallForTop && tooTallForBottom) {
185
+ if (spaceTop > spaceBottom) {
186
+ verticalPreference = 'top';
187
+ } else {
188
+ verticalPreference = 'bottom';
189
+ }
180
190
  }
181
- if (props.placement == 'bottom-end' && tooTallForBottom) {
182
- return 'top-end';
191
+
192
+ // horizontal
193
+ const spaceStart = buttonX.value + buttonWidth.value;
194
+ const spaceEnd = window.innerWidth - buttonX.value;
195
+
196
+ const tooLargeForStart = spaceStart < dropdownWidth.value;
197
+ const tooLargeForEnd = spaceEnd < dropdownWidth.value;
198
+
199
+ let horizontalPreference = props.placement.split('-')[1];
200
+
201
+ if (tooLargeForStart && !tooLargeForEnd) {
202
+ horizontalPreference = 'start';
203
+ } else if (!tooLargeForStart && tooLargeForEnd) {
204
+ horizontalPreference = 'end';
205
+ } else if (tooLargeForStart && tooLargeForEnd) {
206
+ if (spaceStart > spaceEnd) {
207
+ horizontalPreference = 'end';
208
+ } else {
209
+ horizontalPreference = 'start';
210
+ }
183
211
  }
184
- return props.placement;
212
+
213
+ return `${verticalPreference}-${horizontalPreference}`;
185
214
  });
186
215
 
187
216
  const dropdownStyles = computed((): StyleValue => {
@@ -57,6 +57,15 @@ Autocomplete.args = {
57
57
  multiple: false,
58
58
  labelKey: 'label',
59
59
  valueKey: 'value',
60
+ select: {
61
+ options: [
62
+ { label: 'Option 1', value: 'option-1' },
63
+ { label: 'Option 2', value: 'option-2' },
64
+ { label: 'Option 3', value: 'option-3' },
65
+ ],
66
+ labelKey: 'label',
67
+ valueKey: 'value',
68
+ },
60
69
  };
61
70
 
62
71
  export const AutocompleteFetch = (args) => ({
@@ -24,6 +24,7 @@
24
24
  :value-key="valueKey"
25
25
  :inline="true"
26
26
  :required="required"
27
+ :select="select"
27
28
  dropdown-show="always"
28
29
  @update:model-value="onUpdate($event, close)"
29
30
  >
@@ -61,7 +62,7 @@
61
62
  <script lang="ts" setup>
62
63
  import { isArray } from 'lodash';
63
64
  import { PropType, Ref } from 'vue';
64
- import { Option } from '@/types';
65
+ import { Option, SelectConfiguration } from '@/types';
65
66
  import BaseDropdown from './BaseDropdown.vue';
66
67
  import BaseAutocomplete from './BaseAutocomplete.vue';
67
68
  import BaseAutocompleteFetch from './BaseAutocompleteFetch.vue';
@@ -117,6 +118,10 @@ const props = defineProps({
117
118
  default: undefined,
118
119
  type: Number,
119
120
  },
121
+ select: {
122
+ default: undefined,
123
+ type: [Object, undefined] as PropType<SelectConfiguration | undefined>,
124
+ },
120
125
  });
121
126
 
122
127
  const emit = defineEmits(['update:model-value', 'close']);
@@ -197,3 +197,10 @@ export interface NotificationsConfig {
197
197
  footerLabel?: string;
198
198
  footerTo?: RouteLocationRaw;
199
199
  }
200
+
201
+ export interface SelectConfiguration {
202
+ options: Option[];
203
+ valueKey: string;
204
+ labelKey: string;
205
+ onChange: (value: OptionValue) => void;
206
+ }