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
Data Display & Layout.
-
#odt_button(label = nil, **props, &block) ⇒ Object
Actions.
- #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_dropdown_menu(**props, &block) ⇒ Object
-
#odt_heading(text = nil, as: "h2", **props, &block) ⇒ Object
Typography.
-
#odt_input(name = nil, **props) ⇒ Object
Form Controls.
-
#odt_modal(**props, &block) ⇒ Object
Overlays & Menus.
- #odt_password_input(name = nil, **props) ⇒ Object
- #odt_pin_input(name = nil, **props) ⇒ Object
- #odt_progress_bar(value = 0, **props) ⇒ Object
- #odt_radio_group(name = nil, **props) ⇒ Object
- #odt_search_input(name = nil, **props) ⇒ Object
- #odt_stat_card(title = nil, value = nil, **props) ⇒ Object
- #odt_switch(name = nil, **props) ⇒ Object
- #odt_text(text = nil, **props, &block) ⇒ Object
- #odt_text_area(name = nil, **props) ⇒ Object
- #odt_toaster(**props) ⇒ Object
Instance Method Details
#odt_avatar(src: nil, name: nil, **props) ⇒ Object
61 62 63 64 65 |
# File 'lib/odt_ui/helper.rb', line 61 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
Data Display & Layout
56 57 58 59 |
# File 'lib/odt_ui/helper.rb', line 56 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
Actions
38 39 40 41 |
# File 'lib/odt_ui/helper.rb', line 38 def (label = nil, **props, &block) props[:children] = label if label.present? odt_component(:Button, props, &block) end |
#odt_card(**props, &block) ⇒ Object
67 68 69 |
# File 'lib/odt_ui/helper.rb', line 67 def odt_card(**props, &block) odt_component(:Card, props, &block) end |
#odt_checkbox(name = nil, **props) ⇒ Object
113 114 115 116 |
# File 'lib/odt_ui/helper.rb', line 113 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_dropdown_menu(**props, &block) ⇒ Object
128 129 130 |
# File 'lib/odt_ui/helper.rb', line 128 def (**props, &block) odt_component(:DropdownMenu, props, &block) end |
#odt_heading(text = nil, as: "h2", **props, &block) ⇒ Object
Typography
44 45 46 47 48 |
# File 'lib/odt_ui/helper.rb', line 44 def odt_heading(text = nil, as: "h2", **props, &block) props[:as] = as props[:children] = text if text.present? odt_component(:Heading, props, &block) end |
#odt_input(name = nil, **props) ⇒ Object
Form Controls
83 84 85 86 |
# File 'lib/odt_ui/helper.rb', line 83 def odt_input(name = nil, **props) props[:name] = name if name.present? odt_component(:Input, props) end |
#odt_modal(**props, &block) ⇒ Object
Overlays & Menus
124 125 126 |
# File 'lib/odt_ui/helper.rb', line 124 def odt_modal(**props, &block) odt_component(:Modal, props, &block) end |
#odt_password_input(name = nil, **props) ⇒ Object
93 94 95 96 |
# File 'lib/odt_ui/helper.rb', line 93 def odt_password_input(name = nil, **props) props[:name] = name if name.present? odt_component(:PasswordInput, props) end |
#odt_pin_input(name = nil, **props) ⇒ Object
103 104 105 106 |
# File 'lib/odt_ui/helper.rb', line 103 def odt_pin_input(name = nil, **props) props[:name] = name if name.present? odt_component(:PinInput, props) end |
#odt_progress_bar(value = 0, **props) ⇒ Object
77 78 79 80 |
# File 'lib/odt_ui/helper.rb', line 77 def (value = 0, **props) props[:value] = value odt_component(:ProgressBar, props) end |
#odt_radio_group(name = nil, **props) ⇒ Object
118 119 120 121 |
# File 'lib/odt_ui/helper.rb', line 118 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
98 99 100 101 |
# File 'lib/odt_ui/helper.rb', line 98 def odt_search_input(name = nil, **props) props[:name] = name if name.present? odt_component(:SearchInput, props) end |
#odt_stat_card(title = nil, value = nil, **props) ⇒ Object
71 72 73 74 75 |
# File 'lib/odt_ui/helper.rb', line 71 def odt_stat_card(title = nil, value = nil, **props) props[:title] = title if title.present? props[:value] = value if value.present? odt_component(:StatCard, props) end |
#odt_switch(name = nil, **props) ⇒ Object
108 109 110 111 |
# File 'lib/odt_ui/helper.rb', line 108 def odt_switch(name = nil, **props) props[:name] = name if name.present? odt_component(:Switch, props) end |
#odt_text(text = nil, **props, &block) ⇒ Object
50 51 52 53 |
# File 'lib/odt_ui/helper.rb', line 50 def odt_text(text = nil, **props, &block) props[:children] = text if text.present? odt_component(:Text, props, &block) end |
#odt_text_area(name = nil, **props) ⇒ Object
88 89 90 91 |
# File 'lib/odt_ui/helper.rb', line 88 def odt_text_area(name = nil, **props) props[:name] = name if name.present? odt_component(:TextArea, props) end |
#odt_toaster(**props) ⇒ Object
132 133 134 |
# File 'lib/odt_ui/helper.rb', line 132 def odt_toaster(**props) odt_component(:Toaster, props) end |