Module: Inquirex::UI::WidgetRegistry
- Defined in:
- lib/inquirex/ui/widget_registry.rb
Overview
Canonical mapping from Inquirex data types to default widget types per rendering context.
Desktop defaults lean toward richer controls (radio groups, checkbox groups). Mobile defaults lean toward compact controls (dropdowns, toggles).
Adapters (TTY, JS, Rails) use this to pick an appropriate renderer when the DSL author has not specified an explicit ‘widget` hint.
Constant Summary collapse
- WIDGET_TYPES =
All recognized widget type symbols. Adapters may not support every widget; they should fall back gracefully to a simpler one.
%i[ text_input textarea number_input currency_input toggle yes_no_buttons yes_no radio_group dropdown checkbox_group multi_select_dropdown select multi_select enum_select multiline mask slider date_picker email_input phone_input ].freeze
- DEFAULTS =
Default widget per data type and rendering context. Each context key (:desktop, :mobile, :tty, …) maps to a widget type symbol. Adapters consult this table when no explicit ‘widget` hint was given.
TTY defaults align with tty-prompt methods:
text_input → prompt.ask multiline → prompt.multiline number_input → prompt.ask (with numeric conversion) yes_no → prompt.yes? select → prompt.select multi_select → prompt.multi_select { string: { desktop: :text_input, mobile: :text_input, tty: :text_input }, text: { desktop: :textarea, mobile: :textarea, tty: :multiline }, integer: { desktop: :number_input, mobile: :number_input, tty: :number_input }, decimal: { desktop: :number_input, mobile: :number_input, tty: :number_input }, currency: { desktop: :currency_input, mobile: :currency_input, tty: :number_input }, boolean: { desktop: :toggle, mobile: :yes_no_buttons, tty: :yes_no }, enum: { desktop: :radio_group, mobile: :dropdown, tty: :select }, multi_enum: { desktop: :checkbox_group, mobile: :checkbox_group, tty: :multi_select }, date: { desktop: :date_picker, mobile: :date_picker, tty: :text_input }, email: { desktop: :email_input, mobile: :email_input, tty: :text_input }, phone: { desktop: :phone_input, mobile: :phone_input, tty: :text_input } }.freeze
Class Method Summary collapse
-
.default_for(type, context: :desktop) ⇒ Symbol?
Returns the default widget type for a given data type and context.
-
.default_hint_for(type, context: :desktop) ⇒ WidgetHint?
Returns a WidgetHint with the default widget for the given type + context, or nil when no default exists (e.g. for display verbs with no type).
Class Method Details
.default_for(type, context: :desktop) ⇒ Symbol?
Returns the default widget type for a given data type and context.
68 69 70 |
# File 'lib/inquirex/ui/widget_registry.rb', line 68 def self.default_for(type, context: :desktop) DEFAULTS.dig(type&.to_sym, context) end |
.default_hint_for(type, context: :desktop) ⇒ WidgetHint?
Returns a WidgetHint with the default widget for the given type + context, or nil when no default exists (e.g. for display verbs with no type).
78 79 80 81 |
# File 'lib/inquirex/ui/widget_registry.rb', line 78 def self.default_hint_for(type, context: :desktop) = default_for(type, context:) ? WidgetHint.new(type: ) : nil end |