Skip to content

Forms ​

Trek ships Trek::FormBuilder, an extension of ViewComponent::Form's builder, automatically used in admin views. On top of the standard helpers, it provides:

HelperRenders
f.groupa wrapper giving the input nested in it a label, and a hint (errors are listed by Trek::Form::ErrorsComponent)
f.content_editorthe content editor, based on Tiptap
f.image_fieldan image uploader with thumbnail preview (Uppy + Shrine)
f.sound_fieldan audio file uploader
f.switch_boxa toggle switch
f.link_selecta link picker (internal pages & external links)

Each helper renders the matching component from the Trek::Form namespace.

Standard helpers are styled too: a plain f.file_field inside an f.group gets its native ::file-selector-button styled like a narrow Trek::ButtonComponent (following the current data-accent-color), keeping the browser's built-in "file chosen" feedback with no JS — handy for one-off uploads like a spreadsheet import.

slim
= form_with model: [:admin, @book] do |f|
  = f.group :title
    = f.text_field :title
  = f.group :intro
    = f.content_editor :intro, floating: false
  = f.group :published
    = f.switch_box :published

Released under the MIT License.