Skip to content

Commit

Permalink
Dropdown header
Browse files Browse the repository at this point in the history
  • Loading branch information
danharrin committed Jan 30, 2025
1 parent dc432f7 commit ec79d6c
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 27 deletions.
2 changes: 1 addition & 1 deletion docs-assets/app/public/css/filament/support/support.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/support/dist/index.css

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/support/resources/css/components/dropdown/header.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.fi-dropdown-header {
@apply flex w-full gap-2 p-3 text-sm;
@apply flex font-medium w-full gap-2 p-3 text-sm;

& .fi-icon {
@apply size-5 text-gray-400 dark:text-gray-500;
Expand All @@ -23,7 +23,7 @@
}

& span {
@apply text-color-600 dark:text-color-400;
@apply text-(--text) dark:text-(--dark-text);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@php
use Filament\Support\Enums\IconSize;
use Filament\Support\View\Components\Dropdown\Header;
use Illuminate\View\ComponentAttributeBag;
@endphp

Expand All @@ -21,37 +22,18 @@
$attributes
->class([
'fi-dropdown-header',
match ($color) {
'gray' => '',
default => 'fi-color',
},
is_string($color) ? "fi-color-{$color}" : null,
])
->color(Header::class, $color)
}}
>
{{
\Filament\Support\generate_icon_html($icon, attributes: (new ComponentAttributeBag)
->class([
($iconSize instanceof IconSize) ? "fi-size-{$iconSize->value}" : (is_string($iconSize) ? $iconSize : null),
])
->style([
\Filament\Support\get_color_css_variables(
$color,
shades: [400, 500],
alias: 'dropdown.header.icon',
) => $color !== 'gray',
]))
}}

<span
@style([
\Filament\Support\get_color_css_variables(
$color,
shades: [400, 600],
alias: 'dropdown.header.label',
) => $color !== 'gray',
])
>
<span>
{{ $slot }}
</span>
</{{ $tag }}>
57 changes: 57 additions & 0 deletions packages/support/src/View/Components/Dropdown/Header.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Filament\Support\View\Components\Dropdown;

use Filament\Support\Colors\Color;
use Filament\Support\Facades\FilamentColor;
use Filament\Support\View\Components\Contracts\HasColor;
use Filament\Support\View\Components\Contracts\HasDefaultGrayColor;

class Header implements HasColor, HasDefaultGrayColor
{
/**
* @param array<int, string> $color
* @return array<string>
*/
public function getColorClasses(array $color): array
{
$gray = FilamentColor::getColor('gray');

ksort($color);

foreach (array_keys($color) as $shade) {
if ($shade < 600) {
continue;
}

if (Color::isTextContrastRatioAccessible('oklch(1 0 0)', $color[$shade])) {
$text = $shade;

break;
}
}

$text ??= 950;

krsort($color);

foreach (array_keys($color) as $shade) {
if ($shade > 400) {
continue;
}

if (Color::isTextContrastRatioAccessible($gray[900], $color[$shade])) {
$darkText = $shade;

break;
}
}

$darkText ??= 200;

return [
"fi-text-color-{$text}",
"dark:fi-text-color-{$darkText}",
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
"fi-color",
"fi-color-danger",
"fi-text-color-600",
"dark:fi-text-color-400"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
"fi-color",
"fi-color-info",
"fi-text-color-600",
"dark:fi-text-color-400"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
"fi-color",
"fi-color-primary",
"fi-text-color-700",
"dark:fi-text-color-400"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
"fi-color",
"fi-color-success",
"fi-text-color-700",
"dark:fi-text-color-400"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
"fi-color",
"fi-color-warning",
"fi-text-color-700",
"dark:fi-text-color-400"
]
6 changes: 4 additions & 2 deletions tests/src/Support/ColorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Filament\Support\View\Components\Badge;
use Filament\Support\View\Components\Button;
use Filament\Support\View\Components\Contracts\HasColor;
use Filament\Support\View\Components\Dropdown\Header as DropdownHeader;
use Filament\Support\View\Components\Dropdown\Item as DropdownItem;
use Filament\Support\View\Components\Dropdown\Item\Icon as DropdownItemIcon;
use Filament\Support\View\Components\IconButton;
Expand Down Expand Up @@ -53,11 +54,12 @@
->toMatchSnapshot();
})
->with([
'dropdown item icon' => DropdownItemIcon::class,
'dropdown item' => DropdownItem::class,
'badge' => Badge::class,
'button' => new Button(isOutlined: false),
'outlined button' => new Button(isOutlined: true),
'dropdown header' => DropdownHeader::class,
'dropdown item icon' => DropdownItemIcon::class,
'dropdown item' => DropdownItem::class,
'icon button' => IconButton::class,
'link' => Link::class,
])
Expand Down

0 comments on commit ec79d6c

Please sign in to comment.