LocoMotion Component Library

website·Indexed 31 days ago

https://loco-motion.profoundry.us

A UI component library built on Ruby on Rails, ViewComponent, and DaisyUI v5. It features 70 components across categories such as actions, navigation, and data display, providing idiomatic patterns for form building, layout structure, and Rails integration.

Tokens
27.5K
Snippets
143
Records
185
Agent score
52%

What's inside LocoMotion

  1. Overview of the LocoMotion Component Library

    LocoMotion is a Ruby on Rails component library built using ViewComponent and DaisyUI v5. It consists of 70 components organized into categories: Actions, Data Display, Data Input, Feedback, Layout, Loco, Mockup, and Navigation. The library utilizes helper methods with daisy_ and hero_ prefixes.
  2. Use Daisy Feedback components for system status

    The Daisy::Feedback namespace provides components to communicate system state to the user:

    • AlertComponent: Informs users about important information or system changes.
    • LoadingComponent: Indicates background processes are active.
    • ProgressComponent: Linear progress bars.
    • RadialProgressComponent: Circular progress bars.
    • SkeletonComponent: Placeholders for loading content.
    • ToastComponent: Temporary notifications (relies on the Alert component's Stimulus controller).
    • TooltipComponent: Small descriptive popups (includes daisy_tooltip for wrapping entire elements).
  3. Implement a large navigation menu with Daisy::Navigation::MegamenuComponent

    The daisy_megamenu helper creates a horizontal menu where items open popovers containing complex navigation blocks. It uses native HTML popover and popovertarget attributes with CSS anchor positioning, requiring no JavaScript. To make the menu responsive on small screens, add the max-sm:megamenu-vertical class to collapse it into a toggleable full-width popover.
    = daisy_megamenu(css: "max-sm:megamenu-vertical") do
      - # Megamenu content here
  4. Build introduction sections with Daisy::Layout::HeroComponent

    The daisy_hero helper creates large, responsive introduction sections. It supports a content_wrapper_css parameter to control the layout of the internal content (e.g., using max-sm:flex-col to stack content on small screens). Images can be added as the first or last child of the hero to create a split layout.
    = daisy_hero(css: "block max-w-[1000px] mx-4 sm:mx-16 py-8 lg:mx-32 bg-base-200", content_wrapper_css: "max-sm:flex-col") do
        %img.h-40.rounded{ src: image_path('landscapes/mountain-river.jpg'), alt: "Beautiful Landscape" }
        
          %h1.text-5xl.font-bold
            Hello, World!
          %p.my-6
            Welcome to the world of LocoMotion.
          = daisy_button(css: "btn btn-primary", title: "Get Started", href: "/")
  5. Implement basic page structure using DaisyUI components

    Organize the high-level structure of a page using the following DaisyUI components:

    • daisy_hero: Use for page headers and introductions.
    • daisy_card: Use to wrap and group content into sections.
    • daisy_divider: Use to visually separate different content sections.
    • daisy_footer: Use for the page footer.
  6. Integrate checkboxes with Rails Form Builder

    The Loco Motion Form Builder extension provides form.daisy_checkbox to automatically handle name and id attributes from the form object. By default, it emits a hidden field for unchecked boxes (sending "0"), similar to standard Rails check_box. This behavior can be disabled by passing include_hidden: false.
    = form_with(url: "#", method: :post, scope: :user, class: "flex flex-col gap-8") do |form|
        = form.daisy_label(:terms) do
          = form.daisy_checkbox(:terms)
          I accept the terms and conditions
    
        = form.daisy_checkbox(:newsletter, toggle: true, trailing: "Subscribe to newsletter")
  7. Integrate components using ViewComponent in Rails

    When building UI components in Rails, ensure all components inherit from ViewComponent::Base. This allows components to use Rails helpers, access controller data, and request data while maintaining standard Rails naming conventions.
  8. Prevent theme flash on page load

    To prevent a flash of content when a page loads with a non-default theme, add the = theme_preload_script helper to the <head> section of your layout. This inline script sets the theme from localStorage before the page renders.
    -# In your layout's <head>
    = theme_preload_script
  9. Create alerts using the daisy_alert helper

    The daisy_alert helper (based on Daisy::Feedback::AlertComponent) is used to inform users of important system information. Alerts typically include a leading icon to indicate the alert type.

    Common Parameters:

    • icon: The name of the icon to display at the start of the alert.
    • css: CSS classes for styling and coloring.
    • html: A hash of HTML attributes.

    Styling Variants (via css parameter):

    • Colors: alert-info, alert-success, alert-warning, alert-error.
    • Styles: alert-soft (soft style), alert-outline (outline style).
    • Layout: alert-vertical (stacks icon above content). Use responsive modifiers like sm:alert-horizontal to change layout based on screen size.
    # Standard Colored Alert with Icon
    = daisy_alert(icon: "check-circle", css: "alert-success w-full max-w-100") do |alert|
        Success! You did it!
    
    # Soft Style Alert
    = daisy_alert(icon: "information-circle", css: "alert-info alert-soft") do
        Info alert.
    
    # Vertical Alert (Responsive)
    = daisy_alert(icon: "exclamation-triangle", css: "alert-warning alert-vertical sm:alert-horizontal") do
        This alert is vertical on small screens.
    
    # Custom HTML/Icon Content
    = daisy_alert do |alert|
        = loco_icon("star", css: "text-yellow-500")
        Custom icon alert!
  10. Implement selection fields and options

    Choose the appropriate Daisy component based on the selection requirement:

    • daisy_select: For dropdown menus; use option groups for better organization.
    • daisy_radio_button: For mutually exclusive choices.
    • daisy_checkbox: For allowing multiple selections. Always include a daisy_label to ensure accessibility.
  11. Create buttons with Daisy::Actions::ButtonComponent

    The daisy_button helper creates interactive buttons. It supports various styles via the css parameter (e.g., btn-primary, btn-secondary, btn-accent, btn-ghost, btn-link, btn-outline).
    = daisy_button do
      Plain Button
    
    = daisy_button(css: "btn-primary") do
      Primary Button
    
    = daisy_button(css: "btn-outline") do
      Outline Button