Module: Klods::Components::Modal
- Included in:
- Builders
- Defined in:
- lib/klods/components/modal.rb
Instance Method Summary collapse
- #modal(a = nil, b = nil) ⇒ Object
- #modal_actions(a = nil, b = nil) ⇒ Object
- #modal_body(a = nil, b = nil) ⇒ Object
- #modal_close(attrs = nil) ⇒ Object
- #modal_header(a = nil, b = nil) ⇒ Object
- #modal_panel(a = nil, b = nil) ⇒ Object
- #modal_title(a = nil, b = nil) ⇒ Object
Instance Method Details
#modal(a = nil, b = nil) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/klods/components/modal.rb', line 4 def modal(a = nil, b = nil) props, children = Core.normalize_args(a, b) props = props.transform_keys(&:to_s) open_attr = props.delete("open") extra_class = props.delete("class") cls = Core.class_names("klods-modal", Core.resolve_class(extra_class)) attrs = props.merge("class" => cls.empty? ? nil : cls).compact attrs["open"] = true if open_attr Core.el("dialog", attrs, children) end |
#modal_actions(a = nil, b = nil) ⇒ Object
35 36 37 38 |
# File 'lib/klods/components/modal.rb', line 35 def modal_actions(a = nil, b = nil) props, children = Core.normalize_args(a, b) Core.build(tag: "div", base: "klods-modal__actions", props: props, children: children) end |
#modal_body(a = nil, b = nil) ⇒ Object
30 31 32 33 |
# File 'lib/klods/components/modal.rb', line 30 def modal_body(a = nil, b = nil) props, children = Core.normalize_args(a, b) Core.build(tag: "div", base: "klods-modal__body", props: props, children: children) end |
#modal_close(attrs = nil) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/klods/components/modal.rb', line 40 def modal_close(attrs = nil) attrs = (attrs || {}).transform_keys(&:to_s) extra_class = attrs.delete("class") cls = Core.class_names("klods-modal__close", Core.resolve_class(extra_class)) final_attrs = {"type" => "button", "aria-label" => "Close"} .merge(attrs) .merge("class" => cls.empty? ? nil : cls) .compact Core.el("button", final_attrs) end |
#modal_header(a = nil, b = nil) ⇒ Object
20 21 22 23 |
# File 'lib/klods/components/modal.rb', line 20 def modal_header(a = nil, b = nil) props, children = Core.normalize_args(a, b) Core.build(tag: "div", base: "klods-modal__header", props: props, children: children) end |
#modal_panel(a = nil, b = nil) ⇒ Object
15 16 17 18 |
# File 'lib/klods/components/modal.rb', line 15 def modal_panel(a = nil, b = nil) props, children = Core.normalize_args(a, b) Core.build(tag: "div", base: "klods-modal__panel", props: props, children: children) end |
#modal_title(a = nil, b = nil) ⇒ Object
25 26 27 28 |
# File 'lib/klods/components/modal.rb', line 25 def modal_title(a = nil, b = nil) props, children = Core.normalize_args(a, b) Core.build(tag: "h2", base: "klods-modal__title", props: props, children: children) end |