Skip to content

Commit

Permalink
Update styleguide to group colors together
Browse files Browse the repository at this point in the history
  • Loading branch information
danon committed Dec 13, 2024
1 parent e22c2ca commit 1c86da0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
2 changes: 1 addition & 1 deletion app/Feature/LookAndFeel/LookAndFeelServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function boot(): void
Route::middleware(['web', 'auth'])->group(function () {
Route::get('/LookAndFeel/StyleGuide', function (StyleGuide $guide, StyleGuideView $view) {
if ($this->userSetting() === 'modern') {
return $view->view($guide->getColors());
return $view->view($guide->getColorGroups());
}
return response(status:404);
});
Expand Down
14 changes: 10 additions & 4 deletions app/Feature/LookAndFeel/StyleGuide.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

class StyleGuide
{
public function getColors(): array
public function getColorGroups(): array
{
$content = file_get_contents('../resources/feature/lookAndFeel/style-guide.scss');
$colors = [];
$groups = [];
$lines = \explode("\n", $content);
foreach ($lines as $line) {
if (empty(\trim($line))) {
Expand All @@ -19,8 +19,14 @@ public function getColors(): array
if ($value === 'white') {
$value = '#ffffff';
}
$colors[$key] = \trim($value);
$exploded = \explode('-', $key);
if (count($exploded) === 1) {
[$group, $groupValue] = [$exploded[0], $exploded[0]];
} else {
[$group, $groupValue] = $exploded;
}
$groups[$group][$groupValue] = \trim($value);
}
return $colors;
return $groups;
}
}
30 changes: 16 additions & 14 deletions app/Feature/LookAndFeel/StyleGuideView.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,34 @@

class StyleGuideView
{
public function view(array $colors): string
public function view(array $colorGroups): string
{
return Blade::render('
<style>
body { background: #e0e0e0; }
.color-preview {
min-width: 90px;
height: 80px;
min-width: 60px;
height: 40px;
}
code {
background:#d0d0d0;
padding:1px 5px;
border-radius:4px;
}
</style>
<h2 style="font-family:sans-serif;">4programmers - Style guide</h2>
<div style="display:flex; flex-wrap:wrap;">
@foreach ($colors as $colorName => $colorValue)
<div style="padding: 32px 24px; border: 1px solid #d0d0d0; text-align:center;">
<div class="color-preview" style="background:{{$colorValue}}"></div>
<p><code>{{$colorName}}</code></p>
<code>{{$colorValue}}</code>
</div>
@endforeach
</div>
<h2 style="font-family:sans-serif;">4programmers - Primitive colors</h2>
@foreach ($colorGroups as $colors)
<div style="display:flex; flex-wrap:wrap;">
@foreach ($colors as $colorName => $colorValue)
<div style="padding: 24px 16px; border: 1px solid #d0d0d0; text-align:center;">
<div class="color-preview" style="background:{{$colorValue}}"></div>
<p><code>{{$colorName}}</code></p>
<code>{{$colorValue}}</code>
</div>
@endforeach
</div>
@endforeach
',
['colors' => $colors]);
['colorGroups' => $colorGroups]);
}
}

0 comments on commit 1c86da0

Please sign in to comment.