File tree Expand file tree Collapse file tree 5 files changed +98
-35
lines changed Expand file tree Collapse file tree 5 files changed +98
-35
lines changed Original file line number Diff line number Diff line change 35
35
"prettier" : " @github/prettier-config" ,
36
36
"dependencies" : {
37
37
"@styled-system/props" : " ^5.1.5" ,
38
- "eslint-plugin-github" : " ^4.9.1 " ,
38
+ "eslint-plugin-github" : " ^4.9.2 " ,
39
39
"eslint-plugin-jsx-a11y" : " ^6.7.1" ,
40
40
"eslint-traverse" : " ^1.0.0" ,
41
41
"lodash" : " ^4.17.21" ,
Original file line number Diff line number Diff line change 1
- const components = {
1
+ const flattenComponents = require ( '../utils/flatten-components' ) ;
2
+
3
+ const components = flattenComponents ( {
2
4
Button : 'button' ,
3
5
IconButton : 'button' ,
4
6
Link : 'a' ,
5
7
Spinner : 'svg' ,
6
- Octicon : 'svg' ,
7
8
ToggleSwitch : 'button' ,
8
9
Radio : 'input' ,
9
10
TextInput : {
@@ -18,23 +19,6 @@ const components = {
18
19
Link : 'a' ,
19
20
self : 'nav' ,
20
21
} ,
21
- }
22
-
23
- const flattenComponents = ( componentObj ) => {
24
- let result = { } ;
25
-
26
- Object . keys ( componentObj ) . forEach ( ( key ) => {
27
- if ( typeof componentObj [ key ] === 'object' ) {
28
- const test = Object . keys ( componentObj [ key ] ) . forEach ( ( item ) => {
29
- result = { ...result , [ `${ key } ${ item !== 'self' ? `.${ item } ` : '' } ` ] : componentObj [ key ] [ item ] } ;
30
- } ) ;
31
- } else {
32
- result = { ...result , [ key ] : componentObj [ key ] }
33
- }
34
- } ) ;
35
-
36
- return result ;
37
- }
38
-
22
+ } )
39
23
40
- module . exports = flattenComponents ( components ) ;
24
+ module . exports = components ;
Original file line number Diff line number Diff line change
1
+ const { flattenComponents} = require ( '../flatten-components' )
2
+
3
+ const mockComponents = function ( passedObj ) {
4
+ return {
5
+ Button : 'button' ,
6
+ Link : 'a' ,
7
+ Spinner : 'svg' ,
8
+ Radio : 'input' ,
9
+ TextInput : {
10
+ Action : 'button' ,
11
+ self : 'input'
12
+ } ,
13
+ ...passedObj
14
+ }
15
+ }
16
+
17
+ describe ( 'getElementType' , function ( ) {
18
+ it ( 'flattens passed object 1-level deep' , function ( ) {
19
+ const result = flattenComponents ( mockComponents ( ) )
20
+
21
+ const expectedResult = {
22
+ Button : 'button' ,
23
+ Link : 'a' ,
24
+ Spinner : 'svg' ,
25
+ Radio : 'input' ,
26
+ TextInput : 'input' ,
27
+ 'TextInput.Action' : 'button'
28
+ }
29
+
30
+ expect ( result ) . toEqual ( expectedResult )
31
+ } )
32
+
33
+ it ( 'ignores objects nested deeper than 1-level' , function ( ) {
34
+ const result = flattenComponents (
35
+ mockComponents ( {
36
+ Select : {
37
+ Items : {
38
+ self : 'div'
39
+ } ,
40
+ Option : 'option' ,
41
+ self : 'select'
42
+ }
43
+ } )
44
+ )
45
+
46
+ const expectedResult = {
47
+ Button : 'button' ,
48
+ Link : 'a' ,
49
+ Spinner : 'svg' ,
50
+ Radio : 'input' ,
51
+ TextInput : 'input' ,
52
+ 'TextInput.Action' : 'button' ,
53
+ 'Select.Items' : {
54
+ self : 'div'
55
+ } ,
56
+ Select : 'select' ,
57
+ 'Select.Option' : 'option'
58
+ }
59
+
60
+ expect ( result ) . toEqual ( expectedResult )
61
+ } )
62
+ } )
Original file line number Diff line number Diff line change
1
+ function flattenComponents ( componentObj ) {
2
+ let result = { } ;
3
+
4
+ Object . keys ( componentObj ) . forEach ( ( key ) => {
5
+ if ( typeof componentObj [ key ] === 'object' ) {
6
+ const test = Object . keys ( componentObj [ key ] ) . forEach ( ( item ) => {
7
+ result = { ...result , [ `${ key } ${ item !== 'self' ? `.${ item } ` : '' } ` ] : componentObj [ key ] [ item ] } ;
8
+ } ) ;
9
+ } else {
10
+ result = { ...result , [ key ] : componentObj [ key ] }
11
+ }
12
+ } ) ;
13
+
14
+ return result ;
15
+ }
16
+
17
+ exports . flattenComponents = flattenComponents
You can’t perform that action at this time.
0 commit comments