@@ -17,8 +17,6 @@ export default class EccUtilsDesignFormGroup extends LitElement {
17
17
18
18
// TODO
19
19
// build required but empty functionality
20
- // add functionality to collect all ecc-input fields in the group
21
- // same for the form
22
20
@property ( { type : String , reflect : true } ) label = "" ;
23
21
@property ( { type : String , reflect : true } ) key = "" ;
24
22
@property ( { type : String , reflect : true } ) type : "array" | "group" = "group" ;
@@ -35,7 +33,7 @@ export default class EccUtilsDesignFormGroup extends LitElement {
35
33
// group item options
36
34
@property ( { type : Boolean , reflect : true } ) collapsible = false ;
37
35
38
- @state ( ) private arrayItems : Array < {
36
+ @state ( ) private arrayInstances : Array < {
39
37
id : number ;
40
38
items : Element [ ] ;
41
39
} > = [ ] ;
@@ -48,10 +46,13 @@ export default class EccUtilsDesignFormGroup extends LitElement {
48
46
protected firstUpdated ( ) : void {
49
47
if ( this . type === "array" ) {
50
48
this . originalInstance = Array . from ( this . querySelectorAll ( ":scope > *" ) ) ;
51
- this . arrayItems = Array . from ( { length : this . instances } , ( __ , index ) => ( {
52
- id : index ,
53
- items : this . originalInstance ,
54
- } ) ) ;
49
+ this . arrayInstances = Array . from (
50
+ { length : this . instances } ,
51
+ ( __ , index ) => ( {
52
+ id : index ,
53
+ items : this . originalInstance ,
54
+ } )
55
+ ) ;
55
56
} else {
56
57
this . items = Array . from ( this . querySelectorAll ( ":scope > *" ) ) ;
57
58
}
@@ -79,11 +80,7 @@ export default class EccUtilsDesignFormGroup extends LitElement {
79
80
const { parentElement } = element ;
80
81
if ( ! parentElement ) return ;
81
82
82
- const specialAttributes = [
83
- "ecc-array-item" ,
84
- "ecc-group-item" ,
85
- "ecc-form-item" ,
86
- ] ;
83
+ const specialAttributes = [ "ecc-array" , "ecc-group" , "ecc-form" ] ;
87
84
const hasSpecialAttribute = specialAttributes . some ( ( attr ) =>
88
85
parentElement . hasAttribute ( attr )
89
86
) ;
@@ -100,15 +97,15 @@ export default class EccUtilsDesignFormGroup extends LitElement {
100
97
return html `${ this . collapsible
101
98
? repeat (
102
99
this . items ,
103
- ( ) => _ . uniqueId ( "ecc-group-item- " ) ,
100
+ ( ) => _ . uniqueId ( "ecc-group-" ) ,
104
101
( item ) => html `
105
102
< sl-details
106
103
data-testid ="group-collapsible "
107
104
summary =${ `${ this . label } ${ this . required ? "*" : "" } ` }
108
105
>
109
106
< div
110
107
class ="group-content "
111
- ecc-group-item
108
+ ecc-group
112
109
ecc-group-key ="${ this . key } "
113
110
path ="${ this . path } "
114
111
>
@@ -119,12 +116,12 @@ export default class EccUtilsDesignFormGroup extends LitElement {
119
116
)
120
117
: repeat (
121
118
this . items ,
122
- ( ) => _ . uniqueId ( "group-item -" ) ,
119
+ ( ) => _ . uniqueId ( "ecc-group -" ) ,
123
120
( item ) => html `
124
121
< span > ${ this . label } ${ this . required ? "*" : "" } </ span >
125
122
< div
126
123
class ="group-content "
127
- ecc-group-item
124
+ ecc-group
128
125
ecc-group-key ="${ this . key } "
129
126
path ="${ this . path } "
130
127
>
@@ -137,16 +134,22 @@ export default class EccUtilsDesignFormGroup extends LitElement {
137
134
private renderArrayTemplate ( ) : TemplateResult {
138
135
const resolveAddButtonIsActive = ( ) => {
139
136
if ( ! this . maxInstances ) return true ;
140
- if ( Number ( this . maxInstances ) > this . arrayItems . length || 0 ) return true ;
137
+ if ( Number ( this . maxInstances ) > this . arrayInstances . length || 0 )
138
+ return true ;
141
139
return false ;
142
140
} ;
143
141
144
- const resolveDeleteButtonIsActive = ( ) => true ;
142
+ const resolveDeleteButtonIsActive = ( ) => {
143
+ if ( ! this . minInstances ) return true ;
144
+ if ( Number ( this . minInstances ) >= this . arrayInstances . length || 0 )
145
+ return false ;
146
+ return true ;
147
+ } ;
145
148
146
149
const addItem = ( ) => {
147
150
if ( resolveAddButtonIsActive ( ) ) {
148
- this . arrayItems . push ( {
149
- id : this . arrayItems . length ,
151
+ this . arrayInstances . push ( {
152
+ id : this . arrayInstances . length ,
150
153
items : this . originalInstance ,
151
154
} ) ;
152
155
@@ -155,7 +158,7 @@ export default class EccUtilsDesignFormGroup extends LitElement {
155
158
new CustomEvent ( "ecc-utils-array-add" , {
156
159
detail : {
157
160
key : this . key ,
158
- instances : this . arrayItems . length ,
161
+ instances : this . arrayInstances . length ,
159
162
} ,
160
163
bubbles : true ,
161
164
composed : true ,
@@ -166,16 +169,16 @@ export default class EccUtilsDesignFormGroup extends LitElement {
166
169
167
170
const deleteItem = ( index : number ) => {
168
171
if ( resolveDeleteButtonIsActive ( ) ) {
169
- const newItems = [ ...this . arrayItems ] ;
172
+ const newItems = [ ...this . arrayInstances ] ;
170
173
newItems . splice ( index , 1 ) ;
171
174
172
- this . arrayItems = newItems ;
175
+ this . arrayInstances = newItems ;
173
176
this . requestUpdate ( ) ;
174
177
this . dispatchEvent (
175
178
new CustomEvent ( "ecc-utils-array-delete" , {
176
179
detail : {
177
180
key : this . key ,
178
- instances : this . arrayItems . length ,
181
+ instances : this . arrayInstances . length ,
179
182
} ,
180
183
bubbles : true ,
181
184
composed : true ,
@@ -235,14 +238,14 @@ export default class EccUtilsDesignFormGroup extends LitElement {
235
238
</ sl-button >
236
239
</ div >
237
240
${ repeat (
238
- this . arrayItems ,
239
- ( item ) => item . id ,
240
- ( items , index ) => html `
241
+ this . arrayInstances ,
242
+ ( instance ) => instance . id ,
243
+ ( instance , index ) => html `
241
244
< div
242
245
path ="${ this . path } [${ index } ] "
243
- ecc-array-item
244
- class ="array-item "
245
- data-testid ="array-item "
246
+ ecc-array
247
+ class ="array "
248
+ data-testid ="array "
246
249
data-label =${ `${ this . label } -${ index } ` }
247
250
>
248
251
< sl-button
@@ -271,7 +274,7 @@ export default class EccUtilsDesignFormGroup extends LitElement {
271
274
</ sl-button >
272
275
< div class ="array-item-container ">
273
276
${ repeat (
274
- items . items ,
277
+ instance . items ,
275
278
( item ) => item . id ,
276
279
( item ) => arrayDiv ( item , index )
277
280
) }
0 commit comments