From 1be02bb510b7f822e5618e4d1af70c4e224c4e31 Mon Sep 17 00:00:00 2001 From: Benjamin Nussbaum Date: Wed, 18 Feb 2026 13:14:19 +0100 Subject: [PATCH] feat(#149): add UIfor css_variables to DeviceModel --- .../livewire/device-models/index.blade.php | 70 ++++++++++++++++++- 1 file changed, 68 insertions(+), 2 deletions(-) diff --git a/resources/views/livewire/device-models/index.blade.php b/resources/views/livewire/device-models/index.blade.php index 7de5872..fea740a 100644 --- a/resources/views/livewire/device-models/index.blade.php +++ b/resources/views/livewire/device-models/index.blade.php @@ -41,6 +41,9 @@ new class extends Component public $css_name; + /** @var array */ + public array $css_variables = []; + protected $rules = [ 'name' => 'required|string|max:255|unique:device_models,name', 'label' => 'required|string|max:255', @@ -105,10 +108,11 @@ new class extends Component $this->published_at = $deviceModel->published_at?->format('Y-m-d\TH:i'); $this->palette_id = $deviceModel->palette_id; $this->css_name = $deviceModel->css_name; + $this->css_variables = collect($deviceModel->css_variables ?? [])->map(fn (string $value, string $key): array => ['key' => $key, 'value' => $value])->values()->all(); } else { $this->editingDeviceModelId = null; $this->viewingDeviceModelId = null; - $this->reset(['name', 'label', 'description', 'width', 'height', 'colors', 'bit_depth', 'scale_factor', 'rotation', 'mime_type', 'offset_x', 'offset_y', 'published_at', 'palette_id', 'css_name']); + $this->reset(['name', 'label', 'description', 'width', 'height', 'colors', 'bit_depth', 'scale_factor', 'rotation', 'mime_type', 'offset_x', 'offset_y', 'published_at', 'palette_id', 'css_name', 'css_variables']); $this->mime_type = 'image/png'; $this->scale_factor = 1.0; $this->rotation = 0; @@ -135,6 +139,9 @@ new class extends Component 'published_at' => 'nullable|date', 'palette_id' => 'nullable|exists:device_palettes,id', 'css_name' => 'nullable|string|max:255', + 'css_variables' => 'nullable|array', + 'css_variables.*.key' => 'nullable|string|max:255', + 'css_variables.*.value' => 'nullable|string|max:500', ]; if ($this->editingDeviceModelId) { @@ -163,6 +170,7 @@ new class extends Component 'published_at' => $this->published_at, 'palette_id' => $this->palette_id ?: null, 'css_name' => $this->css_name ?: null, + 'css_variables' => $this->normalizeCssVariables(), ]); $message = 'Device model updated successfully.'; } else { @@ -182,12 +190,13 @@ new class extends Component 'published_at' => $this->published_at, 'palette_id' => $this->palette_id ?: null, 'css_name' => $this->css_name ?: null, + 'css_variables' => $this->normalizeCssVariables(), 'source' => 'manual', ]); $message = 'Device model created successfully.'; } - $this->reset(['name', 'label', 'description', 'width', 'height', 'colors', 'bit_depth', 'scale_factor', 'rotation', 'mime_type', 'offset_x', 'offset_y', 'published_at', 'palette_id', 'css_name', 'editingDeviceModelId', 'viewingDeviceModelId']); + $this->reset(['name', 'label', 'description', 'width', 'height', 'colors', 'bit_depth', 'scale_factor', 'rotation', 'mime_type', 'offset_x', 'offset_y', 'published_at', 'palette_id', 'css_name', 'css_variables', 'editingDeviceModelId', 'viewingDeviceModelId']); Flux::modal('device-model-modal')->close(); $this->deviceModels = DeviceModel::all(); @@ -224,9 +233,37 @@ new class extends Component $this->published_at = $deviceModel->published_at?->format('Y-m-d\TH:i'); $this->palette_id = $deviceModel->palette_id; $this->css_name = $deviceModel->css_name; + $this->css_variables = collect($deviceModel->css_variables ?? [])->map(fn (string $value, string $key): array => ['key' => $key, 'value' => $value])->values()->all(); $this->js('Flux.modal("device-model-modal").show()'); } + + public function addCssVariable(): void + { + $this->css_variables = array_merge($this->css_variables, [['key' => '', 'value' => '']]); + } + + public function removeCssVariable(int $index): void + { + $vars = $this->css_variables; + array_splice($vars, $index, 1); + $this->css_variables = array_values($vars); + } + + /** + * @return array|null + */ + private function normalizeCssVariables(): ?array + { + $pairs = collect($this->css_variables) + ->filter(fn (array $p): bool => trim($p['key'] ?? '') !== ''); + + if ($pairs->isEmpty()) { + return null; + } + + return $pairs->mapWithKeys(fn (array $p): array => [$p['key'] => $p['value'] ?? ''])->all(); + } } ?> @@ -356,6 +393,35 @@ new class extends Component name="css_name" :disabled="(bool) $viewingDeviceModelId"/> +
+ CSS Variables + @if ($viewingDeviceModelId) + @if (count($css_variables) > 0) +
+ @foreach ($css_variables as $var) +
+
{{ $var['key'] }}
+
{{ $var['value'] }}
+
+ @endforeach +
+ @else +

No CSS variables

+ @endif + @else +
+ @foreach ($css_variables as $index => $var) +
+ + + +
+ @endforeach + Add variable +
+ @endif +
+ @if (!$viewingDeviceModelId)