-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
180 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { EuiPageTemplate } from '@elastic/eui'; | ||
import type { ReactNode } from 'react'; | ||
import { SidebarContainer } from './sidebar'; | ||
|
||
export interface LayoutProps { | ||
/** | ||
* Nested components. | ||
*/ | ||
children?: ReactNode; | ||
} | ||
|
||
export const Layout: React.FC<LayoutProps> = ( | ||
props: LayoutProps | ||
): ReactNode => { | ||
const { children } = props; | ||
|
||
// In the template, set the `responsive` property to an empty array | ||
// so that the sidebar always shows on the left. Otherwise, if the | ||
// window is resized to be too small, the sidebar will stack on top. | ||
// And that's not the UX we want. | ||
|
||
return ( | ||
<EuiPageTemplate grow={true} responsive={[]}> | ||
<EuiPageTemplate.Sidebar minWidth={50} paddingSize="xs" responsive={[]}> | ||
<SidebarContainer /> | ||
</EuiPageTemplate.Sidebar> | ||
<EuiPageTemplate.Section paddingSize="none" grow={true}> | ||
{children} | ||
</EuiPageTemplate.Section> | ||
</EuiPageTemplate> | ||
); | ||
}; | ||
|
||
Layout.displayName = 'Layout'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './sidebar-container'; |
136 changes: 136 additions & 0 deletions
136
electron/renderer/components/sidebar/sidebar-container.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
import type { EuiButtonIconProps } from '@elastic/eui'; | ||
import { | ||
EuiButtonIcon, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiPopover, | ||
EuiToolTip, | ||
} from '@elastic/eui'; | ||
import { type ReactNode, useCallback, useState } from 'react'; | ||
|
||
export interface SidebarContainerProps { | ||
// | ||
} | ||
|
||
export interface SidebarButtonIconProps { | ||
label: EuiButtonIconProps['aria-label']; | ||
iconType: EuiButtonIconProps['iconType']; | ||
iconColor?: EuiButtonIconProps['color']; | ||
iconSize?: EuiButtonIconProps['iconSize']; | ||
/** | ||
* The content of the popover when the button is clicked. | ||
*/ | ||
children?: ReactNode; | ||
} | ||
|
||
const SidebarButtonIcon: React.FC<SidebarButtonIconProps> = ( | ||
props: SidebarButtonIconProps | ||
): ReactNode => { | ||
const { label, iconType, iconColor, iconSize, children } = props; | ||
|
||
const [showTooltip, setShowTooltip] = useState(true); | ||
const [showPopover, setShowPopover] = useState(false); | ||
|
||
const onClosePopover = useCallback(() => { | ||
setShowTooltip(true); | ||
setShowPopover(false); | ||
}, []); | ||
|
||
const togglePopoverAndTooltip = useCallback(() => { | ||
if (!children) { | ||
return; | ||
} | ||
setShowTooltip((prev) => !prev); | ||
setShowPopover((prev) => !prev); | ||
}, [children]); | ||
|
||
const buttonElmt = ( | ||
<EuiPopover | ||
isOpen={showPopover} | ||
closePopover={onClosePopover} | ||
button={ | ||
<EuiButtonIcon | ||
aria-label={label} | ||
iconType={iconType} | ||
color={iconColor} | ||
iconSize={iconSize} | ||
css={{ | ||
'min-width': 50, | ||
'min-height': 50, | ||
'height': 50, | ||
'width': 50, | ||
}} | ||
onClick={togglePopoverAndTooltip} | ||
/> | ||
} | ||
> | ||
{children} | ||
</EuiPopover> | ||
); | ||
|
||
if (showTooltip) { | ||
return ( | ||
<EuiToolTip aria-label={label} content={label} position="right"> | ||
{buttonElmt} | ||
</EuiToolTip> | ||
); | ||
} | ||
|
||
return buttonElmt; | ||
}; | ||
|
||
SidebarButtonIcon.displayName = 'SidebarButtonIcon'; | ||
|
||
export const SidebarContainer: React.FC<SidebarContainerProps> = ( | ||
props: SidebarContainerProps | ||
): ReactNode => { | ||
return ( | ||
<EuiFlexGroup direction="column" css={{ height: '100%' }}> | ||
<EuiFlexItem grow={false}> | ||
<EuiFlexGroup direction="column" gutterSize="none" alignItems="center"> | ||
<EuiFlexItem grow={false}> | ||
<SidebarButtonIcon | ||
label="Characters" | ||
iconType="user" | ||
iconColor="primary" | ||
iconSize="l" | ||
/> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<SidebarButtonIcon | ||
label="Accounts" | ||
iconType="key" | ||
iconColor="primary" | ||
iconSize="l" | ||
/> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={true}>{/* empty space in the middle */}</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiFlexGroup direction="column" gutterSize="none" alignItems="center"> | ||
<EuiFlexItem grow={false}> | ||
<SidebarButtonIcon | ||
label="Help" | ||
iconType="questionInCircle" | ||
iconColor="text" | ||
iconSize="xl" // https://github.com/elastic/eui/issues/6322 | ||
> | ||
<div>Some help text</div> | ||
</SidebarButtonIcon> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<SidebarButtonIcon | ||
label="Settings" | ||
iconType="gear" | ||
iconColor="text" | ||
iconSize="l" | ||
/> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
}; | ||
|
||
SidebarContainer.displayName = 'SidebarContainer'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters