Skip to content

Commit d15fe3f

Browse files
committed
[AIDAPP-418]: Show color name with preview of color in dropdown when configuring a service request type color
Signed-off-by: Dan Harrin <[email protected]>
1 parent 53c8223 commit d15fe3f

File tree

3 files changed

+177
-0
lines changed

3 files changed

+177
-0
lines changed

src/CommonServiceProvider.php

+25
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
namespace CanyonGBS\Common;
3838

39+
use Filament\Support\Colors\Color;
40+
use Filament\Support\Facades\FilamentColor;
3941
use Spatie\LaravelPackageTools\Package;
4042
use Spatie\LaravelPackageTools\PackageServiceProvider;
4143

@@ -47,4 +49,27 @@ public function configurePackage(Package $package): void
4749
->name('common')
4850
->hasViews();
4951
}
52+
53+
public function packageBooted(): void
54+
{
55+
FilamentColor::register([
56+
'red' => Color::Red,
57+
'orange' => Color::Orange,
58+
'amber' => Color::Amber,
59+
'yellow' => Color::Yellow,
60+
'lime' => Color::Lime,
61+
'green' => Color::Green,
62+
'emerald' => Color::Emerald,
63+
'teal' => Color::Teal,
64+
'cyan' => Color::Cyan,
65+
'sky' => Color::Sky,
66+
'blue' => Color::Blue,
67+
'indigo' => Color::Indigo,
68+
'violet' => Color::Violet,
69+
'purple' => Color::Purple,
70+
'fuchsia' => Color::Fuchsia,
71+
'pink' => Color::Pink,
72+
'rose' => Color::Rose,
73+
]);
74+
}
5075
}

src/Enums/Color.php

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
3+
/*
4+
<COPYRIGHT>
5+
6+
Copyright © 2016-2025, Canyon GBS LLC. All rights reserved.
7+
8+
Canyon GBS Common is licensed under the Elastic License 2.0. For more details,
9+
see https://github.com/canyongbs/common/blob/main/LICENSE.
10+
11+
Notice:
12+
13+
- You may not provide the software to third parties as a hosted or managed
14+
service, where the service provides users with access to any substantial set of
15+
the features or functionality of the software.
16+
- You may not move, change, disable, or circumvent the license key functionality
17+
in the software, and you may not remove or obscure any functionality in the
18+
software that is protected by the license key.
19+
- You may not alter, remove, or obscure any licensing, copyright, or other notices
20+
of the licensor in the software. Any use of the licensor’s trademarks is subject
21+
to applicable law.
22+
- Canyon GBS LLC respects the intellectual property rights of others and expects the
23+
same in return. Canyon GBS™ and Canyon GBS Common are registered trademarks of
24+
Canyon GBS LLC, and we are committed to enforcing and protecting our trademarks
25+
vigorously.
26+
- The software solution, including services, infrastructure, and code, is offered as a
27+
Software as a Service (SaaS) by Canyon GBS LLC.
28+
- Use of this software implies agreement to the license terms and conditions as stated
29+
in the Elastic License 2.0.
30+
31+
For more information or inquiries please visit our website at
32+
https://www.canyongbs.com or contact us via email at [email protected].
33+
34+
</COPYRIGHT>
35+
*/
36+
37+
namespace CanyonGBS\Common\Enums;
38+
39+
use Filament\Support\Contracts\HasLabel;
40+
use Filament\Support\Facades\FilamentColor;
41+
42+
enum Color: string implements HasLabel
43+
{
44+
case Gray = 'gray';
45+
46+
case Red = 'red';
47+
48+
case Orange = 'orange';
49+
50+
case Amber = 'amber';
51+
52+
case Yellow = 'yellow';
53+
54+
case Lime = 'lime';
55+
56+
case Green = 'green';
57+
58+
case Emerald = 'emerald';
59+
60+
case Teal = 'teal';
61+
62+
case Cyan = 'cyan';
63+
64+
case Sky = 'sky';
65+
66+
case Blue = 'blue';
67+
68+
case Indigo = 'indigo';
69+
70+
case Violet = 'violet';
71+
72+
case Purple = 'purple';
73+
74+
case Fuchsia = 'fuchsia';
75+
76+
case Pink = 'pink';
77+
78+
case Rose = 'rose';
79+
80+
public function getLabel(): string
81+
{
82+
return $this->name;
83+
}
84+
85+
public function getRgb(): string
86+
{
87+
$color = FilamentColor::getColors()[$this->value][500];
88+
89+
return "rgb({$color})";
90+
}
91+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
/*
4+
<COPYRIGHT>
5+
6+
Copyright © 2016-2025, Canyon GBS LLC. All rights reserved.
7+
8+
Canyon GBS Common is licensed under the Elastic License 2.0. For more details,
9+
see https://github.com/canyongbs/common/blob/main/LICENSE.
10+
11+
Notice:
12+
13+
- You may not provide the software to third parties as a hosted or managed
14+
service, where the service provides users with access to any substantial set of
15+
the features or functionality of the software.
16+
- You may not move, change, disable, or circumvent the license key functionality
17+
in the software, and you may not remove or obscure any functionality in the
18+
software that is protected by the license key.
19+
- You may not alter, remove, or obscure any licensing, copyright, or other notices
20+
of the licensor in the software. Any use of the licensor’s trademarks is subject
21+
to applicable law.
22+
- Canyon GBS LLC respects the intellectual property rights of others and expects the
23+
same in return. Canyon GBS™ and Canyon GBS Common are registered trademarks of
24+
Canyon GBS LLC, and we are committed to enforcing and protecting our trademarks
25+
vigorously.
26+
- The software solution, including services, infrastructure, and code, is offered as a
27+
Software as a Service (SaaS) by Canyon GBS LLC.
28+
- Use of this software implies agreement to the license terms and conditions as stated
29+
in the Elastic License 2.0.
30+
31+
For more information or inquiries please visit our website at
32+
https://www.canyongbs.com or contact us via email at [email protected].
33+
34+
</COPYRIGHT>
35+
*/
36+
37+
namespace CanyonGBS\Common\Filament\Forms\Components;
38+
39+
use CanyonGBS\Common\Enums\Color;
40+
use Filament\Forms\Components\Select;
41+
42+
class ColorSelect
43+
{
44+
public static function make(string $name = 'color'): Select
45+
{
46+
return Select::make($name)
47+
->allowHtml()
48+
->native(false)
49+
->options(collect(Color::cases())
50+
->mapWithKeys(fn (Color $color): array => [
51+
$color->value => <<<HTML
52+
<div style="display: flex; align-items: center; gap: 0.5rem">
53+
<div style="display: block; height: 1.25rem; width: 1.25rem; border-radius: 100%; background: {$color->getRgb()}"></div>
54+
<span>{$color->getLabel()}</span>
55+
</div>
56+
HTML,
57+
])
58+
->all())
59+
->enum(Color::class);
60+
}
61+
}

0 commit comments

Comments
 (0)