-
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.
- Loading branch information
1 parent
ecaee18
commit dec9f0b
Showing
8 changed files
with
192 additions
and
12 deletions.
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
80 changes: 80 additions & 0 deletions
80
x-pack/plugins/security_solution/public/resolver/view/panels/copyable_panel_field.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,80 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/* eslint-disable react/display-name */ | ||
|
||
import { EuiToolTip, EuiPopover } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import styled from 'styled-components'; | ||
import React, { memo, useState, useContext } from 'react'; | ||
import { WithCopyToClipboard } from '../../../common/lib/clipboard/with_copy_to_clipboard'; | ||
import { useColors } from '../use_colors'; | ||
import { ResolverPanelContext } from './panel_context'; | ||
|
||
interface StyledCopyableField { | ||
readonly backgroundColor: string; | ||
readonly activeBackgroundColor: string; | ||
} | ||
|
||
const StyledCopyableField = styled.div<StyledCopyableField>` | ||
background-color: ${(props) => props.backgroundColor}; | ||
border-radius: 3px; | ||
padding: 4px; | ||
transition: background 0.2s ease; | ||
&:hover { | ||
background-color: ${(props) => props.activeBackgroundColor}; | ||
color: #fff; | ||
} | ||
`; | ||
|
||
export const CopyablePanelField = memo( | ||
({ textToCopy, content }: { textToCopy: string; content: JSX.Element | string }) => { | ||
const { linkColor, copyableBackground } = useColors(); | ||
const [isOpen, setIsOpen] = useState(false); | ||
const panelContext = useContext(ResolverPanelContext); | ||
|
||
const onMouseEnter = () => setIsOpen(true); | ||
|
||
const ButtonContent = memo(() => ( | ||
<StyledCopyableField | ||
backgroundColor={panelContext.isHoveringInPanel ? copyableBackground : 'transparent'} | ||
data-test-subj="resolver:panel:copyable-field" | ||
activeBackgroundColor={linkColor} | ||
onMouseEnter={onMouseEnter} | ||
> | ||
{content} | ||
</StyledCopyableField> | ||
)); | ||
|
||
const onMouseLeave = () => setIsOpen(false); | ||
|
||
return ( | ||
<div onMouseLeave={onMouseLeave}> | ||
<EuiPopover | ||
anchorPosition={'downCenter'} | ||
button={<ButtonContent />} | ||
closePopover={onMouseLeave} | ||
hasArrow={false} | ||
isOpen={isOpen} | ||
panelPaddingSize="s" | ||
> | ||
<EuiToolTip | ||
content={i18n.translate('xpack.securitySolution.resolver.panel.copyToClipboard', { | ||
defaultMessage: 'Copy to Clipboard', | ||
})} | ||
> | ||
<WithCopyToClipboard | ||
data-test-subj="resolver:panel:copy-to-clipboard" | ||
text={textToCopy} | ||
titleSummary={textToCopy} | ||
/> | ||
</EuiToolTip> | ||
</EuiPopover> | ||
</div> | ||
); | ||
} | ||
); |
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
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
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
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
9 changes: 9 additions & 0 deletions
9
x-pack/plugins/security_solution/public/resolver/view/panels/panel_context.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,9 @@ | ||
/* | ||
* 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 from 'react'; | ||
|
||
export const ResolverPanelContext = React.createContext({ isHoveringInPanel: false }); |
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