Skip to content

Commit

Permalink
Simplified actions container
Browse files Browse the repository at this point in the history
  • Loading branch information
kraenhansen committed Nov 4, 2024
1 parent fe4442e commit 096468a
Showing 1 changed file with 28 additions and 35 deletions.
63 changes: 28 additions & 35 deletions packages/compass-editor/src/actions-container.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { type RefObject, useMemo } from 'react';
import React, { type RefObject } from 'react';

import { type Action, ActionButton, FormatIcon } from './action-button';
import type { EditorRef } from './types';
Expand Down Expand Up @@ -27,21 +27,25 @@ export const ActionsContainer = ({
className,
editorRef,
}: ActionsContainerProps) => {
const actions = useMemo(() => {
return [
copyable && (
return (
<div
className={cx(
'multiline-editor-actions',
actionsContainerStyle,
className
)}
>
{copyable && (
<ActionButton
key="Copy"
label="Copy"
icon="Copy"
onClick={() => {
return editorRef.current?.copyAll() ?? false;
}}
></ActionButton>
),
formattable && (
)}
{formattable && (
<ActionButton
key="Format"
label="Format"
icon={
<FormatIcon
Expand All @@ -53,34 +57,23 @@ export const ActionsContainer = ({
return editorRef.current?.prettify() ?? false;
}}
></ActionButton>
),
...(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>
);
}),
];
}, [copyable, formattable, customActions, editorRef]);

return (
<div
className={cx(
'multiline-editor-actions',
actionsContainerStyle,
className
)}
>
{actions}
{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>
);
};

0 comments on commit 096468a

Please sign in to comment.