Skip to content

Commit 032d552

Browse files
committed
whiteboard: font family
1 parent 3d5d408 commit 032d552

File tree

5 files changed

+139
-22
lines changed

5 files changed

+139
-22
lines changed

src/packages/frontend/editors/editor-button-bar.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const FONT_FACES = [
3131
"Courier",
3232
"Courier New",
3333
"Comic Sans MS",
34+
"Cursive",
3435
"Georgia",
3536
"Helvetica",
3637
"Impact",

src/packages/frontend/frame-editors/whiteboard-editor/elements/text.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ export default function Text({ element, focused }: Props) {
2222
project_id={frame.project_id}
2323
file_path={path_split(frame.path).head}
2424
value={element.str?.trim() ? element.str : "Type text"}
25-
style={{
26-
color: element.data?.color,
27-
fontSize: element.data?.fontSize,
28-
}}
25+
style={getStyle(element)}
2926
/>
3027
);
3128
}
@@ -66,13 +63,18 @@ export default function Text({ element, focused }: Props) {
6663
<Markdown
6764
project_id={frame.project_id}
6865
file_path={path_split(frame.path).head}
69-
style={{
70-
color: element.data?.color,
71-
fontSize: element.data?.fontSize,
72-
}}
66+
style={getStyle(element)}
7367
value={value?.trim() ? value : "Type text"}
7468
/>
7569
</Popover>
7670
</div>
7771
);
7872
}
73+
74+
function getStyle(element) {
75+
return {
76+
color: element.data?.color,
77+
fontSize: element.data?.fontSize,
78+
fontFamily: element.data?.fontFamily,
79+
};
80+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export const DEFAULT_FONT_SIZE = 14;
2-
2+
export const DEFAULT_FONT_FAMILY = "Sans";
33
export const minFontSize = 7;
44
export const maxFontSize = 80;

src/packages/frontend/frame-editors/whiteboard-editor/tools/edit-bar.tsx

Lines changed: 79 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,24 @@
22
Editing bar for editing one (or more) selected elements.
33
*/
44

5-
import { useState } from "react";
6-
import { Button, InputNumber, Tooltip } from "antd";
5+
import { CSSProperties, ReactNode, useState } from "react";
6+
import { Button, InputNumber, Select, Tooltip } from "antd";
7+
const { Option } = Select;
78
import { Element } from "../types";
89
import { PANEL_STYLE } from "./panel";
910
import { Icon } from "@cocalc/frontend/components/icon";
1011
import { useFrameContext } from "@cocalc/frontend/frame-editors/frame-tree/frame-context";
1112
import { Actions } from "../actions";
1213
import { BrushPreview, maxRadius } from "./pen";
1314
import ColorPicker from "@cocalc/frontend/components/color-picker";
15+
import { FONT_FACES as FONT_FAMILIES } from "@cocalc/frontend/editors/editor-button-bar";
1416

15-
import { DEFAULT_FONT_SIZE, minFontSize, maxFontSize } from "./defaults";
17+
import {
18+
DEFAULT_FONT_SIZE,
19+
DEFAULT_FONT_FAMILY,
20+
minFontSize,
21+
maxFontSize,
22+
} from "./defaults";
1623

1724
interface Props {
1825
elements: Element[];
@@ -33,6 +40,7 @@ export default function EditBar({ elements }: Props) {
3340
}}
3441
>
3542
<div style={{ display: "flex" }}>
43+
<FontFamily actions={actions} elements={elements} />
3644
<FontSize actions={actions} elements={elements} />
3745
<ColorButton actions={actions} elements={elements} />
3846
<DeleteButton actions={actions} elements={elements} />
@@ -57,7 +65,7 @@ function DeleteButton({ actions, elements }: ButtonProps) {
5765
return (
5866
<Tooltip title="Delete">
5967
<Button
60-
style={BUTTON_STYLE}
68+
style={{ ...BUTTON_STYLE, borderLeft: "1px solid #ccc" }}
6169
type="text"
6270
onClick={() => {
6371
for (const { id } of elements) {
@@ -149,6 +157,73 @@ function getFontSize(elements: Element[]): number | undefined {
149157
return DEFAULT_FONT_SIZE;
150158
}
151159

160+
function FontFamily({ actions, elements }: ButtonProps) {
161+
return (
162+
<SelectFontFamily
163+
onChange={(fontFamily) => {
164+
setDataField({ elements, actions }, { fontFamily });
165+
}}
166+
defaultValue={getFontFamily(elements)}
167+
size="large"
168+
style={{ marginTop: "1px", minWidth: "100px" }}
169+
/>
170+
);
171+
}
172+
173+
export function SelectFontFamily({
174+
onChange,
175+
defaultValue,
176+
size,
177+
style,
178+
}: {
179+
onChange?: (fontFamily: string) => void;
180+
defaultValue?: string;
181+
size?: any;
182+
style?: CSSProperties;
183+
}) {
184+
const v: ReactNode[] = [];
185+
for (const fontFamily of FONT_FAMILIES) {
186+
v.push(
187+
<Option
188+
value={fontFamily}
189+
key={fontFamily}
190+
search={fontFamily.toLowerCase()}
191+
>
192+
<span style={{ fontFamily }}>{fontFamily}</span>
193+
</Option>
194+
);
195+
}
196+
197+
return (
198+
<Tooltip title="Select a font">
199+
<Select
200+
style={style}
201+
size={size}
202+
defaultValue={defaultValue}
203+
showSearch
204+
placeholder="Select a font"
205+
optionFilterProp="children"
206+
onChange={onChange}
207+
filterOption={(input, option) => {
208+
if (!input.trim()) return true;
209+
return option?.search.includes(input.toLowerCase());
210+
}}
211+
>
212+
{v}
213+
</Select>
214+
</Tooltip>
215+
);
216+
}
217+
218+
function getFontFamily(elements: Element[]): string | undefined {
219+
for (const element of elements) {
220+
if (element.data?.fontFamily) {
221+
return element.data?.fontFamily;
222+
}
223+
}
224+
return DEFAULT_FONT_FAMILY;
225+
}
226+
152227
function setDataField(
153228
{
154229
elements,

src/packages/frontend/frame-editors/whiteboard-editor/tools/note.tsx

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import { useFrameContext } from "@cocalc/frontend/frame-editors/frame-tree/frame
1111
import { debounce } from "lodash";
1212
import { STYLE } from "../elements/note";
1313
import { DEFAULT_FONT_SIZE, minFontSize, maxFontSize } from "./defaults";
14-
14+
import { SelectFontFamily } from "./edit-bar";
15+
import { avatar_fontcolor } from "@cocalc/frontend/account/avatar/font-color";
1516

1617
// see https://www.post-it.com/3M/en_US/post-it/ideas/color/
1718
export const COLORS = [
@@ -47,7 +48,7 @@ export default function NoteToolPanel() {
4748
}
4849

4950
function NoteButton({ id }) {
50-
const { fontSize, color } = presets[id] ?? DEFAULT_NOTE;
51+
const { fontSize, color, fontFamily } = presets[id] ?? DEFAULT_NOTE;
5152
return (
5253
<Button
5354
style={{ padding: "5px", height: "35px" }}
@@ -65,6 +66,7 @@ export default function NoteToolPanel() {
6566
>
6667
<NotePreview
6768
fontSize={fontSize}
69+
fontFamily={fontFamily}
6870
color={color}
6971
borderColor={id == selected ? "blue" : "#ccc"}
7072
/>
@@ -77,7 +79,7 @@ export default function NoteToolPanel() {
7779
notePresets.push(<NoteButton key={id} id={id} />);
7880
}
7981

80-
const { fontSize, color } = presets[selected] ?? DEFAULT_NOTE;
82+
const { fontSize, color, fontFamily } = presets[selected] ?? DEFAULT_NOTE;
8183

8284
return (
8385
<div
@@ -107,6 +109,7 @@ export default function NoteToolPanel() {
107109
<NoteParams
108110
color={color}
109111
fontSize={fontSize}
112+
fontFamily={fontFamily}
110113
setColor={(color) => {
111114
setPresets({
112115
...presets,
@@ -119,6 +122,12 @@ export default function NoteToolPanel() {
119122
[selected]: { ...presets[selected], fontSize },
120123
});
121124
}}
125+
setFontFamily={(fontFamily) => {
126+
setPresets({
127+
...presets,
128+
[selected]: { ...presets[selected], fontFamily },
129+
});
130+
}}
122131
/>
123132
)}
124133
</div>
@@ -127,15 +136,22 @@ export default function NoteToolPanel() {
127136

128137
function NotePreview({
129138
fontSize,
139+
fontFamily,
130140
color,
131141
borderColor,
132142
}: {
133143
fontSize: number;
144+
fontFamily?: string;
134145
color: string;
135146
borderColor?: string;
136147
}) {
137148
return (
138-
<Tooltip title={`Font size: ${fontSize}px`}>
149+
<Tooltip
150+
title={
151+
`Font size: ${fontSize}px` +
152+
(fontFamily ? `, Font family: ${fontFamily}` : "")
153+
}
154+
>
139155
<div
140156
style={{
141157
...STYLE,
@@ -145,15 +161,25 @@ function NotePreview({
145161
border: `2px solid ${borderColor ?? "#ccc"}`,
146162
width: "50px",
147163
height: "25px",
148-
fontSize: "8pt",
149-
color: "#888",
164+
fontSize: "14px",
165+
fontFamily,
166+
color: avatar_fontcolor(color),
150167
}}
151-
></div>
168+
>
169+
A
170+
</div>
152171
</Tooltip>
153172
);
154173
}
155174

156-
function NoteParams({ color, fontSize, setColor, setFontSize }) {
175+
function NoteParams({
176+
color,
177+
fontSize,
178+
fontFamily,
179+
setColor,
180+
setFontSize,
181+
setFontFamily,
182+
}) {
157183
return (
158184
<div
159185
style={{
@@ -178,6 +204,17 @@ function NoteParams({ color, fontSize, setColor, setFontSize }) {
178204
Font size (px)
179205
</div>
180206
</div>
207+
<div style={{ width: "100%", display: "flex", marginBottom: "10px" }}>
208+
<SelectFontFamily
209+
onChange={setFontFamily}
210+
defaultValue={fontFamily}
211+
size="small"
212+
style={{ width: "70%", flex: 1 }}
213+
/>
214+
<div style={{ marginLeft: "5px", fontSize: "9pt", paddingTop: "6px" }}>
215+
Font family
216+
</div>
217+
</div>
181218
<ColorPicker color={color} onChange={setColor} defaultPicker="swatches" />
182219
</div>
183220
);
@@ -204,7 +241,9 @@ export function ResetButton({ onClick }) {
204241
// For now just storing these presets in localStorage.
205242
// TODO: move to account settings or the document. NOT SURE?!
206243
// Same problem with pen params.
207-
type Presets = { [id: string]: { color: string; fontSize: number } };
244+
type Presets = {
245+
[id: string]: { color: string; fontSize: number; fontFamily?: string };
246+
};
208247

209248
const key = "whiteboard-note-presets";
210249

0 commit comments

Comments
 (0)