Skip to content

Commit 9fb4fc3

Browse files
feat(rich-text-web): enhance custom fonts support with additional properties
1 parent 04c047c commit 9fb4fc3

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

packages/pluggableWidgets/rich-text-web/src/RichText.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,15 @@
167167
<caption>Custom fonts</caption>
168168
<description />
169169
<properties>
170-
<property key="fontName" type="textTemplate" required="false">
170+
<property key="fontName" type="string" required="false">
171171
<caption>Font name</caption>
172172
<category>Item</category>
173-
<description />
173+
<description>Choose the main font you want to use (e.g., Arial)</description>
174+
</property>
175+
<property key="fontStyle" type="string" required="false">
176+
<caption>Font style</caption>
177+
<category>Item</category>
178+
<description>List of fonts to use in case the first isn't available (e.g., arial, helvetica, sans-serif)</description>
174179
</property>
175180
</properties>
176181
</property>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { CustomFontsType } from "../../typings/RichTextProps";
1515
import { EditorDispatchContext } from "../store/EditorProvider";
1616
import { SET_FULLSCREEN_ACTION } from "../store/store";
1717
import "../utils/customPluginRegisters";
18-
import { FontStyleAttributor, formatFonts } from "../utils/formats/fonts";
18+
import { FontStyleAttributor, formatCustomFonts } from "../utils/formats/fonts";
1919
import "../utils/formats/quill-table-better/assets/css/quill-table-better.scss";
2020
import QuillTableBetter from "../utils/formats/quill-table-better/quill-table-better";
2121
import { RESIZE_MODULE_CONFIG } from "../utils/formats/resizeModuleConfig";
@@ -45,7 +45,7 @@ export interface EditorProps {
4545

4646
// Editor is an uncontrolled React component
4747
const Editor = forwardRef((props: EditorProps, ref: MutableRefObject<Quill | null>) => {
48-
const fonts = formatFonts(props.customFonts);
48+
const fonts = formatCustomFonts(props.customFonts);
4949
const FontStyle = new FontStyleAttributor(fonts);
5050
Quill.register(FontStyle, true);
5151
const { theme, defaultValue, style, className, toolbarId, onTextChange, onSelectionChange, readOnly } = props;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import classNames from "classnames";
22
import Quill from "quill";
33
import { CSSProperties, ReactElement, RefObject, createElement, forwardRef } from "react";
44
import { CustomFontsType, PresetEnum } from "../../typings/RichTextProps";
5-
import { formatFonts } from "../utils/formats/fonts";
5+
import { formatCustomFonts } from "../utils/formats/fonts";
66
import { FormatsContainer, ToolbarContext, presetToNumberConverter } from "./CustomToolbars/ToolbarWrapper";
77
import { TOOLBAR_MAPPING, toolbarContentType } from "./CustomToolbars/constants";
88

@@ -73,7 +73,7 @@ const Toolbar = forwardRef((props: ToolbarProps, ref: RefObject<HTMLDivElement>)
7373
type FontListType = Array<{ value: string; description: string; style: string }>;
7474
value = [
7575
...(currentToolbar.value as FontListType),
76-
...formatFonts(props.customFonts ?? [])
76+
...formatCustomFonts(props.customFonts ?? [])
7777
].sort((a, b) => (a.value ?? "").localeCompare(b.value ?? ""));
7878
}
7979

packages/pluggableWidgets/rich-text-web/src/utils/formats/fonts.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ export class FontStyleAttributor extends StyleAttributor {
5454
}
5555
}
5656

57-
export function formatFonts(fonts: CustomFontsType[] = []): typeof FONT_LIST {
57+
export function formatCustomFonts(fonts: CustomFontsType[] = []): typeof FONT_LIST {
5858
return fonts.map(font => ({
59-
value: font.fontName?.value?.toLowerCase().split(" ").join("-") ?? "",
60-
description: font.fontName?.value ?? "",
61-
style: `'${font.fontName?.value}'`
59+
value: font.fontName?.toLowerCase().split(" ").join("-") ?? "",
60+
description: font.fontName ?? "",
61+
style: font.fontStyle ?? ""
6262
}));
6363
}

packages/pluggableWidgets/rich-text-web/typings/RichTextProps.d.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* WARNING: All changes made to this file will be overwritten
44
* @author Mendix Widgets Framework Team
55
*/
6-
import { ActionValue, DynamicValue, EditableValue } from "mendix";
6+
import { ActionValue, EditableValue } from "mendix";
77

88
export type PresetEnum = "basic" | "standard" | "full" | "custom";
99

@@ -24,7 +24,8 @@ export type OverflowYEnum = "auto" | "scroll" | "hidden";
2424
export type OnChangeTypeEnum = "onLeave" | "onDataChange";
2525

2626
export interface CustomFontsType {
27-
fontName?: DynamicValue<string>;
27+
fontName: string;
28+
fontStyle: string;
2829
}
2930

3031
export type ToolbarConfigEnum = "basic" | "advanced";
@@ -37,6 +38,7 @@ export interface AdvancedConfigType {
3738

3839
export interface CustomFontsPreviewType {
3940
fontName: string;
41+
fontStyle: string;
4042
}
4143

4244
export interface AdvancedConfigPreviewType {

0 commit comments

Comments
 (0)