@v1nt1248/3nclient-lib 0.2.82 → 0.2.84

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,42 +1,31 @@
1
- <script lang="ts" setup generic="T extends Component">
2
- import { type Component, computed, nextTick, onMounted, ref } from 'vue';
1
+ <script lang="ts" setup generic="V extends any">
2
+ import { computed, defineProps, defineEmits, defineSlots, nextTick, onMounted, ref, withDefaults, useTemplateRef } from 'vue';
3
3
  import omit from 'lodash/omit';
4
+ import { determineWindowWidth } from './util';
5
+ import type { Ui3nDialogComponentProps, Ui3nDialogComponentEmits, Ui3nDialogComponentSlots } from './types';
4
6
  import Ui3nButton from '../ui3n-button/ui3n-button.vue';
5
7
  import Ui3nIcon from '../ui3n-icon/ui3n-icon.vue';
6
- import type { Ui3nDialogEvent, Ui3nDialogComponentProps, Ui3nDialogComponentEmits } from './types';
7
- import { ExtractComponentProps } from '@/types';
8
- import { determineWindowWidth } from './util';
9
8
 
10
- const props = defineProps<Ui3nDialogComponentProps<T>>();
11
- const emits = defineEmits<Ui3nDialogComponentEmits>();
12
-
13
- const currentDialogProps = computed(() => ({
14
- title: props.dialogProps?.title || '',
15
- cssClass: props.dialogProps?.cssClass || [],
16
- cssStyle: props.dialogProps?.cssStyle || {},
17
- contentCssClass: props.dialogProps?.contentCssClass || [],
18
- contentCssStyle: props.dialogProps?.contentCssStyle || {},
19
- width: props.dialogProps?.width
20
- ? props.dialogProps?.width
21
- : props.dialogProps?.cssStyle?.width
22
- ? props.dialogProps?.cssStyle?.width
23
- : 380,
24
- confirmButton: props.dialogProps?.confirmButton !== false,
25
- cancelButton: props.dialogProps?.cancelButton !== false,
26
- confirmButtonText: props.dialogProps?.confirmButtonText || 'Done',
27
- cancelButtonText: props.dialogProps?.cancelButtonText || 'Cancel',
28
- confirmButtonColor: props.dialogProps?.confirmButtonColor || 'var(--color-text-button-primary-default)',
29
- cancelButtonColor: props.dialogProps?.cancelButtonColor || 'var(--color-text-button-secondary-default)',
30
- confirmButtonBackground: props.dialogProps?.confirmButtonBackground || 'var(--color-bg-button-primary-default)',
31
- cancelButtonBackground: props.dialogProps?.cancelButtonBackground || 'var(--color-bg-button-secondary-default)',
32
- closeOnClickOverlay: props.dialogProps?.closeOnClickOverlay !== false,
33
- }));
34
-
35
- const show = ref(true);
36
- const data = ref<unknown>(null);
37
- const isValid = ref(true);
38
- const dialogOverlayElement = ref<HTMLElement | null>(null);
39
- const dialogElement = ref<HTMLDivElement | null>(null);
9
+ const props = withDefaults(
10
+ defineProps<Ui3nDialogComponentProps<V>>(), {
11
+ cssClass: () => [],
12
+ cssStyle: () => ({}),
13
+ contentCssClass: () => [],
14
+ contentCssStyle: () => ({}),
15
+ confirmButtonText: 'Done',
16
+ cancelButtonText: 'Cancel',
17
+ confirmButtonColor: 'var(--color-text-button-primary-default)',
18
+ cancelButtonColor: 'var(--color-text-button-secondary-default)',
19
+ confirmButtonBackground: 'var(--color-bg-button-primary-default)',
20
+ cancelButtonBackground: 'var(--color-bg-button-secondary-default)',
21
+ data: null,
22
+ isValid: true,
23
+ },
24
+ );
25
+ const emits = defineEmits<Ui3nDialogComponentEmits<V>>();
26
+ defineSlots<Ui3nDialogComponentSlots>();
27
+
28
+ const dialogElement = useTemplateRef('dialog-el');
40
29
  const isMousedown = ref(false);
41
30
  const dragData = ref({
42
31
  initialLeft: 0,
@@ -48,105 +37,44 @@
48
37
  });
49
38
 
