-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Custom Styled Flyout Panel sub-header component
- Loading branch information
1 parent
ed9f2c5
commit 8b5182d
Showing
2 changed files
with
95 additions
and
34 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
...endpoint/public/applications/endpoint/view/hosts/details/components/flyout_sub_header.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,72 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React, { memo } from 'react'; | ||
import { EuiFlyoutHeader, CommonProps, EuiButtonEmpty } from '@elastic/eui'; | ||
import styled from 'styled-components'; | ||
|
||
export type FlyoutSubHeaderProps = CommonProps & { | ||
children: React.ReactNode; | ||
backButton?: { | ||
title: string; | ||
onClick: (event: React.MouseEvent) => void; | ||
href?: string; | ||
}; | ||
}; | ||
|
||
const StyledEuiFlyoutHeader = styled(EuiFlyoutHeader)` | ||
padding: ${props => props.theme.eui.paddingSizes.s}; | ||
&.hasButtons { | ||
.buttons { | ||
padding-bottom: ${props => props.theme.eui.paddingSizes.s}; | ||
} | ||
.back-button-content { | ||
padding-left: 0; | ||
&-text { | ||
margin-left: 0; | ||
} | ||
} | ||
} | ||
.flyout-content { | ||
padding-left: ${props => props.theme.eui.paddingSizes.m}; | ||
} | ||
`; | ||
|
||
const BUTTON_CONTENT_PROPS = Object.freeze({ className: 'back-button-content' }); | ||
const BUTTON_TEXT_PROPS = Object.freeze({ className: 'back-button-content-text' }); | ||
|
||
/** | ||
* A Eui Flyout Header component that has its styles adjusted to display a panel sub-header. | ||
* Component also provides a way to display a "back" button above the header title. | ||
*/ | ||
export const FlyoutSubHeader = memo<FlyoutSubHeaderProps>( | ||
({ children, backButton, ...otherProps }) => { | ||
return ( | ||
<StyledEuiFlyoutHeader hasBorder {...otherProps} className={backButton && `hasButtons`}> | ||
{backButton && ( | ||
<div className="buttons"> | ||
{/* eslint-disable-next-line @elastic/eui/href-or-on-click */} | ||
<EuiButtonEmpty | ||
data-test-subj="flyoutSubHeaderBackButton" | ||
iconType="arrowLeft" | ||
contentProps={BUTTON_CONTENT_PROPS} | ||
textProps={BUTTON_TEXT_PROPS} | ||
size="xs" | ||
href={backButton?.href ?? ''} | ||
onClick={backButton?.onClick} | ||
> | ||
{backButton?.title} | ||
</EuiButtonEmpty> | ||
</div> | ||
)} | ||
<div className={'flyout-content'}>{children}</div> | ||
</StyledEuiFlyoutHeader> | ||
); | ||
} | ||
); |
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