mirror of
https://github.com/documenso/documenso.git
synced 2025-11-10 04:22:32 +10:00
## Description Adds the ability to align text to the left, center or right for relevant fields. Previously text was always centered which can be less desirable. See attached debug document which has left, center and right text alignments set for fields. <img width="614" alt="image" src="https://github.com/user-attachments/assets/361a030e-813d-458b-9c7a-ff4c9fa5e33c" /> ## Related Issue N/A ## Changes Made - Added text align option - Update the insert in pdf method to support different alignments - Added a debug mode to field insertion ## Testing Performed - Ran manual tests using the debug mode
100 lines
2.8 KiB
TypeScript
100 lines
2.8 KiB
TypeScript
import { Trans, msg } from '@lingui/macro';
|
|
import { useLingui } from '@lingui/react';
|
|
|
|
import { validateFields as validateDateFields } from '@documenso/lib/advanced-fields-validation/validate-fields';
|
|
import { type TDateFieldMeta as DateFieldMeta } from '@documenso/lib/types/field-meta';
|
|
import { Input } from '@documenso/ui/primitives/input';
|
|
import { Label } from '@documenso/ui/primitives/label';
|
|
import {
|
|
Select,
|
|
SelectContent,
|
|
SelectItem,
|
|
SelectTrigger,
|
|
SelectValue,
|
|
} from '@documenso/ui/primitives/select';
|
|
|
|
type DateFieldAdvancedSettingsProps = {
|
|
fieldState: DateFieldMeta;
|
|
handleFieldChange: (key: keyof DateFieldMeta, value: string | boolean) => void;
|
|
handleErrors: (errors: string[]) => void;
|
|
};
|
|
|
|
export const DateFieldAdvancedSettings = ({
|
|
fieldState,
|
|
handleFieldChange,
|
|
handleErrors,
|
|
}: DateFieldAdvancedSettingsProps) => {
|
|
const { _ } = useLingui();
|
|
|
|
// const handleInput = (field: keyof DateFieldMeta, value: string | boolean) => {
|
|
// if (field === 'fontSize') {
|
|
// const fontSize = value === '' ? '' : Number(value);
|
|
// if (typeof fontSize === 'number' && !Number.isNaN(fontSize)) {
|
|
// const errors = validateDateFields({
|
|
// fontSize,
|
|
// type: 'date',
|
|
// });
|
|
// handleErrors(errors);
|
|
// handleFieldChange(field, fontSize.toString());
|
|
// } else {
|
|
// handleErrors(['Invalid font size']);
|
|
// }
|
|
// } else {
|
|
// handleFieldChange(field, value);
|
|
// }
|
|
// };
|
|
|
|
const handleInput = (field: keyof DateFieldMeta, value: string | boolean) => {
|
|
const fontSize = field === 'fontSize' ? Number(value) : Number(fieldState.fontSize ?? 14);
|
|
|
|
const errors = validateDateFields({
|
|
fontSize,
|
|
type: 'date',
|
|
});
|
|
|
|
handleErrors(errors);
|
|
handleFieldChange(field, value);
|
|
};
|
|
|
|
return (
|
|
<div className="flex flex-col gap-4">
|
|
<div>
|
|
<Label>
|
|
<Trans>Font Size</Trans>
|
|
</Label>
|
|
<Input
|
|
id="fontSize"
|
|
type="number"
|
|
className="bg-background mt-2"
|
|
placeholder={_(msg`Field font size`)}
|
|
value={fieldState.fontSize}
|
|
onChange={(e) => handleInput('fontSize', e.target.value)}
|
|
min={8}
|
|
max={96}
|
|
/>
|
|
</div>
|
|
|
|
<div>
|
|
<Label>
|
|
<Trans>Text Align</Trans>
|
|
</Label>
|
|
|
|
<Select
|
|
value={fieldState.textAlign}
|
|
onValueChange={(value) => handleInput('textAlign', value)}
|
|
>
|
|
<SelectTrigger className="bg-background mt-2">
|
|
<SelectValue placeholder="Select text align" />
|
|
</SelectTrigger>
|
|
|
|
<SelectContent>
|
|
<SelectItem value="left">Left</SelectItem>
|
|
<SelectItem value="center">Center</SelectItem>
|
|
<SelectItem value="right">Right</SelectItem>
|
|
</SelectContent>
|
|
</Select>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|