@@ -9,19 +9,36 @@ import React, { useState, useEffect, useRef } from "react";
99 */
1010
1111/**
12- * @param {{ columnIndex: number, column: Column } } props
12+ * @param {Object } props - The component props
13+ * @param {number } props.columnIndex - The index of the column
14+ * @param {Column } props.column - The column data object
15+ * @param {boolean } [props.isOpen=false] - Whether the column is initially open
16+ * @param {Function } [props.onToggle] - Optional callback function for toggle events
1317 * @returns {JSX.Element }
1418 */
1519
16- const ColumnSection = ( { columnIndex, column : { title, links } } ) => {
17- const [ show , setShow ] = useState ( false ) ;
20+ const ColumnSection = ( {
21+ columnIndex,
22+ column : { title, links } ,
23+ isOpen = false ,
24+ onToggle,
25+ } ) => {
26+ const [ show , setShow ] = useState ( isOpen ) ;
1827 const isWindowDefined = typeof window !== "undefined" ;
1928 const initialMatches = isWindowDefined ? window . innerWidth >= 1260 : false ;
2029 const [ isLgDesktop , setIsLgDesktop ] = useState ( initialMatches ) ;
2130
2231 /** @type {React.RefObject<HTMLDivElement> | null } */
2332 const accordionBodyRef = useRef ( null ) ;
2433
34+ // Update local state when prop changes
35+ useEffect ( ( ) => {
36+ if ( ! isLgDesktop && onToggle ) {
37+ handleAnimation ( isOpen ) ;
38+ }
39+ setShow ( isOpen ) ;
40+ } , [ isOpen , isLgDesktop , onToggle ] ) ;
41+
2542 useEffect ( ( ) => {
2643 const mediaWatcher = window . matchMedia ( "screen and (min-width: 1260px)" ) ;
2744 const handleMediaChange = e => setIsLgDesktop ( e . matches ) ;
@@ -33,27 +50,27 @@ const ColumnSection = ({ columnIndex, column: { title, links } }) => {
3350
3451 const handleAnimation = showingContent => {
3552 const accordionBody = accordionBodyRef ?. current ;
36- if ( ! accordionBody ) return ;
37- accordionBody . classList . add ( "collapsing" ) ;
53+ if ( ! accordionBody || ! accordionBody . animate ) return ;
54+ accordionBody . classList . add ( "footer- collapsing" ) ;
3855 const animation = accordionBody . animate (
3956 [
4057 {
4158 maxHeight : showingContent ? `${ accordionBody . scrollHeight } px` : "0px" ,
4259 } ,
4360 ] ,
4461 {
45- duration : 350 ,
62+ duration : 250 ,
4663 easing : "ease-in-out" ,
4764 fill : "forwards" ,
4865 }
4966 ) ;
5067
5168 animation . onfinish = ( ) => {
52- accordionBody . classList . remove ( "collapsing" ) ;
69+ accordionBody . classList . remove ( "footer- collapsing" ) ;
5370 if ( showingContent ) {
54- accordionBody . classList . add ( "show" ) ;
71+ accordionBody . classList . add ( "footer-column- show" ) ;
5572 } else {
56- accordionBody . classList . remove ( "show" ) ;
73+ accordionBody . classList . remove ( "footer-column- show" ) ;
5774 }
5875 } ;
5976 } ;
@@ -64,24 +81,29 @@ const ColumnSection = ({ columnIndex, column: { title, links } }) => {
6481 return ;
6582 }
6683
67- setShow ( prev => {
68- const showingContent = ! prev ;
69- handleAnimation ( showingContent ) ;
70- return showingContent ;
71- } ) ;
84+ if ( onToggle ) {
85+ onToggle ( ) ;
86+ } else {
87+ // Fallback for backward compatibility
88+ setShow ( prev => {
89+ const showingContent = ! prev ;
90+ handleAnimation ( showingContent ) ;
91+ return showingContent ;
92+ } ) ;
93+ }
7294 } ;
7395
7496 return (
7597 < div className = "col-xl flex-footer testname-column" >
7698 < div className = "card accordion-item desktop-disable-xl" >
77- < div className = "accordion-header" >
99+ < div className = "footer- accordion-header" >
78100 < div className = "h5" >
79101 { isLgDesktop ? (
80102 < p className = "accordion-button" > { title } </ p >
81103 ) : (
82104 < button
83105 id = { `footlink-header-${ columnIndex } ` }
84- className = "accordion-button"
106+ className = "footer- accordion-button"
85107 aria-expanded = { show || isLgDesktop }
86108 aria-controls = { `footlink-${ columnIndex } ` }
87109 onClick = { handleToggle }
@@ -90,7 +112,7 @@ const ColumnSection = ({ columnIndex, column: { title, links } }) => {
90112 >
91113 { title }
92114 < FontAwesomeIcon
93- className = { show || isLgDesktop ? "open" : "" }
115+ className = { show || isLgDesktop ? "column- open" : "" }
94116 icon = { faChevronDown }
95117 />
96118 </ button >
@@ -99,7 +121,7 @@ const ColumnSection = ({ columnIndex, column: { title, links } }) => {
99121 </ div >
100122 < div
101123 id = { `footlink-${ columnIndex } ` }
102- className = "accordion-body"
124+ className = "footer- accordion-body"
103125 role = "region"
104126 ref = { accordionBodyRef }
105127 >
@@ -131,6 +153,8 @@ ColumnSection.propTypes = {
131153 } )
132154 ) ,
133155 } ) ,
156+ isOpen : PropTypes . bool ,
157+ onToggle : PropTypes . func ,
134158} ;
135159
136160export { ColumnSection } ;
0 commit comments