Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Color scheme customization #305

Merged
merged 24 commits into from
Aug 13, 2023
Merged

feat: Color scheme customization #305

merged 24 commits into from
Aug 13, 2023

Conversation

matthewlipski
Copy link
Collaborator

@matthewlipski matthewlipski commented Aug 4, 2023

This PR overhauls how users can style the BlockNote editor. This is done in 3 ways:

  • Allowing users to change the colors, fonts, and border radii of the default UI (includes editor itself, and all menus/toolbars)
  • Allowing users to add HTML class names to elements within the editor.
  • Overriding the CSS for UI components.

There are still a few points of contention:

One of the main limitations is the extended theming customizability. I think most people are interested in just changing colors and fonts, for which we have a good solution, but overriding CSS could probably use some improvements for the future.

Another limitation is that the HTML classes set on elements cannot be dynamically changed atm. I can see this being a blocker for some as setting hidden, locked, or selected classes is a pretty common use case. However, the implementation is actually pretty complex so not sure it's worth our time atm.

@vercel
Copy link

vercel bot commented Aug 4, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
blocknote-website ✅ Ready (Inspect) Visit Preview Aug 13, 2023 7:08pm

Copy link
Collaborator

@YousefED YousefED left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks neat! Added some points to discuss, but I think we can quickly move to docs (keep it simple) & tests

examples/editor/src/App.tsx Show resolved Hide resolved
// Sets blockContent class
blockContent.className = styles.blockContent;
// Add custom HTML attributes
const blockContentDOMAttributes =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not blockContentDOMAttributes.blockContent.class?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For each of the DOM element types, you can add custom attributes, not just a custom class

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, you could do this:

constr { class, ...otherAttributes} = this.options.domAttributes?.blockContent || {};

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this also doesn't really work since class is a reserved word for class definitions

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check. We could decide to rename class to className, that's also inline with how React does this

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it's a good idea tbh, since we're not only applying the class to React components. Basic nodes like blockContainer, blockGroup, etc, are defined outside of React, so I think it's better to keep HTML naming conventions for this rather than React ones

examples/editor/src/App.tsx Outdated Show resolved Hide resolved
packages/react/src/BlockNoteTheme.ts Outdated Show resolved Hide resolved
packages/react/src/BlockNoteTheme.ts Show resolved Hide resolved
packages/react/src/BlockNoteView.tsx Outdated Show resolved Hide resolved
examples/editor/src/App.tsx Outdated Show resolved Hide resolved
// Sets blockContent class
blockContent.className = styles.blockContent;
// Add custom HTML attributes
const blockContentDOMAttributes =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, you could do this:

constr { class, ...otherAttributes} = this.options.domAttributes?.blockContent || {};

packages/react/src/BlockNoteTheme.ts Outdated Show resolved Hide resolved
packages/react/src/BlockNoteTheme.ts Outdated Show resolved Hide resolved
packages/react/src/BlockNoteTheme.ts Outdated Show resolved Hide resolved
packages/react/src/ReactBlockSpec.tsx Outdated Show resolved Hide resolved
packages/react/src/defaultTheme.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@YousefED YousefED left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some more comments


Take a look at how this is done in the demo below:

::: sandbox {template=react-ts}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sake of simplicity, I would just make one "red theme" and not a red light / dark theme

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's nice to have both since it both shows off the auto switching from browser settings and saves us having to explain how to pass in a light & dark theme instead of just a single theme. Theming is also not really complicated compared to a lot of the other stuff, since 90% of it is defining colors, so imo we shouldn't run into the issue of people getting overloaded with information.

Copy link
Collaborator

@YousefED YousefED left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

packages/react/src/BlockNoteView.tsx Outdated Show resolved Hide resolved
packages/website/docs/docs/theming.md Show resolved Hide resolved
@matthewlipski matthewlipski marked this pull request as ready for review August 13, 2023 19:20
@matthewlipski matthewlipski merged commit 6309de0 into main Aug 13, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants