Skip to content

Commit

Permalink
System: improved the colour picker to add a pre-set colour palette
Browse files Browse the repository at this point in the history
  • Loading branch information
SKuipers committed Feb 18, 2025
1 parent 2cb38a3 commit d316f0e
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ v29.0.00

Tweaks & Additions
System: removed Date of Birth field from Public Registration when no minimum registration age is set
System: improved the colour picker to add a pre-set colour palette
Attendance: updated Student History view to display Off Timetable days
Library: improved the Library Borrowing page on student profiles
Library: improved the Lending & Activity Log workflow when scanning in IDs from barcodes
Expand Down
2 changes: 1 addition & 1 deletion resources/assets/css/core.min.css

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion src/Forms/Input/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@

/**
* Color
*
* Color palette: https://tailscan.com/colors
*
* @version v21
* @since v21
*/
class Color extends Input
{
protected $showField = true;
/**
* Create an HTML color input.
* @param string $name
Expand All @@ -46,14 +49,21 @@ public function __construct($name)
);
}

public function hideField()
{
$this->showField = false;
return $this;
}

/**
* Gets the HTML output for this form element.
* @return string
*/
protected function getElement()
{
return Component::render(Color::class, $this->getAttributeArray() + [
'color' => !empty($this->getValue()) ? $this->getValue() : '#ffffff'
'color' => !empty($this->getValue()) ? $this->getValue() : '#ffffff',
'showField' => $this->showField,
]);
}
}
62 changes: 58 additions & 4 deletions src/Forms/Input/Color.template.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,59 @@
<div class="flex-grow relative inline-flex items-center" x-data="{'color': '<?= $color; ?>'}">
<input type="color" value="<?= $color; ?>" class="mr-2 w-12" x-model="color" style="-webkit-appearance: none;">
<input type="text" <?= $attributes; ?>
class="<?= $class; ?> rounded-md flex-grow font-sans py-2 text-gray-900 placeholder:text-gray-500 focus:ring-1 focus:ring-inset focus:ring-blue-500 sm:text-sm sm:leading-6" :value="color">
<div class="flex-grow relative inline-flex items-center gap-2" x-data="{'colorSelected': '<?= $color; ?>', isOpen: false, colors: [
'#ffffff','#f5f5f5','#d4d4d4','#737373','#404040','#171717','#000000',
'#b91c1c','#c2410c','#a16207','#15803d','#0e7490','#1d4ed8','#6d28d9','#be185d',
'#ef4444','#f97316','#eab308','#22c55e','#14b8a6','#3b82f6','#8b5cf6','#ec4899',
'#fca5a5','#fdba74','#fde047','#86efac','#5eead4','#93c5fd','#c4b5fd','#f9a8d4',
'#fee2e2','#ffedd5','#fef9c3','#dcfce7','#ccfbf1','#dbeafe','#ede9fe','#fce7f3',
],}" x-cloak>

<button type="button" @click="isOpen = !isOpen"
class="w-10 h-10 rounded-full focus:outline-none inline-flex items-center justify-center shadow hover:ring" :class="{'text-gray-500': colorSelected == '#ffffff', 'text-white': colorSelected != '#ffffff'}"
:style="`background: ${colorSelected};`">
<?= icon('outline', 'swatch', 'size-6'); ?>
</button>

<input type="text" <?= $attributes; ?>
class="<?= $class; ?> <?= $showField ? '' : 'hidden'; ?> rounded-md flex-grow font-sans py-2 text-gray-900 placeholder:text-gray-500 focus:ring-1 focus:ring-inset focus:ring-blue-500 sm:text-sm sm:leading-6" x-model="colorSelected">

<div x-show="isOpen" @click.away="isOpen = false" x-transition:enter="transition ease-out duration-100 transform"
x-transition:enter-start="opacity-0 scale-95" x-transition:enter-end="opacity-100 scale-100"
x-transition:leave="transition ease-in duration-75 transform"
x-transition:leave-start="opacity-100 scale-100" x-transition:leave-end="opacity-0 scale-95"
class="absolute z-50 left-0 top-0 mt-12 rounded-md shadow-lg">
<div class="rounded-md bg-white shadow-xs px-4 pt-4 pb-3">
<div class="grid grid-cols-8 justify-center items-center gap-1">

