From 257ff8aba281a29b9975b98157d2229b52b4586c Mon Sep 17 00:00:00 2001 From: nicolethoen Date: Mon, 29 Aug 2022 14:42:05 -0400 Subject: [PATCH 01/12] fix(CodeEditor): use codeEditorControls and clean up overall --- .../src/components/CodeEditor/CodeEditor.tsx | 91 +++++++++---------- .../CodeEditor/CodeEditorControl.tsx | 29 +++--- .../examples/CodeEditorCustomControl.tsx | 2 +- .../examples/CodeEditorShortcutMainHeader.tsx | 11 +-- .../ClipboardCopy/ClipboardCopy.tsx | 8 +- .../CodeBlock/examples/CodeBlockBasic.tsx | 8 +- .../examples/CodeBlockExpandable.tsx | 8 +- .../src/components/Tooltip/Tooltip.tsx | 13 ++- 8 files changed, 78 insertions(+), 92 deletions(-) diff --git a/packages/react-code-editor/src/components/CodeEditor/CodeEditor.tsx b/packages/react-code-editor/src/components/CodeEditor/CodeEditor.tsx index ff4dbeb36ef..17fdfcdde8f 100644 --- a/packages/react-code-editor/src/components/CodeEditor/CodeEditor.tsx +++ b/packages/react-code-editor/src/components/CodeEditor/CodeEditor.tsx @@ -25,6 +25,7 @@ import CodeIcon from '@patternfly/react-icons/dist/esm/icons/code-icon'; import HelpIcon from '@patternfly/react-icons/dist/esm/icons/help-icon'; import Dropzone from 'react-dropzone'; import { CodeEditorContext } from './CodeEditorUtils'; +import { CodeEditorControl } from './CodeEditorControl'; export interface Shortcut { description: string; @@ -444,8 +445,7 @@ export class CodeEditor extends React.Component { this.timer = window.setTimeout(() => { this.setState({ copied: false }); @@ -486,7 +486,7 @@ export class CodeEditor extends React.Component )); + const tooltipProps = { + position: toolTipPosition, + exitDelay: toolTipDelay, + entryDelay: toolTipDelay, + maxWidth: toolTipMaxWidth, + trigger: 'mouseenter focus' + }; + const editorHeader = (
{
- {isCopyEnabled && (!showEmptyState || !!value) && ( - {copied ? copyButtonSuccessTooltipText : copyButtonToolTipText}
} - exitDelay={copied ? toolTipCopyExitDelay : toolTipDelay} - entryDelay={toolTipDelay} - maxWidth={toolTipMaxWidth} - position={toolTipPosition} - > - - - )} - {isUploadEnabled && ( - {uploadButtonToolTipText}
} - entryDelay={toolTipDelay} - exitDelay={toolTipDelay} - maxWidth={toolTipMaxWidth} - position={toolTipPosition} - > - - - )} - {isDownloadEnabled && (!showEmptyState || !!value) && ( - {downloadButtonToolTipText}} - entryDelay={toolTipDelay} - exitDelay={toolTipDelay} - maxWidth={toolTipMaxWidth} - position={toolTipPosition} - > - - - )} - {customControls && ( - {customControls} - )} + + {isCopyEnabled && (!showEmptyState || !!value) && ( + } + aria-label={copyButtonAriaLabel} + tooltipProps={{ + ...tooltipProps, + 'aria-live': 'polite', + content:
{copied ? copyButtonSuccessTooltipText : copyButtonToolTipText}
, + exitDelay: copied ? tooltipCopyExitDelay : toolTipDelay + }} + onClick={this.copyCode} + /> + )} + {isUploadEnabled && ( + } + aria-label={uploadButtonAriaLabel} + tooltipProps={{content:
{uploadButtonToolTipText}
, ...tooltipProps}} + onClick={open} + /> + )} + {isDownloadEnabled && (!showEmptyState || !!value) && ( + } + aria-label={downloadButtonAriaLabel} + tooltipProps={{content:
{downloadButtonToolTipText}
, ...tooltipProps}} + onClick={this.download} + /> + )} + {customControls && customControls} +
} {
{headerMainContent}
} diff --git a/packages/react-code-editor/src/components/CodeEditor/CodeEditorControl.tsx b/packages/react-code-editor/src/components/CodeEditor/CodeEditorControl.tsx index 5b8298a3416..5a5e733fac4 100644 --- a/packages/react-code-editor/src/components/CodeEditor/CodeEditorControl.tsx +++ b/packages/react-code-editor/src/components/CodeEditor/CodeEditorControl.tsx @@ -7,19 +7,19 @@ import { CodeEditorContext } from './CodeEditorUtils'; */ export interface CodeEditorControlProps extends Omit { - /** Accessible label for the code editor control. */ + /** Accessible label for the code editor control */ 'aria-label'?: string; /** Additional classes added to the code editor control. */ className?: string; - /** Delay in ms before the tooltip appears. */ + /** @deprecated Delay in ms before the tooltip appears. */ entryDelay?: number; - /** Delay in ms before the tooltip disappears. */ + /** @deprecated Delay in ms before the tooltip disappears. */ exitDelay?: number; /** Icon rendered inside the code editor control. */ icon: React.ReactNode; - /** Maximum width of the tooltip (default 150px). */ + /** @deprecated Maximum width of the tooltip (default 150px). */ maxWidth?: string; - /** Copy button popover position. */ + /** @deprecated Copy button popover position. */ position?: | PopoverPosition | 'auto' @@ -35,12 +35,14 @@ export interface CodeEditorControlProps extends Omit { | 'left-end' | 'right-start' | 'right-end'; - /** Text to display in the tooltip. */ - toolTipText: React.ReactNode; - /** Event handler for the click of the button. */ + /** @deprecated Text to display in the tooltip*/ + toolTipText?: React.ReactNode; + /** Event handler for the click of the button */ onClick: (code: string, event?: any) => void; /** Flag indicating that the button is visible above the code editor. */ isVisible?: boolean; + /** Additional tooltip props forwarded to the Tooltip component */ + tooltipProps?: any; } export const CodeEditorControl: React.FunctionComponent = ({ @@ -48,12 +50,13 @@ export const CodeEditorControl: React.FunctionComponent className, 'aria-label': ariaLabel, toolTipText, - exitDelay = 0, - entryDelay = 300, - maxWidth = '100px', - position = 'top', + exitDelay, + entryDelay, + maxWidth, + position, onClick = () => {}, isVisible = true, + tooltipProps = {}, ...props }: CodeEditorControlProps) => { const context = React.useContext(CodeEditorContext); @@ -64,12 +67,12 @@ export const CodeEditorControl: React.FunctionComponent return isVisible ? ( {toolTipText}} + {...tooltipProps} >