From 827ca03f61cb6d9bc7ce541d9c65ed009bda54f8 Mon Sep 17 00:00:00 2001 From: Yassine Doghri Date: Tue, 7 Dec 2021 13:46:08 +0000 Subject: [PATCH] refactor(color-themes): set themes declaration as a config property + generate css file dynamically --- app/Config/Colors.php | 150 +++++++++++++++++++++++ app/Config/Routes.php | 3 + app/Controllers/ColorsController.php | 47 +++++++ app/Resources/styles/index.css | 1 - app/Resources/styles/themes.css | 139 --------------------- app/Views/errors/html/error_404.php | 4 +- app/Views/errors/html/production.php | 4 +- themes/cp_admin/_layout.php | 1 + themes/cp_admin/episode/_card.php | 2 +- themes/cp_admin/episode/list.php | 2 +- themes/cp_admin/settings/theme.php | 9 +- themes/cp_app/embed.php | 1 + themes/cp_app/episode/_layout.php | 3 +- themes/cp_app/episode/_partials/card.php | 2 +- themes/cp_app/home.php | 1 + themes/cp_app/pages/_layout.php | 1 + themes/cp_app/pages/map.php | 1 + themes/cp_app/podcast/_layout.php | 1 + themes/cp_app/podcast/about.php | 2 +- themes/cp_app/podcast/follow.php | 1 + themes/cp_app/post/remote_action.php | 1 + 21 files changed, 225 insertions(+), 151 deletions(-) create mode 100644 app/Config/Colors.php create mode 100644 app/Controllers/ColorsController.php delete mode 100644 app/Resources/styles/themes.css diff --git a/app/Config/Colors.php b/app/Config/Colors.php new file mode 100644 index 00000000..83ac145e --- /dev/null +++ b/app/Config/Colors.php @@ -0,0 +1,150 @@ +> + */ + public array $themes = [ + /* Castopod's brand color */ + 'pine' => [ + 'accent-base' => [174, 100, 29], + 'accent-hover' => [172, 100, 17], + 'accent-muted' => [131, 100, 12], + 'accent-contrast' => [0, 0, 100], + + 'heading-foreground' => [172, 100, 17], + 'heading-background' => [111, 64, 94], + + 'background-elevated' => [0, 0, 100], + 'background-base' => [173, 44, 96], + 'background-navigation' => [172, 100, 17], + 'background-header' => [172, 100, 17], + 'background-highlight' => [111, 64, 94], + 'background-backdrop' => [0, 0, 50], + + 'border-subtle' => [111, 42, 86], + 'border-contrast' => [0, 0, 0], + 'border-navigation' => [131, 100, 12], + + 'text-base' => [158, 8, 3], + 'text-muted' => [172, 8, 38], + ], + /* Red / Rose color */ + 'crimson' => [ + 'accent-base' => [350, 87, 61], + 'accent-hover' => [348, 75, 40], + 'accent-muted' => [348, 73, 32], + 'accent-contrast' => [0, 0, 100], + + 'heading-foreground' => [348, 73, 32], + 'heading-background' => [344, 79, 96], + + 'background-elevated' => [0, 0, 100], + 'background-base' => [350, 44, 96], + 'background-header' => [348, 75, 40], + 'background-highlight' => [344, 79, 96], + 'background-backdrop' => [0, 0, 50], + + 'border-subtle' => [348, 42, 86], + 'border-contrast' => [0, 0, 0], + + 'text-base' => [340, 8, 3], + 'text-muted' => [345, 8, 38], + ], + /* Blue color */ + 'lake' => [ + 'accent-base' => [194, 100, 44], + 'accent-hover' => [194, 100, 22], + 'accent-muted' => [195, 100, 11], + 'accent-contrast' => [0, 0, 100], + + 'heading-foreground' => [194, 100, 22], + 'heading-background' => [195, 100, 92], + + 'background-elevated' => [0, 0, 100], + 'background-base' => [196, 44, 96], + 'background-header' => [194, 100, 22], + 'background-highlight' => [195, 100, 92], + 'background-backdrop' => [0, 0, 50], + + 'border-subtle' => [195, 42, 86], + 'border-contrast' => [0, 0, 0], + + 'text-base' => [194, 8, 3], + 'text-muted' => [195, 8, 38], + ], + /* Orange color */ + 'amber' => [ + 'accent-base' => [17, 100, 57], + 'accent-hover' => [17, 100, 35], + 'accent-muted' => [17, 100, 24], + 'accent-contrast' => [0, 0, 100], + + 'heading-foreground' => [17, 100, 35], + 'heading-background' => [17, 100, 89], + + 'background-elevated' => [0, 0, 100], + 'background-base' => [15, 44, 96], + 'background-header' => [17, 100, 35], + 'background-highlight' => [17, 100, 89], + 'background-backdrop' => [0, 0, 50], + + 'border-subtle' => [17, 42, 86], + 'border-contrast' => [0, 0, 0], + + 'text-base' => [15, 8, 3], + 'text-muted' => [17, 8, 38], + ], + /* Violet color */ + 'jacaranda' => [ + 'accent-base' => [254, 72, 52], + 'accent-hover' => [254, 73, 30], + 'accent-muted' => [254, 71, 19], + 'accent-contrast' => [0, 0, 100], + + 'heading-foreground' => [254, 73, 30], + 'heading-background' => [254, 73, 84], + + 'background-elevated' => [0, 0, 100], + 'background-base' => [253, 44, 96], + 'background-header' => [254, 73, 30], + 'background-highlight' => [254, 88, 91], + 'background-backdrop' => [0, 0, 50], + + 'border-subtle' => [254, 42, 86], + 'border-contrast' => [0, 0, 0], + + 'text-base' => [253, 8, 3], + 'text-muted' => [254, 8, 38], + ], + /* Black color */ + 'onyx' => [ + 'accent-base' => [240, 17, 2], + 'accent-hover' => [240, 17, 17], + 'accent-muted' => [240, 17, 17], + 'accent-contrast' => [0, 0, 100], + + 'heading-foreground' => [240, 17, 17], + 'heading-background' => [240, 17, 94], + + 'background-elevated' => [0, 0, 100], + 'background-base' => [240, 17, 96], + 'background-header' => [240, 12, 17], + 'background-highlight' => [240, 17, 94], + 'background-backdrop' => [0, 0, 50], + + 'border-subtle' => [240, 17, 86], + 'border-contrast' => [0, 0, 0], + + 'text-base' => [240, 8, 3], + 'text-muted' => [240, 8, 38], + ], + ]; +} diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 27fe9fa9..077a76ae 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -51,6 +51,9 @@ $routes->addPlaceholder( $routes->get('manifest.webmanifest', 'WebmanifestController', [ 'as' => 'webmanifest', ]); +$routes->get('styles/themes.css', 'ColorsController', [ + 'as' => 'color-themes-css', +]); // We get a performance increase by specifying the default // route since we don't have to scan directories. diff --git a/app/Controllers/ColorsController.php b/app/Controllers/ColorsController.php new file mode 100644 index 00000000..62955eda --- /dev/null +++ b/app/Controllers/ColorsController.php @@ -0,0 +1,47 @@ +themes; + + $colorsCssBody = ''; + foreach ($colorThemes as $name => $color) { + $colorsCssBody .= ".theme-{$name} {"; + foreach ($color as $variable => $value) { + $colorsCssBody .= "--color-{$variable}: {$value[0]} {$value[1]}% {$value[2]}%;"; + } + $colorsCssBody .= '}'; + } + + cache() + ->save($cacheName, $colorsCssBody, DECADE); + } + + return $this->response->setHeader('Content-Type', 'text/css') + ->setHeader('charset', 'UTF-8') + ->setBody($colorsCssBody); + } +} diff --git a/app/Resources/styles/index.css b/app/Resources/styles/index.css index 62c82209..3af00d80 100644 --- a/app/Resources/styles/index.css +++ b/app/Resources/styles/index.css @@ -2,7 +2,6 @@ @import "./custom.css"; @import "./fonts.css"; @import "./colors.css"; -@import "./themes.css"; @import "./breadcrumb.css"; @import "./dropdown.css"; @import "./choices.css"; diff --git a/app/Resources/styles/themes.css b/app/Resources/styles/themes.css deleted file mode 100644 index 2df7654a..00000000 --- a/app/Resources/styles/themes.css +++ /dev/null @@ -1,139 +0,0 @@ -/* Castopod's brand color */ -.theme-pine { - --color-accent-base: 174 100% 29%; - --color-accent-hover: 172 100% 17%; - --color-accent-muted: 131 100% 12%; - --color-accent-contrast: 0 0% 100%; - - --color-heading-foreground: 172 100% 17%; - --color-heading-background: 111 64% 94%; - - --color-background-elevated: 0 0% 100%; - --color-background-base: 173 44% 96%; - --color-background-navigation: 172 100% 17%; - --color-background-header: 172 100% 17%; - --color-background-highlight: 111 64% 94%; - --color-background-backdrop: 0 0% 50%; - - --color-border-subtle: 111 42% 86%; - --color-border-contrast: 0 0% 0%; - --color-border-navigation: 131 100% 12%; - - --color-text-base: 158 8% 3%; - --color-text-muted: 172 8% 38%; -} - -/* Red / Rose color */ -.theme-crimson { - --color-accent-base: 350 87% 61%; - --color-accent-hover: 348 75% 40%; - --color-accent-muted: 348 73% 32%; - --color-accent-contrast: 0 0% 100%; - - --color-heading-foreground: 348 73% 32%; - --color-heading-background: 344 79% 96%; - - --color-background-elevated: 0 0% 100%; - --color-background-base: 350 44% 96%; - --color-background-header: 348 75% 40%; - --color-background-highlight: 344 79% 96%; - --color-background-backdrop: 0 0% 50%; - - --color-border-subtle: 348 42% 86%; - --color-border-contrast: 0 0% 0%; - - --color-text-base: 340 8% 3%; - --color-text-muted: 345 8% 38%; -} - -/* Blue color */ -.theme-lake { - --color-accent-base: 194 100% 44%; - --color-accent-hover: 194 100% 22%; - --color-accent-muted: 195 100% 11%; - --color-accent-contrast: 0 0% 100%; - - --color-heading-foreground: 194 100% 22%; - --color-heading-background: 195 100% 92%; - - --color-background-elevated: 0 0% 100%; - --color-background-base: 196 44% 96%; - --color-background-header: 194 100% 22%; - --color-background-highlight: 195 100% 92%; - --color-background-backdrop: 0 0% 50%; - - --color-border-subtle: 195 42% 86%; - --color-border-contrast: 0 0% 0%; - - --color-text-base: 194 8% 3%; - --color-text-muted: 195 8% 38%; -} - -/* Orange color */ -.theme-amber { - --color-accent-base: 17 100% 57%; - --color-accent-hover: 17 100% 35%; - --color-accent-muted: 17 100% 24%; - --color-accent-contrast: 0 0% 100%; - - --color-heading-foreground: 17 100% 35%; - --color-heading-background: 17 100% 89%; - - --color-background-elevated: 0 0% 100%; - --color-background-base: 15 44% 96%; - --color-background-header: 17 100% 35%; - --color-background-highlight: 17 100% 89%; - --color-background-backdrop: 0 0% 50%; - - --color-border-subtle: 17 42% 86%; - --color-border-contrast: 0 0% 0%; - - --color-text-base: 15 8% 3%; - --color-text-muted: 17 8% 38%; -} - -/* Violet color */ -.theme-jacaranda { - --color-accent-base: 254 72% 52%; - --color-accent-hover: 254 73% 30%; - --color-accent-muted: 254 71% 19%; - --color-accent-contrast: 0 0% 100%; - - --color-heading-foreground: 254 73% 30%; - --color-heading-background: 254 73% 84%; - - --color-background-elevated: 0 0% 100%; - --color-background-base: 253 44% 96%; - --color-background-header: 254 73% 30%; - --color-background-highlight: 254 88% 91%; - --color-background-backdrop: 0 0% 50%; - - --color-border-subtle: 254 42% 86%; - --color-border-contrast: 0 0% 0%; - - --color-text-base: 253 8% 3%; - --color-text-muted: 254 8% 38%; -} - -/* Black color */ -.theme-onyx { - --color-accent-base: 240 17% 2%; - --color-accent-hover: 240 17% 17%; - --color-accent-muted: 240 17% 17%; - --color-accent-contrast: 0 0% 100%; - - --color-heading-foreground: 240 17% 17%; - --color-heading-background: 240 17% 94%; - - --color-background-elevated: 0 0% 100%; - --color-background-base: 240 17% 96%; - --color-background-header: 240 12% 17%; - --color-background-highlight: 240 17% 94%; - --color-background-backdrop: 0 0% 50%; - - --color-border-subtle: 240 17% 86%; - --color-border-contrast: 0 0% 0%; - - --color-text-base: 240 8% 3%; - --color-text-muted: 240 8% 38%; -} diff --git a/app/Views/errors/html/error_404.php b/app/Views/errors/html/error_404.php index 6650ce45..0feb6b7d 100644 --- a/app/Views/errors/html/error_404.php +++ b/app/Views/errors/html/error_404.php @@ -5,10 +5,12 @@ 404 Page Not Found + ' /> asset('styles/index.css', 'css') ?> - +

404 - File Not Found

diff --git a/app/Views/errors/html/production.php b/app/Views/errors/html/production.php index 7953ee43..f51eff00 100644 --- a/app/Views/errors/html/production.php +++ b/app/Views/errors/html/production.php @@ -7,10 +7,12 @@ Whoops! + ' /> asset('styles/index.css', 'css') ?> - +

Whoops!

We seem to have hit a snag. Please try again later...

diff --git a/themes/cp_admin/_layout.php b/themes/cp_admin/_layout.php index 9cc6cdc0..d98d152f 100644 --- a/themes/cp_admin/_layout.php +++ b/themes/cp_admin/_layout.php @@ -14,6 +14,7 @@ + ' /> asset('styles/index.css', 'css') ?> published_at, $episode->publication_status, 'absolute top-0 left-0 ml-2 mt-2 text-sm'); ?>
- number, $episode->season_number, 'text-xs font-semibold !no-underline border px-1 border-gray-500 mr-1', true) ?> + number, $episode->season_number, 'text-xs font-semibold !no-underline px-1 bg-black/50 mr-1', true) ?> title ?>
diff --git a/themes/cp_admin/episode/list.php b/themes/cp_admin/episode/list.php index a3b8d671..8e1e96a4 100644 --- a/themes/cp_admin/episode/list.php +++ b/themes/cp_admin/episode/list.php @@ -34,7 +34,7 @@ $episode->audio_file_duration, ) . '' . - '' . $episode->title . '' . + '' . $episode->title . '' . '' . '">
- + themes as $themeName => $color): ?> + isChecked="get('App.theme') ? 'true' : 'false' ?>" >
diff --git a/themes/cp_app/embed.php b/themes/cp_app/embed.php index 6be47018..698a63cc 100644 --- a/themes/cp_app/embed.php +++ b/themes/cp_app/embed.php @@ -12,6 +12,7 @@ + ' /> asset('styles/index.css', 'css') ?> + ' /> asset('styles/index.css', 'css') ?> persons as $person): ?> - <?= $person->full_name ?> + <?= $person->full_name ?> diff --git a/themes/cp_app/episode/_partials/card.php b/themes/cp_app/episode/_partials/card.php index 0efc2c93..df1e327c 100644 --- a/themes/cp_app/episode/_partials/card.php +++ b/themes/cp_app/episode/_partials/card.php @@ -4,7 +4,7 @@ audio_file_duration) ?> <?= $episode->title ?> + ->thumbnail_url ?>" alt="title ?>" class="object-cover w-20 rounded-lg shadow-inner aspect-square" />
diff --git a/themes/cp_app/home.php b/themes/cp_app/home.php index 2d4fbf7f..0fd44330 100644 --- a/themes/cp_app/home.php +++ b/themes/cp_app/home.php @@ -27,6 +27,7 @@ + ' /> asset('styles/index.css', 'css') ?> + ' /> asset('styles/index.css', 'css') ?> + ' /> asset('styles/index.css', 'css') ?> + ' /> asset('styles/index.css', 'css') ?> persons as $person): ?> - <?= $person->full_name ?> + <?= $person->full_name ?> diff --git a/themes/cp_app/podcast/follow.php b/themes/cp_app/podcast/follow.php index d84265d1..10032df7 100644 --- a/themes/cp_app/podcast/follow.php +++ b/themes/cp_app/podcast/follow.php @@ -24,6 +24,7 @@ + ' /> asset('styles/index.css', 'css') ?> + ' /> asset('styles/index.css', 'css') ?>