Class: Daisy::Mockup::DeviceComponent

Inherits:
LocoMotion::BaseComponent show all
Defined in:
app/components/daisy/mockup/device_component.rb

Constant Summary

Constants inherited from LocoMotion::BaseComponent

LocoMotion::BaseComponent::EMPTY_PART_IGNORED_TAGS, LocoMotion::BaseComponent::SELF_CLOSING_TAGS

Instance Attribute Summary

Attributes inherited from LocoMotion::BaseComponent

#config, #loco_parent

Instance Method Summary collapse

Methods inherited from LocoMotion::BaseComponent

build, #component_ref, #config_option, #cssify, define_modifier, define_modifiers, define_part, define_parts, define_size, define_sizes, #empty_part_content, #inspect, #part, register_component_initializer, register_component_setup, #rendered_css, #rendered_data, #rendered_html, #rendered_stimulus_controllers, #rendered_tag_name, renders_many, renders_one, set_component_name, #set_loco_parent, #strip_spaces

Methods included from LocoMotion::Concerns::InspectableComponent

#build_inspect_string

Constructor Details

#initialize(**kws) ⇒ DeviceComponent

Creates a new Device component.

Parameters:

  • kws (Hash)

    a customizable set of options

Options Hash (**kws):

  • show_camera (Boolean)

    Whether to show the camera element (default: true).

  • css (String)

    Additional CSS classes for styling. Common options include:

    • Type: ‘mockup-phone`

    • Border: ‘border-2`, `border-primary`

    • Shadow: ‘shadow-lg`, `shadow-xl`



54
55
56
57
58
# File 'app/components/daisy/mockup/device_component.rb', line 54

def initialize(**kws)
  super(**kws)

  @show_camera = config_option(:show_camera, true)
end

Instance Method Details

#before_renderObject

Sets up the component’s CSS classes.



63
64
65
66
# File 'app/components/daisy/mockup/device_component.rb', line 63

def before_render
  add_css(:camera, "mockup-phone-camera")
  add_css(:display, "mockup-phone-display")
end

#callObject

Renders the device with its camera (if enabled) and display content.



71
72
73
74
75
76
77
78
79
# File 'app/components/daisy/mockup/device_component.rb', line 71

def call
  part(:component) do
    concat(part(:camera)) if @show_camera

    concat(part(:display) do
      content
    end)
  end
end