Class: DiscordRDA::Components::TextInput

Inherits:
Base
  • Object
show all
Defined in:
lib/discord_rda/interactions/components.rb

Overview

Text Input (for modals)

Instance Attribute Summary

Attributes inherited from Base

#data, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#to_h

Constructor Details

#initialize(style:, custom_id:, label:, placeholder: nil, min_length: nil, max_length: nil, required: true, value: nil) ⇒ TextInput

Returns a new instance of TextInput.

Parameters:

  • style (Symbol, Integer)

    Input style (:short or :paragraph)

  • custom_id (String)

    Custom ID

  • label (String)

    Input label

  • placeholder (String) (defaults to: nil)

    Placeholder text

  • min_length (Integer) (defaults to: nil)

    Minimum length

  • max_length (Integer) (defaults to: nil)

    Maximum length

  • required (Boolean) (defaults to: true)

    Whether required

  • value (String) (defaults to: nil)

    Default value



270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/discord_rda/interactions/components.rb', line 270

def initialize(style:, custom_id:, label:, placeholder: nil, min_length: nil, max_length: nil, required: true, value: nil)
  style_val = TEXT_INPUT_STYLES[style] || style
  data = {
    style: style_val,
    custom_id: custom_id,
    label: label,
    required: required
  }
  data[:placeholder] = placeholder if placeholder
  data[:min_length] = min_length if min_length
  data[:max_length] = max_length if max_length
  data[:value] = value if value

  super(:text_input, data)
end

Class Method Details

.paragraph(**kwargs) ⇒ Object

Create a paragraph text input

Parameters:

  • kwargs (Hash)

    Text input options



294
295
296
# File 'lib/discord_rda/interactions/components.rb', line 294

def self.paragraph(**kwargs)
  new(style: :paragraph, **kwargs)
end

.short(**kwargs) ⇒ Object

Create a short text input

Parameters:

  • kwargs (Hash)

    Text input options



288
289
290
# File 'lib/discord_rda/interactions/components.rb', line 288

def self.short(**kwargs)
  new(style: :short, **kwargs)
end