1
1
import {
2
2
FC ,
3
+ forwardRef ,
3
4
MutableRefObject ,
4
5
ReactNode ,
6
+ RefAttributes ,
5
7
useCallback ,
6
8
useLayoutEffect ,
7
9
useRef ,
@@ -42,7 +44,8 @@ interface CertificatePageLayoutProps {
42
44
title ?: string
43
45
}
44
46
45
- const CertificatePageLayout : FC < CertificatePageLayoutProps > = ( props : CertificatePageLayoutProps ) => {
47
+ const CertificatePageLayout : FC < CertificatePageLayoutProps & RefAttributes < HTMLDivElement > >
48
+ = forwardRef < HTMLDivElement , CertificatePageLayoutProps > ( ( props , ref ) => {
46
49
const [ queryParams ] : [ URLSearchParams , any ] = useSearchParams ( )
47
50
const viewStyle : CertificatePageLayoutStyle = queryParams . get ( getViewStyleParamKey ( ) ) as CertificatePageLayoutStyle
48
51
@@ -78,6 +81,12 @@ const CertificatePageLayout: FC<CertificatePageLayoutProps> = (props: Certificat
78
81
const handlePrint : ( ) => Promise < void >
79
82
= useCertificatePrint ( props . certificateElRef , props . title ?? '' )
80
83
84
+ if ( typeof ref === 'function' ) {
85
+ ref ( wrapElRef . current )
86
+ } else if ( ref && Object . prototype . hasOwnProperty . call ( ref , 'current' ) ) {
87
+ ref . current = wrapElRef . current
88
+ }
89
+
81
90
useLayoutEffect ( ( ) => {
82
91
const el : HTMLElement = wrapElRef . current
83
92
if ( props . fullScreenCertLayout !== true || ! el ) {
@@ -93,57 +102,59 @@ const CertificatePageLayout: FC<CertificatePageLayoutProps> = (props: Certificat
93
102
< >
94
103
< LoadingSpinner hide = { props . isReady } />
95
104
96
- { props . isReady && (
97
- < div className = { classNames ( styles . wrap , props . className ) } ref = { wrapElRef } >
98
- < div className = { styles [ 'content-wrap' ] } >
99
- { ! props . fullScreenCertLayout && (
100
- < div className = { styles [ 'btns-wrap' ] } >
101
- < ActionButton
102
- icon = { < IconOutline . ChevronLeftIcon /> }
103
- onClick = { handleBackBtnClick }
104
- />
105
- </ div >
106
- ) }
107
- < div
108
- className = { classNames ( styles [ 'certificate-wrap' ] , viewStyle ) }
109
- ref = { certificateWrapRef }
110
- >
111
- < div className = { styles . certifInnerWrap } >
112
- { props . children }
113
- </ div >
114
- </ div >
115
- { ! props . fullScreenCertLayout && (
105
+ < div className = { classNames ( styles . wrap , props . className ) } ref = { wrapElRef } >
106
+ { props . isReady && (
107
+ < >
108
+ < div className = { styles [ 'content-wrap' ] } >
109
+ { ! props . fullScreenCertLayout && (
110
+ < div className = { styles [ 'btns-wrap' ] } >
111
+ < ActionButton
112
+ icon = { < IconOutline . ChevronLeftIcon /> }
113
+ onClick = { handleBackBtnClick }
114
+ />
115
+ </ div >
116
+ ) }
116
117
< div
117
- className = {
118
- classNames (
119
- styles [ 'btns-wrap' ] ,
120
- ( ! props . isCertificateCompleted || props . disableActions ) && styles . disabled ,
121
- )
122
- }
118
+ className = { classNames ( styles [ 'certificate-wrap' ] , viewStyle ) }
119
+ ref = { certificateWrapRef }
123
120
>
124
- < ActionButton
125
- icon = { < IconOutline . PrinterIcon /> }
126
- onClick = { handlePrint }
127
- />
128
- < ActionButton
129
- icon = { < IconOutline . DownloadIcon /> }
130
- onClick = { handleDownload }
131
- />
132
- < ActionButton
133
- icon = { < IconOutline . ShareIcon /> }
134
- onClick = { shareModal . show }
135
- >
136
- Share certificate
137
- </ ActionButton >
121
+ < div className = { styles . certifInnerWrap } >
122
+ { props . children }
123
+ </ div >
138
124
</ div >
139
- ) }
140
- </ div >
141
- { props . afterContent }
142
- { shareModal . modal }
143
- </ div >
144
- ) }
125
+ { ! props . fullScreenCertLayout && (
126
+ < div
127
+ className = {
128
+ classNames (
129
+ styles [ 'btns-wrap' ] ,
130
+ ( ! props . isCertificateCompleted || props . disableActions ) && styles . disabled ,
131
+ )
132
+ }
133
+ >
134
+ < ActionButton
135
+ icon = { < IconOutline . PrinterIcon /> }
136
+ onClick = { handlePrint }
137
+ />
138
+ < ActionButton
139
+ icon = { < IconOutline . DownloadIcon /> }
140
+ onClick = { handleDownload }
141
+ />
142
+ < ActionButton
143
+ icon = { < IconOutline . ShareIcon /> }
144
+ onClick = { shareModal . show }
145
+ >
146
+ Share certificate
147
+ </ ActionButton >
148
+ </ div >
149
+ ) }
150
+ </ div >
151
+ { props . afterContent }
152
+ { shareModal . modal }
153
+ </ >
154
+ ) }
155
+ </ div >
145
156
</ >
146
157
)
147
- }
158
+ } )
148
159
149
160
export default CertificatePageLayout
0 commit comments