Class: Mayu::Component::Helpers

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/mayu/component/helpers.rb

Instance Method Summary collapse

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(message)
  vnode.action(:alert, message)
end

#childrenObject



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


26
27
28
# File 'lib/mayu/component/helpers.rb', line 26

def navigate(path)
  vnode.navigate(path)
end

#propsObject



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, **options)
  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_namesObject



76
# File 'lib/mayu/component/helpers.rb', line 76

def slot_names = children.slots.keys

#stateObject



41
# File 'lib/mayu/component/helpers.rb', line 41

def state = @wrapper.state