um

Forms and settings

Configuration

The seams the components render through, for an app with its own empty states, pager or styles.

The components render a few things through settings rather than calling your helpers: a table's empty state, its pager, submit and control classes, code blocks. Each has a working default, so the gem needs no helper of yours and no pagination library. An app that already owns one of these points the setting at its own version.

# config/initializers/unmagic_components.rb
Unmagic::Components.configure do |config|
  config.empty_state = ->(view, content) { view.render("shared/empty_state", content: content) }
  config.submit_class = ->(_view, variant) { "btn btn-#{variant}" }
end

Settings

empty_state (view, content)
A table's blank slate. content is captured markup or a string.
pagination (view, pagy:, turbo_frame:)
A table's pager.
pagy_for (view, collection)
The pagy object a table pages with. nil hides the pager.
submit_class (view, variant)
The classes on the form builder's submit button.
control_class (view, kind)
The classes on a form control of that kind (:input, :select, :check…). nil leaves it unstyled.
flash_tones a hash
The tone each flash type's toast wears.
modal_frame_id a string
The id of the shared modal's frame. "modal" by default.
highlight (source, language)
Colours source, one html_safe string per line. Rouge by default.
code_block (view, source, language)
Frames a block of code: a payload, a backtrace. A code_view by default.
sortable_item (view, record)
A sortable item's { key:, rank: }.
sortable_url (view)
Where a sortable list posts a drop when it isn't given url:.

Changing them for a while

Unmagic::Components.with_default_configuration runs a block with the built-in settings and puts yours back afterwards, for the current request or job only. This browser runs every request inside it, so it shows the gem's own components inside your app.

See it working