Skip to content

Commit

Permalink
Fixed font change
Browse files Browse the repository at this point in the history
  • Loading branch information
umerfaruk committed Mar 12, 2024
1 parent 8b42714 commit 9a0eff1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<html>
<head>
<link rel="icon" type="image/png" />
<link rel="stylesheet" href="https://urdu-fonts.netlify.app/stylesheet.css">
<title>Urdu Web Editor</title>
</head>

Expand Down
2 changes: 1 addition & 1 deletion demo/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const urduFonts = [
];
const Demo = () => {
const [open, setOpen] = useState(false);
const [value, setValue] = useState(undefined);
const [value, setValue] = useState(null);
const [configuration, setConfiguration] = useState({
richText: true,
language: "ur",
Expand Down
16 changes: 13 additions & 3 deletions src/plugins/fontDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,26 @@ export const defaultFont = ({ configuration }) => {
// --------------------------------------------------
const FontDropDown = ({ fonts, value, onChange = () => {} }) => {
const configuredFonts = (fonts && fonts.length > 0 ? fonts : FONT_FAMILY_OPTIONS);
const selected = () => value && configuredFonts.find(x => x.value === value) || configuredFonts[0];
onFontSelect = (item) => {
onChange(item.key);
}
const items = configuredFonts
.map(i => ({
onClick: () => onChange(i.value),
key: i.value,
label: i.label,
}));

return (
<Dropdown menu={{items}}>
<Dropdown menu={{
items,
selectedKeys : [ selected() ],
onClick: onFontSelect,
}}
onClick={onFontSelect}>
<Button type="text" size="large">
<Space>
{ (value && configuredFonts.find(x => x.value === value)?.label) || configuredFonts[0]?.label}
{ selected().label }
<Icons.Down />
</Space>
</Button>
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ const ToolbarPlugin = ({ configuration, setIsLinkEditMode, locale }) => {
const selection = $getSelection();
if ($isRangeSelection(selection)) {
$patchStyleText(selection, {
"font-family": font.value,
"font-family": font,
});
}
}
});
};

Expand Down

0 comments on commit 9a0eff1

Please sign in to comment.