-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(compass-editor): refactor JSON editor actions container into it…
…s own component (#6441) * Refactor JSON editor action container into its own component * Simplified actions container * Fix types
- Loading branch information
1 parent
5c6c61b
commit d7d58d5
Showing
5 changed files
with
119 additions
and
95 deletions.
There are no files selected for viewing
9 changes: 8 additions & 1 deletion
9
packages/compass-editor/src/actions.tsx → ...ages/compass-editor/src/action-button.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
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,79 @@ | ||
import React, { type RefObject } from 'react'; | ||
|
||
import { type Action, ActionButton, FormatIcon } from './action-button'; | ||
import type { EditorRef } from './types'; | ||
import { css, cx, spacing } from '@mongodb-js/compass-components'; | ||
|
||
type ActionsContainerProps = { | ||
copyable: boolean; | ||
formattable: boolean; | ||
customActions?: Action[]; | ||
className?: string; | ||
editorRef: RefObject<EditorRef>; | ||
}; | ||
|
||
const actionsContainerStyle = css({ | ||
position: 'absolute', | ||
top: spacing[1], | ||
right: spacing[2], | ||
display: 'none', | ||
gap: spacing[2], | ||
}); | ||
|
||
export const ActionsContainer = ({ | ||
copyable, | ||
formattable, | ||
customActions, | ||
className, | ||
editorRef, | ||
}: ActionsContainerProps) => { | ||
return ( | ||
<div | ||
className={cx( | ||
'multiline-editor-actions', | ||
actionsContainerStyle, | ||
className | ||
)} | ||
> | ||
{copyable && ( | ||
<ActionButton | ||
label="Copy" | ||
icon="Copy" | ||
onClick={() => { | ||
return editorRef.current?.copyAll() ?? false; | ||
}} | ||
></ActionButton> | ||
)} | ||
{formattable && ( | ||
<ActionButton | ||
label="Format" | ||
icon={ | ||
<FormatIcon | ||
size={/* leafygreen small */ 14} | ||
role="presentation" | ||
></FormatIcon> | ||
} | ||
onClick={() => { | ||
return editorRef.current?.prettify() ?? false; | ||
}} | ||
></ActionButton> | ||
)} | ||
{customActions && | ||
customActions.map((action) => { | ||
return ( | ||
<ActionButton | ||
key={action.label} | ||
icon={action.icon} | ||
label={action.label} | ||
onClick={() => { | ||
if (!editorRef.current?.editor) { | ||
return false; | ||
} | ||
return action.action(editorRef.current.editor); | ||
}} | ||
></ActionButton> | ||
); | ||
})} | ||
</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