Module: Inquirex::WidgetRegistry
- Defined in:
- lib/inquirex/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). TTY defaults align with tty-prompt methods.
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 =
%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.
{ 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.
56 57 58 |
# File 'lib/inquirex/widget_registry.rb', line 56 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).
66 67 68 69 |
# File 'lib/inquirex/widget_registry.rb', line 66 def self.default_hint_for(type, context: :desktop) = default_for(type, context:) ? WidgetHint.new(type: ) : nil end |