Skip to content

Commit f3217e6

Browse files
Fixed docs (#379)
1 parent b61daac commit f3217e6

File tree

9 files changed

+58
-30
lines changed

9 files changed

+58
-30
lines changed

packages/react/src/BlockNoteTheme.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ export type ComponentStyles = Partial<{
3939
// Menu to edit hyperlinks (in Formatting Toolbar & Hyperlink Toolbar)
4040
EditHyperlinkMenu: CSSObject;
4141
Editor: CSSObject;
42+
// Used in the Image Toolbar
43+
FileInput: CSSObject;
44+
Tabs: CSSObject;
45+
TextInput: CSSObject;
4246
// Wraps Formatting Toolbar & Hyperlink Toolbar
4347
Toolbar: CSSObject;
4448
// Appears on hover for Formatting Toolbar
@@ -129,10 +133,13 @@ export const blockNoteToMantineTheme = (theme: Theme): MantineThemeOverride => {
129133
},
130134
Tabs: {
131135
styles: () => ({
132-
root: {
133-
width: "100%",
134-
backgroundColor: theme.colors.menu.background,
135-
},
136+
root: _.merge<CSSObject, CSSObject>(
137+
{
138+
width: "100%",
139+
backgroundColor: theme.colors.menu.background,
140+
},
141+
theme.componentStyles?.(theme).Tabs || {}
142+
),
136143
tabsList: {
137144
borderColor: theme.colors.hovered.background,
138145
},
@@ -166,6 +173,7 @@ export const blockNoteToMantineTheme = (theme: Theme): MantineThemeOverride => {
166173
},
167174
FileInput: {
168175
styles: () => ({
176+
root: theme.componentStyles?.(theme).FileInput || {},
169177
input: {
170178
color: theme.colors.menu.text,
171179
backgroundColor: theme.colors.menu.background,
@@ -191,6 +199,7 @@ export const blockNoteToMantineTheme = (theme: Theme): MantineThemeOverride => {
191199
},
192200
TextInput: {
193201
styles: () => ({
202+
root: theme.componentStyles?.(theme).TextInput || {},
194203
input: {
195204
color: theme.colors.menu.text,
196205
backgroundColor: theme.colors.menu.background,

packages/website/docs/docs/block-types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ img {
262262
::: info
263263
While custom blocks open a lot of doors for what you can do with BlockNote, we're still working on the API and there are a few limitations for the kinds of blocks you can create.
264264

265-
We'd love to hear your feedback on Github or in our Discord community!
265+
We'd love to hear your feedback on GitHub or in our Discord community!
266266
:::
267267

268268
### Creating a Custom Block Type

packages/website/docs/docs/image-toolbar.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,18 @@ You can use the provided `uploadToTempFilesOrg` function to as a starting point,
3535
::: sandbox {template=react-ts}
3636

3737
```typescript-vue /App.tsx
38-
import { BlockNoteEditor, uploadToTmpFilesOrg } from "@blocknote/core";
38+
import {
39+
BlockNoteEditor,
40+
uploadToTmpFilesDotOrg_DEV_ONLY,
41+
} from "@blocknote/core";
3942
import { BlockNoteView, useBlockNote } from "@blocknote/react";
4043
import "@blocknote/core/style.css";
4144

4245
export default function App() {
4346
// Creates a new editor instance.
4447
const editor: BlockNoteEditor = useBlockNote({
4548
// Sets the example file upload handler.
46-
uploadFile: uploadToTmpFilesOrg,
49+
uploadFile: uploadToTmpFilesDotOrg_DEV_ONLY,
4750
});
4851

4952
return <BlockNoteView editor={editor} theme={"{{ getTheme(isDark) }}"} />;

packages/website/docs/docs/slash-menu.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ export default function App() {
7777
// Renders the editor instance.
7878
return <BlockNoteView editor={editor} theme={"{{ getTheme(isDark) }}"} />;
7979
}
80-
8180
```
8281

8382
```css-vue /styles.css [hidden]

packages/website/docs/docs/theming.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import "@blocknote/core/style.css";
3737

3838
// Custom red light theme
3939
const lightRedTheme = {
40-
type: "light",
4140
colors: {
4241
editor: {
4342
text: "#222222",
@@ -75,7 +74,6 @@ const lightRedTheme = {
7574
// Custom red dark theme
7675
const darkRedTheme = {
7776
...lightRedTheme,
78-
type: "dark",
7977
colors: {
8078
...lightRedTheme.colors,
8179
editor: {
@@ -247,6 +245,12 @@ There are a number of components that you can override styles for:
247245

248246
`Editor:` The editor itself, excluding menus & toolbars.
249247

248+
`FileInput:` Component used for file inputs in the Image Toolbar.
249+
250+
`Tabs:` Component used for tabs in the Image Toolbar.
251+
252+
`TextInput:` Component used for text inputs in the Image Toolbar.
253+
250254
`Toolbar:` Component used for the [Formatting Toolbar](/docs/formatting-toolbar), Hyperlink Toolbar, and [Image Toolbar](/docs/image-toolbar).
251255

252256
`Tooltip:` Component for the tooltip that appears on hover, for Formatting Toolbar & Hyperlink Toolbar buttons.

packages/website/docs/docs/ui-elements.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export default function App() {
116116

117117
// Renders the editor instance.
118118
return (
119-
<BlockNoteView editor={editor} theme={"light"}>
119+
<BlockNoteView editor={editor} theme={"{{ getTheme(isDark) }}"}>
120120
<FormattingToolbarPositioner editor={editor} />
121121
<HyperlinkToolbarPositioner editor={editor} />
122122
<SlashMenuPositioner editor={editor} />

packages/website/docs/examples/alert-block.md

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,10 @@ import { RiAlertFill } from "react-icons/ri";
4646

4747
import { createAlertBlock, insertAlert } from "./Alert";
4848

49-
const theme = "light";
50-
5149
// The custom schema, including all default blocks and the custom Alert block
5250
export const schemaWithAlert = {
5351
...defaultBlockSchema,
54-
alert: createAlertBlock(theme),
52+
alert: createAlertBlock("{{ getTheme(isDark) }}"),
5553
};
5654

5755
export default function App() {
@@ -64,7 +62,7 @@ export default function App() {
6462
});
6563

6664
return (
67-
<BlockNoteView editor={editor} theme={theme}>
65+
<BlockNoteView editor={editor} theme={"{{ getTheme(isDark) }}"}>
6866
{/*Adds alert item to block type dropdown in the Formatting Toolbar*/}
6967
<FormattingToolbarPositioner
7068
editor={editor}
@@ -107,7 +105,6 @@ import {
107105
InlineContent,
108106
ReactSlashMenuItem,
109107
} from "@blocknote/react";
110-
import { useState } from "react";
111108
import { RiAlertFill } from "react-icons/ri";
112109
import { MdCancel, MdCheckCircle, MdError, MdInfo } from "react-icons/md";
113110
import { Menu } from "@mantine/core";
@@ -161,23 +158,27 @@ export const alertPropSchema = {
161158
// Component for the Alert block
162159
export const Alert = (props: {
163160
block: SpecificBlock<
164-
DefaultBlockSchema & { alert: BlockSpec<"alert", typeof alertPropSchema> },
161+
DefaultBlockSchema & {
162+
alert: BlockSpec<"alert", typeof alertPropSchema, true>;
163+
},
165164
"alert"
166165
>;
167166
editor: BlockNoteEditor<
168-
DefaultBlockSchema & { alert: BlockSpec<"alert", typeof alertPropSchema> }
167+
DefaultBlockSchema & {
168+
alert: BlockSpec<"alert", typeof alertPropSchema, true>;
169+
}
169170
>;
170171
theme: "light" | "dark";
171172
}) => {
172-
const [type, setType] = useState(props.block.props.type);
173-
const Icon = alertTypes[type].icon;
173+
const Icon = alertTypes[props.block.props.type].icon;
174174

175175
return (
176176
<div
177177
className={"alert"}
178178
style={{
179179
...alertStyles,
180-
backgroundColor: alertTypes[type].backgroundColor[props.theme],
180+
backgroundColor:
181+
alertTypes[props.block.props.type].backgroundColor[props.theme],
181182
}}>
182183
{/*Icon which opens a menu to choose the Alert type*/}
183184
<Menu zIndex={99999}>
@@ -187,13 +188,18 @@ export const Alert = (props: {
187188
className={"alert-icon-wrapper"}
188189
style={{
189190
...alertIconWrapperStyles,
190-
backgroundColor: alertTypes[type].color,
191+
backgroundColor: alertTypes[props.block.props.type].color,
191192
}}
192193
contentEditable={false}>
193194
{/*Icon itself*/}
194195
<Icon
195196
className={"alert-icon"}
196-
style={{ color: alertTypes[type].backgroundColor[props.theme] }}
197+
style={{
198+
color:
199+
alertTypes[props.block.props.type].backgroundColor[
200+
props.theme
201+
],
202+
}}
197203
size={32}
198204
/>
199205
</div>
@@ -204,12 +210,17 @@ export const Alert = (props: {
204210
<Menu.Divider />
205211
{Object.entries(alertTypes).map(([key, value]) => {
206212
const ItemIcon = value.icon;
207-
213+
208214
return (
209215
<Menu.Item
210216
key={key}
211217
icon={<ItemIcon color={value.color} />}
212-
onClick={() => setType(key as keyof typeof alertTypes)}>
218+
onClick={() =>
219+
props.editor.updateBlock(props.block, {
220+
type: "alert",
221+
props: { type: key as keyof typeof alertTypes },
222+
})
223+
}>
213224
{key.slice(0, 1).toUpperCase() + key.slice(1)}
214225
</Menu.Item>
215226
);
@@ -229,7 +240,9 @@ export const createAlertBlock = (theme: "light" | "dark") =>
229240
"alert",
230241
typeof alertPropSchema,
231242
true,
232-
DefaultBlockSchema & { alert: BlockSpec<"alert", typeof alertPropSchema> }
243+
DefaultBlockSchema & {
244+
alert: BlockSpec<"alert", typeof alertPropSchema, true>;
245+
}
233246
>({
234247
type: "alert" as const,
235248
propSchema: {
@@ -249,7 +262,7 @@ export const insertAlert = {
249262
name: "Alert",
250263
execute: (editor) => {
251264
const block = editor.getTextCursorPosition().block;
252-
const blockIsEmpty = block.content.length === 0;
265+
const blockIsEmpty = block.content!.length === 0;
253266

254267
// Updates current block to an Alert if it's empty, otherwise inserts a new
255268
// one below
@@ -281,7 +294,9 @@ export const insertAlert = {
281294
icon: <RiAlertFill />,
282295
hint: "Used to emphasize text",
283296
} satisfies ReactSlashMenuItem<
284-
DefaultBlockSchema & { alert: BlockSpec<"alert", typeof alertPropSchema> }
297+
DefaultBlockSchema & {
298+
alert: BlockSpec<"alert", typeof alertPropSchema, true>;
299+
}
285300
>;
286301

287302
const alertStyles = {

packages/website/docs/examples/block-manipulation.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ export default function App() {
7878
</div>
7979
);
8080
}
81-
8281
```
8382

8483
```css-vue /styles.css [hidden]

packages/website/docs/examples/keyboard-shortcuts.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ export default function App() {
6262

6363
return <BlockNoteView editor={editor} theme={"{{ getTheme(isDark) }}"} />;
6464
}
65-
6665
```
6766

6867
```css-vue /styles.css [hidden]

0 commit comments

Comments
 (0)