Skip to content

Commit

Permalink
Widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
danharrin committed Jan 30, 2025
1 parent 6e54f06 commit 8109e10
Show file tree
Hide file tree
Showing 28 changed files with 175 additions and 50 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.

Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@
& .fi-wi-stats-overview-stat-description {
@apply flex items-center gap-x-1 text-sm text-gray-500 dark:text-gray-400;

& .fi-icon {
@apply size-5 text-gray-400 dark:text-gray-500;
}

&.fi-color {
@apply text-color-600 dark:text-color-400;
@apply text-(--text) dark:text-(--dark-text);

& .fi-wi-stats-overview-stat-description-icon {
& .fi-icon {
@apply text-color-500;
}
}
}

& .fi-wi-stats-overview-stat-description-icon {
@apply size-5 text-gray-400 dark:text-gray-500;
}

& .fi-wi-stats-overview-stat-chart {
@apply absolute inset-x-0 bottom-0 overflow-hidden rounded-b-xl;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@
@endif
class="fi-section-header"
>
{{ \Filament\Support\generate_icon_html($icon, attributes: (new \Illuminate\View\ComponentAttributeBag)
{{
\Filament\Support\generate_icon_html($icon, attributes: (new \Illuminate\View\ComponentAttributeBag)
->class([
'fi-section-header-icon',
...\Filament\Support\get_component_color_classes(Icon::class, $iconColor),
($iconSize instanceof IconSize) ? "fi-size-{$iconSize->value}" : (is_string($iconSize) ? $iconSize : null),
])) }}
]))
}}

@if ($hasHeading || $hasDescription)
<div class="fi-section-header-text-ctn">
Expand Down
4 changes: 2 additions & 2 deletions packages/widgets/resources/views/chart-widget.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@php
use Filament\Support\Facades\FilamentView;
use Filament\Widgets\View\Components\Chart;
use Filament\Widgets\View\Components\ChartWidget;
$color = $this->getColor();
$heading = $this->getHeading();
Expand Down Expand Up @@ -69,7 +69,7 @@ class="fi-wi-chart-filter"
type: @js($this->getType()),
})"
@class([
...\Filament\Support\get_component_color_classes(Chart::class, $color),
...\Filament\Support\get_component_color_classes(ChartWidget::class, $color),
])
>
<canvas
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
@php
use Filament\Support\Enums\IconPosition;
use Filament\Support\Facades\FilamentView;
use Filament\Widgets\View\Components\StatsOverviewWidget\Stat\Description;
use Filament\Widgets\View\Components\StatsOverviewWidget\Stat\StatsOverviewWidgetStatChart;
$chartColor = $getChartColor() ?? 'gray';
$descriptionColor = $getDescriptionColor() ?? 'gray';
Expand All @@ -9,14 +11,6 @@
$url = $getUrl();
$tag = $url ? 'a' : 'div';
$chartDataChecksum = $generateChartDataChecksum();
$descriptionIconStyles = \Illuminate\Support\Arr::toCssStyles([
\Filament\Support\get_color_css_variables(
$descriptionColor,
shades: [500],
alias: 'widgets::stats-overview-widget.stat.description.icon',
) => $descriptionColor !== 'gray',
]);
@endphp

<{!! $tag !!}
Expand Down Expand Up @@ -47,30 +41,19 @@
<div
@class([
'fi-wi-stats-overview-stat-description',
match ($descriptionColor) {
'gray' => null,
default => 'fi-color',
},
is_string($descriptionColor) ? "fi-color-{$descriptionColor}" : null,
])
@style([
\Filament\Support\get_color_css_variables(
$descriptionColor,
shades: [400, 600],
alias: 'widgets::stats-overview-widget.stat.description',
) => $descriptionColor !== 'gray',
...\Filament\Support\get_component_color_classes(Description::class, $descriptionColor),
])
>
@if ($descriptionIcon && in_array($descriptionIconPosition, [IconPosition::Before, 'before']))
{{ \Filament\Support\generate_icon_html($descriptionIcon, attributes: (new \Illuminate\View\ComponentAttributeBag)->class(['fi-wi-stats-overview-stat-description-icon'])->style([$descriptionIconStyles])) }}
{{ \Filament\Support\generate_icon_html($descriptionIcon, attributes: (new \Illuminate\View\ComponentAttributeBag)) }}
@endif

