@rock555/frontend-core 2.0.2 → 3.0.0

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.
Files changed (66) hide show
  1. package/README.md +95 -95
  2. package/package.json +98 -98
  3. package/src/components/GlobalPendingBar.vue +85 -85
  4. package/src/components/SearchPicker.vue +84 -84
  5. package/src/components/filters/DateRangeField.vue +692 -692
  6. package/src/components/filters/{ExportCsvButton.vue → ExportButton.vue} +62 -60
  7. package/src/components/filters/FiltersBar.vue +150 -150
  8. package/src/components/filters/MonthField.vue +309 -309
  9. package/src/components/filters/SortControl.vue +162 -162
  10. package/src/components/filters/SortControlPanel.vue +242 -242
  11. package/src/components/filters/sortControl.types.ts +25 -25
  12. package/src/components/modals/ConfirmModal.vue +58 -58
  13. package/src/components/modals/ImageViewerModal.vue +200 -200
  14. package/src/components/tables/MultiSortHeader.vue +126 -126
  15. package/src/components/tables/TableBodyRow.vue +62 -62
  16. package/src/components/tables/TableFooterRow.vue +54 -54
  17. package/src/components/tables/TableHeaderRow.vue +75 -75
  18. package/src/components/tables/TableLoadedCount.vue +61 -61
  19. package/src/components/tables/TableLoadedFooter.vue +44 -44
  20. package/src/components/tables/TableSkeletonRows.vue +40 -40
  21. package/src/components/tables/TableVirtualPad.vue +16 -16
  22. package/src/components/tables/cells/BoolBadgeCell.vue +32 -32
  23. package/src/components/tables/multiSortHeader.types.ts +16 -16
  24. package/src/components/ui/FilterCheckbox.vue +1 -1
  25. package/src/components/ui/FilterSelect.vue +2 -0
  26. package/src/components/ui/UiActionTiles.vue +92 -92
  27. package/src/components/ui/UiBackLink.vue +39 -39
  28. package/src/components/ui/UiBadge.vue +60 -60
  29. package/src/components/ui/UiButton.vue +126 -126
  30. package/src/components/ui/UiCard.vue +88 -88
  31. package/src/components/ui/UiCount.vue +35 -35
  32. package/src/components/ui/UiKpiGrid.vue +144 -142
  33. package/src/components/ui/UiPopover.vue +62 -62
  34. package/src/components/ui/UiSearchInput.vue +102 -102
  35. package/src/components/ui/UiSegmented.vue +145 -145
  36. package/src/components/ui/UiTableCard.vue +116 -116
  37. package/src/components/ui/inputs/DateFormInput.vue +2 -2
  38. package/src/components/ui/inputs/FileInput.vue +5 -0
  39. package/src/components/ui/inputs/RadioSegmentFormInput.vue +0 -1
  40. package/src/components/ui/inputs/SelectFormInput.vue +1 -2
  41. package/src/components/ui/inputs/SmartField.vue +15 -13
  42. package/src/components/ui/inputs/TextareaFormInput.vue +2 -2
  43. package/src/components/ui/uiActionTiles.types.ts +10 -10
  44. package/src/components/ui/uiBadge.types.ts +11 -11
  45. package/src/components/ui/uiKpi.types.ts +19 -17
  46. package/src/composables/useAppForm.ts +67 -67
  47. package/src/composables/useConfirm.ts +21 -21
  48. package/src/composables/useFilterState.ts +70 -70
  49. package/src/composables/useServerList.ts +348 -348
  50. package/src/composables/useServerTable.ts +117 -117
  51. package/src/composables/useSharedAsync.ts +51 -51
  52. package/src/composables/useVirtualTable.ts +77 -77
  53. package/src/config.ts +156 -155
  54. package/src/errors/actionCancelled.ts +9 -9
  55. package/src/errors/apiError.helper.ts +161 -161
  56. package/src/errors/useHandleError.ts +33 -33
  57. package/src/helpers/calendarRange.helper.ts +74 -74
  58. package/src/helpers/month.helper.ts +63 -63
  59. package/src/helpers/periodLabel.helper.ts +70 -70
  60. package/src/helpers/periodPresets.helper.ts +76 -76
  61. package/src/helpers/sort.helper.ts +57 -57
  62. package/src/helpers/tableFields.helper.ts +205 -205
  63. package/src/helpers/urlParams.helper.ts +99 -99
  64. package/src/helpers/urlSchema.helper.ts +296 -296
  65. package/src/plugins/modals.plugin.ts +253 -253
  66. package/src/plugins/table.plugin.ts +173 -173
