11import classNames from "classnames" ;
22import Quill from "quill" ;
33import { CSSProperties , ReactElement , RefObject , createElement , forwardRef } from "react" ;
4- import { PresetEnum } from "typings/RichTextProps" ;
4+ import { CustomFontsType , PresetEnum } from "typings/RichTextProps" ;
55import { FormatsContainer , ToolbarContext , presetToNumberConverter } from "./CustomToolbars/ToolbarWrapper" ;
66import { TOOLBAR_MAPPING , toolbarContentType } from "./CustomToolbars/constants" ;
77
88export 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