Class: Daisy::Mockup::DeviceComponent

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

Overview

The DeviceComponent creates realistic device mockups for showcasing mobile and tablet applications. Common use cases include:

  • Displaying mobile app screenshots.

  • Creating marketing materials.

  • Demonstrating responsive designs.

  • Building portfolio pieces.

The component includes an optional camera element and a display area that can contain any content with appropriate sizing classes.

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

Constructor Details

#initialize(**kws) ⇒ DeviceComponent

Creates a new Device component.

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`



50
51
52
53
54
# File 'app/components/daisy/mockup/device_component.rb', line 50

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.



59
60
61
62
63
# File 'app/components/daisy/mockup/device_component.rb', line 59

def before_render
  add_css(:camera, "mockup-phone-camera")
  add_css(:display, "mockup-phone-display")
  add_css(:display, "!mt-0") if !@show_camera
end

#callObject

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



68
69
70
71
72
73
74
75
76
# File 'app/components/daisy/mockup/device_component.rb', line 68

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

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