bfg-common 1.0.58 → 1.0.59

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.
@@ -30,15 +30,17 @@
30
30
  <script setup lang="ts">
31
31
  import { vOnClickOutside } from '@vueuse/components'
32
32
  import type { UI_I_AccordionRecursion } from '~/components/common/accordion/models/interfaces'
33
+ import type { UI_T_ShowType } from '~/components/common/accordion/models/types'
34
+ import { UI_E_ShowType } from '~/components/common/accordion/models/enums'
33
35
  import { constructItems } from '~/components/common/accordion/utils/accordion'
34
36
 
35
37
  const props = withDefaults(
36
38
  defineProps<{
37
39
  testId: string
38
40
  accordion: UI_I_AccordionRecursion[]
39
- isAllCollapsed?: boolean
41
+ showType?: UI_T_ShowType
40
42
  }>(),
41
- { isAllCollapsed: false }
43
+ { showType: 'default' }
42
44
  )
43
45
 
44
46
  const emits = defineEmits<{
@@ -48,7 +50,7 @@ const emits = defineEmits<{
48
50
  const parentName = ref<string>('')
49
51
  const childName = ref<string>('')
50
52
  const accordionLocal = computed<UI_I_AccordionRecursion[]>(() =>
51
- constructItems(props.accordion, props.isAllCollapsed)
53
+ constructItems(props.accordion, UI_E_ShowType[props.showType])
52
54
  )
53
55
 
54
56
  const closeDropMenuMobile = (): void => {
@@ -1,212 +1,212 @@
1
- <template>
2
- <div class="accordion" :class="{ disabled: props.accordion.disabled }">
3
- <nuxt-link
4
- class="accordion-item"
5
- :to="accordionLocal.path"
6
- active-class="active"
7
- @click.prevent="onSelect(accordionLocal)"
8
- >
9
- <div
10
- :class="['heading-wrap', { group: props.accordion.hasChild }]"
11
- :style="{ paddingLeft: `${props.level * 24 || 10}px` }"
12
- @click="toggle"
13
- >
14
- <div class="flex-align-center heading">
15
- <div
16
- v-if="props.accordion.iconClassName"
17
- :class="['icon', props.accordion.iconClassName]"
18
- ></div>
19
- <div :class="['text text-ellipsis', headingClass]">
20
- {{ props.accordion.name }}
21
- </div>
22
- </div>
23
- <button
24
- v-if="props.accordion.hasChild"
25
- :id="`${props.testId}-trigger-button`"
26
- class="btn-trigger"
27
- >
28
- <atoms-the-icon
29
- :class="[
30
- 'trigger-icon',
31
- {
32
- isOpen: accordionLocal.isOpen,
33
- },
34
- ]"
35
- name="angle"
36
- />
37
- </button>
38
- </div>
39
- </nuxt-link>
40
-
41
- <transition
42
- v-if="props.accordion.hasChild"
43
- name="accordion"
44
- @before-enter="end"
45
- @enter="start"
46
- @before-leave="start"
47
- @leave="end"
48
- >
49
- <div v-show="accordionLocal.isOpen" class="accordion__content">
50
- <common-accordion-recursion
51
- v-for="(item, key) in props.accordion.children"
52
- :key="item.id"
53
- :test-id="`${props.testId}-${key}`"
54
- :accordion="item"
55
- :level="props.level + 1"
56
- @change="onSelect"
57
- />
58
- </div>
59
- </transition>
60
- </div>
61
- </template>
62
-
63
- <script setup lang="ts">
64
- import type {
65
- UI_I_AccordionRecursion,
66
- UI_I_HeadingClass,
67
- } from '~/components/common/accordion/models/interfaces'
68
-
69
- const props = withDefaults(
70
- defineProps<{
71
- accordion: UI_I_AccordionRecursion
72
- testId: string
73
- level?: number
74
- }>(),
75
- { level: 0 }
76
- )
77
- const emits = defineEmits<{
78
- (event: 'change', value: UI_I_AccordionRecursion): void
79
- }>()
80
-
81
- const accordionLocal = ref<UI_I_AccordionRecursion>(props.accordion)
82
-
83
- // TODO CHANGE
84
- watch(
85
- accordionLocal,
86
- () => {
87
- if (accordionLocal.value.isOpen !== false)
88
- accordionLocal.value.isOpen = true
89
- },
90
- { immediate: true }
91
- )
92
-
93
- const toggle = (): void => {
94
- if (!props.accordion.hasChild) return
95
-
96
- accordionLocal.value.isOpen = !accordionLocal.value.isOpen
97
- }
98
-
99
- const start = (element: any): void => {
100
- element.style.height = 'auto'
101
- }
102
- const end = (el: any): void => {
103
- el.style.height = 0
104
- }
105
-
106
- const headingClass = computed<UI_I_HeadingClass>(() => {
107
- return {
108
- 'text-normal': !props.accordion.hasChild,
109
- disabled: props.accordion.disabled && !props.accordion.hasChild,
110
- }
111
- })
112
-
113
- const onSelect = (item: UI_I_AccordionRecursion): void => {
114
- emits('change', item)
115
- }
116
- </script>
117
-
118
- <style lang="scss">
119
- @import '~/assets/scss/common/mixins';
120
-
121
- %hover-effect {
122
- margin-bottom: -1px;
123
- border-bottom: 1px solid var(--row-hover-border-color);
124
- background-color: var(--row-hover-bg-color);
125
- cursor: pointer;
126
- }
127
- %active-mode {
128
- background-color: var(--row-selected-bg-color);
129
- color: var(--row-selected-text-color);
130
- }
131
- .accordion {
132
- .accordion-item {
133
- display: block;
134
- text-decoration: none;
135
- color: var(--global-font-color);
136
-
137
- &.active {
138
- background-color: #29414e;
139
- color: #fff;
140
- border-bottom: 1px solid transparent;
141
- cursor: default;
142
- %hover-effect {
143
- margin-bottom: unset;
144
- border-bottom: unset;
145
- background-color: unset;
146
- cursor: unset;
147
- }
148
- }
149
-
150
- .heading-wrap {
151
- width: 100%;
152
- @include flex($align: center, $just: space-between);
153
-
154
- &:not(.group) {
155
- display: block;
156
- padding-right: 14px;
157
- }
158
-
159
- &.group .heading {
160
- width: calc(100% - 30px);
161
- }
162
- .heading {
163
- margin-right: 10px;
164
- //overflow: hidden;
165
- .icon {
166
- margin: 1px 4px 0 0;
167
- }
168
-
169
- .text {
170
- font-weight: 600;
171
-
172
- &.text-normal {
173
- font-weight: 400;
174
-
175
- &.disabled {
176
- opacity: 0.3;
177
- cursor: not-allowed;
178
- }
179
- }
180
- }
181
- }
182
- &:hover:not(:has(> .disabled)) {
183
- @extend %hover-effect;
184
- }
185
- &:has(> .disabled) {
186
- cursor: not-allowed;
187
- }
188
- }
189
- }
190
- &__content {
191
- transition: 0.1s ease-in-out;
192
- overflow: hidden;
193
- }
194
- }
195
-
196
- .btn-trigger {
197
- flex: auto;
198
- margin-right: 10px;
199
-
200
- //padding-right: 10px;
201
- .trigger-icon {
202
- width: 16px;
203
- height: 16px;
204
- transform: rotate(90deg);
205
- margin-left: auto;
206
- fill: var(--triger-icon-color);
207
- &.isOpen {
208
- transform: rotate(180deg);
209
- }
210
- }
211
- }
212
- </style>
1
+ <template>
2
+ <div class="accordion" :class="{ disabled: props.accordion.disabled }">
3
+ <nuxt-link
4
+ class="accordion-item"
5
+ :to="accordionLocal.path"
6
+ active-class="active"
7
+ @click.prevent="onSelect(accordionLocal)"
8
+ >
9
+ <div
10
+ :class="['heading-wrap', { group: props.accordion.hasChild }]"
11
+ :style="{ paddingLeft: `${props.level * 24 || 10}px` }"
12
+ @click="toggle"
13
+ >
14
+ <div class="flex-align-center heading">
15
+ <div
16
+ v-if="props.accordion.iconClassName"
17
+ :class="['icon', props.accordion.iconClassName]"
18
+ ></div>
19
+ <div :class="['text text-ellipsis', headingClass]">
20
+ {{ props.accordion.name }}
21
+ </div>
22
+ </div>
23
+ <button
24
+ v-if="props.accordion.hasChild"
25
+ :id="`${props.testId}-trigger-button`"
26
+ class="btn-trigger"
27
+ >
28
+ <atoms-the-icon
29
+ :class="[
30
+ 'trigger-icon',
31
+ {
32
+ isOpen: accordionLocal.isOpen,
33
+ },
34
+ ]"
35
+ name="angle"
36
+ />
37
+ </button>
38
+ </div>
39
+ </nuxt-link>
40
+
41
+ <transition
42
+ v-if="props.accordion.hasChild"
43
+ name="accordion"
44
+ @before-enter="end"
45
+ @enter="start"
46
+ @before-leave="start"
47
+ @leave="end"
48
+ >
49
+ <div v-show="accordionLocal.isOpen" class="accordion__content">
50
+ <common-accordion-recursion
51
+ v-for="(item, key) in props.accordion.children"
52
+ :key="item.id"
53
+ :test-id="`${props.testId}-${key}`"
54
+ :accordion="item"
55
+ :level="props.level + 1"
56
+ @change="onSelect"
57
+ />
58
+ </div>
59
+ </transition>
60
+ </div>
61
+ </template>
62
+
63
+ <script setup lang="ts">
64
+ import type {
65
+ UI_I_AccordionRecursion,
66
+ UI_I_HeadingClass,
67
+ } from '~/components/common/accordion/models/interfaces'
68
+
69
+ const props = withDefaults(
70
+ defineProps<{
71
+ accordion: UI_I_AccordionRecursion
72
+ testId: string
73
+ level?: number
74
+ }>(),
75
+ { level: 0 }
76
+ )
77
+ const emits = defineEmits<{
78
+ (event: 'change', value: UI_I_AccordionRecursion): void
79
+ }>()
80
+
81
+ const accordionLocal = ref<UI_I_AccordionRecursion>(props.accordion)
82
+
83
+ // TODO CHANGE
84
+ watch(
85
+ accordionLocal,
86
+ () => {
87
+ if (accordionLocal.value.isOpen !== false)
88
+ accordionLocal.value.isOpen = true
89
+ },
90
+ { immediate: true }
91
+ )
92
+
93
+ const toggle = (): void => {
94
+ if (!props.accordion.hasChild) return
95
+
96
+ accordionLocal.value.isOpen = !accordionLocal.value.isOpen
97
+ }
98
+
99
+ const start = (element: any): void => {
100
+ element.style.height = 'auto'
101
+ }
102
+ const end = (el: any): void => {
103
+ el.style.height = 0
104
+ }
105
+
106
+ const headingClass = computed<UI_I_HeadingClass>(() => {
107
+ return {
108
+ 'text-normal': !props.accordion.hasChild,
109
+ disabled: props.accordion.disabled && !props.accordion.hasChild,
110
+ }
111
+ })
112
+
113
+ const onSelect = (item: UI_I_AccordionRecursion): void => {
114
+ emits('change', item)
115
+ }
116
+ </script>
117
+
118
+ <style lang="scss">
119
+ @import '~/assets/scss/common/mixins';
120
+
121
+ %hover-effect {
122
+ margin-bottom: -1px;
123
+ border-bottom: 1px solid var(--row-hover-border-color);
124
+ background-color: var(--row-hover-bg-color);
125
+ cursor: pointer;
126
+ }
127
+ %active-mode {
128
+ background-color: var(--row-selected-bg-color);
129
+ color: var(--row-selected-text-color);
130
+ }
131
+ .accordion {
132
+ .accordion-item {
133
+ display: block;
134
+ text-decoration: none;
135
+ color: var(--global-font-color);
136
+
137
+ &.active {
138
+ background-color: #29414e;
139
+ color: #fff;
140
+ border-bottom: 1px solid transparent;
141
+ cursor: default;
142
+ %hover-effect {
143
+ margin-bottom: unset;
144
+ border-bottom: unset;
145
+ background-color: unset;
146
+ cursor: unset;
147
+ }
148
+ }
149
+
150
+ .heading-wrap {
151
+ width: 100%;
152
+ @include flex($align: center, $just: space-between);
153
+
154
+ &:not(.group) {
155
+ display: block;
156
+ padding-right: 14px;
157
+ }
158
+
159
+ &.group .heading {
160
+ width: calc(100% - 30px);
161
+ }
162
+ .heading {
163
+ margin-right: 10px;
164
+ //overflow: hidden;
165
+ .icon {
166
+ margin: 1px 4px 0 0;
167
+ }
168
+
169
+ .text {
170
+ font-weight: 600;
171
+
172
+ &.text-normal {
173
+ font-weight: 400;
174
+
175
+ &.disabled {
176
+ opacity: 0.3;
177
+ cursor: not-allowed;
178
+ }
179
+ }
180
+ }
181
+ }
182
+ &:hover:not(:has(> .disabled)) {
183
+ @extend %hover-effect;
184
+ }
185
+ &:has(> .disabled) {
186
+ cursor: not-allowed;
187
+ }
188
+ }
189
+ }
190
+ &__content {
191
+ transition: 0.1s ease-in-out;
192
+ overflow: hidden;
193
+ }
194
+ }
195
+
196
+ .btn-trigger {
197
+ flex: auto;
198
+ margin-right: 10px;
199
+
200
+ //padding-right: 10px;
201
+ .trigger-icon {
202
+ width: 16px;
203
+ height: 16px;
204
+ transform: rotate(90deg);
205
+ margin-left: auto;
206
+ fill: var(--triger-icon-color);
207
+ &.isOpen {
208
+ transform: rotate(180deg);
209
+ }
210
+ }
211
+ }
212
+ </style>
@@ -0,0 +1,5 @@
1
+ export enum UI_E_ShowType {
2
+ default,
3
+ expand,
4
+ collapse,
5
+ }
@@ -0,0 +1 @@
1
+ export type UI_T_ShowType = 'default' | 'expand' | 'collapse'
@@ -1,31 +1,31 @@
1
- import { UI_I_AccordionRecursion } from '~/components/common/accordion/models/interfaces'
2
-
3
- const collapseRecursion = (
4
- accordion: UI_I_AccordionRecursion[],
5
- isOpen: boolean
6
- ): UI_I_AccordionRecursion[] =>
7
- accordion.map((item) => {
8
- item.isOpen = isOpen
9
- if (item.hasChild && item.children?.length) {
10
- item.children = collapseRecursion(item.children, isOpen)
11
- }
12
-
13
- return item
14
- })
15
-
16
- const defaultShow = (
17
- accordion: UI_I_AccordionRecursion[]
18
- ): UI_I_AccordionRecursion[] =>
19
- accordion.map((item) => {
20
- if (item.isOpen !== false) item.isOpen = true
21
-
22
- return item
23
- })
24
-
25
- export const constructItems = (
26
- accordion: UI_I_AccordionRecursion[],
27
- isOpen: boolean | null
28
- ): UI_I_AccordionRecursion[] =>
29
- isOpen === null
30
- ? defaultShow(accordion)
31
- : collapseRecursion(accordion, isOpen)
1
+ import type { UI_I_AccordionRecursion } from '~/components/common/accordion/models/interfaces'
2
+
3
+ const collapseRecursion = (
4
+ accordion: UI_I_AccordionRecursion[],
5
+ showType: number
6
+ ): UI_I_AccordionRecursion[] =>
7
+ accordion.map((item) => {
8
+ item.isOpen = showType !== 1
9
+ if (item.hasChild && item.children?.length) {
10
+ item.children = collapseRecursion(item.children, showType)
11
+ }
12
+
13
+ return item
14
+ })
15
+
16
+ const defaultShow = (
17
+ accordion: UI_I_AccordionRecursion[]
18
+ ): UI_I_AccordionRecursion[] =>
19
+ accordion.map((item) => {
20
+ if (item.isOpen !== false) item.isOpen = true
21
+
22
+ return item
23
+ })
24
+
25
+ export const constructItems = (
26
+ accordion: UI_I_AccordionRecursion[],
27
+ showType: number
28
+ ): UI_I_AccordionRecursion[] =>
29
+ showType === 0
30
+ ? defaultShow(accordion)
31
+ : collapseRecursion(accordion, showType)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bfg-common",
3
3
  "private": false,
4
- "version": "1.0.58",
4
+ "version": "1.0.59",
5
5
  "scripts": {
6
6
  "build": "nuxt build",
7
7
  "dev": "nuxt dev --port=3002",