@rock555/frontend-core 2.0.3 → 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.
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
  Публічний пакет на npmjs.com, токен для встановлення не потрібен. У `package.json`:
10
10
 
11
11
  ```json
12
- "@rock555/frontend-core": "^2.0.2"
12
+ "@rock555/frontend-core": "^3.0.0"
13
13
  ```
14
14
 
15
15
  Імпорти `@/_shared/...` міняти не треба, досить аліаса. У `vite.config`:
@@ -37,7 +37,7 @@ optimizeDeps: { exclude: ['@/_shared'] },
37
37
 
38
38
  Свою копію `types/table.d.ts` прибрати: типи колонок ядро підключає само.
39
39
 
40
- Залежності ядра (`peerDependencies`) ставить сам проєкт. Необов'язкові: `vis-data` і `vis-timeline` для `TimelineChart`, `vue-sonner` для `ExportCsvButton`, `motion-v` для `SortControlPanel`.
40
+ Залежності ядра (`peerDependencies`) ставить сам проєкт. Необов'язкові: `vis-data` і `vis-timeline` для `TimelineChart`, `vue-sonner` для `ExportButton`, `motion-v` для `SortControlPanel`.
41
41
 
42
42
  Підключати конфіг так, щоб `SharedConfig.configure()` спрацював до першого рендера. На рівні модуля читати тексти не можна, це перевіряє `tests/core/config-timing.test.ts`.
43
43
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rock555/frontend-core",
3
- "version": "2.0.3",
3
+ "version": "3.0.0",
4
4
  "description": "Спільне фронтове ядро: API-клієнт, таблиці, форми, модалки, хелпери",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -1,5 +1,5 @@
1
1
  <script setup lang="ts">
2
- // Кнопка вивантаження CSV у рядку фільтрів (слот #toolbar у FiltersBar).
2
+ // Кнопка вивантаження файла у рядку фільтрів (слот #toolbar у FiltersBar).
3
3
  //
4
4
  // Тримає всю взаємодію разом: спінер, підпис із періодом і тост про хід справи.
5
5
  // Фіча дає лише «що запустити» — інакше кожна сторінка заводила б свій
@@ -13,21 +13,23 @@ import UiButton from '../ui/UiButton.vue'
13
13
 
14
14
  const labels = SharedConfig.get().labels
15
15
 
16
- const props = defineProps<{
16
+ const props = withDefaults(defineProps<{
17
17
  // Запускає вивантаження і віддає імʼя файла, під яким його збережено.
18
18
  run: () => Promise<string>
19
19
  isExporting: boolean
20
- // Тільки для підпису — щоб було видно, за що саме поїде файл.
21
- period: Period
20
+ format?: 'CSV' | 'XLSX'
21
+ // Тільки для підпису — щоб було видно, за що саме поїде файл. Список без
22
+ // дат періоду не має.
23
+ period?: Period
22
24
  // Чим файл відрізняється від екрана, якщо відрізняється (напр. розріз).
23
25
  note?: string
24
- }>()
26
+ }>(), { format: 'CSV' })
25
27
 
26
28
  // Один тост на весь шлях: вивантаження за великий період довге.
27
29
  //
28
30
  // `error` навмисно не заданий — помилку вже показує onError мутації, а без
29
31
  // цього ключа sonner просто прибирає тост замість того, щоб дублювати її другим.
