Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create menu item component #285

Merged
merged 4 commits into from
Feb 7, 2025
Merged

feat: create menu item component #285

merged 4 commits into from
Feb 7, 2025

Conversation

ADchasacademy
Copy link
Contributor

Reusable Blade Component: <x-menu-item>

Overview

This Blade component defines custom link variants within a menu, supporting different styles: default, highlights, and destructive.

Features

  • Provides a structured way to create styled menu items.
  • Uses Tailwind CSS for styling.
  • Supports three visual variants: default, highlights, and destructive.
  • Hover support for mouse users.
  • Focus support for touch users, ensuring accessibility and visual feedback on both desktop and mobile devices.

Implementation

{{--
    A reusable Blade component for defining custom link variants within a menu.
    Supports "default," "highlights," and "destructive" styles.
--}}

@props([
    'label',
    'variant' => 'default',
    'href' => '#',
])

@php
    $baseClasses = 'block rounded-lg px-4 py-2 text-center transition-all duration-200 ease-out';
    $hoverClasses = 'cursor-pointer hover:bg-slate-600 focus:bg-slate-600 focus:outline-0';

    $variantClasses = match ($variant) {
        'highlights' => 'font-bold text-indigo-400',
        'destructive' => 'text-red-400',
        default => 'text-slate-200',
    };
@endphp

<a
    href="{{ $href }}"
    {{ $attributes->merge(['class' => "$baseClasses $variantClasses $hoverClasses"]) }}
>
    {{ $label }}
</a>

Example Usage

<nav>
    <ul class="flex flex-col">
        <li><x-menu-item href="/" label="Edit" /></li>
        <li><x-menu-item href="/" label="Change visibility" /></li>
        <li><x-menu-item href="/" label="Delete" variant="destructive" /></li>
        <li><x-menu-item label="Cancel" variant="highlights" /></li>
    </ul>
</nav>

Image from Gyazo

closes #60

beforeAW
beforeAW previously approved these changes Feb 6, 2025
Copy link
Contributor

@beforeAW beforeAW left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

resources/views/components/menu-item/index.blade.php Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this component will need to support being both a link and a button because it will also open other modals and for that a button with an @click is needed! if you want some inspiration you can check how i did it with the button component

resources/views/components/menu-item/index.blade.php Outdated Show resolved Hide resolved
resources/views/components/menu-item/index.blade.php Outdated Show resolved Hide resolved
@beforeAW beforeAW dismissed their stale review February 6, 2025 14:02

Saw the comments

@ell-ska ell-ska temporarily deployed to issue_60 - u04-imdb-clone PR #285 February 7, 2025 14:17 — with Render Destroyed
Copy link
Contributor

@ell-ska ell-ska left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great!

@ADchasacademy ADchasacademy merged commit 7d58725 into main Feb 7, 2025
1 check passed
@ADchasacademy ADchasacademy deleted the issue_60 branch February 7, 2025 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

create menu item component
4 participants