-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #818 from GeorgeBatt-SV/MOS-1546-editor-toolbar-ad…
…just MOS-1546
- Loading branch information
Showing
14 changed files
with
236 additions
and
125 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
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
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
16 changes: 16 additions & 0 deletions
16
containers/mosaic/src/components/Field/FormFieldTextEditor/Toolbar/PrimaryToolbar.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,16 @@ | ||
import type { PropsWithChildren, ReactElement } from "react"; | ||
|
||
import React from "react"; | ||
|
||
import testIds from "@root/utils/testIds"; | ||
import { StyledPrimaryToolbar } from "../FormFieldTextEditor.styled"; | ||
|
||
function PrimaryToolbar({ children, focus }: PropsWithChildren<{focus?: boolean}>): ReactElement { | ||
return ( | ||
<StyledPrimaryToolbar $focus={focus} data-testid={testIds.TEXT_EDITOR_PRIMARY_TOOLBAR}> | ||
{children} | ||
</StyledPrimaryToolbar> | ||
); | ||
} | ||
|
||
export default PrimaryToolbar; |
74 changes: 74 additions & 0 deletions
74
containers/mosaic/src/components/Field/FormFieldTextEditor/Toolbar/ToolbarControlRow.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,74 @@ | ||
import type { ReactElement } from "react"; | ||
|
||
import React, { useMemo } from "react"; | ||
|
||
import type { ControlsConfig } from "../FormFieldTextEditorTypes"; | ||
import type { ToolbarControlsProps } from "./ToolbarControls"; | ||
|
||
import { ControlButton, ControlMenuDropdown, resolveControls } from "./Controls"; | ||
import { ControlGroup, ControlRow } from "../FormFieldTextEditor.styled"; | ||
import testIds from "@root/utils/testIds"; | ||
|
||
type ToolbarControlRowProps = Omit<ToolbarControlsProps, "controls"> & { | ||
controls: ControlsConfig; | ||
} | ||
|
||
export function ToolbarControlRow({ | ||
editor, | ||
controls: controlsDef, | ||
selectionTypes, | ||
inputSettings = {}, | ||
disabled, | ||
}: ToolbarControlRowProps): ReactElement { | ||
const groups = useMemo(() => resolveControls(controlsDef, selectionTypes), [controlsDef, selectionTypes]); | ||
|
||
return ( | ||
<ControlRow> | ||
{groups.map((group, groupIndex) => ( | ||
<ControlGroup key={groupIndex}> | ||
{group.map((control, index) => Array.isArray(control) ? ( | ||
<ControlMenuDropdown | ||
key={index} | ||
editor={editor} | ||
controls={control} | ||
inputSettings={inputSettings} | ||
testId={`${testIds.TEXT_EDITOR_CONTROL}:menu-${groupIndex}-${index}`} | ||
disabled={disabled} | ||
/> | ||
) : "MenuButton" in control ? ( | ||
<ControlMenuDropdown | ||
key={index} | ||
editor={editor} | ||
controls={control.controls} | ||
MenuButton={control.MenuButton} | ||
inputSettings={inputSettings} | ||
disabled={disabled} | ||
/> | ||
) : "Component" in control ? ( | ||
<control.Component | ||
{...control} | ||
key={index} | ||
editor={editor} | ||
inputSettings={inputSettings} | ||
data-testid={`${testIds.TEXT_EDITOR_CONTROL}:${control.name}`} | ||
disabled={disabled} | ||
/> | ||
) : ( | ||
<ControlButton | ||
key={control.name} | ||
onClick={(event) => control.cmd({ editor, inputSettings, event })} | ||
label={control.label} | ||
shortcut={control.shortcut} | ||
active={editor.isActive(control.name)} | ||
square | ||
data-testid={`${testIds.TEXT_EDITOR_CONTROL}:${control.name}`} | ||
disabled={disabled} | ||
> | ||
<control.Icon /> | ||
</ControlButton> | ||
))} | ||
</ControlGroup> | ||
))} | ||
</ControlRow> | ||
); | ||
} |
76 changes: 17 additions & 59 deletions
76
containers/mosaic/src/components/Field/FormFieldTextEditor/Toolbar/ToolbarControls.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 |
---|---|---|
@@ -1,78 +1,36 @@ | ||
import type { ReactElement } from "react"; | ||
import type { Editor } from "@tiptap/core"; | ||
|
||
import React, { useMemo } from "react"; | ||
import React from "react"; | ||
|
||
import type { ControlsConfig, SelectionType, TextEditorInputSettings } from "../FormFieldTextEditorTypes"; | ||
|
||
import { ControlButton, ControlMenuDropdown, resolveControls } from "./Controls"; | ||
import { ControlGroup, ControlGroups } from "../FormFieldTextEditor.styled"; | ||
import testIds from "@root/utils/testIds"; | ||
import { ToolbarControlRow } from "./ToolbarControlRow"; | ||
import { ToolbarOffset, ToolbarOverflow } from "../FormFieldTextEditor.styled"; | ||
|
||
export interface ToolbarControlsProps { | ||
controls: ControlsConfig; | ||
controls: ControlsConfig[]; | ||
editor: Editor; | ||
selectionTypes?: SelectionType[]; | ||
inputSettings: TextEditorInputSettings; | ||
disabled?: boolean; | ||
} | ||
|
||
export function ToolbarControls({ | ||
editor, | ||
controls: controlsDef, | ||
selectionTypes, | ||
inputSettings = {}, | ||
disabled, | ||
controls: controlRows, | ||
...props | ||
}: ToolbarControlsProps): ReactElement { | ||
const groups = useMemo(() => resolveControls(controlsDef, selectionTypes), [controlsDef, selectionTypes]); | ||
|
||
return ( | ||
<ControlGroups> | ||
{groups.map((group, groupIndex) => ( | ||
<ControlGroup key={groupIndex}> | ||
{group.map((control, index) => Array.isArray(control) ? ( | ||
<ControlMenuDropdown | ||
key={index} | ||
editor={editor} | ||
controls={control} | ||
inputSettings={inputSettings} | ||
testId={`${testIds.TEXT_EDITOR_CONTROL}:menu-${groupIndex}-${index}`} | ||
disabled={disabled} | ||
/> | ||
) : "MenuButton" in control ? ( | ||
<ControlMenuDropdown | ||
key={index} | ||
editor={editor} | ||
controls={control.controls} | ||
MenuButton={control.MenuButton} | ||
inputSettings={inputSettings} | ||
disabled={disabled} | ||
/> | ||
) : "Component" in control ? ( | ||
<control.Component | ||
{...control} | ||
key={index} | ||
editor={editor} | ||
inputSettings={inputSettings} | ||
data-testid={`${testIds.TEXT_EDITOR_CONTROL}:${control.name}`} | ||
disabled={disabled} | ||
/> | ||
) : ( | ||
<ControlButton | ||
key={control.name} | ||
onClick={(event) => control.cmd({ editor, inputSettings, event })} | ||
label={control.label} | ||
shortcut={control.shortcut} | ||
active={editor.isActive(control.name)} | ||
square | ||
data-testid={`${testIds.TEXT_EDITOR_CONTROL}:${control.name}`} | ||
disabled={disabled} | ||
> | ||
<control.Icon /> | ||
</ControlButton> | ||
))} | ||
</ControlGroup> | ||
))} | ||
</ControlGroups> | ||
<ToolbarOverflow> | ||
<ToolbarOffset> | ||
{controlRows.map((controlRow, index) => ( | ||
<ToolbarControlRow | ||
controls={controlRow} | ||
key={index} | ||
{...props} | ||
/> | ||
))} | ||
</ToolbarOffset> | ||
</ToolbarOverflow> | ||
); | ||
} |
Oops, something went wrong.