@weni/unnnic-system 2.0.24 → 2.0.26

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": "@weni/unnnic-system",
3
- "version": "2.0.24",
3
+ "version": "2.0.26",
4
4
  "type": "commonjs",
5
5
  "files": [
6
6
  "dist",
@@ -74,4 +74,4 @@
74
74
  "vite": "4.3.5",
75
75
  "vue-eslint-parser": "^9.4.2"
76
76
  }
77
- }
77
+ }
@@ -28,7 +28,7 @@
28
28
  />
29
29
  </div>
30
30
  <div
31
- v-if="$slots.icon"
31
+ v-if="hasIcon"
32
32
  class="unnnic-modal-container-background-body__icon-slot"
33
33
  >
34
34
  <slot name="icon"></slot>
@@ -126,7 +126,10 @@ export default {
126
126
  return !(this.alertMessage === null || this.alertMessage.length === 0);
127
127
  },
128
128
  hasButton() {
129
- return !!this.$slots.options;
129
+ return !!this.$slots.options?.().length;
130
+ },
131
+ hasIcon() {
132
+ return !!this.$slots.icon?.().length;
130
133
  },
131
134
  },
132
135
  mounted() {
@@ -0,0 +1,435 @@
1
+ <template>
2
+ <div
3
+ :class="[
4
+ 'unnnic-modal',
5
+ `type-${type}`,
6
+ {
7
+ 'show-close-button': showCloseButton,
8
+ 'show-actions-area':
9
+ validate || actionPrimaryLabel || actionSecondaryLabel,
10
+ },
11
+ ]"
12
+ @click.self="closeByDarkBackground"
13
+ >
14
+ <div class="container">
15
+ <template v-if="type === 'default'">
16
+ <div
17
+ v-if="showCloseButton"
18
+ class="header"
19
+ >
20
+ <UnnnicIcon
21
+ icon="close-1"
22
+ size="sm"
23
+ clickable
24
+ @click="$emit('close')"
25
+ />
26
+ </div>
27
+
28
+ <div class="content">
29
+ <slot></slot>
30
+ </div>
31
+ </template>
32
+
33
+ <div
34
+ v-else-if="type === 'video'"
35
+ class="content"
36
+ >
37
+ <div class="aspect-ratio-box">
38
+ <iframe
39
+ class="aspect-ratio-box-inside"
40
+ type="text/html"
41
+ :src="url"
42
+ frameborder="0"
43
+ allowfullscreen
44
+ />
45
+ </div>
46
+ </div>
47
+
48
+ <template v-else-if="type === 'alert'">
49
+ <div
50
+ v-if="showCloseButton"
51
+ class="header"
52
+ >
53
+ <UnnnicIcon
54
+ icon="close-1"
55
+ size="sm"
56
+ clickable
57
+ @click="$emit('close')"
58
+ />
59
+ </div>
60
+
61
+ <div :class="['content', { 'with-validation': validate }]">
62
+ <div
63
+ v-if="icon"
64
+ class="icon"
65
+ >
66
+ <UnnnicIcon
67
+ :icon="icon"
68
+ :scheme="scheme"
69
+ size="xl"
70
+ ></UnnnicIcon>
71
+ </div>
72
+
73
+ <div
74
+ v-if="$slots.title || title"
75
+ class="title"
76
+ >
77
+ <slot
78
+ v-if="$slots.title"
79
+ name="title"
80
+ ></slot>
81
+
82
+ <template v-else>{{ title }}</template>
83
+ </div>
84
+
85
+ <div
86
+ v-if="$slots.description || description"
87
+ class="description"
88
+ >
89
+ <slot
90
+ v-if="$slots.description"
91
+ name="description"
92
+ ></slot>
93
+
94
+ <template v-else>{{ description }}</template>
95
+ </div>
96
+
97
+ <div
98
+ v-if="validate"
99
+ class="confirm-text"
100
+ >
101
+ <UnnnicInput
102
+ v-model="confirmText"
103
+ :placeholder="validatePlaceholder"
104
+ >
105
+ <template #label>
106
+ <span v-html="validateLabel" />
107
+ </template>
108
+ </UnnnicInput>
109
+ </div>
110
+
111
+ <div
112
+ v-if="validate || actionPrimaryLabel || actionSecondaryLabel"
113
+ class="actions"
114
+ :style="{ marginTop: validate ? '0' : undefined }"
115
+ >
116
+ <UnnnicButton
117
+ v-if="validate || actionSecondaryLabel"
118
+ type="tertiary"
119
+ :disabled="actionPrimaryLoading"
120
+ @click="
121
+ $attrs['click-action-secondary']
122
+ ? $emit('click-action-secondary', { close: justClose })
123
+ : $emit('close')
124
+ "
125
+ >
126
+ {{ actionSecondaryLabel }}
127
+ </UnnnicButton>
128
+
129
+ <UnnnicButton
130
+ v-if="validate || actionPrimaryLabel"
131
+ :type="actionPrimaryButtonType"
132
+ :class="
133
+ actionPrimaryButtonType === 'primary'
134
+ ? ['button', buttonType]
135
+ : undefined
136
+ "
137
+ :disabled="disabled || actionPrimaryLoading"
138
+ :loading="actionPrimaryLoading"
139
+ @click="
140
+ $attrs['click-action-primary']
141
+ ? $emit('click-action-primary', { close: justClose })
142
+ : null
143
+ "
144
+ >
145
+ {{ actionPrimaryLabel }}
146
+ </UnnnicButton>
147
+ </div>
148
+ </div>
149
+ </template>
150
+ </div>
151
+ </div>
152
+ </template>
153
+
154
+ <script>
155
+ import UnnnicIcon from '../Icon.vue';
156
+ import UnnnicInput from '../Input/Input.vue';
157
+ import UnnnicButton from '../Button/Button.vue';
158
+
159
+ export default {
160
+ components: {
161
+ UnnnicIcon,
162
+ UnnnicInput,
163
+ UnnnicButton,
164
+ },
165
+
166
+ props: {
167
+ type: {
168
+ type: String,
169
+ default: 'default',
170
+ },
171
+
172
+ url: String,
173
+ icon: String,
174
+ scheme: String,
175
+ title: String,
176
+ description: String,
177
+ validate: String,
178
+ validatePlaceholder: String,
179
+ validateLabel: String,
180
+
181
+ actionPrimaryLabel: String,
182
+ actionPrimaryLoading: Boolean,
183
+ actionPrimaryButtonType: {
184
+ type: String,
185
+ default: 'primary',
186
+ },
187
+
188
+ actionSecondaryLabel: String,
189
+
190
+ showCloseButton: Boolean,
191
+ },
192
+
193
+ emits: ['close', 'click-action-primary', 'click-action-secondary'],
194
+
195
+ data() {
196
+ return {
197
+ confirmText: '',
198
+ };
199
+ },
200
+
201
+ computed: {
202
+ isPersistent() {
203
+ return this.data?.persistent;
204
+ },
205
+
206
+ buttonType() {
207
+ if (this.disabled) {
208
+ return '';
209
+ }
210
+
211
+ if (this.scheme === 'feedback-red') {
212
+ return 'danger';
213
+ }
214
+
215
+ if (this.scheme === 'feedback-yellow') {
216
+ return 'alert';
217
+ }
218
+
219
+ return '';
220
+ },
221
+
222
+ disabled() {
223
+ if (this.validate) {
224
+ return this.confirmText !== this.validate;
225
+ }
226
+ // return (
227
+ // _.get(this.data, 'validate.text') &&
228
+ // this.confirmText !== this.data.validate.text
229
+ // );
230
+
231
+ return false;
232
+ },
233
+ },
234
+
235
+ methods: {
236
+ closeByDarkBackground() {
237
+ this.$emit('close');
238
+ },
239
+ close() {
240
+ this.justClose();
241
+
242
+ if (this.data?.onClose) {
243
+ this.data.onClose();
244
+ }
245
+ },
246
+
247
+ justClose() {
248
+ // this.closeModal(this.id);
249
+ },
250
+ },
251
+ };
252
+ </script>
253
+
254
+ <style lang="scss" scoped>
255
+ @import '../../assets/scss/unnnic.scss';
256
+
257
+ .unnnic-modal {
258
+ z-index: 5;
259
+ position: fixed;
260
+ top: 0;
261
+ right: 0;
262
+ bottom: 0;
263
+ left: 0;
264
+ background-color: rgba(0, 0, 0, $unnnic-opacity-level-overlay);
265
+ display: flex;
266
+ align-items: center;
267
+ padding: 0 12.88%;
268
+ box-sizing: border-box;
269
+
270
+ .container {
271
+ flex: 1;
272
+ max-height: 90vh;
273
+ box-sizing: border-box;
274
+ display: flex;
275
+ flex-direction: column;
276
+
277
+ border-radius: $unnnic-border-radius-sm;
278
+ background-color: $unnnic-color-background-carpet;
279
+ box-shadow: $unnnic-shadow-level-separated;
280
+ padding-top: $unnnic-spacing-stack-giant;
281
+
282
+ padding: $unnnic-spacing-stack-giant $unnnic-inline-md;
283
+
284
+ .content {
285
+ $scroll-size: $unnnic-inline-nano;
286
+
287
+ flex: 1;
288
+ overflow: overlay;
289
+
290
+ padding-right: calc(#{$unnnic-inline-xs} + #{$scroll-size});
291
+ width: 100%;
292
+
293
+ &::-webkit-scrollbar {
294
+ width: $scroll-size;
295
+ }
296
+
297
+ &::-webkit-scrollbar-thumb {
298
+ background: $unnnic-color-neutral-cleanest;
299
+ border-radius: $unnnic-border-radius-pill;
300
+ }
301
+
302
+ &::-webkit-scrollbar-track {
303
+ background: $unnnic-color-neutral-soft;
304
+ border-radius: $unnnic-border-radius-pill;
305
+ }
306
+ }
307
+ }
308
+
309
+ &.type-video {
310
+ .container {
311
+ max-width: 60 * $unnnic-font-size;
312
+ margin: 0 auto;
313
+ padding: 0 $unnnic-inline-md;
314
+ // padding-top: $unnnic-spacing-stack-giant;
315
+ padding-bottom: $unnnic-spacing-stack-lg;
316
+ }
317
+
318
+ .content {
319
+ .aspect-ratio-box {
320
+ height: 0;
321
+ overflow: hidden;
322
+ padding-top: calc(9 / 16 * 100%);
323
+ position: relative;
324
+ }
325
+
326
+ .aspect-ratio-box-inside {
327
+ position: absolute;
328
+ top: 0;
329
+ left: 0;
330
+ width: 100%;
331
+ height: 100%;
332
+ }
333
+ }
334
+ }
335
+
336
+ &.type-default .container {
337
+ max-width: 31.125 * $unnnic-font-size;
338
+ margin: 0 auto;
339
+ padding: 0 $unnnic-inline-md;
340
+ padding-top: $unnnic-spacing-stack-sm;
341
+ padding-bottom: $unnnic-spacing-stack-giant;
342
+ }
343
+
344
+ .icon {
345
+ text-align: center;
346
+ margin-bottom: $unnnic-spacing-stack-sm;
347
+ }
348
+
349
+ &.type-confirm,
350
+ &.type-alert {
351
+ .title {
352
+ text-align: center;
353
+ font-family: $unnnic-font-family-secondary;
354
+ color: $unnnic-color-neutral-darkest;
355
+ font-weight: $unnnic-font-weight-black;
356
+ font-size: $unnnic-font-size-title-sm;
357
+ line-height: ($unnnic-font-size-title-sm + $unnnic-line-height-medium);
358
+ padding-bottom: $unnnic-spacing-stack-md;
359
+ }
360
+
361
+ .description {
362
+ text-align: center;
363
+
364
+ font-family: $unnnic-font-family-secondary;
365
+ color: $unnnic-color-neutral-cloudy;
366
+ font-weight: $unnnic-font-weight-regular;
367
+ font-size: $unnnic-font-size-body-lg;
368
+ line-height: ($unnnic-font-size-body-lg + $unnnic-line-height-medium);
369
+ }
370
+ }
371
+
372
+ &.show-close-button .container {
373
+ padding-top: $unnnic-spacing-stack-sm;
374
+
375
+ .header {
376
+ display: flex;
377
+ justify-content: flex-end;
378
+ margin-bottom: $unnnic-spacing-stack-xs;
379
+ }
380
+ }
381
+
382
+ &.show-actions-area .container {
383
+ padding-bottom: $unnnic-spacing-stack-lg;
384
+ }
385
+
386
+ &.confirm .container {
387
+ max-width: 31.125 * $unnnic-font-size;
388
+ margin: 0 auto;
389
+ padding: 0 $unnnic-spacing-stack-lg;
390
+ padding-top: $unnnic-spacing-stack-giant;
391
+ padding-bottom: $unnnic-inline-md;
392
+
393
+ .description {
394
+ margin-bottom: $unnnic-spacing-stack-giant;
395
+ }
396
+ }
397
+
398
+ &.type-alert .container {
399
+ max-width: 31.125 * $unnnic-font-size;
400
+ margin: 0 auto;
401
+
402
+ .header {
403
+ margin-bottom: $unnnic-spacing-stack-xs;
404
+ text-align: right;
405
+ }
406
+
407
+ .content.with-validation .description {
408
+ margin-bottom: $unnnic-spacing-stack-lg;
409
+ }
410
+
411
+ .confirm-text {
412
+ margin-bottom: $unnnic-spacing-stack-lg;
413
+ }
414
+
415
+ .actions {
416
+ display: grid;
417
+ column-gap: $unnnic-inline-lg;
418
+ grid-auto-flow: column;
419
+ margin-top: $unnnic-spacing-stack-giant;
420
+
421
+ .button {
422
+ &.danger:not([disabled]) {
423
+ background-color: $unnnic-color-feedback-red;
424
+ color: $unnnic-color-neutral-snow;
425
+ }
426
+
427
+ &.alert:not([disabled]) {
428
+ background-color: $unnnic-color-feedback-yellow;
429
+ color: $unnnic-color-neutral-snow;
430
+ }
431
+ }
432
+ }
433
+ }
434
+ }
435
+ </style>
@@ -161,11 +161,8 @@ export default {
161
161
  window.removeEventListener('resize', this.handleResize);
162
162
  },
163
163
  mounted() {
164
- const fallbackLabelWidth = 32 + this.sliderVal.toString().length * 4.5;
165
- this.sliderWidth = this.$refs.input.clientWidth;
166
- this.labelWidth =
167
- this.$refs.tooltip.$refs.label.clientWidth || fallbackLabelWidth;
168
- this.tooltipOffset = this.getNewTooltipPosition();
164
+ this.checkInputWidth();
165
+ this.checkTooltipLabelWidth();
169
166
  },
170
167
  methods: {
171
168
  configureTooltip() {
@@ -185,9 +182,40 @@ export default {
185
182
 
186
183
  this.handleValueChange();
187
184
  },
185
+ checkInputWidth() {
186
+ const intervalId = setInterval(() => {
187
+ const inputElement = this.$refs.input;
188
+ if (inputElement) {
189
+ const { offsetWidth } = inputElement;
190
+ if (offsetWidth > 0) {
191
+ this.sliderWidth = offsetWidth;
192
+ this.configureTooltip();
193
+ clearInterval(intervalId);
194
+ }
195
+ }
196
+ }, 100);
197
+ },
198
+ checkTooltipLabelWidth() {
199
+ const intervalId = setInterval(() => {
200
+ const tooltipLabel = this.$refs.tooltip?.$refs.label;
201
+ if (!tooltipLabel) {
202
+ return;
203
+ }
204
+
205
+ const { clientWidth } = tooltipLabel;
206
+ if (clientWidth > 0) {
207
+ this.labelWidth = clientWidth;
208
+ this.configureTooltip();
209
+ clearInterval(intervalId);
210
+ }
211
+ }, 100);
212
+ },
188
213
  getNewTooltipPosition() {
189
- const haldThumbWidth = 12 / 2;
190
- const halfLabelWidth = (this.labelWidth === 0 ? 32 : this.labelWidth) / 2;
214
+ if (this.sliderWidth === 0 || this.labelWidth === 0) {
215
+ return 0;
216
+ }
217
+ const halfThumbWidth = 12 / 2;
218
+ const halfLabelWidth = this.labelWidth / 2 || 16;
191
219
  const centerPosition = this.sliderWidth / 2;
192
220
 
193
221
  let percentOfRange =
@@ -199,7 +227,7 @@ export default {
199
227
  const valuePXPosition = percentOfRange * this.sliderWidth;
200
228
  const distFromCenter = valuePXPosition - centerPosition;
201
229
  const percentDistFromCenter = distFromCenter / centerPosition;
202
- const offset = percentDistFromCenter * haldThumbWidth;
230
+ const offset = percentDistFromCenter * halfThumbWidth;
203
231
 
204
232
  const finalLabelPosition = valuePXPosition - halfLabelWidth - offset;
205
233
  return finalLabelPosition;