Instructions:
Craft the prompt to generate a well-structured and effective Laravel Blade Media Card Anonymous UI Components styled with Tailwind CSS, and Alpine.js integrated for reactive JavaScript components
Context:
Media Card: For showcasing multimedia content like videos or audio.
code
Media Preview: Thumbnail or actual media player.
Title: Name of the video or track.
Description: Media description or summary.
Assumptions:
Development environment already setup.
Laravel framework installed and properly configured.
Tailwind CSS installed and properly configured in your Laravel project.
Alpine JS installed and properly configured in your Laravel project.
Constraints and Requirements:
Single File: The Anonymous UI Components must be reusable and contained in a single file
Styling: The Tailwind CSS styling, and Alpine.js must be inline
Color Scheme: Consistent with brand identity (e.g., primary and secondary colors)
Responsive Design: Ensure all sections and components are mobile-friendly
Efficient Design: Ensure all sections and components are robust, responsive, reusable, highly maintainable, efficient, and dynamic Blade components in Laravel, incorporating best practices and leveraging the full potential of Tailwind CSS and Alpine.js
Animations: Subtle animations (e.g., fade-ins, hover effects) to enhance user engagement without overwhelming the user
Best Practices: Adhere to industry best practices, coding standards and production-ready
Assistant
Certainly! Below is a well-structured and reusable Laravel Blade component for a Media Card. This component leverages Tailwind CSS for styling and Alpine.js for interactivity, all contained within a single Blade file. It adheres to the specified constraints and requirements, ensuring responsiveness, efficient design, and adherence to best practices.
Media Card Blade Component (resources/views/components/media-card.blade.php)
blade
@props([
'mediaUrl', // URL of the media (image, video, audio)
'title', // Title of the media
'description', // Description of the media
'mediaType' => 'image', // Type of media: 'image', 'video', 'audio'
])
<div
x-data="{ isHovered: false, isPlaying: false }"
class="max-w-sm rounded overflow-hidden shadow-lg bg-white dark:bg-gray-800 transition-transform transform hover:scale-105"
@mouseenter="isHovered = true"
@mouseleave="isHovered = false"
>
<!-- Media Preview -->
<div class="relative">
@if ($mediaType === 'image')
<img
class="w-full h-48 object-cover"
src="{{ $mediaUrl }}"
alt="{{ $title }}"
>
@elseif ($mediaType === 'video')
<video
class="w-full h-48 object-cover"
src="{{ $mediaUrl }}"
@click="isPlaying = !isPlaying"
x-show="!isPlaying"
x-transition.opacity.duration.500
poster="{{ $mediaUrl }}#t=0.5"
>
Your browser does not support the video tag.
</video>
@elseif ($mediaType === 'audio')
<div class="w-full h-48 flex items-center justify-center bg-gray-200 dark:bg-gray-700">
<audio controls class="w-11/12">
<source src="{{ $mediaUrl }}" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
</div>
@endif
<!-- Play Button for Video -->
@if ($mediaType === 'video')
<button
x-show="!isPlaying"
@click="isPlaying = true"
class="absolute inset-0 flex items-center justify-center bg-black bg-opacity-50 text-white text-4xl hover:bg-opacity-70 transition"
aria-label="Play Video"
>
▶
</button>
@endif
</div>
<!-- Content -->
<div class="px-6 py-4">
<div class="font-bold text-xl mb-2 text-gray-900 dark:text-white transition-colors">
{{ $title }}
</div>
<p class="text-gray-700 dark:text-gray-300 text-base transition-colors">
{{ $description }}
</p>
</div>
<!-- Hover Effects -->
<div
x-show="isHovered"
class="px-6 pt-4 pb-2 bg-gray-100 dark:bg-gray-700 transition-opacity duration-300"
x-transition
>
<a href="#" class="text-indigo-600 dark:text-indigo-400 hover:underline">Learn More</a>
</div>
</div>
Usage Example
You can utilize this component anywhere in your Blade templates as follows:
blade
<x-media-card
mediaUrl="https://example.com/path-to-media.jpg"
title="Amazing Landscape"
description="A beautiful view of the mountains during sunset."
mediaType="image"
/>
<x-media-card
mediaUrl="https://example.com/path-to-video.mp4"
title="Inspiring Video"
description="An inspiring video about nature."
mediaType="video"
/>
<x-media-card
mediaUrl="https://example.com/path-to-audio.mp3"
title="Relaxing Music"
description="Soothing tunes to help you relax."
mediaType="audio"
/>
Key Features & Compliance with Requirements
Single File Component: The entire component is encapsulated within a single Blade file, making it highly reusable across your Laravel project.
Tailwind CSS Styling: Utilizes Tailwind CSS classes for styling, ensuring a consistent and responsive design. The component adapts to light and dark modes using dark: variants.
Alpine.js Integration: Incorporates Alpine.js for interactive elements such as hover effects and video play controls. The x-data, x-show, and transition directives handle the reactive behavior seamlessly.
Responsive Design: The component is designed to be mobile-friendly, with flexible width and scalable elements ensuring optimal display across various screen sizes.
Color Scheme: Adjusts automatically to light and dark themes, maintaining consistency with the brand identity. You can further customize the colors by modifying the Tailwind classes.
Animations & Transitions: Implements subtle animations like scaling on hover, fade-ins, and transition effects to enhance user engagement without being intrusive.
Accessibility: Includes aria-label for the play button to improve accessibility for screen readers.
Best Practices:
Reusability: Accepts parameters (mediaUrl, title, description, mediaType) to accommodate different media types and content dynamically.
Maintainability: Clear separation of concerns with HTML structure, Tailwind classes, and Alpine.js logic.
Efficiency: Minimal dependencies and optimized asset loading ensure efficient performance.
Customization Tips
Color Scheme: Adjust the Tailwind CSS classes to match your specific brand colors. For example, replace bg-white and dark:bg-gray-800 with your primary and secondary colors.
Animations: Modify the transition durations and effects to better suit your design preferences. Tailwind provides extensive utilities for customizing animations.
Media Types: Extend support for additional media types by adding conditional blocks based on the mediaType prop.
Final Notes
Ensure that your Laravel project has Tailwind CSS and Alpine.js properly installed and configured. This component leverages the latest versions (Tailwind CSS 3.x and Alpine.js 3.x) as specified. You can further enhance this component by integrating additional features such as lazy loading for media, dynamic routing for the "Learn More" link, or incorporating Blade directives for conditionally displaying content.
By following this structure and utilizing the provided code, you'll have a robust, efficient, and aesthetically pleasing Media Card component ready for production use in your Laravel applications.