@@ -1,242 +1,242 @@
1
- <script setup lang="ts" generic="TBy extends string">
2
- // Вміст поповера сортування: вертикальний список активних ключів, порядок =
3
- // пріоритет, міняється перетягуванням.
4
- //
5
- // Вертикальний список, а не чипи в ряд: у чипів різна ширина, вони переносяться
6
- // на другий рядок, і тягнути по горизонталі в ціль змінного розміру помітно
7
- // важче. Тут одна вісь руху й однакові за висотою цілі.
8
- //
9
- // Номери пріоритету показуємо, але вводити ними не даємо: цифра — підпис до
10
- // позиції, а не спосіб її задати.
11
-
12
- import { SharedConfig } from '../../config'
13
- import { GripVertical, Plus, X } from '@lucide/vue'
14
- import { ReorderGroup, ReorderItem } from 'motion-v'
15
- import { computed } from 'vue'
16
- import UiButton from '../ui/UiButton.vue'
17
- import UiIconButton from '../ui/UiIconButton.vue'
18
- import UiPopover from '../ui/UiPopover.vue'
19
- import type { SortDirection, SortEntry, SortKeyOption } from './sortControl.types'
20
-
21
- const props = defineProps<{
22
- sort: Array<SortEntry<TBy>>
23
- keys: ReadonlyArray<SortKeyOption<TBy>>
24
- emptyText: string
25
- }>()
26
-
27
- const emit = defineEmits<{ 'update:sort': [value: Array<SortEntry<TBy>>] }>()
28
-
29
- const optionOf = (by: TBy) => props.keys.find(key => key.value === by)
30
-
31
- // Ключі, яких у стеку ще немає, — меню «Додати». Порожній список ховає кнопку.
32
- const availableKeys = computed(
33
- () => props.keys.filter(key => !props.sort.some(entry => entry.by === key.value)),
34
- )
35
-
36
- function setDirection(by: TBy, direction: SortDirection): void {
37
- emit('update:sort', props.sort.map(entry => entry.by === by ? { by, direction } : entry))
38
- }
39
-
40
- function add(option: SortKeyOption<TBy>): void {
41
- emit('update:sort', [
42
- ...props.sort,
43
- { by: option.value, direction: option.defaultDirection },
44
- ])
45
- }
46
-
47
- function remove(by: TBy): void {
48
- emit('update:sort', props.sort.filter(entry => entry.by !== by))
49
- }
50
- </script>
51
-
52
- <template>
53
- <div class="sort-panel">
54
- <p v-if="!sort.length" class="sort-panel__empty">{{ emptyText }}</p>
55
-
56
- <!-- values/@update:values — API ReorderGroup: він сам переставляє масив,
57
- нам лишається віддати результат назовні. -->
58
- <ReorderGroup
59
- v-else
60
- class="sort-panel__list"
61
- axis="y"
62
- :values="sort"
63
- @update:values="emit('update:sort', $event)"
64
- >
65
- <ReorderItem
66
- v-for="(entry, index) in sort"
67
- :key="entry.by"
68
- class="sort-panel__item"
69
- :value="entry"
70
- :while-drag="{ scale: 1.03, boxShadow: '0 8px 20px rgba(0,0,0,0.14)' }"
71
- >
72
- <!-- Тягнути можна за весь рядок; ручка — підказка, що це можливо. -->
73
- <GripVertical :size="14" class="sort-panel__grip" />
74
- <span class="sort-panel__num">{{ index + 1 }}</span>
75
-
76
- <span class="sort-panel__label">{{ optionOf(entry.by)?.label }}</span>
77
-
78
- <span class="sort-panel__dirs">
79
- <button
80
- v-for="dir in (['desc', 'asc'] as const)"
81
- :key="dir"
82
- type="button"
83
- class="sort-panel__dir"
84
- :class="{ 'sort-panel__dir--on': entry.direction === dir }"
85
- @click="setDirection(entry.by, dir)"
86
- >
87
- {{ optionOf(entry.by)?.directions[dir] }}
88
- </button>
89
- </span>
90
-
91
- <UiIconButton
92
- variant="ghost"
93
- tone="muted"
94
- :title="SharedConfig.get().labels.sortRemove"
95
- @click="remove(entry.by)"
96
- >
97
- <X :size="14" />
98
- </UiIconButton>
99
- </ReorderItem>
100
- </ReorderGroup>
101
-
102
- <UiPopover v-if="availableKeys.length" align="start">
103
- <template #trigger>
104
- <UiButton variant="ghost" size="sm" class="sort-panel__add">
105
- <Plus :size="14" /> {{ SharedConfig.get().labels.sortAdd }}
106
- </UiButton>
107
- </template>
108
-
109
- <template #default="{ close }">
110
- <div class="sort-panel__menu">
111
- <button
112
- v-for="option in availableKeys"
113
- :key="option.value"
114
- type="button"
115
- class="sort-panel__menu-item"
116
- @click="add(option); close()"
117
- >
118
- {{ option.label }}
119
- </button>
120
- </div>
121
- </template>
122
- </UiPopover>
123
- </div>
124
- </template>
125
-
126
- <style scoped lang="scss">
127
- .sort-panel {
128
- display: flex;
129
- flex-direction: column;
130
- gap: 6px;
131
- padding: 10px;
132
- width: 340px;
133
-
134
- &__empty {
135
- margin: 0;
136
- padding: 6px 4px;
137
- font-size: 12px;
138
- color: $color-muted;
139
- }
140
-
141
- &__list {
142
- display: flex;
143
- flex-direction: column;
144
- gap: 4px;
145
- // Список перетягують — свій маркер списку тут лише заважав би.
146
- margin: 0;
147
- padding: 0;
148
- list-style: none;
149
- }
150
-
151
- &__item {
152
- display: flex;
153
- align-items: center;
154
- gap: 6px;
155
- padding: 6px 6px 6px 4px;
156
- background: $color-page-bg;
157
- border: 1px solid $color-border;
158
- border-radius: 8px;
159
- cursor: grab;
160
- // Курсор тягнення на всьому рядку, але текст усередині не виділяємо —
161
- // інакше замість перетягування виходить виділення підпису.
162
- user-select: none;
163
-
164
- &:active { cursor: grabbing; }
165
- }
166
-
167
- &__grip {
168
- flex-shrink: 0;
169
- color: $color-muted;
170
- }
171
-
172
- &__num {
173
- flex-shrink: 0;
174
- width: 16px;
175
- text-align: center;
176
- font-size: 11px;
177
- font-weight: 600;
178
- color: $color-muted;
179
- font-variant-numeric: tabular-nums;
180
- }
181
-
182
- &__label {
183
- flex: 1;
184
- min-width: 0;
185
- font-size: 13px;
186
- color: $color-text;
187
- white-space: nowrap;
188
- overflow: hidden;
189
- text-overflow: ellipsis;
190
- }
191
-
192
- &__dirs {
193
- flex-shrink: 0;
194
- display: inline-flex;
195
- gap: 2px;
196
- padding: 2px;
197
- background: $color-surface;
198
- border: 1px solid $color-border;
199
- border-radius: 999px;
200
- }
201
-
202
- &__dir {
203
- padding: 2px 8px;
204
- border: none;
205
- border-radius: 999px;
206
- background: none;
207
- font-size: 11px;
208
- color: $color-muted;
209
- white-space: nowrap;
210
-
211
- &:hover { color: $color-text; }
212
-
213
- &--on {
214
- background: $color-accent;
215
- color: $color-surface;
216
- }
217
- }
218
-
219
- &__add {
220
- align-self: flex-start;
221
- }
222
-
223
- &__menu {
224
- display: flex;
225
- flex-direction: column;
226
- padding: 6px;
227
- min-width: 200px;
228
- }
229
-
230
- &__menu-item {
231
- padding: 7px 10px;
232
- border: none;
233
- border-radius: 6px;
234
- background: none;
235
- font-size: 13px;
236
- color: $color-text;
237
- text-align: left;
238
-
239
- &:hover { background: $color-accent-dim; }
240
- }
241
- }
242
- </style>
1
+ <script setup lang="ts" generic="TBy extends string">
2
+ // Вміст поповера сортування: вертикальний список активних ключів, порядок =
3
+ // пріоритет, міняється перетягуванням.
4
+ //
5
+ // Вертикальний список, а не чипи в ряд: у чипів різна ширина, вони переносяться
6
+ // на другий рядок, і тягнути по горизонталі в ціль змінного розміру помітно
7
+ // важче. Тут одна вісь руху й однакові за висотою цілі.
8
+ //
9
+ // Номери пріоритету показуємо, але вводити ними не даємо: цифра — підпис до
10
+ // позиції, а не спосіб її задати.
11
+
12
+ import { SharedConfig } from '../../config'
13
+ import { GripVertical, Plus, X } from '@lucide/vue'
14
+ import { ReorderGroup, ReorderItem } from 'motion-v'
15
+ import { computed } from 'vue'
16
+ import UiButton from '../ui/UiButton.vue'
17
+ import UiIconButton from '../ui/UiIconButton.vue'
18
+ import UiPopover from '../ui/UiPopover.vue'
19
+ import type { SortDirection, SortEntry, SortKeyOption } from './sortControl.types'
20
+
21
+ const props = defineProps<{
22
+ sort: Array<SortEntry<TBy>>
23
+ keys: ReadonlyArray<SortKeyOption<TBy>>
24
+ emptyText: string
25
+ }>()
26
+
27
+ const emit = defineEmits<{ 'update:sort': [value: Array<SortEntry<TBy>>] }>()
28
+
29
+ const optionOf = (by: TBy) => props.keys.find(key => key.value === by)
30
+
31
+ // Ключі, яких у стеку ще немає, — меню «Додати». Порожній список ховає кнопку.
32
+ const availableKeys = computed(
33
+ () => props.keys.filter(key => !props.sort.some(entry => entry.by === key.value)),
34
+ )
35
+
36
+ function setDirection(by: TBy, direction: SortDirection): void {
37
+ emit('update:sort', props.sort.map(entry => entry.by === by ? { by, direction } : entry))
38
+ }
39
+
40
+ function add(option: SortKeyOption<TBy>): void {
41
+ emit('update:sort', [
42
+ ...props.sort,
43
+ { by: option.value, direction: option.defaultDirection },
44
+ ])
45
+ }
46
+
47
+ function remove(by: TBy): void {
48
+ emit('update:sort', props.sort.filter(entry => entry.by !== by))
49
+ }
50
+ </script>
51
+
52
+ <template>
53
+ <div class="sort-panel">
54
+ <p v-if="!sort.length" class="sort-panel__empty">{{ emptyText }}</p>
55
+
56
+ <!-- values/@update:values — API ReorderGroup: він сам переставляє масив,
57
+ нам лишається віддати результат назовні. -->
58
+ <ReorderGroup
59
+ v-else
60
+ class="sort-panel__list"
61
+ axis="y"
62
+ :values="sort"
63
+ @update:values="emit('update:sort', $event)"
64
+ >
65
+ <ReorderItem
66
+ v-for="(entry, index) in sort"
67
+ :key="entry.by"
68
+ class="sort-panel__item"
69
+ :value="entry"
70
+ :while-drag="{ scale: 1.03, boxShadow: '0 8px 20px rgba(0,0,0,0.14)' }"
71
+ >
72
+ <!-- Тягнути можна за весь рядок; ручка — підказка, що це можливо. -->
73
+ <GripVertical :size="14" class="sort-panel__grip" />
74
+ <span class="sort-panel__num">{{ index + 1 }}</span>
75
+
76
+ <span class="sort-panel__label">{{ optionOf(entry.by)?.label }}</span>
77
+
78
+ <span class="sort-panel__dirs">
79
+ <button
80
+ v-for="dir in (['desc', 'asc'] as const)"
81
+ :key="dir"
82
+ type="button"
83
+ class="sort-panel__dir"
84
+ :class="{ 'sort-panel__dir--on': entry.direction === dir }"
85
+ @click="setDirection(entry.by, dir)"
86
+ >
87
+ {{ optionOf(entry.by)?.directions[dir] }}
88
+ </button>
89
+ </span>
90
+
91
+ <UiIconButton
92
+ variant="ghost"
93
+ tone="muted"
94
+ :title="SharedConfig.get().labels.sortRemove"
95
+ @click="remove(entry.by)"
96
+ >
97
+ <X :size="14" />
98
+ </UiIconButton>
99
+ </ReorderItem>
100
+ </ReorderGroup>
101
+
102
+ <UiPopover v-if="availableKeys.length" align="start">
103
+ <template #trigger>
104
+ <UiButton variant="ghost" size="sm" class="sort-panel__add">
105
+ <Plus :size="14" /> {{ SharedConfig.get().labels.sortAdd }}
106
+ </UiButton>
107
+ </template>
108
+
109
+ <template #default="{ close }">
110
+ <div class="sort-panel__menu">
111
+ <button
112
+ v-for="option in availableKeys"
113
+ :key="option.value"
114
+ type="button"
115
+ class="sort-panel__menu-item"
116
+ @click="add(option); close()"
117
+ >
118
+ {{ option.label }}
119
+ </button>
120
+ </div>
121
+ </template>
122
+ </UiPopover>
123
+ </div>
124
+ </template>
125
+
126
+ <style scoped lang="scss">
127
+ .sort-panel {
128
+ display: flex;
129
+ flex-direction: column;
130
+ gap: 6px;
131
+ padding: 10px;
132
+ width: 340px;
133
+
134
+ &__empty {
135
+ margin: 0;
136
+ padding: 6px 4px;
137
+ font-size: 12px;
138
+ color: $color-muted;
139
+ }
140
+
141
+ &__list {
142
+ display: flex;
143
+ flex-direction: column;
144
+ gap: 4px;
145
+ // Список перетягують — свій маркер списку тут лише заважав би.
146
+ margin: 0;
147
+ padding: 0;
148
+ list-style: none;
149
+ }
150
+
151
+ &__item {
152
+ display: flex;
153
+ align-items: center;
154
+ gap: 6px;
155
+ padding: 6px 6px 6px 4px;
156
+ background: $color-page-bg;
157
+ border: 1px solid $color-border;
158
+ border-radius: 8px;
159
+ cursor: grab;
160
+ // Курсор тягнення на всьому рядку, але текст усередині не виділяємо —
161
+ // інакше замість перетягування виходить виділення підпису.
162
+ user-select: none;
163
+
164
+ &:active { cursor: grabbing; }
165
+ }
166
+
167
+ &__grip {
168
+ flex-shrink: 0;
169
+ color: $color-muted;
170
+ }
171
+
172
+ &__num {
173
+ flex-shrink: 0;
174
+ width: 16px;
175
+ text-align: center;
176
+ font-size: 11px;
177
+ font-weight: 600;
178
+ color: $color-muted;
179
+ font-variant-numeric: tabular-nums;
180
+ }
181
+
182
+ &__label {
183
+ flex: 1;
184
+ min-width: 0;
185
+ font-size: 13px;
186
+ color: $color-text;
187
+ white-space: nowrap;
188
+ overflow: hidden;
189
+ text-overflow: ellipsis;
190
+ }
191
+
192
+ &__dirs {
193
+ flex-shrink: 0;
194
+ display: inline-flex;
195
+ gap: 2px;
196
+ padding: 2px;
197
+ background: $color-surface;
198
+ border: 1px solid $color-border;
199
+ border-radius: 999px;
200
+ }
201
+
202
+ &__dir {
203
+ padding: 2px 8px;
204
+ border: none;
205
+ border-radius: 999px;
206
+ background: none;
207
+ font-size: 11px;
208
+ color: $color-muted;
209
+ white-space: nowrap;
210
+
211
+ &:hover { color: $color-text; }
212
+
213
+ &--on {
214
+ background: $color-accent-ink;
215
+ color: $color-surface;
216
+ }
217
+ }
218
+
219
+ &__add {
220
+ align-self: flex-start;
221
+ }
222
+
223
+ &__menu {
224
+ display: flex;
225
+ flex-direction: column;
226
+ padding: 6px;
227
+ min-width: 200px;
228
+ }
229
+
230
+ &__menu-item {
231
+ padding: 7px 10px;
232
+ border: none;
233
+ border-radius: 6px;
234
+ background: none;
235
+ font-size: 13px;
236
+ color: $color-text;
237
+ text-align: left;
238
+
239
+ &:hover { background: $color-accent-dim; }
240
+ }
241
+ }
242
+ </style>
@@ -1,25 +1,25 @@
1
- // Типи SortControl окремим .ts, а не експортом із .vue: гейт типів — plain
2
- // `tsc`, для нього `*.vue` це заглушка без іменованих експортів (§9a CLAUDE.md).
3
-
4
- import type { ServerSortEntry, SortDirection } from '../../composables/useServerTable'
5
-
6
- /**
7
- * Ключ, за яким можна сортувати: що це, як підписати обидва напрямки і з якого
8
- * починати.
9
- *
10
- * Напрямки підписуємо СЛОВАМИ, а не «asc/desc»: для грошей зрозуміло і те й
11
- * інше, а для ознаки на кшталт «наше авто» — ні. «Спочатку авто парку» відповідає на
12
- * питання користувача, «за зростанням» лише називає механіку.
13
- */
14
- export interface SortKeyOption<TBy extends string = string> {
15
- value: TBy
16
- label: string
17
- directions: Record<SortDirection, string>
18
- /**
19
- * Напрямок при першому додаванні ключа. Для чисел і дат цікавий максимум,
20
- * для тексту — початок алфавіту.
21
- */
22
- defaultDirection: SortDirection
23
- }
24
-
25
- export type { ServerSortEntry as SortEntry, SortDirection }
1
+ // Типи SortControl окремим .ts, а не експортом із .vue: гейт типів — plain
2
+ // `tsc`, для нього `*.vue` це заглушка без іменованих експортів (§9a CLAUDE.md).
3
+
4
+ import type { ServerSortEntry, SortDirection } from '../../composables/useServerTable'
5
+
6
+ /**
7
+ * Ключ, за яким можна сортувати: що це, як підписати обидва напрямки і з якого
8
+ * починати.
9
+ *
10
+ * Напрямки підписуємо СЛОВАМИ, а не «asc/desc»: для грошей зрозуміло і те й
11
+ * інше, а для ознаки на кшталт «наше авто» — ні. «Спочатку авто парку» відповідає на
12
+ * питання користувача, «за зростанням» лише називає механіку.
13
+ */
14
+ export interface SortKeyOption<TBy extends string = string> {
15
+ value: TBy
16
+ label: string
17
+ directions: Record<SortDirection, string>
18
+ /**
19
+ * Напрямок при першому додаванні ключа. Для чисел і дат цікавий максимум,
20
+ * для тексту — початок алфавіту.
21
+ */
22
+ defaultDirection: SortDirection
23
+ }
24
+
25
+ export type { ServerSortEntry as SortEntry, SortDirection }
@@ -1,58 +1,58 @@
1
- <script setup lang="ts">
2
- // Підтвердження дії — замість window.confirm: той — системний сірий діалог без
3
- // стилю й без розрізнення небезпечної дії, і на ньому кнопка «OK» однакова для
4
- // «Видалити назавжди» і «Зберегти». Тут — заголовок-питання, пояснення
5
- // наслідків і кнопка зі словом дії; незворотне — червоним.
6
- //
7
- // Відкривати через useConfirm(), а не modals.show напряму: результат — boolean.
8
-
9
- import ModalCard from './ModalCard.vue'
10
- import { SharedConfig } from '../../config'
11
- import { useCurrentModal } from '../../plugins/modals.plugin'
12
- import UiButton from '../ui/UiButton.vue'
13
-
14
- withDefaults(defineProps<{
15
- /** Питання: «Видалити платіж?» */
16
- title: string
17
- /** Наслідки, якщо вони неочевидні. Абзаци — через порожній рядок. */
18
- text?: string
19
- /** Слово дії на кнопці: «Видалити», «Зняти», «Підтвердити». */
20
- confirmText?: string
21
- /** Незворотна дія — червона кнопка. */
22
- isDanger?: boolean
23
- }>(), {
24
- text: undefined,
25
- confirmText: () => SharedConfig.get().labels.yes,
26
- isDanger: false,
27
- })
28
-
29
- const { resolve } = useCurrentModal<boolean>()
30
- // Enter підтверджує сам: фокус одразу на кнопці дії (autofocus). Окремий
31
- // хоткей тут шкодив би — Enter на «Скасувати» тоді підтверджував би.
32
-
33
- </script>
34
-
35
- <template>
36
- <ModalCard :title="title" @close="resolve(false)">
37
- <p v-if="text" class="confirm__text">{{ text }}</p>
38
-
39
- <template #footer>
40
- <UiButton variant="ghost" @click="resolve(false)">{{ SharedConfig.get().labels.cancel }}</UiButton>
41
- <UiButton :variant="isDanger ? 'danger' : 'primary'" autofocus @click="resolve(true)">
42
- {{ confirmText }}
43
- </UiButton>
44
- </template>
45
- </ModalCard>
46
- </template>
47
-
48
- <style scoped lang="scss">
49
- .confirm__text {
50
- margin: 0;
51
- max-width: 420px;
52
- font-size: 14px;
53
- line-height: 1.5;
54
- color: $color-text;
55
- // Абзаци з тексту питання — як є.
56
- white-space: pre-line;
57
- }
58
- </style>
1
+ <script setup lang="ts">
2
+ // Підтвердження дії — замість window.confirm: той — системний сірий діалог без
3
+ // стилю й без розрізнення небезпечної дії, і на ньому кнопка «OK» однакова для
4
+ // «Видалити назавжди» і «Зберегти». Тут — заголовок-питання, пояснення
5
+ // наслідків і кнопка зі словом дії; незворотне — червоним.
6
+ //
7
+ // Відкривати через useConfirm(), а не modals.show напряму: результат — boolean.
8
+
9
+ import ModalCard from './ModalCard.vue'
10
+ import { SharedConfig } from '../../config'
11
+ import { useCurrentModal } from '../../plugins/modals.plugin'
12
+ import UiButton from '../ui/UiButton.vue'
13
+
14
+ withDefaults(defineProps<{
15
+ /** Питання: «Видалити платіж?» */
16
+ title: string
17
+ /** Наслідки, якщо вони неочевидні. Абзаци — через порожній рядок. */
18
+ text?: string
19
+ /** Слово дії на кнопці: «Видалити», «Зняти», «Підтвердити». */
20
+ confirmText?: string
21
+ /** Незворотна дія — червона кнопка. */
22
+ isDanger?: boolean
23
+ }>(), {
24
+ text: undefined,
25
+ confirmText: () => SharedConfig.get().labels.yes,
26
+ isDanger: false,
27
+ })
28
+
29
+ const { resolve } = useCurrentModal<boolean>()
30
+ // Enter підтверджує сам: фокус одразу на кнопці дії (autofocus). Окремий
31
+ // хоткей тут шкодив би — Enter на «Скасувати» тоді підтверджував би.
32
+
33
+ </script>
34
+
35
+ <template>
36
+ <ModalCard :title="title" @close="resolve(false)">
37
+ <p v-if="text" class="confirm__text">{{ text }}</p>
38
+
39
+ <template #footer>
40
+ <UiButton variant="ghost" @click="resolve(false)">{{ SharedConfig.get().labels.cancel }}</UiButton>
41
+ <UiButton :variant="isDanger ? 'danger' : 'primary'" autofocus @click="resolve(true)">
42
+ {{ confirmText }}
43
+ </UiButton>
44
+ </template>
45
+ </ModalCard>
46
+ </template>
47
+
48
+ <style scoped lang="scss">
49
+ .confirm__text {
50
+ margin: 0;
51
+ max-width: 420px;
52
+ font-size: 14px;
53
+ line-height: 1.5;
54
+ color: $color-text;
55
+ // Абзаци з тексту питання — як є.
56
+ white-space: pre-line;
57
+ }
58
+ </style>