50
39
  const cssStyle = computed(() => ({
51
- width: determineWindowWidth({ width: currentDialogProps.value.width, style: currentDialogProps.value.cssStyle }),
52
- ...omit(currentDialogProps.value.cssStyle, 'width'),
53
- ...(props.dialogProps?.draggable && {
40
+ width: determineWindowWidth({ width: props.width, style: props.cssStyle }),
41
+ ...omit(props.cssStyle, 'width'),
42
+ ...(props.draggable && {
54
43
  left: `${dragData.value.left}px`,
55
44
  top: `${dragData.value.top}px`,
56
45
  }),
57
46
  }));
58
47
 
59
48
  const iconData = computed(() => {
60
- if (!props.dialogProps?.icon) return null;
49
+ if (!props.icon) {
50
+ return null;
51
+ }
61
52
 
62
- if (typeof props.dialogProps.icon === 'string') {
53
+ if (typeof props.icon === 'string') {
63
54
  return {
64
- icon: props.dialogProps.icon,
65
- width: 14,
66
- height: 14,
55
+ icon: props.icon,
56
+ size: 14,
67
57
  color: 'var(--color-icon-control-secondary-default)',
68
58
  };
69
59
  }
70
60
 
71
61
  return {
72
- icon: props.dialogProps.icon.icon,
73
- width: props.dialogProps.icon.size || 14,
74
- height: props.dialogProps.icon.size || 14,
75
- color: props.dialogProps.icon.color || 'var(--color-icon-control-secondary-default)',
62
+ icon: props.icon.icon,
63
+ size: props.icon.size || 14,
64
+ color: props.icon.color || 'var(--color-icon-control-secondary-default)',
76
65
  };
77
66
  });
78
67
 
79
- function selectData(value: unknown) {
80
- data.value = value;
81
- if (
82
- !currentDialogProps.value.confirmButton &&
83
- !currentDialogProps.value.cancelButton &&
84
- props.dialogProps?.onConfirm
85
- ) {
86
- props.dialogProps?.onConfirm(data.value);
87
- closeDialog();
88
- }
89
- }
90
-
91
- function validate(value: boolean) {
92
- isValid.value = value;
93
- }
94
-
95
- function closeDialog(arg?: { ev?: Event; withAction?: boolean }) {
96
- const { ev, withAction = true } = arg || {};
97
- if (ev) {
98
- ev.stopImmediatePropagation();
99
- ev.preventDefault();
100
- }
101
- show.value = false;
102
- props.dialogProps?.onClose && props.dialogProps.onClose(data.value);
103
- if (withAction) {
104
- emits('close', data.value);
105
- }
106
- }
107
-
108
68
  function onKeydown(event: KeyboardEvent) {
109
69
  const { code } = event;
110
70
 
111
- if (code === 'Escape' && props.dialogProps?.closeOnEsc) {
71
+ if (code === 'Escape' && props.closeOnEsc) {
112
72
  event.preventDefault();
113
73
  event.stopPropagation();
114
- startEmit('cancel');
115
- }
116
- }
117
-
118
- function startEmit(event: Ui3nDialogEvent, ev?: Event) {
119
- if (event === 'click-overlay') {
120
- emits(event);
121
- currentDialogProps.value.closeOnClickOverlay && closeDialog({ ev });
122
- return;
123
- }
124
-
125
- if (event === 'confirm') {
126
- props.dialogProps?.onConfirm && props.dialogProps.onConfirm(data.value);
127
- closeDialog();
128
- }
129
-
130
- if (event === 'cancel') {
131
- props.dialogProps?.onCancel && props.dialogProps.onCancel(data.value);
132
- closeDialog();
133
- }
134
-
135
- if (data.value) {
136
- // @ts-ignore
137
- emits(event, data.value);
138
- } else {
139
- // @ts-ignore
140
- emits(event);
74
+ emits('action', { event: 'cancel', data: props.data });
141
75
  }
142
76
  }
143
77
 
144
- function handleEvent(event: Event, eventName: Ui3nDialogEvent) {
145
- event.stopImmediatePropagation();
146
- event.preventDefault();
147
- startEmit(eventName);
148
- }
149
-
150
78
  /* drag */
151
79
  function onDragstart() {
152
80
  return false;
@@ -177,20 +105,20 @@
177
105
  onMounted(() => {
178
106
  if (dialogElement.value) {
179
107
  dialogElement.value.style.setProperty(
180
- '--dialog-confirm-button-color',
181
- currentDialogProps.value.confirmButtonColor!,
108
+ '--ui3n-dialog-confirm-button-color',
109
+ props.confirmButtonColor,
182
110
  );
183
111
  dialogElement.value.style.setProperty(
184
- '--dialog-cancel-button-color',
185
- currentDialogProps.value.cancelButtonColor!,
112
+ '--ui3n-dialog-cancel-button-color',
113
+ props.cancelButtonColor,
186
114
  );
187
115
  dialogElement.value.style.setProperty(
188
- '--dialog-confirm-background-color',
189
- currentDialogProps.value.confirmButtonBackground!,
116
+ '--ui3n-dialog-confirm-background-color',
117
+ props.confirmButtonBackground,
190
118
  );
191
119
  dialogElement.value.style.setProperty(
192
- '--dialog-cancel-background-color',
193
- currentDialogProps.value.cancelButtonBackground!,
120
+ '--ui3n-dialog-cancel-background-color',
121
+ props.cancelButtonBackground,
194
122
  );
195
123
 
196
124
  nextTick(() => {
@@ -208,163 +136,166 @@
208
136
 
209
137
  <template>
210
138
  <div
211
- v-if="show"
212
- ref="dialogOverlayElement"
213
- :class="$style.overlay"
214
- @click.self.prevent="startEmit('click-overlay', $event)"
139
+ :id="id"
140
+ ref="dialog-el"
141
+ tabindex="1"
142
+ :class="[$style.dialog, draggable && isMousedown && $style.draggable, ...cssClass]"
143
+ :style="cssStyle"
144
+ v-on="
145
+ draggable
146
+ ? {
147
+ dragstart: onDragstart,
148
+ mousedown: onMousedown,
149
+ mouseup: onMouseup,
150
+ mousemove: onMousemove,
151
+ keydown: onKeydown,
152
+ }
153
+ : { keydown: onKeydown }
154
+ "
215
155
  >
156
+ <!-- HEADER -->
216
157
  <div
217
- :id="dialogProps?.id"
218
- ref="dialogElement"
219
- tabindex="1"
220
- :class="[
221
- $style.dialog,
222
- dialogProps?.draggable && isMousedown && $style.draggable,
223
- ...currentDialogProps.cssClass!,
224
- ]"
225
- :style="cssStyle"
226
- v-on="
227
- dialogProps?.draggable
228
- ? {
229
- dragstart: onDragstart,
230
- mousedown: onMousedown,
231
- mouseup: onMouseup,
232
- mousemove: onMousemove,
233
- keydown: onKeydown,
234
- }
235
- : { keydown: onKeydown }
236
- "
158
+ v-if="title"
159
+ :class="[$style.title, $style.titleDefault]"
237
160
  >
238
- <div
239
- v-if="currentDialogProps.title"
240
- :class="$style.title"
241
- >
242
- <ui3n-icon
243
- v-if="iconData"
244
- v-bind="iconData"
245
- :class="$style.icon"
246
- />
161
+ <ui3n-icon
162
+ v-if="iconData"
163
+ v-bind="iconData"
164
+ :class="$style.icon"
165
+ />
247
166
 
248
- <span>{{ currentDialogProps.title }}</span>
249
- </div>
167
+ <span>{{ title }}</span>
168
+ </div>
250
169
 
251
- <ui3n-button
252
- :class="$style.closeBtn"
253
- type="icon"
254
- size="small"
255
- color="transparent"
256
- icon="round-close"
257
- icon-size="16"
258
- icon-color="var(--color-icon-control-primary-default)"
259
- @click="closeDialog({ ev: $event })"
260
- />
170
+ <div
171
+ v-if="$slots['header']"
172
+ :class="$style.title"
173
+ >
174
+ <slot name="header" />
175
+ </div>
176
+
177
+ <div
178
+ v-if="$slots['body']"
179
+ :class="$style.content"
180
+ >
181
+ <slot name="body" />
182
+ </div>
261
183
 
262
- <div
263
- v-if="component"
264
- :class="[$style.content, ...currentDialogProps.contentCssClass!]"
265
- :style="currentDialogProps.contentCssStyle"
184
+ <div
185
+ v-if="confirmButton || cancelButton"
186
+ :class="[$style.actions, $style.actionsDefault]"
187
+ >
188
+ <ui3n-button
189
+ v-if="cancelButton"
190
+ type="custom"
191
+ :color="cancelButtonBackground"
192
+ :text-color="cancelButtonColor"
193
+ @click.stop.prevent="() => emits('action', { event: 'cancel', data: props.data })"
266
194
  >
267
- <!-- @vue-ignore -->
268
- <component
269
- :is="component"
270
- v-bind="componentProps as ExtractComponentProps<T>"
271
- @select="selectData"
272
- @validate="validate"
273
- @close="closeDialog({ ev: $event })"
274
- @confirm="startEmit('confirm')"
275
- @cancel="startEmit('cancel')"
276
- />
277
- </div>
278
-
279
- <div
280
- v-if="currentDialogProps.confirmButton || currentDialogProps.cancelButton"
281
- :class="[
282
- $style.actions,
283
- currentDialogProps.confirmButton && currentDialogProps.cancelButton && $style.bothBtns,
284
- ]"
195
+ {{ cancelButtonText }}
196
+ </ui3n-button>
197
+
198
+ <ui3n-button
199
+ v-if="confirmButton"
200
+ type="custom"
201
+ :color="confirmButtonBackground"
202
+ :text-color="confirmButtonColor"
203
+ :disabled="!isValid"
204
+ @click.stop.prevent="() => emits('action', { event: 'confirm', data: props.data })"
285
205
  >
286
- <ui3n-button
287
- v-if="currentDialogProps.cancelButton"
288
- type="custom"
289
- :color="currentDialogProps.cancelButtonBackground"
290
- :text-color="currentDialogProps.cancelButtonColor"
291
- @click="handleEvent($event, 'cancel')"
292
- >
293
- {{ currentDialogProps.cancelButtonText }}
294
- </ui3n-button>
295
-
296
- <ui3n-button
297
- v-if="currentDialogProps.confirmButton"
298
- type="custom"
299
- :color="currentDialogProps.confirmButtonBackground"
300
- :text-color="currentDialogProps.confirmButtonColor"
301
- :disabled="!isValid"
302
- @click="handleEvent($event, 'confirm')"
303
- >
304
- {{ currentDialogProps.confirmButtonText }}
305
- </ui3n-button>
306
- </div>
206
+ {{ confirmButtonText }}
207
+ </ui3n-button>
307
208
  </div>
209
+
210
+ <div
211
+ v-if="$slots['actions']"
212
+ :class="$style.actions"
213
+ >
214
+ <slot name="actions" />
215
+ </div>
216
+
217
+
218
+ <ui3n-button
219
+ :class="$style.closeBtn"
220
+ type="icon"
221
+ size="small"
222
+ color="var(--color-bg-block-primary-default)"
223
+ icon="round-close"
224
+ icon-size="16"
225
+ icon-color="var(--color-icon-control-primary-default)"
226
+ @click.stop.prevent="emits('action', { event: 'close' })"
227
+ />
308
228
  </div>
309
229
  </template>
310
230
 
311
231
  <style lang="scss" module>
312
232
  @use '../../assets/styles/mixins' as mixins;
313
233
 
314
- .overlay {
234
+ .modal-overlay {
315
235
  position: fixed;
316
236
  z-index: 1000;
317
237
  inset: 0;
318
238
  display: flex;
319
239
  justify-content: center;
320
240
  align-items: center;
321
- background-color: rgba(0, 0, 0, 0.4);
241
+ background-color: var(--shadow-close);
322
242
  }
323
243
 
324
244
  .dialog {
325
- --dialog-border-radius: 8px;
326
- --dialog-title-height: 48px;
327
- --dialog-title-padding: 0 32px 0 16px;
328
- --dialog-title-font-size: 14px;
329
- --dialog-actions-height: 64px;
330
- --dialog-actions-padding: 16px;
331
- --dialog-confirm-button-color: var(--color-text-button-primary-default);
332
- --dialog-cancel-button-color: var(--color-text-button-secondary-default);
333
- --dialog-confirm-background-color: var(--color-bg-button-primary-default);
334
- --dialog-cancel-background-color: var(--color-bg-button-secondary-default);
245
+ --ui3n-dialog-border-radius: 8px;
246
+ --ui3n-dialog-title-height: 48px;
247
+ --ui3n-dialog-title-padding: 0 32px 0 16px;
248
+ --ui3n-dialog-title-font-size: 14px;
249
+ --ui3n-dialog-actions-height: 64px;
250
+ --ui3n-dialog-actions-padding: 16px;
251
+ --ui3n-dialog-confirm-button-color: var(--color-text-button-primary-default);
252
+ --ui3n-dialog-cancel-button-color: var(--color-text-button-secondary-default);
253
+ --ui3n-dialog-confirm-background-color: var(--color-bg-button-primary-default);
254
+ --ui3n-dialog-cancel-background-color: var(--color-bg-button-secondary-default);
335
255
 
336
256
  position: relative;
337
257
  display: flex;
338
258
  flex-direction: column;
339
259
  height: auto;
260
+ min-height: var(--spacing-xxl);
340
261
  max-height: 95%;
341
262
  background-color: var(--color-bg-block-primary-default);
342
- border-radius: var(--dialog-border-radius);
263
+ border-radius: var(--ui3n-dialog-border-radius);
343
264
  outline: none;
344
- @include mixins.elevation();
265
+ @include mixins.elevation(2);
345
266
 
346
267
  &.draggable {
347
268
  cursor: move;
348
269
  }
349
270
  }
350
271
 
272
+ .closeBtn {
273
+ position: absolute;
274
+ right: 4px;
275
+ top: 12px;
276
+ z-index: 5;
277
+ }
278
+
351
279
  .title {
352
280
  position: relative;
353
281
  width: 100%;
354
- min-height: var(--dialog-title-height);
355
- height: var(--dialog-title-height);
282
+ min-height: var(--ui3n-dialog-title-height);
283
+ height: var(--ui3n-dialog-title-height);
284
+ }
285
+
286
+ .titleDefault {
356
287
  display: flex;
357
288
  justify-content: flex-start;
358
289
  align-items: center;
359
290
  column-gap: var(--spacing-s);
360
- padding: var(--dialog-title-padding);
291
+ padding: var(--ui3n-dialog-title-padding);
361
292
  border-bottom: 1px solid var(--color-border-block-primary-default);
362
293
 
363
294
  span {
364
295
  display: block;
365
296
  position: relative;
366
297
  flex-grow: 1;
367
- font-size: var(--dialog-title-font-size);
298
+ font-size: var(--ui3n-dialog-title-font-size);
368
299
  font-weight: 600;
369
300
  color: var(--color-text-control-primary-default);
370
301
  @include mixins.text-overflow-ellipsis();
@@ -375,36 +306,23 @@
375
306
  }
376
307
  }
377
308
 
378
- .dragHandleIcon {
379
- position: absolute;
380
- left: 0;
381
- top: 16px;
382
- }
383
-
384
- .closeBtn {
385
- position: absolute;
386
- right: 4px;
387
- top: 12px;
388
- z-index: 5;
389
- }
390
-
391
309
  .content {
392
310
  flex-grow: 2;
393
311
  overflow-y: auto;
394
312
  }
395
313
 
396
314
  .actions {
397
- padding: var(--dialog-actions-padding);
398
- display: flex;
315
+ position: relative;
399
316
  width: 100%;
400
- min-height: var(--dialog-actions-height);
401
- height: var(--dialog-actions-height);
317
+ min-height: var(--ui3n-dialog-actions-height);
318
+ height: var(--ui3n-dialog-actions-height);
319
+ }
320
+
321
+ .actionsDefault {
322
+ padding: var(--ui3n-dialog-actions-padding);
323
+ display: flex;
402
324
  justify-content: flex-end;
403
325
  align-items: center;
404
326
  gap: var(--spacing-s);
405
327
  }
406
-
407
- .bothBtns {
408
- margin-left: var(--spacing-s);
409
- }
410
328
  </style>
@@ -1,10 +0,0 @@
1
- import { Component } from '../../../vue/dist/vue.esm-bundler.js';
2
- import { Ui3nDialogComponentProps } from '../../components/ui3n-dialog/types';
3
- import { DialogInstance } from './types';
4
- export declare function storeDialogs(context: any): {
5
- $dialogs: {
6
- open: <T extends Component>(params: Ui3nDialogComponentProps<T>) => DialogInstance | undefined;
7
- close: (id: string) => void;
8
- closeAll: () => void;
9
- };
10
- };