Skip to content

Commit 02ec6dd

Browse files
committed
Move Preview/Edit to bottom
1 parent f0d95e7 commit 02ec6dd

1 file changed

Lines changed: 46 additions & 43 deletions

File tree

client/src/components/TextEditorWithPreview.tsx

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -27,43 +27,10 @@ export const TextEditorWithPreview = ({
2727
const [activeTab, setActiveTab] = useState<'edit' | 'preview'>('edit');
2828

2929
return (
30-
<div className={cn("relative border border-border rounded-lg overflow-hidden bg-background", className)}>
31-
<div
32-
className="absolute top-2 right-2 z-10 flex bg-background/90 backdrop-blur-sm rounded border border-border shadow-sm overflow-hidden">
33-
<Button
34-
type="button"
35-
variant="ghost"
36-
size="sm"
37-
onClick={() => setActiveTab('edit')}
38-
className={cn(
39-
"h-7 px-2 text-xs rounded-r-none border-r border-border transition-all",
40-
activeTab === 'edit'
41-
? "bg-primary text-primary-foreground border-primary shadow-sm hover:bg-primary/90"
42-
: "text-muted-foreground hover:text-foreground hover:bg-muted/50"
43-
)}
44-
disabled={disabled}
45-
>
46-
<Edit3 className="h-3 w-3 mr-1"/>
47-
Edit
48-
</Button>
49-
<Button
50-
type="button"
51-
variant="ghost"
52-
size="sm"
53-
onClick={() => setActiveTab('preview')}
54-
className={cn(
55-
"h-7 px-2 text-xs rounded-l-none transition-all",
56-
activeTab === 'preview'
57-
? "bg-primary text-primary-foreground border-primary shadow-sm hover:bg-primary/90"
58-
: "text-muted-foreground hover:text-foreground hover:bg-muted/50"
59-
)}
60-
disabled={disabled}
61-
>
62-
<Eye className="h-3 w-3 mr-1"/>
63-
Preview
64-
</Button>
65-
</div>
66-
30+
<div className={cn(
31+
"relative border border-border rounded-lg overflow-hidden bg-background transition-all focus-within:ring-2 focus-within:ring-primary focus-within:border-primary",
32+
className
33+
)}>
6734
<div className="relative">
6835
{activeTab === 'edit' ? (
6936
<Textarea
@@ -73,11 +40,11 @@ export const TextEditorWithPreview = ({
7340
placeholder={placeholder}
7441
rows={rows}
7542
disabled={disabled}
76-
className="border-0 resize-none focus:ring-0 focus:ring-offset-0 rounded-lg bg-transparent pr-24"
43+
className="border-0 resize-none focus:ring-0 focus:ring-offset-0 focus-visible:ring-0 focus-visible:ring-offset-0 rounded-none bg-transparent outline-none p-3 min-h-[140px]"
7744
/>
7845
) : (
7946
<div
80-
className="p-3 min-h-[140px] bg-background rounded-lg pr-24"
47+
className="p-3 min-h-[140px] bg-background rounded-t-lg"
8148
style={{minHeight: `${rows * 1.5}em`}}
8249
>
8350
{value.trim() ? (
@@ -94,13 +61,49 @@ export const TextEditorWithPreview = ({
9461
)}
9562
</div>
9663

97-
{activeTab === 'edit' && value.length > 0 && (
98-
<div className="px-3 py-2 border-t border-border bg-muted/20">
64+
{(activeTab === 'edit' && value.length > 0) || activeTab === 'preview' ? (
65+
<div className="px-3 py-1.5 border-t border-border bg-muted/20 flex justify-between items-center">
9966
<div className="text-xs text-muted-foreground">
100-
{value.length} characters • Supports markdown formatting
67+
{activeTab === 'edit' && `${value.length} characters • Supports markdown formatting`}
68+
{activeTab === 'preview' && 'Preview mode'}
69+
</div>
70+
<div
71+
className="flex bg-background/90 backdrop-blur-sm rounded border border-border shadow-sm overflow-hidden">
72+
<Button
73+
type="button"
74+
variant="ghost"
75+
size="sm"
76+
onClick={() => setActiveTab('edit')}
77+
className={cn(
78+
"h-6 px-2 text-xs rounded-r-none border-r border-border transition-all",
79+
activeTab === 'edit'
80+
? "bg-primary text-primary-foreground border-primary shadow-sm hover:bg-primary/90"
81+
: "text-muted-foreground hover:text-foreground hover:bg-muted/50"
82+
)}
83+
disabled={disabled}
84+
>
85+
<Edit3 className="h-3 w-3 mr-1"/>
86+
Edit
87+
</Button>
88+
<Button
89+
type="button"
90+
variant="ghost"
91+
size="sm"
92+
onClick={() => setActiveTab('preview')}
93+
className={cn(
94+
"h-6 px-2 text-xs rounded-l-none transition-all",
95+
activeTab === 'preview'
96+
? "bg-primary text-primary-foreground border-primary shadow-sm hover:bg-primary/90"
97+
: "text-muted-foreground hover:text-foreground hover:bg-muted/50"
98+
)}
99+
disabled={disabled}
100+
>
101+
<Eye className="h-3 w-3 mr-1"/>
102+
Preview
103+
</Button>
101104
</div>
102105
</div>
103-
)}
106+
) : null}
104107
</div>
105108
);
106109
};

0 commit comments

Comments
 (0)