Skip to content

Your favorite shift management application!

feat: Replaces manual color controls with centralized ColorPicker (#97)

panteL938f673b019f
diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md
index 4e0cffd..b40a6e3 100644
--- a/.github/copilot-instructions.md
+++ b/.github/copilot-instructions.md
@@ -191,7 +191,8 @@ t("common.created", { item: t("shift.shift_one") }); // Parametrized
- **Dialogs**: Read-only info or confirmations only (no forms)
- **Confirmation**: Use `ConfirmationDialog` component (NEVER native `confirm()`)
-- **Colors**: `PRESET_COLORS` array, hex format, 20% opacity for backgrounds
+- **Colors**: Use `ColorPicker` component (`components/ui/color-picker.tsx`) for all color selections - supports preset colors + custom picker
+- **Color Format**: `PRESET_COLORS` array, hex format, 20% opacity for backgrounds
- **Dates**: `formatDateToLocal()` for YYYY-MM-DD
### UI/UX Design Principles
diff --git a/components/calendar-settings-sheet.tsx b/components/calendar-settings-sheet.tsx
index 712060d..ffb5ac1 100644
--- a/components/calendar-settings-sheet.tsx
+++ b/components/calendar-settings-sheet.tsx
@@ -15,6 +15,7 @@ import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Checkbox } from "@/components/ui/checkbox";
+import { ColorPicker } from "@/components/ui/color-picker";
import { getCachedPassword } from "@/lib/password-cache";
import { useCalendars } from "@/hooks/useCalendars";
import { PRESET_COLORS } from "@/lib/constants";
@@ -238,28 +239,12 @@ export function CalendarSettingsSheet({
</div>
{/* Calendar Color */}
- <div className="space-y-2.5">
- <Label className="text-sm font-medium flex items-center gap-2">
- <div className="w-1 h-4 bg-gradient-to-b from-primary to-primary/50 rounded-full"></div>
- {t("form.colorLabel")}
- </Label>
- <div className="grid grid-cols-4 gap-2">
- {PRESET_COLORS.map((colorObj) => (
- <button
- key={colorObj.value}
- type="button"
- onClick={() => setSelectedColor(colorObj.value)}
- className={`h-11 rounded-lg transition-all ${
- selectedColor === colorObj.value
- ? "ring-2 ring-primary ring-offset-2 ring-offset-background scale-105"
- : "hover:scale-105"
- }`}
- style={{ backgroundColor: colorObj.value }}
- title={colorObj.name}
- />
- ))}
- </div>
- </div>
+ <ColorPicker
+ color={selectedColor}
+ onChange={setSelectedColor}
+ label={t("form.colorLabel")}
+ presetColors={PRESET_COLORS}
+ />
{/* Password Section */}
<div className="space-y-4 pt-2">
diff --git a/components/calendar-sheet.tsx b/components/calendar-sheet.tsx
index 0a66d83..92df42d 100644
--- a/components/calendar-sheet.tsx
+++ b/components/calendar-sheet.tsx
@@ -7,6 +7,7 @@ import { BaseSheet } from "@/components/ui/base-sheet";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Checkbox } from "@/components/ui/checkbox";
+import { ColorPicker } from "@/components/ui/color-picker";
import { PRESET_COLORS } from "@/lib/constants";
interface CalendarSheetProps {
@@ -131,50 +132,12 @@ export function CalendarSheet({
/>
</div>
- <div className="space-y-3">
- <Label className="text-sm font-medium flex items-center gap-2">
- <div className="w-1 h-4 bg-gradient-to-b from-primary to-primary/50 rounded-full"></div>
- {t("form.colorLabel")}
- </Label>
- <div className="grid grid-cols-4 gap-3 p-4 bg-muted/30 rounded-xl border border-border/30">
- {PRESET_COLORS.map((colorObj) => (
- <button
- key={colorObj.value}
- type="button"
- onClick={() => setSelectedColor(colorObj.value)}
- className={`
- relative w-full aspect-square rounded-xl transition-all duration-200
- hover:scale-110 active:scale-95
- ${
- selectedColor === colorObj.value
- ? "ring-4 ring-primary/30 shadow-lg scale-105"
- : "ring-2 ring-border/20 hover:ring-border/40"
- }
- `}
- style={{
- backgroundColor: colorObj.value,
- boxShadow:
- selectedColor === colorObj.value
- ? `0 8px 24px ${colorObj.value}40`
- : `0 2px 8px ${colorObj.value}20`,
- }}
- aria-label={colorObj.name}
- >
- {selectedColor === colorObj.value && (
- <motion.div
- initial={{ scale: 0 }}
- animate={{ scale: 1 }}
- className="absolute inset-0 flex items-center justify-center"
- >
- <div className="w-6 h-6 rounded-full bg-white/90 backdrop-blur-sm flex items-center justify-center shadow-lg">
- <div className="w-2 h-2 bg-primary rounded-full"></div>
- </div>
- </motion.div>
- )}
- </button>
- ))}
- </div>
- </div>
+ <ColorPicker
+ color={selectedColor}
+ onChange={setSelectedColor}
+ label={t("form.colorLabel")}
+ presetColors={PRESET_COLORS}
+ />
<div className="space-y-3 p-4 bg-primary/5 border border-primary/20 rounded-xl">
<div className="flex items-center space-x-2">
diff --git a/components/note-sheet.tsx b/components/note-sheet.tsx
index d3f9bf9..b435e3d 100644
--- a/components/note-sheet.tsx
+++ b/components/note-sheet.tsx
@@ -6,6 +6,7 @@ import { BaseSheet } from "@/components/ui/base-sheet";
import { Button } from "@/components/ui/button";
import { Label } from "@/components/ui/label";
import { Textarea } from "@/components/ui/textarea";
+import { ColorPicker } from "@/components/ui/color-picker";
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
import {
Select,
@@ -19,7 +20,7 @@ import { CalendarNote } from "@/lib/db/schema";
import { format } from "date-fns";
import { getDateLocale } from "@/lib/locales";
import { PRESET_COLORS } from "@/lib/constants";
-import { Check, AlertCircle } from "lucide-react";
+import { AlertCircle } from "lucide-react";
import { Alert, AlertDescription } from "@/components/ui/alert";
interface NoteSheetProps {
@@ -299,27 +300,12 @@ export function NoteSheet({
{type === "event" && (
<div className="space-y-4 pl-6 border-l-2 border-border/50">
{/* Color Selection */}
- <div className="space-y-2">
- <Label className="text-sm font-medium">
- {t("note.eventColor")}
- </Label>
- <div className="flex flex-wrap gap-2">
- {PRESET_COLORS.map((presetColor) => (
- <button
- key={presetColor.value}
- type="button"
- onClick={() => setColor(presetColor.value)}
- className="relative w-10 h-10 rounded-lg border-2 border-border/30 hover:border-border transition-colors focus:outline-none focus:ring-2 focus:ring-primary/30"
- style={{ backgroundColor: presetColor.value }}
- aria-label={presetColor.name}
- >
- {color === presetColor.value && (
- <Check className="absolute inset-0 m-auto h-5 w-5 text-white drop-shadow-md" />
- )}
- </button>
- ))}
- </div>
- </div>
+ <ColorPicker
+ color={color}
+ onChange={setColor}
+ label={t("note.eventColor")}
+ presetColors={PRESET_COLORS}
+ />
{/* Recurring Pattern */}
<div className="space-y-2">