Skip to content

Commit 95ef2d6

Browse files
authored
feat(app): improve rename dialogs (anomalyco#1681)
1 parent 2909a56 commit 95ef2d6

5 files changed

Lines changed: 115 additions & 168 deletions

File tree

‎apps/app/src/app/index.css‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@
7676
--dls-canvas: var(--slate-2);
7777
--dls-surface-muted: var(--slate-3);
7878
--dls-border: #262626;
79-
--dls-accent: var(--blue-9);
80-
--dls-accent-hover: var(--blue-10);
81-
--dls-accent-rgb: 59 142 247;
79+
--dls-accent: var(--blue-8);
80+
--dls-accent-hover: var(--blue-9);
81+
--dls-accent-rgb: 59 158 255;
8282
--dls-secondary-rgb: 176 180 186;
8383
--dls-text-primary: var(--slate-12);
8484
--dls-text-secondary: var(--slate-11);
@@ -375,7 +375,7 @@ select:disabled {
375375
--foreground: var(--slate-12);
376376
--card: var(--slate-2);
377377
--card-foreground: var(--slate-12);
378-
--popover: var(--slate-2);
378+
--popover: var(--slate-1);
379379
--popover-foreground: var(--slate-12);
380380
--primary-foreground: var(--slate-12);
381381
--secondary: var(--slate-3);

‎apps/app/src/components/ui/dialog.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function DialogContent({
5151
<DialogPrimitive.Popup
5252
data-slot="dialog-content"
5353
className={cn(
54-
"fixed top-1/2 start-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 rtl:translate-x-1/2 -translate-y-1/2 gap-6 rounded-4xl bg-popover p-6 text-sm text-popover-foreground shadow-xl ring-1 ring-foreground/5 duration-100 outline-none sm:max-w-md dark:ring-foreground/10 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
54+
"fixed top-1/2 start-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 rtl:translate-x-1/2 -translate-y-1/2 gap-6 overflow-hidden rounded-4xl bg-popover p-6 text-sm text-popover-foreground shadow-xl ring-1 ring-foreground/5 duration-100 outline-none sm:max-w-md dark:ring-foreground/10 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
5555
className
5656
)}
5757
{...props}
@@ -100,7 +100,7 @@ function DialogFooter({
100100
<div
101101
data-slot="dialog-footer"
102102
className={cn(
103-
"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
103+
"-mx-6 -mb-6 flex flex-col-reverse gap-2 rounded-b-4xl border-t bg-muted/20 p-4 sm:flex-row sm:justify-end",
104104
className
105105
)}
106106
{...props}

‎apps/app/src/components/ui/input.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function Input({ className, type, ...props }: React.ComponentProps<"input">) {
99
type={type}
1010
data-slot="input"
1111
className={cn(
12-
"h-9 w-full min-w-0 rounded-lg border border-transparent bg-input/50 px-3 py-1 text-base transition-[color,box-shadow,background-color] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/30 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",
12+
"h-9 w-full min-w-0 rounded-lg border border-border px-3 py-1 text-base transition-[color,box-shadow,background-color] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/30 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 relative inline-flex bg-background not-dark:bg-clip-padding text-foreground shadow-xs/5 ring-ring/24 before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-lg)-1px)] not-has-disabled:not-has-focus-visible:not-has-aria-invalid:before:shadow-[0_1px_--theme(--color-black/4%)] has-focus-visible:has-aria-invalid:border-destructive/64 has-focus-visible:has-aria-invalid:ring-destructive/16 has-aria-invalid:border-destructive/36 has-focus-visible:border-ring has-autofill:bg-foreground/4 has-disabled:opacity-64 has-[:disabled,:focus-visible,[aria-invalid]]:shadow-none has-focus-visible:ring-[3px] sm:text-sm dark:bg-background/40 dark:has-autofill:bg-foreground/8 dark:has-aria-invalid:ring-destructive/24 dark:not-has-disabled:not-has-focus-visible:not-has-aria-invalid:before:shadow-[0_-1px_--theme(--color-white/6%)]",
1313
className
1414
)}
1515
{...props}
Lines changed: 54 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
/** @jsxImportSource react */
2-
import { useEffect, useRef } from "react";
3-
import { X } from "lucide-react";
2+
import { useRef } from "react";
43

5-
import { t } from "../../../../i18n";
4+
import { Button } from "@/components/ui/button";
65
import {
7-
inputClass,
8-
pillGhostClass,
9-
pillPrimaryClass,
10-
pillSecondaryClass,
11-
} from "../../workspace/modal-styles";
6+
Dialog,
7+
DialogContent,
8+
DialogDescription,
9+
DialogFooter,
10+
DialogHeader,
11+
DialogTitle,
12+
} from "@/components/ui/dialog";
13+
import { Field, FieldLabel } from "@/components/ui/field";
14+
import { Input } from "@/components/ui/input";
15+
import { t } from "../../../../i18n";
1216

1317
export type RenameSessionModalProps = {
1418
open: boolean;
@@ -23,83 +27,50 @@ export type RenameSessionModalProps = {
2327
export function RenameSessionModal(props: RenameSessionModalProps) {
2428
const inputRef = useRef<HTMLInputElement | null>(null);
2529

26-
useEffect(() => {
27-
if (!props.open) return;
28-
const frame = requestAnimationFrame(() => {
29-
inputRef.current?.focus();
30-
inputRef.current?.select();
31-
});
32-
return () => cancelAnimationFrame(frame);
33-
}, [props.open]);
34-
35-
if (!props.open) return null;
36-
3730
return (
38-
<div className="fixed inset-0 z-50 bg-gray-1/60 backdrop-blur-sm flex items-center justify-center p-4">
39-
<div className="bg-gray-2 border border-gray-6/70 w-full max-w-lg rounded-2xl shadow-2xl overflow-hidden">
40-
<div className="p-6">
41-
<div className="flex items-start justify-between gap-4">
42-
<div>
43-
<h3 className="text-lg font-semibold text-gray-12">
44-
{t("session.rename_title")}
45-
</h3>
46-
<p className="text-sm text-gray-11 mt-1">
47-
{t("session.rename_description")}
48-
</p>
49-
</div>
50-
<button
51-
type="button"
52-
className={`${pillGhostClass} !p-2 rounded-full`}
53-
onClick={props.onClose}
54-
>
55-
<X size={16} />
56-
</button>
57-
</div>
31+
<Dialog
32+
open={props.open}
33+
onOpenChange={(open) => {
34+
if (!open) props.onClose();
35+
}}
36+
>
37+
<DialogContent className="sm:max-w-lg" initialFocus={inputRef}>
38+
<DialogHeader>
39+
<DialogTitle>{t("session.rename_title")}</DialogTitle>
40+
<DialogDescription>{t("session.rename_description")}</DialogDescription>
41+
</DialogHeader>
5842

59-
<div className="mt-6">
60-
<label className="mb-1.5 block text-[13px] font-medium text-dls-text">
61-
{t("session.rename_label")}
62-
</label>
63-
<input
64-
ref={inputRef}
65-
type="text"
66-
value={props.title}
67-
onChange={(event) => props.onTitleChange(event.currentTarget.value)}
68-
onKeyDown={(event) => {
69-
if (
70-
event.key !== "Enter" ||
71-
event.nativeEvent.isComposing ||
72-
event.keyCode === 229
73-
)
74-
return;
75-
event.preventDefault();
76-
if (props.canSave) props.onSave();
77-
}}
78-
placeholder={t("session.rename_placeholder")}
79-
className={`${inputClass} bg-gray-3`}
80-
/>
81-
</div>
43+
<Field>
44+
<FieldLabel htmlFor="rename-session-title">{t("session.rename_label")}</FieldLabel>
45+
<Input
46+
ref={inputRef}
47+
id="rename-session-title"
48+
type="text"
49+
value={props.title}
50+
onChange={(event) => props.onTitleChange(event.currentTarget.value)}
51+
onKeyDown={(event) => {
52+
if (event.nativeEvent.isComposing || event.key === "Process") {
53+
return;
54+
}
55+
if (event.key !== "Enter") {
56+
return;
57+
}
58+
event.preventDefault();
59+
if (props.canSave) props.onSave();
60+
}}
61+
placeholder={t("session.rename_placeholder")}
62+
/>
63+
</Field>
8264

83-
<div className="mt-6 flex justify-end gap-2">
84-
<button
85-
type="button"
86-
className={pillSecondaryClass}
87-
onClick={props.onClose}
88-
disabled={props.busy}
89-
>
90-
{t("common.cancel")}
91-
</button>
92-
<button
93-
type="button"
94-
className={pillPrimaryClass}
95-
onClick={props.onSave}
96-
disabled={!props.canSave}
97-
>
98-
{t("common.save")}
99-
</button>
100-
</div>
101-
</div>
102-
</div>
103-
</div>
65+
<DialogFooter>
66+
<Button variant="outline" type="button" onClick={props.onClose} disabled={props.busy}>
67+
{t("common.cancel")}
68+
</Button>
69+
<Button type="button" onClick={props.onSave} disabled={!props.canSave}>
70+
{t("common.save")}
71+
</Button>
72+
</DialogFooter>
73+
</DialogContent>
74+
</Dialog>
10475
);
10576
}
Lines changed: 54 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
/** @jsxImportSource react */
2-
import { useEffect, useRef } from "react";
3-
import { X } from "lucide-react";
2+
import { useRef } from "react";
43

4+
import { Button } from "@/components/ui/button";
5+
import {
6+
Dialog,
7+
DialogContent,
8+
DialogDescription,
9+
DialogFooter,
10+
DialogHeader,
11+
DialogTitle,
12+
} from "@/components/ui/dialog";
13+
import { Field, FieldLabel } from "@/components/ui/field";
14+
import { Input } from "@/components/ui/input";
515
import { t } from "../../../i18n";
6-
import { inputClass, pillGhostClass, pillPrimaryClass, pillSecondaryClass } from "./modal-styles";
716

817
export type RenameWorkspaceModalProps = {
918
open: boolean;
@@ -18,83 +27,50 @@ export type RenameWorkspaceModalProps = {
1827
export function RenameWorkspaceModal(props: RenameWorkspaceModalProps) {
1928
const inputRef = useRef<HTMLInputElement | null>(null);
2029

21-
useEffect(() => {
22-
if (!props.open) return;
23-
const frame = requestAnimationFrame(() => {
24-
inputRef.current?.focus();
25-
inputRef.current?.select();
26-
});
27-
return () => cancelAnimationFrame(frame);
28-
}, [props.open]);
29-
30-
if (!props.open) return null;
31-
3230
return (
33-
<div className="fixed inset-0 z-50 bg-gray-1/60 backdrop-blur-sm flex items-center justify-center p-4">
34-
<div className="bg-gray-2 border border-gray-6/70 w-full max-w-lg rounded-2xl shadow-2xl overflow-hidden">
35-
<div className="p-6">
36-
<div className="flex items-start justify-between gap-4">
37-
<div>
38-
<h3 className="text-lg font-semibold text-gray-12">
39-
{t("workspace.rename_title")}
40-
</h3>
41-
<p className="text-sm text-gray-11 mt-1">
42-
{t("workspace.rename_description")}
43-
</p>
44-
</div>
45-
<button
46-
type="button"
47-
className={`${pillGhostClass} !p-2 rounded-full`}
48-
onClick={props.onClose}
49-
>
50-
<X size={16} />
51-
</button>
52-
</div>
31+
<Dialog
32+
open={props.open}
33+
onOpenChange={(open) => {
34+
if (!open) props.onClose();
35+
}}
36+
>
37+
<DialogContent className="sm:max-w-lg" initialFocus={inputRef}>
38+
<DialogHeader>
39+
<DialogTitle>{t("workspace.rename_title")}</DialogTitle>
40+
<DialogDescription>{t("workspace.rename_description")}</DialogDescription>
41+
</DialogHeader>
5342

54-
<div className="mt-6">
55-
<label className="mb-1.5 block text-[13px] font-medium text-dls-text">
56-
{t("workspace.rename_label")}
57-
</label>
58-
<input
59-
ref={inputRef}
60-
type="text"
61-
value={props.title}
62-
onChange={(event) => props.onTitleChange(event.currentTarget.value)}
63-
onKeyDown={(event) => {
64-
if (
65-
event.key !== "Enter" ||
66-
event.nativeEvent.isComposing ||
67-
event.keyCode === 229
68-
)
69-
return;
70-
event.preventDefault();
71-
if (props.canSave) props.onSave();
72-
}}
73-
placeholder={t("workspace.rename_placeholder")}
74-
className={`${inputClass} bg-gray-3`}
75-
/>
76-
</div>
43+
<Field>
44+
<FieldLabel htmlFor="rename-workspace-title">{t("workspace.rename_label")}</FieldLabel>
45+
<Input
46+
ref={inputRef}
47+
id="rename-workspace-title"
48+
type="text"
49+
value={props.title}
50+
onChange={(event) => props.onTitleChange(event.currentTarget.value)}
51+
onKeyDown={(event) => {
52+
if (event.nativeEvent.isComposing || event.key === "Process") {
53+
return;
54+
}
55+
if (event.key !== "Enter") {
56+
return;
57+
}
58+
event.preventDefault();
59+
if (props.canSave) props.onSave();
60+
}}
61+
placeholder={t("workspace.rename_placeholder")}
62+
/>
63+
</Field>
7764

78-
<div className="mt-6 flex justify-end gap-2">
79-
<button
80-
type="button"
81-
className={pillSecondaryClass}
82-
onClick={props.onClose}
83-
disabled={props.busy}
84-
>
85-
{t("common.cancel")}
86-
</button>
87-
<button
88-
type="button"
89-
className={pillPrimaryClass}
90-
onClick={props.onSave}
91-
disabled={!props.canSave}
92-
>
93-
{t("common.save")}
94-
</button>
95-
</div>
96-
</div>
97-
</div>
98-
</div>
65+
<DialogFooter>
66+
<Button variant="outline" type="button" onClick={props.onClose} disabled={props.busy}>
67+
{t("common.cancel")}
68+
</Button>
69+
<Button type="button" onClick={props.onSave} disabled={!props.canSave}>
70+
{t("common.save")}
71+
</Button>
72+
</DialogFooter>
73+
</DialogContent>
74+
</Dialog>
9975
);
10076
}

0 commit comments

Comments
 (0)