Skip to content

Commit 1930313

Browse files
Added example for changing editor font (#399)
1 parent c448aac commit 1930313

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

packages/website/docs/.vitepress/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ const EXAMPLES_SIDEBAR = [
133133
text: "Saving & Loading",
134134
link: "/examples/saving-loading",
135135
},
136+
{
137+
text: "Changing Font",
138+
link: "/examples/changing-font",
139+
},
136140
],
137141
},
138142
{
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
title: Changing Font
3+
description: In this example, we change the editor font.
4+
imageTitle: Changing Font
5+
path: /examples/changing-font
6+
---
7+
8+
<script setup>
9+
import { useData } from 'vitepress';
10+
import { getTheme, getStyles } from "../demoUtils";
11+
12+
const { isDark } = useData();
13+
</script>
14+
15+
# Changing Font
16+
17+
In this example, we override some of the default editor CSS to change the font.
18+
19+
**Relevant Docs:**
20+
21+
- [Advanced: Overriding CSS](/docs/theming#advanced-overriding-css)
22+
23+
::: sandbox {template=react-ts}
24+
25+
```typescript-vue /App.tsx
26+
import "@blocknote/core/style.css";
27+
import {
28+
BlockNoteView,
29+
darkDefaultTheme,
30+
lightDefaultTheme,
31+
Theme,
32+
useBlockNote,
33+
} from "@blocknote/react";
34+
35+
const componentStyles = (theme: Theme) => ({
36+
Editor: {
37+
'[data-node-type="blockContainer"] *': {
38+
fontFamily: "Comic Sans MS",
39+
},
40+
},
41+
});
42+
43+
// Default dark theme with additional component styles.
44+
const theme = {
45+
light: {
46+
...lightDefaultTheme,
47+
componentStyles,
48+
},
49+
dark: {
50+
...darkDefaultTheme,
51+
componentStyles,
52+
},
53+
} satisfies {
54+
light: Theme;
55+
dark: Theme;
56+
};
57+
58+
function App() {
59+
const editor = useBlockNote();
60+
61+
return <BlockNoteView editor={editor} theme={theme} />;
62+
}
63+
64+
export default App;
65+
66+
```
67+
68+
```css-vue /styles.css [hidden]
69+
{{ getStyles(isDark) }}
70+
```
71+
72+
:::
73+
74+
There are several useful CSS selectors that you can use to style different parts of the editor:
75+
76+
- `[data-node-type="blockContainer"]` selects all blocks.
77+
- `[data-content-type="X"]` selects the content of all blocks of type X (excluding child blocks). Can also have `[data-Y="..."]` attributes for each of the block's props that don't use the default value. E.g. `[data-content-type="heading"][data-level="2"]` will select all heading blocks with heading level 2.
78+
- `[data-node-type="blockGroup"]` selects all wrapper elements for child blocks.

0 commit comments

Comments
 (0)