Class: Line::Message::Builder::Flex::Button
- Includes:
- Actionable, Position::Margin, Position::Offset, Position::Vertical, Size::AdjustMode, Size::Flex
- Defined in:
- lib/line/message/builder/flex/button.rb
Overview
Represents a "button" component in a LINE Flex Message.
Buttons are interactive elements that users can tap to trigger an action
(e.g., open a URL, send a message, or trigger a postback). They have
various styling options, including style (primary, secondary, link),
color and height.
An action is mandatory for a button component.
Buttons have no padding properties of their own; use the padding of the surrounding Box to inset a button.
Example
Line::Message::Builder.with do
flex alt_text: "Button Example" do
bubble do
body do
style: :primary, height: :sm do
"Buy Now", label: "Buy" # Action definition
end
end
end
end
end
Example: Tinting a primary button
Line::Message::Builder.with do
flex alt_text: "Button Example" do
bubble do
body do
style: :primary, color: "#1DB446" do
"Buy Now", label: "Buy"
end
end
end
end
end
See also:
- https://developers.line.biz/en/reference/messaging-api/#button
- Actionable for defining the button's action (mandatory)
- Position::Vertical for
gravityproperty - Position::Margin for
marginproperty - Position::Offset for offset properties
- Size::Flex for flex sizing property
- Size::AdjustMode for
adjust_modeproperty
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(context: nil, **options) ⇒ Button
constructor
Initializes a new Flex Message Button component.
Methods included from Size::AdjustMode
Methods included from Size::Flex
Methods included from Position::Offset
Methods included from Position::Margin
Methods included from Position::Vertical
Methods included from Actionable
included, #message, #postback, #uri
Methods inherited from Base
inherited, #method_missing, #quick_reply, #respond_to_missing?, #to_h
Constructor Details
#initialize(context: nil, **options) ⇒ Button
Initializes a new Flex Message Button component.
The provided block is instance-eval'd, primarily used to define the
button's action using methods from the Actionable module (e.g., message).
[context]
An optional context for the builder
[options]
A hash of options to set instance variables
(e.g., :style, :height, and options from included modules)
[block]
A block to define the button's action and other properties.
This block is where you should call an action method like message or postback.
124 125 126 |
# File 'lib/line/message/builder/flex/button.rb', line 124 def initialize(context: nil, **, &) super # Calls Base#initialize, sets options, and evals block (which should define the action) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Line::Message::Builder::Base