Module: OdtUi::Helper
- Defined in:
- lib/odt_ui/helper.rb
Instance Method Summary collapse
- #odt_avatar(src: nil, name: nil, **props) ⇒ Object
- #odt_badge(label = nil, **props, &block) ⇒ Object
-
#odt_button(label = nil, **props, &block) ⇒ Object
Shorthand Component Helpers =========================================================================.
- #odt_card(**props, &block) ⇒ Object
- #odt_checkbox(name = nil, **props) ⇒ Object
-
#odt_component(name, props = {}, html_options = {}, &block) ⇒ Object
Generic component mount helper Example: <%= odt_component :Button, variant: "primary" do %> Submit <% end %>.
- #odt_heading(text = nil, level: 1, **props, &block) ⇒ Object
- #odt_input(name = nil, **props) ⇒ Object
- #odt_password_input(name = nil, **props) ⇒ Object
- #odt_radio_group(name = nil, **props) ⇒ Object
- #odt_search_input(name = nil, **props) ⇒ Object
- #odt_stat_card(**props) ⇒ Object
- #odt_switch(name = nil, **props) ⇒ Object
- #odt_text(text = nil, **props, &block) ⇒ Object
Instance Method Details
#odt_avatar(src: nil, name: nil, **props) ⇒ Object
58 59 60 61 62 |
# File 'lib/odt_ui/helper.rb', line 58 def odt_avatar(src: nil, name: nil, **props) props[:src] = src if src.present? props[:name] = name if name.present? odt_component(:Avatar, props) end |
#odt_badge(label = nil, **props, &block) ⇒ Object
53 54 55 56 |
# File 'lib/odt_ui/helper.rb', line 53 def odt_badge(label = nil, **props, &block) props[:children] = label if label.present? odt_component(:Badge, props, &block) end |
#odt_button(label = nil, **props, &block) ⇒ Object
=========================================================================
Shorthand Component Helpers
37 38 39 40 |
# File 'lib/odt_ui/helper.rb', line 37 def (label = nil, **props, &block) props[:children] = label if label.present? odt_component(:Button, props, &block) end |
#odt_card(**props, &block) ⇒ Object
79 80 81 |
# File 'lib/odt_ui/helper.rb', line 79 def odt_card(**props, &block) odt_component(:Card, props, &block) end |
#odt_checkbox(name = nil, **props) ⇒ Object
92 93 94 95 |
# File 'lib/odt_ui/helper.rb', line 92 def odt_checkbox(name = nil, **props) props[:name] = name if name.present? odt_component(:Checkbox, props) end |
#odt_component(name, props = {}, html_options = {}, &block) ⇒ Object
Generic component mount helper Example:
<%= odt_component :Button, variant: "primary" do %>
Submit
<% end %>
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/odt_ui/helper.rb', line 10 def odt_component(name, props = {}, = {}, &block) props_hash = props.dup if block_given? content = capture(&block) props_hash[:children] = content.strip if content.present? end # Camelize keys if needed, or pass directly as camelCase formatted_props = props_hash.transform_keys { |key| key.to_s.camelize(:lower) } tag.div( "", class: ["odt-rails-root", [:class]].compact.join(" "), data: { controller: "odt-component", odt_component_name_value: name.to_s, odt_component_props_value: formatted_props.to_json }, **.except(:class) ) end |
#odt_heading(text = nil, level: 1, **props, &block) ⇒ Object
42 43 44 45 46 |
# File 'lib/odt_ui/helper.rb', line 42 def odt_heading(text = nil, level: 1, **props, &block) props[:level] = level props[:children] = text if text.present? odt_component(:Heading, props, &block) end |
#odt_input(name = nil, **props) ⇒ Object
64 65 66 67 |
# File 'lib/odt_ui/helper.rb', line 64 def odt_input(name = nil, **props) props[:name] = name if name.present? odt_component(:Input, props) end |
#odt_password_input(name = nil, **props) ⇒ Object
69 70 71 72 |
# File 'lib/odt_ui/helper.rb', line 69 def odt_password_input(name = nil, **props) props[:name] = name if name.present? odt_component(:PasswordInput, props) end |
#odt_radio_group(name = nil, **props) ⇒ Object
97 98 99 100 |
# File 'lib/odt_ui/helper.rb', line 97 def odt_radio_group(name = nil, **props) props[:name] = name if name.present? odt_component(:RadioGroup, props) end |
#odt_search_input(name = nil, **props) ⇒ Object
74 75 76 77 |
# File 'lib/odt_ui/helper.rb', line 74 def odt_search_input(name = nil, **props) props[:name] = name if name.present? odt_component(:SearchInput, props) end |
#odt_stat_card(**props) ⇒ Object
83 84 85 |
# File 'lib/odt_ui/helper.rb', line 83 def odt_stat_card(**props) odt_component(:StatCard, props) end |
#odt_switch(name = nil, **props) ⇒ Object
87 88 89 90 |
# File 'lib/odt_ui/helper.rb', line 87 def odt_switch(name = nil, **props) props[:name] = name if name.present? odt_component(:Switch, props) end |
#odt_text(text = nil, **props, &block) ⇒ Object
48 49 50 51 |
# File 'lib/odt_ui/helper.rb', line 48 def odt_text(text = nil, **props, &block) props[:children] = text if text.present? odt_component(:Text, props, &block) end |