<div class="w-8 h-8 overflow-hidden inline-flex justify-center items-center rounded-full cursor-pointer border-4 border-white focus:outline-none focus:ring" title="<?= __('Custom Colour'); ?>">
<input type="color" value="<?= $color; ?>" class="-mx-px -my-px p-0" x-model="colorSelected" style="-webkit-appearance: none;" @click="isOpen = false">
<div class="absolute pointer-events-none" :class="{'text-gray-500': colorSelected == '#ffffff', 'text-white': colorSelected != '#ffffff'}">
<?= icon('solid', 'eye-dropper', 'size-4 mt-1'); ?>
</div>
</div>

<template x-for="(color, index) in colors" :key="index">
<div
class="">
<template x-if="colorSelected === color">
<div
class="w-8 h-8 inline-flex rounded-full cursor-pointer border-4 border-white ring ring-gray-300"
:style="`background: ${color};`"></div>
</template>

<template x-if="colorSelected != color">
<div
@click="colorSelected = color"
@keydown.enter="colorSelected = color"
role="checkbox"
tabindex="0"
:aria-checked="colorSelected"
class="w-8 h-8 inline-flex rounded-full cursor-pointer border-4 border-white focus:outline-none focus:ring"
:style="`background: ${color};`"></div>
</template>
</div>
</template>
</div>


</div>
</div>
</div>
6 changes: 6 additions & 0 deletions src/UI/Icons/IconsOutline.template.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12.75 11.25 15 15 9.75m-3-7.036A11.959 11.959 0 0 1 3.598 6 11.99 11.99 0 0 0 3 9.749c0 5.592 3.824 10.29 9 11.623 5.176-1.332 9-6.03 9-11.622 0-1.31-.21-2.571-.598-3.751h-.152c-3.196 0-6.1-1.248-8.25-3.285Z" />
</svg>

