Skip to content

Commit

Permalink
Chart widget
Browse files Browse the repository at this point in the history
  • Loading branch information
danharrin committed Jan 30, 2025
1 parent c64d0af commit 6e54f06
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 19 deletions.
21 changes: 2 additions & 19 deletions packages/widgets/resources/views/chart-widget.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@php
use Filament\Support\Facades\FilamentView;
use Filament\Widgets\View\Components\Chart;
$color = $this->getColor();
$heading = $this->getHeading();
Expand Down Expand Up @@ -68,11 +69,7 @@ class="fi-wi-chart-filter"
type: @js($this->getType()),
})"
@class([
match ($color) {
'gray' => null,
default => 'fi-color',
},
is_string($color) ? "fi-color-{$color}" : null,
...\Filament\Support\get_component_color_classes(Chart::class, $color),
])
>
<canvas
Expand All @@ -85,25 +82,11 @@ class="fi-wi-chart-filter"
<span
x-ref="backgroundColorElement"
class="fi-wi-chart-bg-color"
@style([
\Filament\Support\get_color_css_variables(
$color,
shades: [50, 400],
alias: 'widgets::chart-widget.background',
) => $color !== 'gray',
])
></span>

<span
x-ref="borderColorElement"
class="fi-wi-chart-border-color"
@style([
\Filament\Support\get_color_css_variables(
$color,
shades: [400, 500],
alias: 'widgets::chart-widget.border',
) => $color !== 'gray',
])
></span>

<span
Expand Down
18 changes: 18 additions & 0 deletions packages/widgets/src/View/Components/Chart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Filament\Widgets\View\Components;

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

class Chart 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"
]
3 changes: 3 additions & 0 deletions tests/src/Support/ColorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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 Illuminate\Support\Str;

uses(TestCase::class);
Expand Down Expand Up @@ -58,9 +59,11 @@
->toMatchSnapshot();
})
->with([
// Support
'badge' => Badge::class,
'button' => new Button(isOutlined: false),
'outlined button' => new Button(isOutlined: true),
'chart widget' => Chart::class,
'dropdown header' => DropdownHeader::class,
'dropdown item icon' => DropdownItemIcon::class,
'dropdown item' => DropdownItem::class,
Expand Down

0 comments on commit 6e54f06

Please sign in to comment.