lau-ecom-design-system 1.0.21 → 1.0.22

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,7 +1,7 @@
1
1
  <script lang="ts" setup>
2
2
  import { ref, computed, onMounted, onBeforeUnmount, watch, nextTick } from "vue";
3
3
  import {
4
- LauEcomUpcIconCheck as LauEcomUpcIconSearch,
4
+ LauEcomUpcIconSearch,
5
5
  LauEcomCoreIconNavClose as LauEcomUpcIconClose,
6
6
  } from "../LauEcomIcon";
7
7
 
@@ -13,6 +13,11 @@ interface Props {
13
13
  isDisabled?: boolean;
14
14
  modelValue?: string;
15
15
  forceClose?: boolean;
16
+ buttonColorClass?: string;
17
+ buttonTextColorClass?: string;
18
+ buttonClass?: string;
19
+ inputClass?: string;
20
+ containerClass?: string;
16
21
  }
17
22
 
18
23
  const props = withDefaults(defineProps<Props>(), {
@@ -20,6 +25,11 @@ const props = withDefaults(defineProps<Props>(), {
20
25
  isDisabled: false,
21
26
  modelValue: "",
22
27
  forceClose: false,
28
+ buttonColorClass: "dsEcom-bg-primary-60 hover:dsEcom-bg-primary-70",
29
+ buttonTextColorClass: "dsEcom-text-white",
30
+ buttonClass: "",
31
+ inputClass: "dsEcom-h-10 dsEcom-rounded-lg",
32
+ containerClass: ""
23
33
  });
24
34
 
25
35
  // Log de props iniciales
@@ -33,6 +43,7 @@ console.log('🔍 InputSearch Props:', {
33
43
  const emit = defineEmits({
34
44
  "update:modelValue": (value: string) => true,
35
45
  "search": (value: string) => true,
46
+ "click:search-icon": () => true
36
47
  });
37
48
 
38
49
  const searchQuery = ref(props.modelValue);
@@ -49,6 +60,7 @@ const handleSearch = () => {
49
60
  if (searchQuery.value && searchQuery.value.trim()) {
50
61
  emit("search", searchQuery.value);
51
62
  emit("update:modelValue", searchQuery.value);
63
+ emit("click:search-icon");
52
64
  closeSearch();
53
65
  }
54
66
  };
@@ -88,9 +100,9 @@ const handleFocus = () => {
88
100
 
89
101
  const containerClasses = computed(() => {
90
102
  const classes = [
91
- "dsEcom-transition-transform dsEcom-duration-300 dsEcom-ease-in-out",
103
+ "dsEcom-transition-transform dsEcom-duration-300 dsEcom-ease-in-out dsEcom-relative",
92
104
  {
93
- "dsEcom-relative dsEcom-w-[250px] md:dsEcom-w-[350px]": !isExpanded.value
105
+ "dsEcom-w-[250px] md:dsEcom-w-[350px]": !isExpanded.value
94
106
  }
95
107
  ];
96
108
  console.log('🔍 Container classes updated:', { isExpanded: isExpanded.value });
@@ -111,9 +123,24 @@ const expandedContainer = ref<HTMLElement | null>(null);
111
123
  const updateExpandedPosition = () => {
112
124
  if (originalContainer.value && expandedContainer.value) {
113
125
  const rect = originalContainer.value.getBoundingClientRect();
114
- const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
115
- expandedContainer.value.style.top = `${rect.top + scrollTop}px`;
116
- console.log('🔍 Updated expanded position:', { top: rect.top + scrollTop });
126
+ const viewportHeight = window.innerHeight;
127
+
128
+ // Si el input original está fuera de la vista (arriba o abajo), posicionamos el expandido en una posición visible
129
+ let topPosition;
130
+ if (rect.top < 0) {
131
+ topPosition = '20px'; // Si está arriba de la vista, lo ponemos cerca del tope
132
+ } else if (rect.top > viewportHeight) {
133
+ topPosition = '20px'; // Si está abajo de la vista, también lo ponemos cerca del tope
134
+ } else {
135
+ topPosition = `${rect.top}px`; // Si está visible, mantenemos su posición actual
136
+ }
137
+
138
+ expandedContainer.value.style.position = 'fixed';
139
+ expandedContainer.value.style.top = topPosition;
140
+ expandedContainer.value.style.left = '50%';
141
+ expandedContainer.value.style.transform = 'translateX(-50%)';
142
+ expandedContainer.value.style.width = '656px';
143
+ expandedContainer.value.style.maxWidth = '90vw';
117
144
  }
118
145
  };
119
146
 
@@ -154,36 +181,77 @@ watch(() => props.modelValue, (newValue) => {
154
181
  searchQuery.value = newValue;
155
182
  }
156
183
  });
184
+
185
+ const buttonClasses = computed(() => {
186
+ const defaultClasses = "dsEcom-absolute dsEcom-right-0 dsEcom-top-1/2 -dsEcom-translate-y-1/2 dsEcom-p-2 dsEcom-rounded-r-lg dsEcom-transition-all dsEcom-duration-300";
187
+
188
+ // Si hay buttonClass, usamos esas clases directamente
189
+ if (props.buttonClass) {
190
+ return [defaultClasses, props.buttonClass];
191
+ }
192
+
193
+ // Si no, usamos las clases de color tradicionales
194
+ return [
195
+ defaultClasses,
196
+ props.buttonColorClass,
197
+ props.buttonTextColorClass
198
+ ];
199
+ });
157
200
  </script>
158
201
 
159
202
  <template>
160
203
  <div class="dsEcom-relative">
161
204
  <div
162
- :class="containerClasses"
205
+ :class="[containerClasses, props.containerClass]"
163
206
  ref="originalContainer"
164
207
  >
165
- <input
166
- v-model="searchQuery"
167
- type="text"
168
- :placeholder="placeholder"
169
- :disabled="isDisabled"
170
- class="lau-ecom-input dsEcom-border dsEcom-border-neutral-80 dsEcom-rounded-lg dsEcom-px-4 dsEcom-h-10 dsEcom-w-full dsEcom-focus:outline-none dsEcom-focus:ring-2 dsEcom-focus:ring-primary-60"
171
- @focus="handleFocus"
172
- @input="handleInput"
173
- @keyup.enter="handleSearch"
174
- :class="{ 'dsEcom-invisible': isExpanded }"
175
- />
176
- <button
177
- v-if="searchQuery.length >= 3 && !isExpanded"
178
- @click="handleSearch"
179
- class="dsEcom-absolute dsEcom-right-2 dsEcom-top-1/2 -dsEcom-translate-y-1/2 dsEcom-bg-primary-60 hover:dsEcom-bg-primary-70 dsEcom-text-white dsEcom-p-2 dsEcom-rounded-lg dsEcom-transition-all dsEcom-duration-300"
180
- >
181
- <LauEcomUpcIconSearch width="20" height="20" />
182
- </button>
208
+ <div class="dsEcom-relative" :class="{ 'dsEcom-invisible': isExpanded }">
209
+ <input
210
+ v-model="searchQuery"
211
+ type="text"
212
+ :placeholder="placeholder"
213
+ :disabled="isDisabled"
214
+ :class="[
215
+ 'lau-ecom-input dsEcom-border dsEcom-border-neutral-80 dsEcom-pl-4 dsEcom-pr-24 dsEcom-w-full dsEcom-focus:outline-none dsEcom-focus:ring-2 dsEcom-focus:ring-primary-60',
216
+ props.inputClass,
217
+ { 'dsEcom-opacity-0': isExpanded }
218
+ ]"
219
+ @focus="handleFocus"
220
+ @input="handleInput"
221
+ @keyup.enter="handleSearch"
222
+ />
223
+ <div class="dsEcom-absolute dsEcom-right-0 dsEcom-inset-y-0 dsEcom-flex dsEcom-items-stretch">
224
+ <button
225
+ v-if="searchQuery.length >= 3"
226
+ @click="clearSearch"
227
+ :class="[
228
+ 'dsEcom-flex dsEcom-items-center dsEcom-px-1.5 dsEcom-text-neutral-100 hover:dsEcom-text-neutral-80 dsEcom-transition-all dsEcom-duration-300',
229
+ props.inputClass
230
+ ]"
231
+ >
232
+ <LauEcomUpcIconClose width="16" height="16" />
233
+ </button>
234
+
235
+ <button
236
+ @click="handleSearch"
237
+ :class="[
238
+ 'dsEcom-flex dsEcom-items-center dsEcom-px-3 dsEcom-transition-all dsEcom-duration-300',
239
+ props.inputClass?.includes('rounded') ? props.inputClass : 'dsEcom-rounded-r-lg',
240
+ props.buttonColorClass,
241
+ props.buttonTextColorClass,
242
+ 'dsEcom-border-0'
243
+ ]"
244
+ style="margin: 1px; height: calc(100% - 2px);"
245
+ >
246
+ <LauEcomUpcIconSearch width="20" height="20" color="currentColor" />
247
+ </button>
248
+ </div>
249
+ </div>
183
250
  </div>
184
251
 
185
252
  <!-- Overlay -->
186
253
  <div
254
+ v-show="isExpanded"
187
255
  :class="overlayClasses"
188
256
  @click="closeSearch"
189
257
  ></div>
@@ -191,8 +259,8 @@ watch(() => props.modelValue, (newValue) => {
191
259
  <!-- Versión expandida -->
192
260
  <div
193
261
  v-show="isExpanded"
194
- class="dsEcom-fixed dsEcom-w-[656px] dsEcom-left-1/2 dsEcom-transform -dsEcom-translate-x-1/2 dsEcom-z-50"
195
- :style="{ top: isExpanded ? `${originalContainer?.getBoundingClientRect().top}px` : '0' }"
262
+ class="dsEcom-fixed dsEcom-z-50 dsEcom-bg-white dsEcom-shadow-lg dsEcom-overflow-hidden"
263
+ :class="[props.inputClass?.includes('rounded') ? props.inputClass : 'dsEcom-rounded-lg']"
196
264
  ref="expandedContainer"
197
265
  >
198
266
  <div class="dsEcom-relative">
@@ -201,27 +269,38 @@ watch(() => props.modelValue, (newValue) => {
201
269
  type="text"
202
270
  :placeholder="placeholder"
203
271
  :disabled="isDisabled"
204
- class="lau-ecom-input dsEcom-border dsEcom-border-neutral-80 dsEcom-rounded-lg dsEcom-px-4 dsEcom-h-10 dsEcom-w-full dsEcom-focus:outline-none dsEcom-focus:ring-2 dsEcom-focus:ring-primary-60 dsEcom-bg-white"
272
+ :class="[
273
+ 'lau-ecom-input dsEcom-border dsEcom-border-neutral-80 dsEcom-pl-4 dsEcom-pr-24 dsEcom-w-full dsEcom-focus:outline-none dsEcom-focus:ring-2 dsEcom-focus:ring-primary-60',
274
+ props.inputClass
275
+ ]"
205
276
  @input="handleInput"
206
277
  @keyup.enter="handleSearch"
207
278
  autofocus
208
279
  />
209
-
210
- <div class="dsEcom-absolute dsEcom-right-2 dsEcom-top-1/2 -dsEcom-translate-y-1/2 dsEcom-flex dsEcom-gap-2">
280
+ <div class="dsEcom-absolute dsEcom-right-0 dsEcom-inset-y-0 dsEcom-flex dsEcom-items-stretch">
211
281
  <button
212
282
  v-if="searchQuery.length >= 3"
213
283
  @click="clearSearch"
214
- class="dsEcom-text-neutral-100 hover:dsEcom-text-neutral-80 dsEcom-transition-all dsEcom-duration-300"
284
+ :class="[
285
+ 'dsEcom-flex dsEcom-items-center dsEcom-px-1.5 dsEcom-text-neutral-100 hover:dsEcom-text-neutral-80 dsEcom-transition-all dsEcom-duration-300',
286
+ props.inputClass
287
+ ]"
215
288
  >
216
289
  <LauEcomUpcIconClose width="16" height="16" />
217
290
  </button>
218
291
 
219
292
  <button
220
- v-if="searchQuery.length >= 3"
221
293
  @click="handleSearch"
222
- class="dsEcom-bg-primary-60 hover:dsEcom-bg-primary-70 dsEcom-text-white dsEcom-p-2 dsEcom-rounded-lg dsEcom-transition-all dsEcom-duration-300"
294
+ :class="[
295
+ 'dsEcom-flex dsEcom-items-center dsEcom-px-3 dsEcom-transition-all dsEcom-duration-300',
296
+ { 'dsEcom-rounded-r-lg': !props.inputClass?.includes('rounded') },
297
+ props.buttonColorClass,
298
+ props.buttonTextColorClass,
299
+ 'dsEcom-border-0'
300
+ ]"
301
+ style="margin: 1px; height: calc(100% - 2px);"
223
302
  >
224
- <LauEcomUpcIconSearch width="20" height="20" />
303
+ <LauEcomUpcIconSearch width="20" height="20" color="currentColor" />
225
304
  </button>
226
305
  </div>
227
306
  </div>