30
- function exportCsv(): void {
32
+ function exportFile(): void {
31
33
  toast.promise(props.run(), {
32
34
  loading: labels.exportPreparing,
33
35
  success: (filename: string) => labels.exportDone(filename),
@@ -40,21 +42,21 @@ function exportCsv(): void {
40
42
  variant="ghost"
41
43
  size="sm"
42
44
  :disabled="isExporting"
43
- :title="labels.exportTitle(period.from, period.to, note)"
44
- @click="exportCsv"
45
+ :title="labels.exportTitle(format, period, note)"
46
+ @click="exportFile"
45
47
  >
46
48
  <component
47
49
  :is="isExporting ? Loader2 : Download"
48
50
  :size="14"
49
- :class="{ 'export-csv__spin': isExporting }"
51
+ :class="{ 'export-button__spin': isExporting }"
50
52
  />
51
- Export CSV
53
+ Export {{ format }}
52
54
  </UiButton>
53
55
  </template>
54
56
 
55
57
  <style scoped lang="scss">
56
58
  // Слот-контент належить ЦЬОМУ компоненту, тож анімація живе тут, а не в
57
59
  // фільтрах, які його показують.
58
- .export-csv__spin { animation: export-csv-spin 1s linear infinite; }
59
- @keyframes export-csv-spin { to { transform: rotate(360deg); } }
60
+ .export-button__spin { animation: export-button-spin 1s linear infinite; }
61
+ @keyframes export-button-spin { to { transform: rotate(360deg); } }
60
62
  </style>
@@ -211,7 +211,7 @@ function remove(by: TBy): void {
211
211
  &:hover { color: $color-text; }
212
212
 
213
213
  &--on {
214
- background: $color-accent;
214
+ background: $color-accent-ink;
215
215
  color: $color-surface;
216
216
  }
217
217
  }
@@ -42,7 +42,7 @@ const emit = defineEmits<{ 'update:modelValue': [value: boolean] }>()
42
42
  user-select: none;
43
43
  transition: all 0.15s ease;
44
44
 
45
- &:hover { border-color: $color-border-strong; }
45
+ &:hover:not(&--active) { border-color: $color-border-strong; }
46
46
 
47
47
  // Не display:none — інпут випав би з таб-порядку й перестав ловити пробіл.
48
48
  &__input {
@@ -316,6 +316,8 @@ function onSelect(value: unknown): void {
316
316
  background: $color-accent-dim;
317
317
  border-color: $color-accent;
318
318
  color: $color-accent-ink;
319
+
320
+ &:hover:not(:disabled) { border-color: $color-accent; }
319
321
  }
320
322
  }
321
323
 
@@ -22,7 +22,7 @@ withDefaults(defineProps<{
22
22
  <div v-else class="ui-kpi__value" :class="card.tone && `ui-kpi__value--${card.tone}`">
23
23
  {{ card.value }}<span v-if="card.note" class="ui-kpi__note"><span class="ui-kpi__note-dot">·</span>{{ card.note }}</span>
24
24
  </div>
25
- <div class="ui-kpi__label">
25
+ <div class="ui-kpi__label" :title="card.labelHint">
26
26
  {{ card.label }}
27
27
  <!-- Для позначок біля підпису (напр. «комісія попередня»). -->
28
28
  <slot name="suffix" :card="card" />
@@ -68,6 +68,8 @@ withDefaults(defineProps<{
68
68
  }
69
69
 
70
70
  &__body {
71
+ // Довгий підпис переноситься, а числа сусідніх карток лишаються в одну лінію.
72
+ align-self: flex-start;
71
73
  display: flex;
72
74
  flex-direction: column;
73
75
  gap: 2px;
@@ -24,10 +24,10 @@ const labels = SharedConfig.get().labels
24
24
  :name="name"
25
25
  :label="label"
26
26
  :is-required="isRequired"
27
- v-slot="{ field, handleChange, inputId }"
27
+ v-slot="{ field, handleChange }"
28
28
  >
29
29
  <span class="date-input">
30
- <input :id="inputId" class="date-input__field" type="date" :min="min" :max="max" v-bind="field"/>
30
+ <input class="date-input__field" type="date" :min="min" :max="max" v-bind="field"/>
31
31
  <button
32
32
  v-if="clearable && field.value"
33
33
  type="button"
@@ -98,6 +98,11 @@ const onDragOver = (val: boolean) => isDragging.value = val;
98
98
  z-index: -1;
99
99
  }
100
100
 
101
+ &__input:focus-visible + &__label {
102
+ outline: 2px solid $color-accent;
103
+ outline-offset: 2px;
104
+ }
105
+
101
106
  &__label {
102
107
  display: flex;
103
108
  align-items: center;
@@ -137,7 +137,6 @@ const uid = useId();
137
137
  border-color: $color-accent;
138
138
  background: $color-accent-dim;
139
139
  color: $color-accent-ink;
140
- font-weight: 600;
141
140
  }
142
141
  }
143
142
  </style>
@@ -15,10 +15,9 @@ defineProps<{
15
15
  :name="name"
16
16
  :label="label"
17
17
  :is-required="isRequired"
18
- v-slot="{field, handleChange, inputId}"
18
+ v-slot="{ field, handleChange }"
19
19
  >
20
20
  <select
21
- :id="inputId"
22
21
  v-bind="field"
23
22
  @change="(e) => {
24
23
  const val = (e.target as HTMLSelectElement).value;
@@ -17,6 +17,7 @@ defineProps<{
17
17
  isRequired?: boolean
18
18
  }>();
19
19
 
20
+ // id едет прямо в `field`: кто делает v-bind="field", тот уже связан с подписью.
20
21
  // Поле, которое ставит себе :id="inputId" из слота, получает связь с подписью:
21
22
  // клик по ней ставит фокус, читалка экрана называет поле.
22
23
  const inputId = useId();
@@ -44,7 +45,7 @@ const inputId = useId();
44
45
  <span class="smart-field__tip">{{ hint }}</span>
45
46
  </button>
46
47
  </span>
47
- <slot v-bind="vee" :input-id="inputId"></slot>
48
+ <slot v-bind="vee" :field="{ ...vee.field, id: inputId }" :input-id="inputId"></slot>
48
49
  <span class="ui-errors" v-if="vee.errors.length">
49
50
  <span class="ui-error" v-for="err in vee.errors" :key="err">
50
51
  {{ err }}
@@ -59,6 +60,19 @@ const inputId = useId();
59
60
 
60
61
  // Глобальные стили полей формы. SmartField — единственная обёртка инпутов,
61
62
  // поэтому стили инпутов живут здесь (а не в каждой модалке/фильтре).
63
+ // Поза .smart-field: радіо й діапазон дат малюють помилки самі, без цієї обгортки.
64
+ .ui-errors {
65
+ display: flex;
66
+ flex-direction: column;
67
+ gap: 2px;
68
+ }
69
+
70
+ .ui-error {
71
+ font-size: 12px;
72
+ line-height: 1.3;
73
+ color: $color-danger;
74
+ }
75
+
62
76
  .smart-field {
63
77
  display: flex;
64
78
  flex-direction: column;
@@ -150,18 +164,6 @@ const inputId = useId();
150
164
  min-height: 60px;
151
165
  }
152
166
 
153
- // Помилки валідації — завжди червоні (єдина обгортка інпутів = на весь проєкт).
154
- .ui-errors {
155
- display: flex;
156
- flex-direction: column;
157
- gap: 2px;
158
- }
159
-
160
- .ui-error {
161
- font-size: 12px;
162
- line-height: 1.3;
163
- color: $color-danger;
164
- }
165
167
 
166
168
  // Поле з помилкою — червона рамка (поки помилка присутня у DOM).
167
169
  &:has(.ui-errors) {
@@ -25,7 +25,7 @@ withDefaults(defineProps<{
25
25
  </script>
26
26
 
27
27
  <template>
28
- <SmartField v-slot="{ field, inputId }" :name="name" :label="label" :hint="hint" :is-required="isRequired">
29
- <textarea :id="inputId" v-bind="{ ...field, ...$attrs }" :rows="rows" :placeholder="placeholder" />
28
+ <SmartField v-slot="{ field }" :name="name" :label="label" :hint="hint" :is-required="isRequired">
29
+ <textarea v-bind="{ ...field, ...$attrs }" :rows="rows" :placeholder="placeholder" />
30
30
  </SmartField>
31
31
  </template>
@@ -9,6 +9,8 @@ export interface UiKpiCardItem {
9
9
  key: string
10
10
  icon: Component
11
11
  label: string
12
+ /** Підказка при наведенні на підпис: пояснює те, що в ньому скорочено. */
13
+ labelHint?: string
12
14
  /** null = даних ще нема → замість числа скелетон. */
13
15
  value: string | null
14
16
  /** Дрібна приписка праворуч від значення через крапку (напр. частка палива «12,3%»). */
package/src/config.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  // проект передаёт один раз при старте — `SharedConfig.configure(...)` до монтирования.
3
3
 
4
4
  import type { Component } from 'vue'
5
+ import type { Period } from './helpers/period.helper'
5
6
  import type { ApiProblemEntry } from './api/errors/apiProblem'
6
7
 
7
8
  export type SharedLabels = {
@@ -55,7 +56,7 @@ export type SharedLabels = {
55
56
  resetFilters: string
56
57
  exportPreparing: string
57
58
  exportDone: (filename: string) => string
58
- exportTitle: (from: string, to: string, note?: string) => string
59
+ exportTitle: (format: string, period?: Period, note?: string) => string
59
60
  /** Поле періоду. */
60
61
  allDates: string
61
62
  periodRemove: string