♻️ side panel redesign, smart date picker positioning, form polish
Browse files at this commiteafd591de4006332b3e1eb1fbe1ac915dea5887fParent: 212dcef- refactor
- ♻️ side panel redesign, smart date picker positioning, form polish
6 changed files +93 -30
- src/components/events/event-form.tsx +0 -2
- src/components/exams/exam-form.tsx +1 -3
- src/components/ui/date-picker.tsx +33 -7
- src/components/ui/icons.tsx +9 -0
- src/components/ui/side-panel.tsx +10 -9
- src/index.css +40 -9
src/components/events/event-form.tsxmodified+0 -2
| @@ -4,7 +4,6 @@ import type { Event } from "@/api/types"; | ||
| 4 | 4 | import { Button } from "@/components/ui/button"; |
| 5 | 5 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; |
| 6 | 6 | import { DatePicker } from "@/components/ui/date-picker"; |
| 7 | -import { IconSave } from "@/components/ui/icons"; | |
| 8 | 7 | import { Input } from "@/components/ui/input"; |
| 9 | 8 | import { Label } from "@/components/ui/label"; |
| 10 | 9 | import { Textarea } from "@/components/ui/textarea"; |
| @@ -217,7 +216,6 @@ export function EventForm(props: { | ||
| 217 | 216 | {error() && <p class="text-sm text-destructive">{error()}</p>} |
| 218 | 217 | <div class="flex flex-wrap items-center gap-2"> |
| 219 | 218 | <Button type="submit" class="h-10" disabled={pending()}> |
| 220 | - <IconSave /> | |
| 221 | 219 | {props.submitLabel ?? t("common.save")} |
| 222 | 220 | </Button> |
| 223 | 221 | {props.onCancel && ( |
src/components/exams/exam-form.tsxmodified+1 -3
| @@ -7,7 +7,6 @@ import { EXAM_KINDS, EXAM_MODES } from "@/api/types"; | ||
| 7 | 7 | import { Button } from "@/components/ui/button"; |
| 8 | 8 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; |
| 9 | 9 | import { DatePicker } from "@/components/ui/date-picker"; |
| 10 | -import { IconSave } from "@/components/ui/icons"; | |
| 11 | 10 | import { Input } from "@/components/ui/input"; |
| 12 | 11 | import { Label } from "@/components/ui/label"; |
| 13 | 12 | import { Select } from "@/components/ui/select"; |
| @@ -264,7 +263,7 @@ export function ExamForm(props: { | ||
| 264 | 263 | </Show> |
| 265 | 264 | </div> |
| 266 | 265 | <Show when={mode() === "sync" || mode() === "async"}> |
| 267 | - <div class="grid gap-3 sm:grid-cols-2"> | |
| 266 | + <div class="grid gap-3"> | |
| 268 | 267 | <div class="space-y-1.5"> |
| 269 | 268 | <Label for="exam-starts">{t("events.starts")}</Label> |
| 270 | 269 | <div class="grid grid-cols-[minmax(0,1fr)_7rem] gap-2"> |
| @@ -332,7 +331,6 @@ export function ExamForm(props: { | ||
| 332 | 331 | {error() && <p class="text-sm text-destructive">{error()}</p>} |
| 333 | 332 | <div class="flex flex-wrap items-center gap-2"> |
| 334 | 333 | <Button type="submit" disabled={pending()}> |
| 335 | - <IconSave /> | |
| 336 | 334 | {props.submitLabel ?? t("common.save")} |
| 337 | 335 | </Button> |
| 338 | 336 | {props.onCancel && ( |
src/components/ui/date-picker.tsxmodified+33 -7
| @@ -49,6 +49,7 @@ export function DatePicker(props: { | ||
| 49 | 49 | }) { |
| 50 | 50 | let root: HTMLDivElement | undefined; |
| 51 | 51 | const [open, setOpen] = createSignal(false); |
| 52 | + const [position, setPosition] = createSignal({ left: 0, top: 0, width: 288 }); | |
| 52 | 53 | const selected = createMemo(() => parseDate(props.value)); |
| 53 | 54 | const [month, setMonth] = createSignal(selected() ?? new Date()); |
| 54 | 55 | const days = createMemo(() => monthDays(month())); |
| @@ -63,11 +64,33 @@ export function DatePicker(props: { | ||
| 63 | 64 | |
| 64 | 65 | createEffect(() => { |
| 65 | 66 | if (!open()) return; |
| 67 | + const updatePosition = () => { | |
| 68 | + if (!root) return; | |
| 69 | + const rect = root.getBoundingClientRect(); | |
| 70 | + const panelWidth = Math.min(288, Math.max(240, window.innerWidth - 24)); | |
| 71 | + const left = Math.min(Math.max(12, rect.left), window.innerWidth - panelWidth - 12); | |
| 72 | + const estimatedHeight = 300; | |
| 73 | + const viewportPadding = 12; | |
| 74 | + const availableBelow = window.innerHeight - rect.bottom - viewportPadding; | |
| 75 | + const availableAbove = rect.top - viewportPadding; | |
| 76 | + const opensAbove = availableBelow < estimatedHeight && availableAbove > availableBelow; | |
| 77 | + const rawTop = opensAbove ? rect.top - estimatedHeight - 8 : rect.bottom + 8; | |
| 78 | + const maxTop = Math.max(viewportPadding, window.innerHeight - estimatedHeight - viewportPadding); | |
| 79 | + const top = Math.min(Math.max(viewportPadding, rawTop), maxTop); | |
| 80 | + setPosition({ left, top, width: panelWidth }); | |
| 81 | + }; | |
| 82 | + updatePosition(); | |
| 66 | 83 | const closeOnOutside = (event: MouseEvent) => { |
| 67 | 84 | if (root && !root.contains(event.target as Node)) setOpen(false); |
| 68 | 85 | }; |
| 86 | + window.addEventListener("resize", updatePosition); | |
| 87 | + window.addEventListener("scroll", updatePosition, true); | |
| 69 | 88 | document.addEventListener("mousedown", closeOnOutside); |
| 70 | - onCleanup(() => document.removeEventListener("mousedown", closeOnOutside)); | |
| 89 | + onCleanup(() => { | |
| 90 | + window.removeEventListener("resize", updatePosition); | |
| 91 | + window.removeEventListener("scroll", updatePosition, true); | |
| 92 | + document.removeEventListener("mousedown", closeOnOutside); | |
| 93 | + }); | |
| 71 | 94 | }); |
| 72 | 95 | |
| 73 | 96 | const moveMonth = (delta: number) => { |
| @@ -97,13 +120,16 @@ export function DatePicker(props: { | ||
| 97 | 120 | <IconCalendar class="pointer-events-none absolute right-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" /> |
| 98 | 121 | </div> |
| 99 | 122 | <Show when={open()}> |
| 100 | - <div class="absolute z-50 mt-2 w-72 rounded-md border bg-popover p-3 text-popover-foreground shadow-lg"> | |
| 123 | + <div | |
| 124 | + class="fixed z-[80] rounded-xl border border-border/80 bg-popover p-2.5 text-popover-foreground shadow-xl" | |
| 125 | + style={{ left: `${position().left}px`, top: `${position().top}px`, width: `${position().width}px` }} | |
| 126 | + > | |
| 101 | 127 | <div class="mb-3 flex items-center justify-between gap-2"> |
| 102 | - <Button type="button" variant="ghost" size="sm" class="h-8 w-8 p-0" onClick={() => moveMonth(-1)}> | |
| 128 | + <Button type="button" variant="ghost" size="sm" class="h-8 w-8 rounded-lg p-0" onClick={() => moveMonth(-1)}> | |
| 103 | 129 | <IconChevronLeft class="h-4 w-4" /> |
| 104 | 130 | </Button> |
| 105 | - <p class="text-sm font-medium capitalize">{monthLabel()}</p> | |
| 106 | - <Button type="button" variant="ghost" size="sm" class="h-8 w-8 p-0" onClick={() => moveMonth(1)}> | |
| 131 | + <p class="min-w-0 truncate px-2 text-sm font-semibold capitalize">{monthLabel()}</p> | |
| 132 | + <Button type="button" variant="ghost" size="sm" class="h-8 w-8 rounded-lg p-0" onClick={() => moveMonth(1)}> | |
| 107 | 133 | <IconChevronRight class="h-4 w-4" /> |
| 108 | 134 | </Button> |
| 109 | 135 | </div> |
| @@ -116,7 +142,7 @@ export function DatePicker(props: { | ||
| 116 | 142 | <span>Cmt</span> |
| 117 | 143 | <span>Paz</span> |
| 118 | 144 | </div> |
| 119 | - <div class="mt-1 grid grid-cols-7 gap-1"> | |
| 145 | + <div class="mt-1 grid grid-cols-7 gap-0.5"> | |
| 120 | 146 | <For each={days()}> |
| 121 | 147 | {(date) => ( |
| 122 | 148 | <Show when={date} fallback={<span class="h-8" />}> |
| @@ -125,7 +151,7 @@ export function DatePicker(props: { | ||
| 125 | 151 | type="button" |
| 126 | 152 | variant={sameDay(selected(), day()) ? "default" : "ghost"} |
| 127 | 153 | size="sm" |
| 128 | - class="h-8 rounded-sm p-0 text-xs" | |
| 154 | + class="h-8 rounded-lg p-0 text-xs" | |
| 129 | 155 | onClick={() => pick(day())} |
| 130 | 156 | > |
| 131 | 157 | {day().getDate()} |
src/components/ui/icons.tsxmodified+9 -0
| @@ -52,6 +52,15 @@ export function IconCheck(props: IconProps) { | ||
| 52 | 52 | ); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | +export function IconX(props: IconProps) { | |
| 56 | + return ( | |
| 57 | + <Svg {...props}> | |
| 58 | + <path d="M18 6 6 18" /> | |
| 59 | + <path d="m6 6 12 12" /> | |
| 60 | + </Svg> | |
| 61 | + ); | |
| 62 | +} | |
| 63 | + | |
| 55 | 64 | export function IconAlert(props: IconProps) { |
| 56 | 65 | return ( |
| 57 | 66 | <Svg {...props}> |
src/components/ui/side-panel.tsxmodified+10 -9
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | import { Dialog as DialogPrimitive } from "@kobalte/core/dialog"; |
| 2 | 2 | import type { ParentProps } from "solid-js"; |
| 3 | +import { IconX } from "@/components/ui/icons"; | |
| 3 | 4 | import { cn } from "@/lib/cn"; |
| 4 | 5 | |
| 5 | 6 | export function SidePanel(props: ParentProps<{ |
| @@ -12,29 +13,29 @@ export function SidePanel(props: ParentProps<{ | ||
| 12 | 13 | return ( |
| 13 | 14 | <DialogPrimitive open={props.open} onOpenChange={props.onOpenChange}> |
| 14 | 15 | <DialogPrimitive.Portal> |
| 15 | - <DialogPrimitive.Overlay class="fixed inset-0 z-50 bg-black/35 backdrop-blur-[1px] dark:bg-black/60" /> | |
| 16 | + <DialogPrimitive.Overlay class="fixed inset-0 z-50 bg-black/25 backdrop-blur-[1px] dark:bg-black/55" /> | |
| 16 | 17 | <DialogPrimitive.Content |
| 17 | 18 | class={cn( |
| 18 | - "fixed inset-y-0 right-0 z-50 flex w-full max-w-xl flex-col border-l border-border bg-popover text-popover-foreground shadow-xl outline-none transition-transform duration-200", | |
| 19 | + "fixed inset-y-0 right-0 z-50 flex w-full max-w-[34rem] flex-col border-l border-border/80 bg-background text-foreground shadow-[0_20px_70px_hsl(var(--foreground)/0.18)] outline-none transition-transform duration-200 sm:inset-y-3 sm:right-3 sm:rounded-2xl sm:border sm:border-border/80", | |
| 19 | 20 | props.class, |
| 20 | 21 | )} |
| 21 | 22 | > |
| 22 | - <div class="flex items-start justify-between gap-4 border-b border-border px-5 py-4"> | |
| 23 | - <div> | |
| 24 | - <DialogPrimitive.Title class="font-display text-lg font-semibold leading-none"> | |
| 23 | + <div class="flex items-start justify-between gap-4 border-b border-border/80 bg-card px-6 py-5 sm:rounded-t-2xl"> | |
| 24 | + <div class="min-w-0 space-y-1"> | |
| 25 | + <DialogPrimitive.Title class="truncate font-display text-base font-semibold leading-6 tracking-tight"> | |
| 25 | 26 | {props.title} |
| 26 | 27 | </DialogPrimitive.Title> |
| 27 | 28 | {props.description && ( |
| 28 | - <DialogPrimitive.Description class="mt-1.5 text-sm text-muted-foreground"> | |
| 29 | + <DialogPrimitive.Description class="text-sm leading-5 text-muted-foreground"> | |
| 29 | 30 | {props.description} |
| 30 | 31 | </DialogPrimitive.Description> |
| 31 | 32 | )} |
| 32 | 33 | </div> |
| 33 | - <DialogPrimitive.CloseButton class="rounded-sm px-2 py-1 text-sm text-muted-foreground transition-colors hover:bg-muted hover:text-foreground"> | |
| 34 | - × | |
| 34 | + <DialogPrimitive.CloseButton class="inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md border border-border/80 bg-background text-muted-foreground shadow-sm transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"> | |
| 35 | + <IconX class="h-4 w-4" /> | |
| 35 | 36 | </DialogPrimitive.CloseButton> |
| 36 | 37 | </div> |
| 37 | - <div class="min-h-0 flex-1 overflow-y-auto px-5 py-4">{props.children}</div> | |
| 38 | + <div class="side-panel-body min-h-0 flex-1 overflow-y-auto bg-muted/20 px-6 pt-5">{props.children}</div> | |
| 38 | 39 | </DialogPrimitive.Content> |
| 39 | 40 | </DialogPrimitive.Portal> |
| 40 | 41 | </DialogPrimitive> |
src/index.cssmodified+40 -9
| @@ -15,8 +15,8 @@ | ||
| 15 | 15 | --ui-text-1: 180 11% 7%; |
| 16 | 16 | --ui-text-2: 180 6% 31%; |
| 17 | 17 | --ui-text-3: 180 4% 49%; |
| 18 | - --ui-accent: 217 91% 60%; | |
| 19 | - --ui-accent-muted: 214 95% 93%; | |
| 18 | + --ui-accent: 204 86% 48%; | |
| 19 | + --ui-accent-muted: 204 88% 91%; | |
| 20 | 20 | --ui-success: 142 72% 29%; |
| 21 | 21 | --ui-success-muted: 138 76% 97%; |
| 22 | 22 | --ui-warning: 32 95% 44%; |
| @@ -45,13 +45,13 @@ | ||
| 45 | 45 | --muted: var(--ui-surface-2); |
| 46 | 46 | --muted-foreground: var(--ui-text-2); |
| 47 | 47 | --accent: var(--ui-accent-muted); |
| 48 | - --accent-foreground: 217 91% 28%; | |
| 48 | + --accent-foreground: 204 86% 25%; | |
| 49 | 49 | --destructive: var(--ui-danger); |
| 50 | 50 | --destructive-foreground: 0 0% 100%; |
| 51 | 51 | --border: var(--ui-border-1); |
| 52 | 52 | --input: var(--ui-border-1); |
| 53 | 53 | --ring: var(--ui-accent); |
| 54 | - --radius: 0.625rem; | |
| 54 | + --radius: 0.75rem; | |
| 55 | 55 | --success: var(--ui-success); |
| 56 | 56 | --warning: var(--ui-warning); |
| 57 | 57 | --info: var(--ui-info); |
| @@ -70,8 +70,8 @@ | ||
| 70 | 70 | --ui-text-1: 180 14% 94%; |
| 71 | 71 | --ui-text-2: 180 8% 67%; |
| 72 | 72 | --ui-text-3: 190 6% 48%; |
| 73 | - --ui-accent: 213 94% 68%; | |
| 74 | - --ui-accent-muted: 213 47% 17%; | |
| 73 | + --ui-accent: 199 92% 62%; | |
| 74 | + --ui-accent-muted: 199 48% 16%; | |
| 75 | 75 | --ui-success: 142 69% 58%; |
| 76 | 76 | --ui-success-muted: 142 39% 10%; |
| 77 | 77 | --ui-warning: 38 92% 50%; |
| @@ -81,7 +81,7 @@ | ||
| 81 | 81 | --ui-info: 199 89% 63%; |
| 82 | 82 | --ui-info-muted: 200 50% 13%; |
| 83 | 83 | --primary-foreground: 210 20% 98%; |
| 84 | - --accent-foreground: 213 94% 86%; | |
| 84 | + --accent-foreground: 199 92% 84%; | |
| 85 | 85 | --destructive-foreground: 0 0% 100%; |
| 86 | 86 | } |
| 87 | 87 | |
| @@ -125,11 +125,11 @@ | ||
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | .data-shell { |
| 128 | - @apply rounded-lg border border-border bg-card; | |
| 128 | + @apply rounded-xl border border-border bg-card; | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | .data-table-wrap { |
| 132 | - @apply max-h-[62vh] overflow-auto rounded-lg border border-border bg-card; | |
| 132 | + @apply max-h-[62vh] overflow-auto rounded-xl border border-border bg-card; | |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | .data-table { |
| @@ -156,6 +156,37 @@ | ||
| 156 | 156 | background-color: hsl(var(--muted) / 0.28); |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | + .side-panel-body form { | |
| 160 | + @apply space-y-5 pb-5; | |
| 161 | + } | |
| 162 | + | |
| 163 | + .side-panel-body form > .space-y-3, | |
| 164 | + .side-panel-body form > .space-y-4, | |
| 165 | + .side-panel-body form > .space-y-1\.5, | |
| 166 | + .side-panel-body form > .grid { | |
| 167 | + @apply rounded-xl border border-border/80 bg-card p-4 shadow-sm; | |
| 168 | + } | |
| 169 | + | |
| 170 | + .side-panel-body label { | |
| 171 | + @apply text-[11px] font-semibold uppercase tracking-[0.12em] text-muted-foreground; | |
| 172 | + } | |
| 173 | + | |
| 174 | + .side-panel-body input, | |
| 175 | + .side-panel-body textarea, | |
| 176 | + .side-panel-body select { | |
| 177 | + @apply rounded-lg bg-background/80; | |
| 178 | + } | |
| 179 | + | |
| 180 | + .side-panel-body form > .flex:last-child, | |
| 181 | + .side-panel-body form > .flex.flex-wrap:last-child { | |
| 182 | + @apply sticky bottom-0 -mx-6 justify-end border-t border-border/80 bg-background/95 px-6 py-3 shadow-[0_-16px_32px_hsl(var(--background)/0.9)]; | |
| 183 | + } | |
| 184 | + | |
| 185 | + .side-panel-body form > .flex:last-child button, | |
| 186 | + .side-panel-body form > .flex.flex-wrap:last-child button { | |
| 187 | + @apply rounded-lg; | |
| 188 | + } | |
| 189 | + | |
| 159 | 190 | .num, |
| 160 | 191 | .mono { |
| 161 | 192 | font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace; |