@@ -12,6 +12,8 @@ import { responsiveSizes } from "../common/variables";
1212import DxcButton from "../button/Button" ;
1313import scrollbarStyles from "../styles/scroll" ;
1414import ApplicationLayoutContext from "../layout/ApplicationLayoutContext" ;
15+ import DxcSearchBarTrigger from "../search-bar/SearchBarTrigger" ;
16+ import DxcSearchBar from "../search-bar/SearchBar" ;
1517
1618const MAX_MAIN_NAV_SIZE = "60%" ;
1719const LEVEL_LIMIT = 1 ;
@@ -132,9 +134,16 @@ const sanitizeNavItems = (navItems: HeaderProps["navItems"], level?: number): (G
132134 return sanitizedItems ;
133135} ;
134136
135- const DxcHeader = ( { appTitle, navItems, sideContent, responsiveBottomContent } : HeaderProps ) : JSX . Element => {
137+ const DxcHeader = ( {
138+ appTitle,
139+ navItems,
140+ responsiveBottomContent,
141+ searchBar,
142+ sideContent,
143+ } : HeaderProps ) : JSX . Element => {
136144 const [ isResponsive , setIsResponsive ] = useState ( false ) ;
137145 const [ isMenuVisible , setIsMenuVisible ] = useState ( false ) ;
146+ const [ showSearch , setShowSearch ] = useState ( false ) ;
138147 const logo = useContext ( ApplicationLayoutContext ) . logo || undefined ;
139148
140149 useEffect ( ( ) => {
@@ -157,58 +166,89 @@ const DxcHeader = ({ appTitle, navItems, sideContent, responsiveBottomContent }:
157166 } ;
158167 const sanitizedNavItems = useMemo ( ( ) => ( navItems ? sanitizeNavItems ( navItems ) : [ ] ) , [ navItems ] ) ;
159168
169+ const handleCancelSearch = ( ) => {
170+ if ( typeof searchBar ?. onCancel === "function" ) {
171+ searchBar . onCancel ( ) ;
172+ }
173+ setShowSearch ( false ) ;
174+ } ;
175+
176+ useEffect ( ( ) => {
177+ setShowSearch ( false ) ;
178+ } , [ isResponsive ] ) ;
179+
160180 return (
161181 < MainContainer isResponsive = { isResponsive } isMenuVisible = { isMenuVisible } >
162182 < HeaderContainer >
163183 < DxcGrid
164184 templateColumns = {
165- ! isResponsive && sanitizedNavItems && sanitizedNavItems . length > 0
166- ? [ `auto` , `minmax(auto, ${ MAX_MAIN_NAV_SIZE } )` , `auto` ]
167- : [ "auto" , "auto" ]
185+ showSearch && ! isResponsive
186+ ? [ "auto" ]
187+ : ! isResponsive && sanitizedNavItems && sanitizedNavItems . length > 0
188+ ? [ `auto` , `minmax(auto, ${ MAX_MAIN_NAV_SIZE } )` , `auto` ]
189+ : [ "auto" , "auto" ]
168190 }
169191 templateRows = { [ "var(--height-xxxl)" ] }
170192 gap = "var(--spacing-gap-ml)"
171193 placeItems = "center"
172194 >
173- < BrandingContainer >
174- { logo && (
175- < LogoContainer
176- role = { logo . onClick ? "button" : undefined }
177- onClick = { typeof logo . onClick === "function" ? logo . onClick : undefined }
178- as = { logo . href ? "a" : undefined }
179- href = { logo . href }
180- hasAction = { ! ! ( logo . onClick || logo . href ) }
181- >
182- { typeof logo . src === "string" ? (
183- < DxcImage src = { logo . src } alt = { logo . alt } height = "var(--height-m)" objectFit = "contain" />
184- ) : (
185- logo . src
186- ) }
187- </ LogoContainer >
188- ) }
189- { appTitle && ! isResponsive && (
190- < >
191- { logo && < DxcDivider orientation = "vertical" /> }
192- < DxcHeading text = { appTitle } as = "h1" level = { 5 } />
193- </ >
194- ) }
195- </ BrandingContainer >
196- { ! isResponsive && sanitizedNavItems && sanitizedNavItems . length > 0 && (
195+ { ( ! showSearch || isResponsive ) && (
196+ < BrandingContainer >
197+ { logo && (
198+ < LogoContainer
199+ role = { logo . onClick ? "button" : undefined }
200+ onClick = { typeof logo . onClick === "function" ? logo . onClick : undefined }
201+ as = { logo . href ? "a" : undefined }
202+ href = { logo . href }
203+ hasAction = { ! ! ( logo . onClick || logo . href ) }
204+ >
205+ { typeof logo . src === "string" ? (
206+ < DxcImage src = { logo . src } alt = { logo . alt } height = "var(--height-m)" objectFit = "contain" />
207+ ) : (
208+ logo . src
209+ ) }
210+ </ LogoContainer >
211+ ) }
212+ { appTitle && ! isResponsive && (
213+ < >
214+ { logo && < DxcDivider orientation = "vertical" /> }
215+ < DxcHeading text = { appTitle } as = "h1" level = { 5 } />
216+ </ >
217+ ) }
218+ </ BrandingContainer >
219+ ) }
220+
221+ { ! isResponsive && ( ( sanitizedNavItems && sanitizedNavItems . length > 0 ) || ( ! ! searchBar && showSearch ) ) && (
197222 < MainNavContainer >
198- < DxcNavigationTree
199- items = { sanitizedNavItems }
200- displayGroupLines = { false }
201- displayBorder = { false }
202- displayControlsAfter
203- hasPopOver
204- isHorizontal
205- />
223+ { ! ! searchBar && showSearch ? (
224+ < DxcSearchBar
225+ autoFocus = { true }
226+ onBlur = { searchBar . onBlur }
227+ onCancel = { handleCancelSearch }
228+ onChange = { searchBar . onChange }
229+ onEnter = { searchBar . onEnter }
230+ placeholder = { searchBar . placeholder }
231+ />
232+ ) : (
233+ < DxcNavigationTree
234+ items = { sanitizedNavItems }
235+ displayGroupLines = { false }
236+ displayBorder = { false }
237+ displayControlsAfter
238+ hasPopOver
239+ isHorizontal
240+ />
241+ ) }
206242 </ MainNavContainer >
207243 ) }
208- { ( sideContent || isResponsive ) && (
244+
245+ { ( ! showSearch || isResponsive ) && ( sideContent || isResponsive || ! ! searchBar ) && (
209246 < RightSideContainer >
247+ { ! ! searchBar && ! isResponsive && (
248+ < DxcSearchBarTrigger onTriggerClick = { ( ) => setShowSearch ( ! showSearch ) } />
249+ ) }
210250 { typeof sideContent === "function" ? sideContent ( isResponsive ) : sideContent }
211- { isResponsive && ( ( navItems && navItems . length ) || responsiveBottomContent ) && (
251+ { isResponsive && ( ( navItems && navItems . length ) || responsiveBottomContent || ! ! searchBar ) && (
212252 < HamburguerButton onClick = { toggleMenu } />
213253 ) }
214254 </ RightSideContainer >
@@ -219,6 +259,14 @@ const DxcHeader = ({ appTitle, navItems, sideContent, responsiveBottomContent }:
219259 < ResponsiveMenuContainer >
220260 < ResponsiveMenu >
221261 { appTitle && < DxcHeading text = { appTitle } as = "h1" level = { 5 } /> }
262+ { ! ! searchBar && (
263+ < DxcSearchBar
264+ onBlur = { searchBar . onBlur }
265+ onChange = { searchBar . onChange }
266+ onEnter = { searchBar . onEnter }
267+ placeholder = { searchBar . placeholder }
268+ />
269+ ) }
222270 < DxcNavigationTree
223271 items = { sanitizedNavItems }
224272 displayGroupLines = { false }
0 commit comments