Skip to content

Commit f4218cc

Browse files
feat(rich-text-web): add support for custom fonts in Toolbar component
1 parent 9c22202 commit f4218cc

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

packages/pluggableWidgets/rich-text-web/src/components/EditorWrapper.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ function EditorWrapperInner(props: EditorWrapperProps): ReactElement {
185185
preset={preset}
186186
quill={quillRef.current}
187187
toolbarContent={toolbarPreset}
188+
customFonts={props.customFonts}
188189
/>
189190
</If>
190191
<Editor

packages/pluggableWidgets/rich-text-web/src/components/Toolbar.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import classNames from "classnames";
22
import Quill from "quill";
33
import { CSSProperties, ReactElement, RefObject, createElement, forwardRef } from "react";
4-
import { PresetEnum } from "typings/RichTextProps";
4+
import { CustomFontsType, PresetEnum } from "typings/RichTextProps";
55
import { FormatsContainer, ToolbarContext, presetToNumberConverter } from "./CustomToolbars/ToolbarWrapper";
66
import { TOOLBAR_MAPPING, toolbarContentType } from "./CustomToolbars/constants";
77

88
export interface ToolbarProps {
9+
customFonts?: CustomFontsType[];
910
id: string;
1011
preset: PresetEnum;
11-
style?: CSSProperties;
1212
quill?: Quill | null;
13+
style?: CSSProperties;
1314
toolbarContent: toolbarContentType[];
1415
}
1516

@@ -65,6 +66,20 @@ const Toolbar = forwardRef((props: ToolbarProps, ref: RefObject<HTMLDivElement>)
6566
{toolbarGroup.children.map((toolbar, idx) => {
6667
const currentToolbar = TOOLBAR_MAPPING[toolbar];
6768
const key = `toolbar_${id}_${index}_${idx}`;
69+
let value = currentToolbar.value;
70+
71+
if (currentToolbar.title === "Font type") {
72+
type FontListType = Array<{ value: string; description: string; style: string }>;
73+
value = [
74+
...(currentToolbar.value as FontListType),
75+
...(props.customFonts ?? []).map((font: CustomFontsType) => ({
76+
value: font.fontName?.value?.toLowerCase().split(" ").join("-"),
77+
description: font.fontName?.value,
78+
style: `'${font.fontName?.value}'`
79+
}))
80+
].sort((a, b) => (a.value ?? "").localeCompare(b.value ?? ""));
81+
}
82+
6883
return currentToolbar.custom
6984
? createElement(currentToolbar.component, {
7085
key,
@@ -77,7 +92,7 @@ const Toolbar = forwardRef((props: ToolbarProps, ref: RefObject<HTMLDivElement>)
7792
key,
7893
className: classNames(currentToolbar.className),
7994
presetValue: currentToolbar.presetValue,
80-
value: currentToolbar.value,
95+
value,
8196
title: currentToolbar.title
8297
},
8398
currentToolbar.children && createElement(currentToolbar.children)

0 commit comments

Comments
 (0)