text customization edited, now there is a live preview of before applying the changes and added button of apply the change
This commit is contained in:
parent
ac5b6a943f
commit
3cfb7d0792
1 changed files with 63 additions and 15 deletions
|
|
@ -8,7 +8,7 @@ import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectVa
|
||||||
import { Slider } from '@/components/ui/slider';
|
import { Slider } from '@/components/ui/slider';
|
||||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||||
import { useContext, useEffect, useState } from 'react'
|
import { useContext, useEffect, useState } from 'react'
|
||||||
import { AlignLeft, AlignCenter, AlignRight, Bold, Italic, Underline, Strikethrough } from "lucide-react";
|
import { AlignLeft, AlignCenter, AlignRight, Bold, Italic, Underline, Strikethrough } from 'lucide-react';
|
||||||
import CollapsibleComponent from './CollapsibleComponent';
|
import CollapsibleComponent from './CollapsibleComponent';
|
||||||
|
|
||||||
const fonts = [
|
const fonts = [
|
||||||
|
|
@ -37,6 +37,7 @@ const TextCustomization = () => {
|
||||||
const [underline, setUnderline] = useState(false);
|
const [underline, setUnderline] = useState(false);
|
||||||
const [linethrough, setLinethrough] = useState(false);
|
const [linethrough, setLinethrough] = useState(false);
|
||||||
const [textAlign, setTextAlign] = useState('left');
|
const [textAlign, setTextAlign] = useState('left');
|
||||||
|
const [previewText, setPreviewText] = useState('');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (activeObject?.type === "i-text") {
|
if (activeObject?.type === "i-text") {
|
||||||
|
|
@ -50,6 +51,7 @@ const TextCustomization = () => {
|
||||||
setUnderline(activeObject?.underline || false);
|
setUnderline(activeObject?.underline || false);
|
||||||
setLinethrough(activeObject?.linethrough || false);
|
setLinethrough(activeObject?.linethrough || false);
|
||||||
setTextAlign(activeObject?.textAlign || 'left');
|
setTextAlign(activeObject?.textAlign || 'left');
|
||||||
|
setPreviewText(activeObject?.text || '');
|
||||||
}
|
}
|
||||||
}, [activeObject])
|
}, [activeObject])
|
||||||
|
|
||||||
|
|
@ -60,58 +62,78 @@ const TextCustomization = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const updatePreview = (properties) => {
|
||||||
|
setPreviewText(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
const applyChanges = () => {
|
||||||
|
updateActiveObject({
|
||||||
|
text,
|
||||||
|
fontFamily,
|
||||||
|
fontSize,
|
||||||
|
fontStyle,
|
||||||
|
fontWeight,
|
||||||
|
lineHeight,
|
||||||
|
charSpacing,
|
||||||
|
underline,
|
||||||
|
linethrough,
|
||||||
|
textAlign
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const handleTextChange = (newText) => {
|
const handleTextChange = (newText) => {
|
||||||
setText(newText)
|
setText(newText);
|
||||||
updateActiveObject({ text: newText })
|
updatePreview({ text: newText });
|
||||||
|
setPreviewText(newText);
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleFontFamilyChange = (newFontFamily) => {
|
const handleFontFamilyChange = (newFontFamily) => {
|
||||||
setFontFamily(newFontFamily)
|
setFontFamily(newFontFamily);
|
||||||
updateActiveObject({ fontFamily: newFontFamily })
|
updatePreview({ fontFamily: newFontFamily });
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleFontSizeChange = (newFontSize) => {
|
const handleFontSizeChange = (newFontSize) => {
|
||||||
setFontSize(newFontSize)
|
setFontSize(newFontSize)
|
||||||
updateActiveObject({ fontSize: newFontSize })
|
updatePreview({ fontSize: newFontSize })
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleTextAlignChange = (newTextAlign) => {
|
const handleTextAlignChange = (newTextAlign) => {
|
||||||
setTextAlign(newTextAlign)
|
setTextAlign(newTextAlign)
|
||||||
updateActiveObject({ textAlign: newTextAlign })
|
updatePreview({ textAlign: newTextAlign })
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleFontStyleChange = () => {
|
const handleFontStyleChange = () => {
|
||||||
const newFontStyle = fontStyle === 'normal' ? 'italic' : 'normal'
|
const newFontStyle = fontStyle === 'normal' ? 'italic' : 'normal'
|
||||||
setFontStyle(newFontStyle)
|
setFontStyle(newFontStyle)
|
||||||
updateActiveObject({ fontStyle: newFontStyle })
|
updatePreview({ fontStyle: newFontStyle })
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleFontWeightChange = () => {
|
const handleFontWeightChange = () => {
|
||||||
const newFontWeight = fontWeight === 'normal' ? 'bold' : 'normal'
|
const newFontWeight = fontWeight === 'normal' ? 'bold' : 'normal'
|
||||||
setFontWeight(newFontWeight)
|
setFontWeight(newFontWeight)
|
||||||
updateActiveObject({ fontWeight: newFontWeight })
|
updatePreview({ fontWeight: newFontWeight })
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleLineHeightChange = (newLineHeight) => {
|
const handleLineHeightChange = (newLineHeight) => {
|
||||||
setLineHeight(newLineHeight)
|
setLineHeight(newLineHeight)
|
||||||
updateActiveObject({ lineHeight: newLineHeight })
|
updatePreview({ lineHeight: newLineHeight })
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleCharSpacingChange = (newCharSpacing) => {
|
const handleCharSpacingChange = (newCharSpacing) => {
|
||||||
setCharSpacing(newCharSpacing)
|
setCharSpacing(newCharSpacing)
|
||||||
updateActiveObject({ charSpacing: newCharSpacing })
|
updatePreview({ charSpacing: newCharSpacing })
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleUnderlineChange = () => {
|
const handleUnderlineChange = () => {
|
||||||
const newUnderline = !underline
|
const newUnderline = !underline
|
||||||
setUnderline(newUnderline)
|
setUnderline(newUnderline)
|
||||||
updateActiveObject({ underline: newUnderline })
|
updatePreview({ underline: newUnderline })
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleLinethroughChange = () => {
|
const handleLinethroughChange = () => {
|
||||||
const newLinethrough = !linethrough
|
const newLinethrough = !linethrough
|
||||||
setLinethrough(newLinethrough)
|
setLinethrough(newLinethrough)
|
||||||
updateActiveObject({ linethrough: newLinethrough })
|
updatePreview({ linethrough: newLinethrough })
|
||||||
}
|
}
|
||||||
|
|
||||||
const content = () => {
|
const content = () => {
|
||||||
|
|
@ -135,6 +157,7 @@ const TextCustomization = () => {
|
||||||
<TabsTrigger value="text">Text</TabsTrigger>
|
<TabsTrigger value="text">Text</TabsTrigger>
|
||||||
<TabsTrigger value="style">Style</TabsTrigger>
|
<TabsTrigger value="style">Style</TabsTrigger>
|
||||||
</TabsList>
|
</TabsList>
|
||||||
|
|
||||||
<TabsContent value="text" className="space-y-1">
|
<TabsContent value="text" className="space-y-1">
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<Label htmlFor="text-content">Text Content</Label>
|
<Label htmlFor="text-content">Text Content</Label>
|
||||||
|
|
@ -150,7 +173,7 @@ const TextCustomization = () => {
|
||||||
<SelectTrigger>
|
<SelectTrigger>
|
||||||
<SelectValue placeholder="Select a font" />
|
<SelectValue placeholder="Select a font" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent className="h-[250px]">
|
||||||
<SelectGroup>
|
<SelectGroup>
|
||||||
{fonts.map((font) => (
|
{fonts.map((font) => (
|
||||||
<SelectItem style={{ fontFamily: font }} key={font} value={font}>
|
<SelectItem style={{ fontFamily: font }} key={font} value={font}>
|
||||||
|
|
@ -273,8 +296,33 @@ const TextCustomization = () => {
|
||||||
<CollapsibleComponent text={"Text Control"}>
|
<CollapsibleComponent text={"Text Control"}>
|
||||||
{content()}
|
{content()}
|
||||||
</CollapsibleComponent>
|
</CollapsibleComponent>
|
||||||
|
<div className="mt-4 space-y-4">
|
||||||
|
{
|
||||||
|
previewText &&
|
||||||
|
<div className="p-4 border rounded-md overflow-hidden">
|
||||||
|
<p className="font-bold mb-2">Preview:</p>
|
||||||
|
<p style={{
|
||||||
|
fontFamily,
|
||||||
|
fontSize: `${fontSize}px`,
|
||||||
|
fontStyle,
|
||||||
|
fontWeight,
|
||||||
|
lineHeight,
|
||||||
|
letterSpacing: `${charSpacing}px`,
|
||||||
|
textDecoration: `${underline ? 'underline' : ''} ${linethrough ? 'line-through' : ''}`,
|
||||||
|
textAlign
|
||||||
|
}} className='truncate'>
|
||||||
|
{previewText}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
<Button onClick={applyChanges} className="w-full">
|
||||||
|
Apply Changes
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default TextCustomization
|
export default TextCustomization
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue