bfg-common 1.5.407 → 1.5.408

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,277 +1,277 @@
1
- <template>
2
- <div class="column-switch-wrap flex-align-center relative" @click.stop>
3
- <button
4
- :id="columnSwitchId"
5
- :data-id="`${props.testId}-toggle-button`"
6
- class="column-switch-btn"
7
- @click.stop="toggle"
8
- >
9
- <atoms-the-icon
10
- name="column-switch"
11
- width="16px"
12
- height="16px"
13
- class="toggle-icon"
14
- />
15
- </button>
16
-
17
- <div
18
- v-show="open"
19
- :id="`${columnSwitchId}-dropdown-menu`"
20
- :style="dropdownStyles"
21
- class="dropdown-menu"
22
- >
23
- <div class="column-switch">
24
- <div class="switch-header" data-id="switch-header-show-cols-title">
25
- {{ localization.common.showColumns }}
26
- </div>
27
- <ul class="switch-content list-unstyled">
28
- <li
29
- v-for="(item, key) in columnKeysPresent"
30
- :key="`${item.key}_${key}`"
31
- :data-id="`switch-content-${item.id}`"
32
- >
33
- <div class="clr-checkbox-wrapper">
34
- <input
35
- :id="`${props.testId}-${item.id}`"
36
- v-model="item.show"
37
- :data-id="`${props.testId}-${item.testId}`"
38
- :disabled="isLast && item.show"
39
- type="checkbox"
40
- @change="change($event, key)"
41
- />
42
- <label
43
- :for="`${props.testId}-${item.id}`"
44
- class="clr-control-label"
45
- :data-id="`${props.testId || 'data-grid'}-${item.id}-label`"
46
- >{{ item.text }}</label
47
- >
48
- </div>
49
- </li>
50
- </ul>
51
- <div class="switch-footer">
52
- <button
53
- :id="`${props.testId}-select-all-button`"
54
- :data-id="`${props.testId}-select-all-button`"
55
- class="btn btn-sm btn-link switch-button export-link"
56
- @click="selectAll"
57
- >
58
- {{ localization.common.selectAll }}
59
- </button>
60
- </div>
61
- </div>
62
- </div>
63
- </div>
64
- </template>
65
-
66
- <script setup lang="ts">
67
- import type {
68
- UI_I_HTMLSelectElement,
69
- UI_I_Localization,
70
- } from '~/lib/models/interfaces'
71
- import type { UI_I_ColumnKey } from '~/components/atoms/table/dataGrid/lib/models/interfaces'
72
-
73
- const props = withDefaults(
74
- defineProps<{
75
- columnKeys: UI_I_ColumnKey[]
76
- testId?: string
77
- }>(),
78
- { testId: 'ui-data-grid-column-switch' }
79
- )
80
- const emits = defineEmits<{
81
- (event: 'update:column-keys', value: UI_I_ColumnKey[]): void
82
- }>()
83
-
84
- const columnKeysPresent = computed<UI_I_ColumnKey[]>(() => {
85
- return props.columnKeys.map((item): UI_I_ColumnKey => {
86
- const testId = item.text
87
- .toLowerCase()
88
- .replace(/\s/g, '_')
89
- .replace(/[^a-zA-Z_]/g, '')
90
- .replace(/__+/g, '_')
91
- .replace(/_$/, '')
92
- return { ...item, id: useUniqueId(), testId: `show-column-${testId}` }
93
- })
94
- })
95
-
96
- const localization = computed<UI_I_Localization>(() => useLocal())
97
-
98
- const columnSwitchId = ref<string>('')
99
-
100
- const isLast = computed<boolean>(
101
- () => props.columnKeys.filter((columnKey) => columnKey.show).length === 1
102
- )
103
-
104
- const change = (event: UI_I_HTMLSelectElement, key: number): void => {
105
- const newColumnKeys = props.columnKeys.map((columnKey, item) => {
106
- if (item !== key) {
107
- return columnKey
108
- }
109
-
110
- columnKey.show = event.target.checked
111
- return columnKey
112
- })
113
- emits('update:column-keys', newColumnKeys)
114
- }
115
- const selectAll = (): void => {
116
- const newColumnKeys = props.columnKeys.map((columnKey) => {
117
- columnKey.show = true
118
- return columnKey
119
- })
120
- emits('update:column-keys', newColumnKeys)
121
- }
122
-
123
- const windowClick = (): void => {
124
- hide()
125
- }
126
- onMounted(() => {
127
- window.addEventListener('click', windowClick)
128
- columnSwitchId.value = `column-switch-${useUniqueId()}`
129
- })
130
- onUnmounted(() => {
131
- window.removeEventListener('click', windowClick)
132
- })
133
-
134
- const open = ref<boolean>(false)
135
- const hide = (): void => {
136
- open.value = false
137
- }
138
- const toggle = (): void => {
139
- open.value = !open.value
140
- if (!open.value) {
141
- return
142
- }
143
-
144
- setTimeout(() => {
145
- setDropdownStyle()
146
- }, 0)
147
- }
148
-
149
- const dropdownStyles = ref<any>({})
150
- const setDropdownStyle = (): void => {
151
- dropdownStyles.value = {}
152
-
153
- const elem = document.getElementById(columnSwitchId.value)
154
- if (!elem) {
155
- setTimeout(() => setDropdownStyle(), 0)
156
- return
157
- }
158
- const { x, y, height } = elem.getBoundingClientRect()
159
-
160
- const dropdownMenu = document.getElementById(
161
- `${columnSwitchId.value}-dropdown-menu`
162
- )
163
-
164
- if (!dropdownMenu) return
165
-
166
- dropdownStyles.value.maxHeight = 'max-content'
167
-
168
- const windowH = window.innerHeight
169
-
170
- const dropdownMenuH = dropdownMenu.getBoundingClientRect().height
171
-
172
- if (y + dropdownMenuH >= windowH) {
173
- if (y - dropdownMenuH <= 0) {
174
- dropdownStyles.value.top = 'auto'
175
- dropdownStyles.value.bottom = '0'
176
- dropdownStyles.value.overflowY = 'auto'
177
- dropdownStyles.value.maxHeight = '100vh'
178
-
179
- const columnWwitch = document.querySelector(
180
- `#${columnSwitchId.value}-dropdown-menu .column-switch`
181
- )
182
-
183
- if (!columnWwitch) return
184
-
185
- columnWwitch.style.overflowY = 'hidden'
186
- } else {
187
- dropdownStyles.value.top = `${y - dropdownMenuH}px`
188
- }
189
- } else {
190
- dropdownStyles.value.top = `${y + height}px`
191
- }
192
-
193
- dropdownStyles.value.left = `${x}px`
194
- }
195
- const windowResize = (): void => {
196
- hide()
197
- }
198
- watch(
199
- () => dropdownStyles.value.top,
200
- (newValue: number) => {
201
- if (!newValue) return
202
-
203
- if (parseInt(newValue) < 0) {
204
- window.removeEventListener('resize', windowResize)
205
- } else {
206
- window.addEventListener('resize', windowResize)
207
- }
208
- }
209
- )
210
- </script>
211
-
212
- <style scoped lang="scss">
213
- .column-switch-wrap {
214
- .column-switch-btn {
215
- cursor: pointer;
216
- padding: 0;
217
- border: 0;
218
- display: flex;
219
- background-color: transparent;
220
-
221
- .toggle-icon {
222
- fill: #575757;
223
- }
224
- &:hover {
225
- .toggle-icon {
226
- fill: #0079b8;
227
- }
228
- }
229
- }
230
-
231
- .dropdown-menu {
232
- position: fixed;
233
- z-index: var(--z-fixed);
234
- visibility: unset;
235
- //transform: translateY(-100%);
236
- background-color: var(--block-view-bg-color);
237
- border-color: var(--global-border-color);
238
-
239
- .column-switch {
240
- border-style: none;
241
- box-shadow: none;
242
- height: 85%;
243
- max-height: calc(15rem + 100px);
244
- padding: 18px;
245
- width: 250px;
246
- display: flex;
247
- flex-direction: column;
248
-
249
- .switch-header {
250
- font-size: 16px;
251
- color: var(--global-font-color4);
252
- padding-bottom: 12px;
253
- }
254
-
255
- .switch-content {
256
- overflow-y: auto;
257
- .clr-control-label {
258
- white-space: normal;
259
- }
260
- }
261
-
262
- .switch-footer {
263
- button {
264
- padding: 0;
265
- margin: 0;
266
- font-size: 12px;
267
- letter-spacing: 1px;
268
- color: #0079b8;
269
- text-transform: uppercase;
270
- display: flex;
271
- align-items: center;
272
- }
273
- }
274
- }
275
- }
276
- }
277
- </style>
1
+ <template>
2
+ <div class="column-switch-wrap flex-align-center relative" @click.stop>
3
+ <button
4
+ :id="columnSwitchId"
5
+ :data-id="`${props.testId}-toggle-button`"
6
+ class="column-switch-btn"
7
+ @click.stop="toggle"
8
+ >
9
+ <atoms-the-icon
10
+ name="column-switch"
11
+ width="16px"
12
+ height="16px"
13
+ class="toggle-icon"
14
+ />
15
+ </button>
16
+
17
+ <div
18
+ v-show="open"
19
+ :id="`${columnSwitchId}-dropdown-menu`"
20
+ :style="dropdownStyles"
21
+ class="dropdown-menu"
22
+ >
23
+ <div class="column-switch">
24
+ <div class="switch-header" data-id="switch-header-show-cols-title">
25
+ {{ localization.common.showColumns }}
26
+ </div>
27
+ <ul class="switch-content list-unstyled">
28
+ <li
29
+ v-for="(item, key) in columnKeysPresent"
30
+ :key="`${item.key}_${key}`"
31
+ :data-id="`switch-content-${item.id}`"
32
+ >
33
+ <div class="clr-checkbox-wrapper">
34
+ <input
35
+ :id="`${props.testId}-${item.id}`"
36
+ v-model="item.show"
37
+ :data-id="`${props.testId}-${item.testId}`"
38
+ :disabled="isLast && item.show"
39
+ type="checkbox"
40
+ @change="change($event, key)"
41
+ />
42
+ <label
43
+ :for="`${props.testId}-${item.id}`"
44
+ class="clr-control-label"
45
+ :data-id="`${props.testId || 'data-grid'}-${item.id}-label`"
46
+ >{{ item.text }}</label
47
+ >
48
+ </div>
49
+ </li>
50
+ </ul>
51
+ <div class="switch-footer">
52
+ <button
53
+ :id="`${props.testId}-select-all-button`"
54
+ :data-id="`${props.testId}-select-all-button`"
55
+ class="btn btn-sm btn-link switch-button export-link"
56
+ @click="selectAll"
57
+ >
58
+ {{ localization.common.selectAll }}
59
+ </button>
60
+ </div>
61
+ </div>
62
+ </div>
63
+ </div>
64
+ </template>
65
+
66
+ <script setup lang="ts">
67
+ import type {
68
+ UI_I_HTMLSelectElement,
69
+ UI_I_Localization,
70
+ } from '~/lib/models/interfaces'
71
+ import type { UI_I_ColumnKey } from '~/components/atoms/table/dataGrid/lib/models/interfaces'
72
+
73
+ const props = withDefaults(
74
+ defineProps<{
75
+ columnKeys: UI_I_ColumnKey[]
76
+ testId?: string
77
+ }>(),
78
+ { testId: 'ui-data-grid-column-switch' }
79
+ )
80
+ const emits = defineEmits<{
81
+ (event: 'update:column-keys', value: UI_I_ColumnKey[]): void
82
+ }>()
83
+
84
+ const columnKeysPresent = computed<UI_I_ColumnKey[]>(() => {
85
+ return props.columnKeys.map((item): UI_I_ColumnKey => {
86
+ const testId = item.text
87
+ .toLowerCase()
88
+ .replace(/\s/g, '_')
89
+ .replace(/[^\p{L}_]/gu, '') // разрешает буквы любых языков
90
+ .replace(/__+/g, '_')
91
+ .replace(/_$/, '')
92
+ return { ...item, id: useUniqueId(), testId: `show-column-${testId}` }
93
+ })
94
+ })
95
+
96
+ const localization = computed<UI_I_Localization>(() => useLocal())
97
+
98
+ const columnSwitchId = ref<string>('')
99
+
100
+ const isLast = computed<boolean>(
101
+ () => props.columnKeys.filter((columnKey) => columnKey.show).length === 1
102
+ )
103
+
104
+ const change = (event: UI_I_HTMLSelectElement, key: number): void => {
105
+ const newColumnKeys = props.columnKeys.map((columnKey, item) => {
106
+ if (item !== key) {
107
+ return columnKey
108
+ }
109
+
110
+ columnKey.show = event.target.checked
111
+ return columnKey
112
+ })
113
+ emits('update:column-keys', newColumnKeys)
114
+ }
115
+ const selectAll = (): void => {
116
+ const newColumnKeys = props.columnKeys.map((columnKey) => {
117
+ columnKey.show = true
118
+ return columnKey
119
+ })
120
+ emits('update:column-keys', newColumnKeys)
121
+ }
122
+
123
+ const windowClick = (): void => {
124
+ hide()
125
+ }
126
+ onMounted(() => {
127
+ window.addEventListener('click', windowClick)
128
+ columnSwitchId.value = `column-switch-${useUniqueId()}`
129
+ })
130
+ onUnmounted(() => {
131
+ window.removeEventListener('click', windowClick)
132
+ })
133
+
134
+ const open = ref<boolean>(false)
135
+ const hide = (): void => {
136
+ open.value = false
137
+ }
138
+ const toggle = (): void => {
139
+ open.value = !open.value
140
+ if (!open.value) {
141
+ return
142
+ }
143
+
144
+ setTimeout(() => {
145
+ setDropdownStyle()
146
+ }, 0)
147
+ }
148
+
149
+ const dropdownStyles = ref<any>({})
150
+ const setDropdownStyle = (): void => {
151
+ dropdownStyles.value = {}
152
+
153
+ const elem = document.getElementById(columnSwitchId.value)
154
+ if (!elem) {
155
+ setTimeout(() => setDropdownStyle(), 0)
156
+ return
157
+ }
158
+ const { x, y, height } = elem.getBoundingClientRect()
159
+
160
+ const dropdownMenu = document.getElementById(
161
+ `${columnSwitchId.value}-dropdown-menu`
162
+ )
163
+
164
+ if (!dropdownMenu) return
165
+
166
+ dropdownStyles.value.maxHeight = 'max-content'
167
+
168
+ const windowH = window.innerHeight
169
+
170
+ const dropdownMenuH = dropdownMenu.getBoundingClientRect().height
171
+
172
+ if (y + dropdownMenuH >= windowH) {
173
+ if (y - dropdownMenuH <= 0) {
174
+ dropdownStyles.value.top = 'auto'
175
+ dropdownStyles.value.bottom = '0'
176
+ dropdownStyles.value.overflowY = 'auto'
177
+ dropdownStyles.value.maxHeight = '100vh'
178
+
179
+ const columnWwitch = document.querySelector(
180
+ `#${columnSwitchId.value}-dropdown-menu .column-switch`
181
+ )
182
+
183
+ if (!columnWwitch) return
184
+
185
+ columnWwitch.style.overflowY = 'hidden'
186
+ } else {
187
+ dropdownStyles.value.top = `${y - dropdownMenuH}px`
188
+ }
189
+ } else {
190
+ dropdownStyles.value.top = `${y + height}px`
191
+ }
192
+
193
+ dropdownStyles.value.left = `${x}px`
194
+ }
195
+ const windowResize = (): void => {
196
+ hide()
197
+ }
198
+ watch(
199
+ () => dropdownStyles.value.top,
200
+ (newValue: number) => {
201
+ if (!newValue) return
202
+
203
+ if (parseInt(newValue) < 0) {
204
+ window.removeEventListener('resize', windowResize)
205
+ } else {
206
+ window.addEventListener('resize', windowResize)
207
+ }
208
+ }
209
+ )
210
+ </script>
211
+
212
+ <style scoped lang="scss">
213
+ .column-switch-wrap {
214
+ .column-switch-btn {
215
+ cursor: pointer;
216
+ padding: 0;
217
+ border: 0;
218
+ display: flex;
219
+ background-color: transparent;
220
+
221
+ .toggle-icon {
222
+ fill: #575757;
223
+ }
224
+ &:hover {
225
+ .toggle-icon {
226
+ fill: #0079b8;
227
+ }
228
+ }
229
+ }
230
+
231
+ .dropdown-menu {
232
+ position: fixed;
233
+ z-index: var(--z-fixed);
234
+ visibility: unset;
235
+ //transform: translateY(-100%);
236
+ background-color: var(--block-view-bg-color);
237
+ border-color: var(--global-border-color);
238
+
239
+ .column-switch {
240
+ border-style: none;
241
+ box-shadow: none;
242
+ height: 85%;
243
+ max-height: calc(15rem + 100px);
244
+ padding: 18px;
245
+ width: 250px;
246
+ display: flex;
247
+ flex-direction: column;
248
+
249
+ .switch-header {
250
+ font-size: 16px;
251
+ color: var(--global-font-color4);
252
+ padding-bottom: 12px;
253
+ }
254
+
255
+ .switch-content {
256
+ overflow-y: auto;
257
+ .clr-control-label {
258
+ white-space: normal;
259
+ }
260
+ }
261
+
262
+ .switch-footer {
263
+ button {
264
+ padding: 0;
265
+ margin: 0;
266
+ font-size: 12px;
267
+ letter-spacing: 1px;
268
+ color: #0079b8;
269
+ text-transform: uppercase;
270
+ display: flex;
271
+ align-items: center;
272
+ }
273
+ }
274
+ }
275
+ }
276
+ }
277
+ </style>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bfg-common",
3
3
  "private": false,
4
- "version": "1.5.407",
4
+ "version": "1.5.408",
5
5
  "scripts": {
6
6
  "build": "nuxt build",
7
7
  "dev": "nuxt dev --port=3002",