Skip to content

Commit

Permalink
update search bar layout
Browse files Browse the repository at this point in the history
Signed-off-by: Hailong Cui <ihailong@amazon.com>
  • Loading branch information
Hailong-am committed Oct 18, 2024
1 parent 8d30da4 commit a15ee48
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 44 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@
.left-navigation-wrapper {
display: flex;
flex-direction: column;

.navGroup-container {
margin-right: -$euiSizeS;
}
}

.flex-1-container {
Expand Down Expand Up @@ -112,7 +116,11 @@

.navGroupEnabledNavTopWrapper {
padding: 0 $euiSizeS;
padding-left: $euiSize;
padding-left: $euiSizeS;

.homeICon {
margin-left: $euiSizeS;
}
}

.searchBar-wrapper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ export function CollapsibleNavGroupEnabled({
style={{ paddingTop: 0 }}
>
<NavGroups
className="navGroup-container"
navLinks={navLinksForRender}
navigateToApp={navigateToApp}
onNavItemClick={(event, navItem) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ export const CollapsibleNavTop = ({
<EuiFlexGroup responsive={false} justifyContent="spaceBetween">
{!shouldShrinkNavigation ? (
<EuiFlexItem grow={false}>
<EuiButtonEmpty flush="both" {...homeLinkProps} onClick={onIconClick}>
<EuiButtonEmpty
flush="both"
{...homeLinkProps}
onClick={onIconClick}
className="homeICon"
>
<EuiIcon
type={homeIcon}
size="xl"
Expand Down
4 changes: 3 additions & 1 deletion src/core/public/chrome/ui/header/collapsible_nav_groups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface NavGroupsProps {
navLinks: ChromeNavLink[];
suffix?: React.ReactElement;
style?: React.CSSProperties;
className?: string;
appId?: string;
navigateToApp: InternalApplicationStart['navigateToApp'];
onNavItemClick: (
Expand All @@ -38,6 +39,7 @@ export function NavGroups({
navLinks,
suffix,
style,
className: containerClassName,
appId,
navigateToApp,
onNavItemClick,
Expand Down Expand Up @@ -189,7 +191,7 @@ export function NavGroups({
.filter((navItem) => !!navItem.id);

return (
<EuiFlexItem style={style}>
<EuiFlexItem style={style} className={containerClassName}>
<EuiSideNav items={sideNavItems} isOpenOnMobile mobileBreakpoints={[]} />
{suffix}
</EuiFlexItem>
Expand Down
77 changes: 38 additions & 39 deletions src/core/public/chrome/ui/header/header_search_bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,10 @@ export const HeaderSearchBar = ({ globalSearchCommands, panel, onSearchResultCli
const [results, setResults] = useState([] as React.JSX.Element[]);
const [isLoading, setIsLoading] = useState(false);
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
const [panelWidth, setPanelWidth] = useState(0);
const inputElRef = useRef<HTMLElement | null>();
const inputRef = (node: HTMLElement | null) => (inputElRef.current = node);

const closePopover = () => {
setIsPopoverOpen(false);
setResults([]);
};

const resultSection = (items: ReactNode[], sectionHeader: string) => {
Expand All @@ -108,7 +106,7 @@ export const HeaderSearchBar = ({ globalSearchCommands, panel, onSearchResultCli
{items.length ? (
<EuiListGroup flush={true} gutterSize="none" maxWidth={false}>
{items.map((item, index) => (
<EuiListGroupItem key={index} label={item} size="s" />
<EuiListGroupItem key={index} label={item} color="text" />
))}
</EuiListGroup>
) : (
Expand Down Expand Up @@ -184,7 +182,6 @@ export const HeaderSearchBar = ({ globalSearchCommands, panel, onSearchResultCli
setIsLoading(false);
setResults(sections);
} else {
setIsPopoverOpen(false);
setResults([]);
}
};
Expand All @@ -203,47 +200,49 @@ export const HeaderSearchBar = ({ globalSearchCommands, panel, onSearchResultCli
data-test-subj="search-input"
className="searchInput"
onFocus={() => {
const inputEl = inputElRef.current;
if (inputEl) {
const width = inputEl.getBoundingClientRect().width;
setPanelWidth(width);
}
setIsPopoverOpen(true);
}}
/>
);

const searchBarPanel = (
<EuiPanel
hasBorder={false}
hasShadow={false}
paddingSize="s"
data-test-subj="search-result-panel"
>
<EuiFlexGroup direction="column" gutterSize="s">
<EuiFlexItem>{searchBar}</EuiFlexItem>
<EuiFlexItem>{searchResultSections}</EuiFlexItem>
</EuiFlexGroup>
</EuiPanel>
);

if (panel) {
return (
<EuiPanel
hasBorder={false}
hasShadow={false}
paddingSize="s"
data-test-subj="search-result-panel"
>
<EuiFlexGroup direction="column" gutterSize="s">
<EuiFlexItem>{searchBar}</EuiFlexItem>
<EuiFlexItem>{searchResultSections}</EuiFlexItem>
</EuiFlexGroup>
</EuiPanel>
);
return searchBarPanel;
} else {
return (
<EuiPopover
button={searchBar}
buttonRef={inputRef}
panelStyle={{ minWidth: panelWidth }}
zIndex={2000}
panelPaddingSize="s"
attachToAnchor={true}
ownFocus={false}
display="block"
isOpen={isPopoverOpen}
closePopover={() => {
setIsPopoverOpen(false);
}}
>
{searchResultSections}
</EuiPopover>
<>
{!isPopoverOpen && searchBar}
{isPopoverOpen && (
<EuiPopover
panelStyle={{ minWidth: '400px', minHeight: '300px' }}
button={<></>}
zIndex={2000}
panelPaddingSize="s"
attachToAnchor={true}
ownFocus={true}
display="block"
isOpen={isPopoverOpen}
closePopover={() => {
closePopover();
}}
>
{searchBarPanel}
</EuiPopover>
)}
</>
);
}
};

0 comments on commit a15ee48

Please sign in to comment.