Fields
Rich editor
RichEditor edits formatted text and stores clean HTML, with toolbars, attachments and sanitizing.
use Xelqun\Forms\Components\RichEditor;
RichEditor::make('content')->minHeight('16rem');
The editor loads only when a form needs it. The server cleans the HTML before it's saved.
Toolbar
toolbarButtons() takes the buttons in groups. disableToolbarButtons() removes some from the defaults.
RichEditor::make('content')->toolbarButtons([
['bold', 'italic', 'underline'],
['h2', 'h3'],
['bulletList', 'orderedList', 'link'],
]);
RichEditor::make('content')->disableToolbarButtons(['codeBlock']);
Attachments
RichEditor::make('content')
->fileAttachments()
->fileAttachmentsDisk('public')
->fileAttachmentsDirectory('posts')
->fileAttachmentsMaxSize(2048);
fileAttachmentsAcceptedFileTypes() lists the MIME types. SVG can carry scripts, so it isn't one of the defaults.
Sanitizing
The server sanitizes what's saved. sanitizeUsing() cleans it your own way: it gets $html and returns the result.
RichEditor::make('content')->sanitizeUsing(fn (string $html): string => clean($html));
A sanitizer of your own replaces the built-in one, so anything it lets through reaches your pages.