set text line height

This commit is contained in:
hamid zarghami
2026-05-06 09:22:06 +03:30
parent 793ae82914
commit 5de205a84f
5 changed files with 35 additions and 1 deletions
@@ -7,6 +7,19 @@ type TextSettingsProps = {
onUpdate: (id: string, updates: Partial<EditorObject>) => void;
};
const normalizeNumericInput = (value: string): string => {
const persianDigits = "۰۱۲۳۴۵۶۷۸۹";
const arabicDigits = "٠١٢٣٤٥٦٧٨٩";
return value
.replace(/[۰-۹]/g, (d) => String(persianDigits.indexOf(d)))
.replace(/[٠-٩]/g, (d) => String(arabicDigits.indexOf(d)))
.replace("٫", ".")
.replace(",", ".");
};
const parseNumber = (value: string): number => Number(normalizeNumericInput(value));
const TextSettings = ({ selectedObject, onUpdate }: TextSettingsProps) => {
return (
<>
@@ -19,9 +32,22 @@ const TextSettings = ({ selectedObject, onUpdate }: TextSettingsProps) => {
label="اندازه فونت"
type="number"
value={selectedObject.fontSize || 24}
step="1"
onChange={(e) =>
onUpdate(selectedObject.id, {
fontSize: parseInt(e.target.value) || 24,
fontSize: parseNumber(e.target.value) || 24,
})
}
/>
<Input
label="فاصله خطوط"
type="number"
value={selectedObject.lineHeight ?? 1.2}
step="0.1"
min="0.5"
onChange={(e) =>
onUpdate(selectedObject.id, {
lineHeight: parseNumber(e.target.value) || 1.2,
})
}
/>