<?php } elseif ($icon == 'swatch') { ?>

<svg class="<?= $class; ?>" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="<?= $strokeWidth; ?>" stroke="currentColor" aria-hidden="true">
<path stroke-linecap="round" stroke-linejoin="round" d="M4.098 19.902a3.75 3.75 0 0 0 5.304 0l6.401-6.402M6.75 21A3.75 3.75 0 0 1 3 17.25V4.125C3 3.504 3.504 3 4.125 3h5.25c.621 0 1.125.504 1.125 1.125v4.072M6.75 21a3.75 3.75 0 0 0 3.75-3.75V8.197M6.75 21h13.125c.621 0 1.125-.504 1.125-1.125v-5.25c0-.621-.504-1.125-1.125-1.125h-4.072M10.5 8.197l2.88-2.88c.438-.439 1.15-.439 1.59 0l3.712 3.713c.44.44.44 1.152 0 1.59l-2.879 2.88M6.75 17.25h.008v.008H6.75v-.008Z" />
</svg>

<?php } elseif ($icon == 'notifications') { ?>
<svg class="<?= $class; ?>" style="max-width: 2.5rem;" x="0px" y="0px" viewBox="0 0 100 100" style="enable-background:new 0 0 100 100;" aria-hidden="true"><g i:extraneous="self"><path d="M87.5,67.2L83,61.8c-2.8-3.4-4.3-7.7-4.3-12.1V39.6c0-14.6-11-26.7-25.1-28.5v-5c0-2-1.6-3.6-3.6-3.6 c-2,0-3.6,1.6-3.6,3.6v5C32.3,12.9,21.3,25,21.3,39.6v10.1c0,4.4-1.5,8.7-4.3,12.1l-4.4,5.4c-2.3,2.8-2.8,6.7-1.2,10 c1.6,3.3,4.8,5.4,8.5,5.4h13.8c0.8,8.4,7.8,14.9,16.4,14.9s15.6-6.6,16.4-14.9h13.8c3.7,0,6.9-2.1,8.5-5.4 C90.2,73.9,89.8,70.1,87.5,67.2z M50,90.3c-4.6,0-8.4-3.4-9.1-7.8h18.2C58.4,86.9,54.6,90.3,50,90.3z M82.2,74.1 c-0.2,0.4-0.7,1.3-2,1.3H19.8c-1.3,0-1.8-0.9-2-1.3s-0.5-1.4,0.3-2.4l4.4-5.4c3.8-4.7,5.9-10.6,5.9-16.7V39.6 C28.5,27.7,38.1,18,50,18s21.5,9.7,21.5,21.5v10.1c0,6.1,2.1,12,5.9,16.7l4.4,5.4C82.7,72.7,82.4,73.7,82.2,74.1z"/></g></svg>

Expand Down
6 changes: 6 additions & 0 deletions src/UI/Icons/IconsSolid.template.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,12 @@
<path fill-rule="evenodd" d="M3.75 2A1.75 1.75 0 0 0 2 3.75v3.5C2 8.216 2.784 9 3.75 9h3.5A1.75 1.75 0 0 0 9 7.25v-3.5A1.75 1.75 0 0 0 7.25 2h-3.5ZM3.5 3.75a.25.25 0 0 1 .25-.25h3.5a.25.25 0 0 1 .25.25v3.5a.25.25 0 0 1-.25.25h-3.5a.25.25 0 0 1-.25-.25v-3.5ZM3.75 11A1.75 1.75 0 0 0 2 12.75v3.5c0 .966.784 1.75 1.75 1.75h3.5A1.75 1.75 0 0 0 9 16.25v-3.5A1.75 1.75 0 0 0 7.25 11h-3.5Zm-.25 1.75a.25.25 0 0 1 .25-.25h3.5a.25.25 0 0 1 .25.25v3.5a.25.25 0 0 1-.25.25h-3.5a.25.25 0 0 1-.25-.25v-3.5Zm7.5-9c0-.966.784-1.75 1.75-1.75h3.5c.966 0 1.75.784 1.75 1.75v3.5A1.75 1.75 0 0 1 16.25 9h-3.5A1.75 1.75 0 0 1 11 7.25v-3.5Zm1.75-.25a.25.25 0 0 0-.25.25v3.5c0 .138.112.25.25.25h3.5a.25.25 0 0 0 .25-.25v-3.5a.25.25 0 0 0-.25-.25h-3.5Zm-7.26 1a1 1 0 0 0-1 1v.01a1 1 0 0 0 1 1h.01a1 1 0 0 0 1-1V5.5a1 1 0 0 0-1-1h-.01Zm9 0a1 1 0 0 0-1 1v.01a1 1 0 0 0 1 1h.01a1 1 0 0 0 1-1V5.5a1 1 0 0 0-1-1h-.01Zm-9 9a1 1 0 0 0-1 1v.01a1 1 0 0 0 1 1h.01a1 1 0 0 0 1-1v-.01a1 1 0 0 0-1-1h-.01Zm9 0a1 1 0 0 0-1 1v.01a1 1 0 0 0 1 1h.01a1 1 0 0 0 1-1v-.01a1 1 0 0 0-1-1h-.01Zm-3.5-1.5a1 1 0 0 1 1-1H12a1 1 0 0 1 1 1v.01a1 1 0 0 1-1 1h-.01a1 1 0 0 1-1-1V12Zm6-1a1 1 0 0 0-1 1v.01a1 1 0 0 0 1 1H17a1 1 0 0 0 1-1V12a1 1 0 0 0-1-1h-.01Zm-1 6a1 1 0 0 1 1-1H17a1 1 0 0 1 1 1v.01a1 1 0 0 1-1 1h-.01a1 1 0 0 1-1-1V17Zm-4-1a1 1 0 0 0-1 1v.01a1 1 0 0 0 1 1H12a1 1 0 0 0 1-1V17a1 1 0 0 0-1-1h-.01Z" clip-rule="evenodd" />
</svg>

<?php } elseif ($icon == 'eye-dropper') { ?>

<svg class="<?= $class; ?>" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
<path fill-rule="evenodd" d="M12.1 3.667a3.502 3.502 0 1 1 6.782 1.738 3.487 3.487 0 0 1-.907 1.57 3.495 3.495 0 0 1-1.617.919L16 7.99V10a.75.75 0 0 1-.22.53l-.25.25a.75.75 0 0 1-1.06 0l-.845-.844L7.22 16.34A2.25 2.25 0 0 1 5.629 17H5.12a.75.75 0 0 0-.53.22l-1.56 1.56a.75.75 0 0 1-1.061 0l-.75-.75a.75.75 0 0 1 0-1.06l1.56-1.561a.75.75 0 0 0 .22-.53v-.508c0-.596.237-1.169.659-1.59l6.405-6.406-.844-.845a.75.75 0 0 1 0-1.06l.25-.25A.75.75 0 0 1 10 4h2.01l.09-.333ZM4.72 13.84l6.405-6.405 1.44 1.439-6.406 6.405a.75.75 0 0 1-.53.22H5.12c-.258 0-.511.044-.75.129a2.25 2.25 0 0 0 .129-.75v-.508a.75.75 0 0 1 .22-.53Z" clip-rule="evenodd" />
</svg>

<?php } elseif ($icon == 'squares') { ?>

<svg class="<?= $class; ?>" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
Expand Down

0 comments on commit d316f0e

Please sign in to comment.