<span>
{{ $description }}
</span>

@if ($descriptionIcon && in_array($descriptionIconPosition, [IconPosition::After, 'after']))
{{ \Filament\Support\generate_icon_html($descriptionIcon, attributes: (new \Illuminate\View\ComponentAttributeBag)->class(['fi-wi-stats-overview-stat-description-icon'])->style([$descriptionIconStyles])) }}
{{ \Filament\Support\generate_icon_html($descriptionIcon, attributes: (new \Illuminate\View\ComponentAttributeBag)) }}
@endif
</div>
@endif
Expand All @@ -93,18 +76,7 @@
})"
@class([
'fi-wi-stats-overview-stat-chart',
match ($chartColor) {
'gray' => null,
default => 'fi-color',
},
is_string($chartColor) ? "fi-color-{$chartColor}" : null,
])
@style([
\Filament\Support\get_color_css_variables(
$chartColor,
shades: [50, 400, 500],
alias: 'widgets::stats-overview-widget.stat.chart',
) => $chartColor !== 'gray',
...\Filament\Support\get_component_color_classes(StatsOverviewWidgetStatChart::class, $chartColor),
])
>
<canvas x-ref="canvas"></canvas>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Filament\Support\View\Components\Contracts\HasColor;
use Filament\Support\View\Components\Contracts\HasDefaultGrayColor;

class Chart implements HasColor, HasDefaultGrayColor
class ChartWidget implements HasColor, HasDefaultGrayColor
{
/**
* @param array<int, string> $color
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Filament\Widgets\View\Components\StatsOverviewWidget\Stat;

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 Description 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,18 @@
<?php

namespace Filament\Widgets\View\Components\StatsOverviewWidget\Stat;

use Filament\Support\View\Components\Contracts\HasColor;
use Filament\Support\View\Components\Contracts\HasDefaultGrayColor;

class StatsOverviewWidgetStatChart implements HasColor, HasDefaultGrayColor
{
/**
* @param array<int, string> $color
* @return array<string>
*/
public function getColorClasses(array $color): array
{
return [];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
"fi-color",
"fi-color-danger"
]
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,4 @@
[
"fi-color",
"fi-color-info"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
"fi-color",
"fi-color-primary"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
"fi-color",
"fi-color-success"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
"fi-color",
"fi-color-warning"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
"fi-color",
"fi-color-danger"
]
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,4 @@
[
"fi-color",
"fi-color-info"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
"fi-color",
"fi-color-primary"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
"fi-color",
"fi-color-success"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
"fi-color",
"fi-color-warning"
]
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"
]
9 changes: 6 additions & 3 deletions tests/src/Support/ColorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
use Filament\Support\View\Components\Section\Icon as SectionIcon;
use Filament\Support\View\Components\Toggle;
use Filament\Tests\TestCase;
use Filament\Widgets\View\Components\Chart;
use Filament\Widgets\View\Components\ChartWidget;
use Filament\Widgets\View\Components\StatsOverviewWidget\Stat\Description as StatsOverviewWidgetStatDescription;
use Filament\Widgets\View\Components\StatsOverviewWidget\Stat\StatsOverviewWidgetStatChart;
use Illuminate\Support\Str;

uses(TestCase::class);
Expand Down Expand Up @@ -59,11 +61,10 @@
->toMatchSnapshot();
})
->with([
// Support
'badge' => Badge::class,
'button' => new Button(isOutlined: false),
'outlined button' => new Button(isOutlined: true),
'chart widget' => Chart::class,
'chart widget' => ChartWidget::class,
'dropdown header' => DropdownHeader::class,
'dropdown item icon' => DropdownItemIcon::class,
'dropdown item' => DropdownItem::class,
Expand All @@ -72,6 +73,8 @@
'link' => Link::class,
'modal icon' => ModalIcon::class,
'section icon' => SectionIcon::class,
'stats overview widget stat description' => StatsOverviewWidgetStatDescription::class,
'stats overview widget stat chart' => StatsOverviewWidgetStatChart::class,
'toggle' => Toggle::class,
])
->with(fn (): array => array_keys(app(ColorManager::class)->getColors()));

0 comments on commit 8109e10

Please sign in to comment.