1
1
import * as React from 'react' ;
2
2
3
+ import { DeviceBreakpointsType } from '@/types' ;
3
4
import { pickAriaProps } from '@/utils/aria/aria' ;
4
5
5
6
// inner components
@@ -10,27 +11,49 @@ import {
10
11
FooterMobileColumnFlow ,
11
12
FooterPositionType ,
12
13
IFooterStandAlone ,
14
+ MobileSort ,
13
15
} from './types' ;
16
+ import { getOrderConfiguration } from './utils/getOrderConfiguration' ;
14
17
15
18
// simple container tag
16
19
const FOOTER = 'footer' ;
17
20
21
+ const DEFAULT_SORT : MobileSort = {
22
+ column : FooterMobileColumnFlow . DEFAULT ,
23
+ firstContent : FooterPositionType . LEFT ,
24
+ secondContent : FooterPositionType . CENTER ,
25
+ thirdContent : FooterPositionType . RIGHT ,
26
+ } ;
27
+
18
28
const FooterStandAloneComponent = (
19
- { ...props } : IFooterStandAlone ,
29
+ { orderInverse = [ ] , footerMobileSortConfig = DEFAULT_SORT , ...props } : IFooterStandAlone ,
20
30
ref : React . ForwardedRef < HTMLElement > | undefined | null
21
31
) : JSX . Element | null => {
22
32
if ( ! props . children ) {
23
33
return null ;
24
34
}
25
35
26
36
const ariaProps = pickAriaProps ( props ) ;
27
-
28
37
const asFooter = props . simpleContainer ? undefined : FOOTER ;
29
38
39
+ // START CONTENT: Remove when footerMobileSortConfig is removed
40
+ if ( footerMobileSortConfig ?. column === FooterMobileColumnFlow . REVERSE ) {
41
+ orderInverse . push ( DeviceBreakpointsType . MOBILE ) ;
42
+ }
43
+ // END CONTENT
44
+
45
+ const setVertical =
46
+ props . contentDirection === ContentDirectionType . VERTICAL ||
47
+ // START CONTENT: Remove when forceVertical is removed
48
+ props . forceVertical ;
49
+ // END CONTENT
50
+
51
+ const orderConfiguration = getOrderConfiguration ( props . tabInverse || [ ] , orderInverse ) ;
52
+
30
53
const renderChildren = ( children : JSX . Element | JSX . Element [ ] ) => {
31
54
const childrenArray = React . Children . toArray ( children ) ;
32
55
33
- const positions = {
56
+ const positions : { [ key in FooterPositionType ] : React . ReactNode [ ] } = {
34
57
[ FooterPositionType . LEFT ] : [ ] ,
35
58
[ FooterPositionType . CENTER ] : [ ] ,
36
59
[ FooterPositionType . RIGHT ] : [ ] ,
@@ -42,13 +65,18 @@ const FooterStandAloneComponent = (
42
65
let position = ( child as JSX . Element ) ?. props ?. [ 'data-position' ] ;
43
66
44
67
// START CONTENT: Remove when footerMobileSortConfig is removed
45
- if ( props . footerMobileSortConfig ) {
46
- if ( props . footerMobileSortConfig . firstContent === position ) {
47
- position = FooterPositionType . LEFT ;
48
- } else if ( props . footerMobileSortConfig . secondContent === position ) {
49
- position = FooterPositionType . CENTER ;
50
- } else if ( props . footerMobileSortConfig . thirdContent === position ) {
51
- position = FooterPositionType . RIGHT ;
68
+ if ( footerMobileSortConfig && props . device === DeviceBreakpointsType . MOBILE ) {
69
+ const { firstContent, secondContent, thirdContent } = footerMobileSortConfig ;
70
+
71
+ if ( position === firstContent ) {
72
+ positions [ FooterPositionType . LEFT ] . push ( child ) ;
73
+ return ;
74
+ } else if ( position === secondContent ) {
75
+ positions [ FooterPositionType . CENTER ] . push ( child ) ;
76
+ return ;
77
+ } else if ( position === thirdContent ) {
78
+ positions [ FooterPositionType . RIGHT ] . push ( child ) ;
79
+ return ;
52
80
}
53
81
}
54
82
// END CONTENT
@@ -70,35 +98,29 @@ const FooterStandAloneComponent = (
70
98
const sections = Object . entries ( positions ) . map ( ( [ position , children ] ) => (
71
99
< FooterSection
72
100
key = { position }
73
- forceVertical = { forceVertical }
101
+ alignItems = { props . alignItems }
102
+ orderConfiguration = { {
103
+ flexReverse : orderConfiguration [ props . device ] . flexReverse ,
104
+ reverse : orderConfiguration [ props . device ] . reverse ,
105
+ } }
74
106
position = { position }
107
+ setVertical = { setVertical }
75
108
styles = { props . styles }
76
- tabInverse = { tabInverse }
77
109
>
78
110
{ children }
79
111
</ FooterSection >
80
112
) ) ;
81
113
82
- return < > { tabInverse ? sections . reverse ( ) : sections } </ > ;
114
+ return < > { orderConfiguration [ props . device ] . reverse ? sections . reverse ( ) : sections } </ > ;
83
115
} ;
84
116
85
- // START CONTENT: Remove when contentDirection is removed
86
- const forceVertical =
87
- props . forceVertical || props . contentDirection === ContentDirectionType . VERTICAL ;
88
- // END CONTENT
89
-
90
- // START CONTENT: Remove when footerMobileSortConfig is removed
91
- const tabInverse =
92
- props . tabInverse || props . footerMobileSortConfig ?. column === FooterMobileColumnFlow . REVERSE ;
93
- // END CONTENT
94
-
95
117
return (
96
118
< FooterStyled
97
119
{ ...ariaProps }
98
120
{ ...props }
99
121
ref = { ref }
100
- $forceVertical = { forceVertical }
101
- $tabInverse = { tabInverse }
122
+ $flexReverse = { orderConfiguration [ props . device ] . flexReverse }
123
+ $setVertical = { setVertical }
102
124
as = { asFooter }
103
125
data-testid = { props . dataTestId }
104
126
lineSeparatorLineStyles = { props . lineSeparatorLineStyles }
0 commit comments