fix: adjust field cropping

This commit is contained in:
David Nguyen
2025-03-12 00:22:09 +11:00
parent bacb581825
commit c992a36b4b
3 changed files with 8 additions and 25 deletions

View File

@@ -345,28 +345,9 @@ export const insertFieldInPDF = async (pdf: PDFDocument, field: FieldWithSignatu
* - True = text will overflow downwards. * - True = text will overflow downwards.
* - False = text will overflow sideways. * - False = text will overflow sideways.
*/ */
const isMultiline = (() => { const isMultiline =
// No multiline for date, number or email fields, it MUST overflow on X axis. field.type === FieldType.TEXT &&
if ( (textWidth > fieldWidth || field.customText.includes('\n'));
field.type === FieldType.DATE ||
field.type === FieldType.NUMBER ||
field.type === FieldType.EMAIL
) {
return false;
}
// If width of text overflows, multiline is enabled.
if (textWidth > fieldWidth) {
return true;
}
// If the text contains a newline, it must be multiline.
if (field.customText.includes('\n')) {
return true;
}
return false;
})();
// Add padding similar to web display (roughly 0.5rem equivalent in PDF units) // Add padding similar to web display (roughly 0.5rem equivalent in PDF units)
const padding = 8; const padding = 8;

View File

@@ -80,7 +80,7 @@ export function FieldRootContainer({ field, children, color, className }: FieldR
data-field-type={field.type} data-field-type={field.type}
data-inserted={field.inserted ? 'true' : 'false'} data-inserted={field.inserted ? 'true' : 'false'}
className={cn( className={cn(
'field--FieldRootContainer field-card-container dark-mode-disabled group relative z-20 flex h-full w-full items-center overflow-clip rounded-[2px] bg-white/90 ring-2 ring-gray-200 transition-all', 'field--FieldRootContainer field-card-container dark-mode-disabled group relative z-20 flex h-full w-full items-center rounded-[2px] bg-white/90 ring-2 ring-gray-200 transition-all',
color?.base, color?.base,
{ {
'px-2': field.type !== FieldType.SIGNATURE && field.type !== FieldType.FREE_SIGNATURE, 'px-2': field.type !== FieldType.SIGNATURE && field.type !== FieldType.FREE_SIGNATURE,

View File

@@ -62,7 +62,9 @@ export const FieldContent = ({ field, documentMeta }: FieldIconProps) => {
<Checkbox <Checkbox
className="h-3 w-3" className="h-3 w-3"
id={`checkbox-${index}`} id={`checkbox-${index}`}
checked={checkedValues.includes(item.value)} checked={checkedValues.includes(
item.value === '' ? `empty-value-${index + 1}` : item.value, // I got no idea...
)}
/> />
{item.value && ( {item.value && (
@@ -171,7 +173,7 @@ export const FieldContent = ({ field, documentMeta }: FieldIconProps) => {
return ( return (
<div <div
className={cn( className={cn(
'text-field-card-foreground flex h-full w-full items-center justify-center gap-x-1.5 whitespace-nowrap text-center text-[clamp(0.07rem,25cqw,0.825rem)]', 'text-field-card-foreground flex h-full w-full items-center justify-center gap-x-1.5 overflow-clip whitespace-nowrap text-center text-[clamp(0.07rem,25cqw,0.825rem)]',
{ {
// Using justify instead of align because we also vertically center the text. // Using justify instead of align because we also vertically center the text.
'justify-start': field.inserted && !isSignatureField && textAlign === 'left', 'justify-start': field.inserted && !isSignatureField && textAlign === 'left',