Customization
The editor's inside is a shadow tree: your stylesheet's selectors cannot reach it. Styling goes through two interfaces made to cross that boundary.
These names are a public contract: they will not change without a major version.
1. CSS custom properties
Set them on the editor or any ancestor.
| Property | Default | Affects |
|---|---|---|
--orte-font-family | system UI fonts, then Hiragino Sans / Noto Sans JP | Text in the editor |
--orte-text-color | #111827 | Text |
--orte-editor-bg | #ffffff | Editing area background |
--orte-toolbar-bg | #f9fafb | Toolbar background |
--orte-border-color | #d1d5db | Outer border, toolbar divider |
--orte-border-radius | 0.5rem | Outer corners |
--orte-min-height | 16rem | Minimum height of the editing area |
--orte-accent-color | #2563eb | Focus ring, pressed buttons, links, quote border |
--orte-muted-color | #6b7280 | Quote text |
--orte-icon-size | 1.125rem | Toolbar icons (default and replaced ones) |
--orte-code-bg / --orte-code-color | #1e293b / #f8fafc | Code blocks |
--orte-danger-color / --orte-danger-bg | #dc2626 / #fef2f2 | Error messages (e.g. an invalid link) |
ohashi-rich-text-editor {
--orte-border-radius: 0;
--orte-min-height: 24rem;
}
Dark mode
The editor does not guess when your site is dark. Switch the properties under whatever condition your site uses:
.dark ohashi-rich-text-editor {
--orte-text-color: #f8fafc;
--orte-editor-bg: #0f172a;
--orte-toolbar-bg: #1e293b;
--orte-border-color: #334155;
}
2. ::part()
| Part | Element |
|---|---|
container | Outer frame |
toolbar | Toolbar (hidden while it has no buttons) |
group | A group of buttons (separated by | in the toolbar attribute) |
btn | Every button |
btn-<tool> | One button: btn-bold, btn-ul, btn-link, … |
btn-active | Added to a button while its formatting applies at the caret |
icon | The icon inside a button |
content | Editing area |
popover, popover-link | The link dialog |
input, input-link-url, input-link-blank | Its URL field and "open in a new tab" checkbox |
btn-primary, btn-link-apply, btn-link-remove, btn-popover-close | Its buttons |
popover-image, btn-image-width, input-image-alt, btn-image-apply | The image settings (width presets, alternative text); the active preset also has btn-active |
notice, notice-error, notice-info | A message between the toolbar and the text (an error, or progress such as an upload) |
notice-message, notice-code, btn-notice-close | Its text, its error code and its close button |
ohashi-rich-text-editor::part(content) {
padding: 1.5rem;
font-size: 1.05rem;
line-height: 1.9;
}
::part() cannot be followed by class or attribute selectors; pseudo-classes
such as :hover, :focus-visible and :disabled work. State is therefore a
part name of its own:
ohashi-rich-text-editor::part(btn) { border-radius: 9999px; }
ohashi-rich-text-editor::part(btn-active) { background: #fef3c7; }
ohashi-rich-text-editor::part(btn):disabled { opacity: 0.3; }
3. Toolbar
Choose and group the buttons with the toolbar attribute (| starts a new
group):
<!-- the default -->
<ohashi-rich-text-editor toolbar="undo redo | bold italic strike | paragraph h2 h3 quote | ul ol | link code image">
<!-- a comment box -->
<ohashi-rich-text-editor toolbar="bold italic | link">
A tool you leave out is switched off completely: its keyboard shortcut
(including the browser's own, such as Ctrl/Cmd+B) does nothing. Hiding a
button with ::part(btn-bold) { display: none } only hides it.
| Tool | Shortcut |
|---|---|
undo / redo | Ctrl/Cmd+Z / Ctrl/Cmd+Shift+Z |
bold / italic | Ctrl/Cmd+B / Ctrl/Cmd+I |
link | Ctrl/Cmd+K |
strike, paragraph, h2, h3, quote, ul, ol, code | — |
image (shown only with an upload-url; see Image uploads) | — |
The toolbar is one Tab stop; the arrow keys, Home and End move between buttons.
Inside a code block, Enter adds a line. To leave the block, press Enter on an empty last line (Enter twice at the end). A quote is left the same way: Enter on its empty last line. When a code block, quote, list or heading is the last thing in the editor, ↓ or → at its end makes a new paragraph below it. Empty paragraphs at the very end are not saved.
With Blade, set a default for every editor in config/ohashi-editor.php; an
editor's own attribute still wins:
'toolbar' => 'bold italic | link',
4. Language
<ohashi-rich-text-editor locale="ja">
English is the default and Japanese ships with the editor.
With Blade, <x-ohashi-editor> picks the language for you: the editor's own
locale attribute, else config('ohashi-editor.locale')
(OHASHI_EDITOR_LOCALE), else your app's locale (app()->getLocale(), so
ja or ja_JP gives Japanese) when the editor ships that language, and
English otherwise. The UI language is never guessed from the browser, and the
page's lang is left to describe the content.
Add a language or change any text from JavaScript; missing strings fall back to
English. Set locale (or the config value) to its code to use it:
import { defineOhashiEditorLocale } from '@2bo-velocity/ohashirichtexteditor'
defineOhashiEditorLocale('fr', { bold: 'Gras', italic: 'Italique', link: 'Lien' })
5. Icons
The default icons are Lucide icons. Replace one for a single editor with a slot — your page's CSS applies to it, so icon fonts work:
<ohashi-rich-text-editor>
<i slot="icon-bold" class="fa-solid fa-bold"></i>
</ohashi-rich-text-editor>
or for every editor on the page:
import { defineOhashiEditorIcons } from '@2bo-velocity/ohashirichtexteditor'
defineOhashiEditorIcons({ bold: '<svg viewBox="0 0 24 24">…</svg>' })
Strings are inserted as markup: pass SVG you wrote, never anything a user supplied.
What still crosses the boundary
Inherited properties — color, font-family, line-height — flow from the
page into the editor. The editor sets the ones that matter on itself, so the
page's values do not leak in unless you set the custom properties above.