-
Notifications
You must be signed in to change notification settings - Fork 376
fix(CodeEditor): use codeEditorControls and clean up overall #7931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
257ff8a
fix(CodeEditor): use codeEditorControls and clean up overall
nicolethoen 71ba55a
fix lint errors
nicolethoen e28609b
use better variable names
nicolethoen 191f1f0
clean up per PR comments
nicolethoen 42494c2
add back useCallback
nicolethoen 6889d36
clean up
nicolethoen c6e9bd6
clean up
nicolethoen 888aba8
fix lint errors
nicolethoen 95298fa
add console warnings when using deprecated props
nicolethoen d1bc327
fix lint errors
nicolethoen 44ffa43
update warning messages
nicolethoen 96054c0
fix lint again
nicolethoen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -7,19 +7,19 @@ import { CodeEditorContext } from './CodeEditorUtils'; | |
| */ | ||
|
|
||
| export interface CodeEditorControlProps extends Omit<ButtonProps, 'onClick'> { | ||
| /** 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. */ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you open an issue to remove these for breaking change release please.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| 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,41 +35,82 @@ export interface CodeEditorControlProps extends Omit<ButtonProps, 'onClick'> { | |
| | '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<CodeEditorControlProps> = ({ | ||
| icon, | ||
| 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); | ||
|
|
||
| if (entryDelay !== undefined) { | ||
| // eslint-disable-next-line no-console | ||
| console.warn( | ||
| 'CodeEditorControl: entryDelay prop has been deprecated. ' + | ||
| 'Pass the entryDelay via the tooltipProps prop instead.' | ||
| ); | ||
| } | ||
|
|
||
| if (exitDelay !== undefined) { | ||
| // eslint-disable-next-line no-console | ||
| console.warn( | ||
| 'CodeEditorControl: exitDelay prop has been deprecated. ' + | ||
| 'Pass the exitDelay via the tooltipProps prop instead.' | ||
| ); | ||
| } | ||
|
|
||
| if (maxWidth !== undefined) { | ||
| // eslint-disable-next-line no-console | ||
| console.warn( | ||
| 'CodeEditorControl: maxWidth prop has been deprecated. ' + 'Pass the maxWidth via the tooltipProps prop instead.' | ||
| ); | ||
| } | ||
|
|
||
| if (position !== undefined) { | ||
| // eslint-disable-next-line no-console | ||
| console.warn( | ||
| 'CodeEditorControl: position prop has been deprecated. ' + 'Pass the position via the tooltipProps prop instead.' | ||
| ); | ||
| } | ||
|
|
||
| if (toolTipText !== undefined) { | ||
| // eslint-disable-next-line no-console | ||
| console.warn( | ||
| 'CodeEditorControl: toolTipText prop has been deprecated. ' + | ||
| 'Pass the toolTipText by setting the content field in tooltipProps prop instead.' | ||
| ); | ||
| } | ||
|
|
||
| const onCustomClick = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => { | ||
| onClick(context.code, event); | ||
| }; | ||
|
|
||
| return isVisible ? ( | ||
| <Tooltip | ||
| trigger="mouseenter focus click" | ||
| exitDelay={exitDelay} | ||
| entryDelay={entryDelay} | ||
| maxWidth={maxWidth} | ||
| position={position} | ||
| content={<div>{toolTipText}</div>} | ||
| {...tooltipProps} | ||
| > | ||
| <Button className={className} onClick={onCustomClick} variant="control" aria-label={ariaLabel} {...props}> | ||
| {icon} | ||
|
|
||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🥳