Button
The Bootstrap button component, implemented in Ruby. Use it like any other matestack component in your apps, pages and components. It offers customizable options to simply achieve what is possible in bootstrap with this component. See below for more information about the possible options.

btn(*args, &block)

Returns a bootstrap button containing text or content specified by a block. Also the button is customizable with the following options.
Optional options
  • :variant - Specify a variant for the button. Variant represent bootstraps contextual classes and can have one of the following values: :primary, :secondary, :success, :info, :warning, :info, :light, :dark or your custom contextual class. The default is :primary
  • :outline - Set true for outline button styling
  • :size - Use :block, :sm, :md or :lg to change the size of the button. The default is nil.
  • :type - Specify the type button tags. By default is set as button. You can set is for example as submit, reset, etc.
  • :text - Expects a string with the text that should go inside the button
  • :link - Expects a hash with parameters for a link component, button will act as a link (a tag with btn css classes)
  • :transition - Expects a hash with parameters for a transition component, button will act as a transition (a tag with btn css classes)
  • :action - Expects a hash with parameters for a action component, button will act as a action (a tag with btn css classes)
  • :onclick - Expects a hash with parameters for a onclick component, button will act as a onclick (a tag with btn css classes)
  • Html attributes - all w3c confirm html attributes for div's can be set via options and will be added to the surrounding button div.

Examples

Example 1: Basic Bootstrap btn with predefined styes

The btn implemented in ruby has by default primary as styling
1
bs_btn "Primary"
2
bs_btn "Secondary", variant: :secondary
3
bs_btn "Success", variant: :success
4
bs_btn "Danger", variant: :danger
5
bs_btn "Warning", variant: :warning
6
bs_btn "Info", variant: :info
7
bs_btn "Light", variant: :light
8
bs_btn "Dark", variant: :dark
9
bs_btn "Link", variant: :link
10
11
bs_btn "Outline Primary", variant: :primary, outline: true
12
bs_btn "Outline Secondary", variant: :secondary, outline: true
13
...
Copied!
returns
1
<btn type="button" class="btn btn-primary">Primary</btn>
2
<btn type="button" class="btn btn-secondary">Secondary</btn>
3
<btn type="button" class="btn btn-success">Success</btn>
4
<btn type="button" class="btn btn-danger">Danger</btn>
5
<btn type="button" class="btn btn-warning">Warning</btn>
6
<btn type="button" class="btn btn-info">Info</btn>
7
<btn type="button" class="btn btn-light">Light</btn>
8
<btn type="button" class="btn btn-dark">Dark</btn>
9
<btn type="button" class="btn btn-link">Link</btn>
10
11
<btn type="button" class="btn btn-outline-primary"> Outline Primary</btn>
12
<btn type="button" class="btn btn-outline-secondary">Outline Secondary</btn>
Copied!
1
bs_btn action: { path: root_path, method: :post ... } do
2
plain "Action"
3
end
4
bs_btn transition: { path: root_path ... } do
5
plain "Transition"
6
end
7
bs_btn link: { path: root_path ... } do
8
plain "Link"
9
end
10
bs_btn onclick: { emit: "test" ... } do
11
plain "Onclick"
12
end
Copied!

Example 3: Yield a given block

1
bs_btn id: 'foo', class: 'bar' do
2
plain "Click me"
3
end
Copied!
returns
1
<btn id="foo" type="button" class="btn btn-primary bar">
2
Click me
3
</btn>
Copied!

Example 4: Using btn size parameter

1
bs_btn "Small btn", variant: :success, size: :sm
2
bs_btn "Large btn", variant: :secondary, size: :lg
Copied!
returns
1
<btn type="button" class="btn btn-success btn-sm">Small btn</btn>
2
3
<btn type="button" class="btn btn-secondary btn-lg">Large btn</btn>
Copied!