Class: Mayu::Component::Helpers
- Inherits:
-
Object
- Object
- Mayu::Component::Helpers
- Extended by:
- T::Sig
- Defined in:
- lib/mayu/component/helpers.rb
Instance Method Summary collapse
- #alert(message) ⇒ Object
- #children ⇒ Object
- #fetch(url, method: :GET, headers: {}, body: nil) ⇒ Object
- #handler(name, *args, **kwargs) ⇒ Object
-
#initialize(wrapper) ⇒ Helpers
constructor
A new instance of Helpers.
- #merge_props(*sources) ⇒ Object
- #navigate(path) ⇒ Object
- #props ⇒ Object
- #scroll_into_view(selector, **options) ⇒ Object
- #slot(name = nil, &fallback) ⇒ Object
- #slot_names ⇒ Object
- #state ⇒ Object
Constructor Details
#initialize(wrapper) ⇒ Helpers
Returns a new instance of Helpers.
9 10 11 |
# File 'lib/mayu/component/helpers.rb', line 9 def initialize(wrapper) @wrapper = wrapper end |
Instance Method Details
#alert(message) ⇒ Object
36 37 38 |
# File 'lib/mayu/component/helpers.rb', line 36 def alert() vnode.action(:alert, ) end |
#children ⇒ Object
46 |
# File 'lib/mayu/component/helpers.rb', line 46 def children = props[:children] |
#fetch(url, method: :GET, headers: {}, body: nil) ⇒ Object
21 22 23 |
# File 'lib/mayu/component/helpers.rb', line 21 def fetch(url, method: :GET, headers: {}, body: nil) vnode.fetch(url, method:, headers:, body:) end |
#handler(name, *args, **kwargs) ⇒ Object
83 84 85 |
# File 'lib/mayu/component/helpers.rb', line 83 def handler(name, *args, **kwargs) HandlerRef.new(@wrapper.instance, name, args, kwargs) end |
#merge_props(*sources) ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/mayu/component/helpers.rb', line 49 def merge_props(*sources) result = sources.reduce({}, &:merge) if result.delete(:class) classes = sources.map { _1[:class] }.flatten.compact result[:class] = T.unsafe(@wrapper.instance).styles[*classes] end result.transform_keys { _1.to_s.tr("-", "_").to_sym } end |
#navigate(path) ⇒ Object
26 27 28 |
# File 'lib/mayu/component/helpers.rb', line 26 def navigate(path) vnode.navigate(path) end |
#props ⇒ Object
43 |
# File 'lib/mayu/component/helpers.rb', line 43 def props = @wrapper.props |
#scroll_into_view(selector, **options) ⇒ Object
31 32 33 |
# File 'lib/mayu/component/helpers.rb', line 31 def scroll_into_view(selector, **) vnode.action(:scroll_into_view, { selector:, options: }) end |
#slot(name = nil, &fallback) ⇒ Object
73 |
# File 'lib/mayu/component/helpers.rb', line 73 def slot(name = nil, &fallback) = children.slot(name, &fallback) |
#slot_names ⇒ Object
76 |
# File 'lib/mayu/component/helpers.rb', line 76 def slot_names = children.slots.keys |
#state ⇒ Object
41 |
# File 'lib/mayu/component/helpers.rb', line 41 def state = @wrapper.state |