Skip to content

Commit

Permalink
Updated theme selection in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewlipski committed Aug 11, 2023
1 parent 0b68085 commit bf17981
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 52 deletions.
3 changes: 1 addition & 2 deletions packages/website/docs/docs/block-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ export default function App() {

// Creates a new editor instance.
const editor = useBlockNote({
theme: "{{ getTheme(isDark) }}",
// Tells BlockNote which blocks to use.
blockSchema: customSchema,
slashMenuItems: [
Expand All @@ -213,7 +212,7 @@ export default function App() {
});

// Renders the editor instance using a React component.
return <BlockNoteView editor={editor} />;
return <BlockNoteView editor={editor} theme={"{{ getTheme(isDark) }}"} />;
}
```

Expand Down
3 changes: 1 addition & 2 deletions packages/website/docs/docs/blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export default function App() {

// Creates a new editor instance.
const editor: BlockNoteEditor = useBlockNote({
theme: "{{ getTheme(isDark) }}",
// Listens for when the editor's contents change.
onEditorContentChange: (editor) =>
// Converts the editor's contents to an array of Block objects.
Expand All @@ -98,7 +97,7 @@ export default function App() {
// objects, below.
return (
<div>
<BlockNoteView editor={editor}/>
<BlockNoteView editor={editor} theme={"{{ getTheme(isDark) }}"} />
<pre>{JSON.stringify(blocks, null, 2)}</pre>
</div>
);
Expand Down
12 changes: 4 additions & 8 deletions packages/website/docs/docs/converting-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export default function App() {

// Creates a new editor instance.
const editor: BlockNoteEditor = useBlockNote({
theme: "{{ getTheme(isDark) }}",
// Listens for when the editor's contents change.
onEditorContentChange: (editor) => {
// Converts the editor's contents from Block objects to Markdown and
Expand All @@ -79,7 +78,7 @@ export default function App() {
// Renders the editor instance, and its contents as Markdown below.
return (
<div>
<BlockNoteView editor={editor} />
<BlockNoteView editor={editor} theme={"{{ getTheme(isDark) }}"} />
<pre>{markdown}</pre>
</div>
);
Expand Down Expand Up @@ -133,7 +132,6 @@ export default function App() {

// Creates a new editor instance.
const editor: BlockNoteEditor = useBlockNote({
theme: "{{ getTheme(isDark) }}",
// Makes the editor non-editable.
editable: false
})
Expand All @@ -158,7 +156,7 @@ export default function App() {
value={markdown}
onChange={(event) => setMarkdown(event.target.value)}
/>
<BlockNoteView editor={editor} />
<BlockNoteView editor={editor} theme={"{{ getTheme(isDark) }}"} />
</div>
);
}
Expand Down Expand Up @@ -217,7 +215,6 @@ export default function App() {

// Creates a new editor instance.
const editor: BlockNoteEditor = useBlockNote({
theme: "{{ getTheme(isDark) }}",
// Listens for when the editor's contents change.
onEditorContentChange: (editor) => {
// Converts the editor's contents from Block objects to HTML and saves
Expand All @@ -233,7 +230,7 @@ export default function App() {
// Renders the editor instance, and its contents as HTML below.
return (
<div>
<BlockNoteView editor={editor} />
<BlockNoteView editor={editor} theme={"{{ getTheme(isDark) }}"} />
<pre>{html}</pre>
</div>
);
Expand Down Expand Up @@ -287,7 +284,6 @@ export default function App() {

// Creates a new editor instance.
const editor: BlockNoteEditor = useBlockNote({
theme: "{{ getTheme(isDark) }}",
// Makes the editor non-editable.
editable: false
})
Expand All @@ -312,7 +308,7 @@ export default function App() {
value={html}
onChange={(event) => setHTML(event.target.value)}
/>
<BlockNoteView editor={editor} />
<BlockNoteView editor={editor} theme={"{{ getTheme(isDark) }}"} />
</div>
);
}
Expand Down
6 changes: 2 additions & 4 deletions packages/website/docs/docs/cursor-selections.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ import "@blocknote/core/style.css";
export default function App() {
// Creates a new editor instance.
const editor: BlockNoteEditor = useBlockNote({
theme: "{{ getTheme(isDark) }}",
// Listens for when the text cursor position changes.
onTextCursorPositionChange: (editor) => {
// Gets the block currently hovered by the text cursor.
Expand Down Expand Up @@ -125,7 +124,7 @@ export default function App() {
})

// Renders the editor instance.
return <BlockNoteView editor={editor}/>;
return <BlockNoteView editor={editor} theme={ "{{ getTheme(isDark) }}"} />;
}
```

Expand Down Expand Up @@ -179,7 +178,6 @@ import "@blocknote/core/style.css";
export default function App() {
// Creates a new editor instance.
const editor: BlockNoteEditor = useBlockNote({
theme: "{{ getTheme(isDark) }}",
// Listens for when the text cursor position changes.
onTextCursorPositionChange: (editor) => {
// Gets the blocks currently spanned by the selection.
Expand Down Expand Up @@ -226,7 +224,7 @@ export default function App() {
});

// Renders the editor instance.
return <BlockNoteView editor={editor} />;
return <BlockNoteView editor={editor} theme={"{{ getTheme(isDark) }}"} />;
}
```

Expand Down
6 changes: 1 addition & 5 deletions packages/website/docs/docs/editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export type BlockNoteEditorOptions = Partial<{
customElements: CustomElements;
uiFactories: UiFactories;
defaultStyles: boolean;
theme: "light" | "dark";
}>;
```

Expand All @@ -58,8 +57,6 @@ export type BlockNoteEditorOptions = Partial<{

`defaultStyles`: Whether to use the default font and reset the styles of `<p>`, `<li>`, `<h1>`, etc. elements that are used in BlockNote. Defaults to true if undefined.

`theme:` Whether to use the light or dark theme.

## Demo: Saving & Restoring Editor Contents

By default, BlockNote doesn't preserve the editor contents when your app is reopened or refreshed. However, using the editor options, you can change this by using the editor options.
Expand All @@ -79,7 +76,6 @@ const initialContent: string | null = localStorage.getItem("editorContent");
export default function App() {
// Creates a new editor instance.
const editor: BlockNoteEditor | null = useBlockNote({
theme: "{{ getTheme(isDark) }}",
// If the editor contents were previously saved, restores them.
initialContent: initialContent ? JSON.parse(initialContent) : undefined,
// Serializes and saves the editor contents to local storage.
Expand All @@ -92,7 +88,7 @@ export default function App() {
});

// Renders the editor instance.
return <BlockNoteView editor={editor} />;
return <BlockNoteView editor={editor} theme={"{{ getTheme(isDark) }}"} />;
}
```

Expand Down
6 changes: 2 additions & 4 deletions packages/website/docs/docs/formatting-toolbar.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,11 @@ const CustomFormattingToolbar = (props: { editor: BlockNoteEditor }) => {

export default function App() {
// Creates a new editor instance.
const editor: BlockNoteEditor = useBlockNote({
theme: "{{ getTheme(isDark) }}",
});
const editor: BlockNoteEditor = useBlockNote();

// Renders the editor instance.
return (
<BlockNoteView editor={editor}>
<BlockNoteView editor={editor} theme={"{{ getTheme(isDark) }}"}>
<FormattingToolbarPositioner
editor={editor}
formattingToolbar={CustomFormattingToolbar}
Expand Down
6 changes: 2 additions & 4 deletions packages/website/docs/docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,10 @@ import "@blocknote/core/style.css";

export default function App() {
// Creates a new editor instance.
const editor: BlockNoteEditor = useBlockNote({
theme: "{{ getTheme(isDark) }}"
});
const editor: BlockNoteEditor = useBlockNote();

// Renders the editor instance using a React component.
return <BlockNoteView editor={editor} />;
return <BlockNoteView editor={editor} theme={"{{ getTheme(isDark) }}"} />;
}
```

Expand Down
6 changes: 2 additions & 4 deletions packages/website/docs/docs/real-time-collaboration.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ const provider = new YPartyKitProvider(
export default function App() {
// Creates a new editor instance.
const editor: BlockNoteEditor | null = useBlockNote({
theme: "{{ getTheme(isDark) }}",
collaboration: {
provider,
fragment: doc.getXmlFragment("document-store"),
Expand All @@ -106,7 +105,7 @@ export default function App() {
});
// Renders the editor instance using a React component.
return <BlockNoteView editor={editor} />;
return <BlockNoteView editor={editor} theme={"{{ getTheme(isDark) }}"} />;
}
```
Expand Down Expand Up @@ -136,7 +135,6 @@ const provider = new YPartyKitProvider(
export default function App() {
// Creates a new editor instance.
const editor: BlockNoteEditor | null = useBlockNote({
theme: "{{ getTheme(isDark) }}",
collaboration: {
provider,
fragment: doc.getXmlFragment("document-store"),
Expand All @@ -148,7 +146,7 @@ export default function App() {
});
// Renders the editor instance using a React component.
return <BlockNoteView editor={editor} />;
return <BlockNoteView editor={editor} theme={"{{ getTheme(isDark) }}"} />;
}
```
Expand Down
12 changes: 4 additions & 8 deletions packages/website/docs/docs/side-menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,11 @@ const CustomSideMenu = (props: SideMenuProps) => (

export default function App() {
// Creates a new editor instance.
const editor: BlockNoteEditor = useBlockNote({
theme: "{{ getTheme(isDark) }}",
});
const editor: BlockNoteEditor = useBlockNote();

// Renders the editor instance.
return (
<BlockNoteView editor={editor}>
<BlockNoteView editor={editor} theme={"{{ getTheme(isDark) }}"}>
<FormattingToolbarPositioner editor={editor} />
<HyperlinkToolbarPositioner editor={editor} />
<SlashMenuPositioner editor={editor} />
Expand Down Expand Up @@ -130,13 +128,11 @@ const CustomDragHandleMenu = (props: {

export default function App() {
// Creates a new editor instance.
const editor: BlockNoteEditor = useBlockNote({
theme: "{{ getTheme(isDark) }}",
});
const editor: BlockNoteEditor = useBlockNote();

// Renders the editor instance.
return (
<BlockNoteView editor={editor}>
<BlockNoteView editor={editor} theme={"{{ getTheme(isDark) }}"}>
<FormattingToolbarPositioner editor={editor} />
<HyperlinkToolbarPositioner editor={editor} />
<SlashMenuPositioner editor={editor} />
Expand Down
3 changes: 1 addition & 2 deletions packages/website/docs/docs/slash-menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,11 @@ const customSlashMenuItemList = [
export default function App() {
// Creates a new editor instance.
const editor: BlockNoteEditor = useBlockNote({
theme: "{{ getTheme(isDark) }}",
slashMenuItems: customSlashMenuItemList,
});

// Renders the editor instance.
return <BlockNoteView editor={editor} />;
return <BlockNoteView editor={editor} theme={"{{ getTheme(isDark) }}"} />;
}

```
Expand Down
2 changes: 1 addition & 1 deletion packages/website/docs/docs/theming.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export default function App() {

:::

If we pass both a light and dark theme to `BlockNoteView`, like in the demo, BlockNote automatically chooses which one to use based on the user's browser settings. However, you can just pass a single theme instead, if you want to use the same one regardless of browser settings.
If we pass both a light and dark theme to `BlockNoteView`, like in the demo, BlockNote automatically chooses which one to use based on the user's browser settings. However, you can just pass `"light"`/`"dark"` (for the light & dark default themes), or a single custom theme instead, if you want to use the same one regardless of browser settings.

## Adding DOM Attributes

Expand Down
12 changes: 4 additions & 8 deletions packages/website/docs/docs/ui-elements.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,11 @@ import "@blocknote/core/style.css";

export default function App() {
// Creates a new editor instance.
const editor: BlockNoteEditor = useBlockNote({
theme: "{{ getTheme(isDark) }}",
});
const editor: BlockNoteEditor = useBlockNote();

// Renders the editor instance.
return (
<BlockNoteView editor={editor}>
<BlockNoteView editor={editor} theme={"{{ getTheme(isDark) }}"}>
<FormattingToolbarPositioner editor={editor} />
<HyperlinkToolbarPositioner editor={editor} />
<SlashMenuPositioner editor={editor} />
Expand Down Expand Up @@ -110,13 +108,11 @@ import "@blocknote/core/style.css";

export default function App() {
// Creates a new editor instance.
const editor: BlockNoteEditor = useBlockNote({
theme: "{{ getTheme(isDark) }}",
});
const editor: BlockNoteEditor = useBlockNote();

// Renders the editor instance.
return (
<BlockNoteView editor={editor}>
<BlockNoteView editor={editor} theme={"{{ getTheme(isDark) }}"}>
<FormattingToolbarPositioner editor={editor} />
<HyperlinkToolbarPositioner editor={editor} />
<SlashMenuPositioner editor={editor} />
Expand Down

0 comments on commit bf17981

Please sign in to comment.