Skip to main content

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.

info

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.

PropertyDefaultAffects
--orte-font-familysystem UI fonts, then Hiragino Sans / Noto Sans JPText in the editor
--orte-text-color#111827Text
--orte-editor-bg#ffffffEditing area background
--orte-toolbar-bg#f9fafbToolbar background
--orte-border-color#d1d5dbOuter border, toolbar divider
--orte-border-radius0.5remOuter corners
--orte-min-height16remMinimum height of the editing area
--orte-accent-color#2563ebFocus ring, pressed buttons, links, quote border
--orte-muted-color#6b7280Quote text
--orte-icon-size1.125remToolbar icons (default and replaced ones)
--orte-code-bg / --orte-code-color#1e293b / #f8fafcCode blocks
--orte-danger-color / --orte-danger-bg#dc2626 / #fef2f2Error 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()​

PartElement
containerOuter frame
toolbarToolbar (hidden while it has no buttons)
groupA group of buttons (separated by | in the toolbar attribute)
btnEvery button
btn-<tool>One button: btn-bold, btn-ul, btn-link, …
btn-activeAdded to a button while its formatting applies at the caret
iconThe icon inside a button
contentEditing area
popover, popover-linkThe link dialog
input, input-link-url, input-link-blankIts URL field and "open in a new tab" checkbox
btn-primary, btn-link-apply, btn-link-remove, btn-popover-closeIts buttons
popover-image, btn-image-width, input-image-alt, btn-image-applyThe image settings (width presets, alternative text); the active preset also has btn-active
notice, notice-error, notice-infoA message between the toolbar and the text (an error, or progress such as an upload)
notice-message, notice-code, btn-notice-closeIts 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.

ToolShortcut
undo / redoCtrl/Cmd+Z / Ctrl/Cmd+Shift+Z
bold / italicCtrl/Cmd+B / Ctrl/Cmd+I
linkCtrl/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.