-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: improve field sizing #1486
Conversation
Allows for smaller field sizing in addition to improving our styling when displaying labels on smaller fields. This is the minimum currently supported field size until we perform a more extensive refactor of our current drag and drop system.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
3 Skipped Deployments
|
WalkthroughThe pull request introduces modifications across multiple components in the application, primarily focusing on responsive text sizing. Changes include updates to class names for various text elements, ensuring they adapt better to different screen sizes. Additionally, new constants for default dimensions and adjustments to translation files in multiple languages enhance localization. The overall logic and functionality of the components remain unchanged, with improvements concentrated on visual presentation and responsiveness. Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Warning There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure. 🔧 eslint
packages/ui/primitives/auto-sized-text.tsxOops! Something went wrong! :( ESLint: 8.57.1 ESLint couldn't find the config "@documenso/eslint-config" to extend from. Please check that the name of the config is correct. The config "@documenso/eslint-config" was referenced from the config file in "/.eslintrc.cjs". If you still have problems, please stop by https://eslint.org/chat/help to chat with the team. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
💤 Files with no reviewable changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 10 out of 25 changed files in this pull request and generated 4 suggestions.
Files not reviewed (15)
- packages/lib/translations/de/common.po: Language not supported
- packages/lib/translations/de/web.po: Language not supported
- packages/lib/translations/en/common.po: Language not supported
- packages/lib/translations/en/web.po: Language not supported
- packages/lib/translations/es/common.po: Language not supported
- packages/lib/translations/es/web.po: Language not supported
- packages/lib/translations/fr/common.po: Language not supported
- packages/lib/translations/fr/web.po: Language not supported
- packages/tailwind-config/package.json: Language not supported
- apps/web/src/app/(signing)/sign/[token]/number-field.tsx: Evaluated as low risk
- apps/web/src/app/(signing)/sign/[token]/text-field.tsx: Evaluated as low risk
- packages/tailwind-config/index.cjs: Evaluated as low risk
- apps/web/src/app/(signing)/sign/[token]/name-field.tsx: Evaluated as low risk
- apps/web/src/app/(signing)/sign/[token]/dropdown-field.tsx: Evaluated as low risk
- apps/web/src/app/(signing)/sign/[token]/email-field.tsx: Evaluated as low risk
Comments skipped due to low confidence (1)
packages/ui/primitives/document-flow/add-fields.tsx:3
- Missing semicolon at the end of the function.
handleAdvancedSettings = () => {
const isElementTooBig = | ||
childDimensions.width > parentDimensions.width || childDimensions.height > targetHeight; | ||
|
||
console.log({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove console.log statements from production code.
Copilot is powered by AI, so mistakes are possible. Review output carefully before use.
fontSizeLowerBound.current = fontSize.current; | ||
} | ||
|
||
console.log({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove console.log statements from production code.
Copilot is powered by AI, so mistakes are possible. Review output carefully before use.
fontSizeLowerBound.current = 0; | ||
fontSizeUpperBound.current = parentDimensions.height; | ||
|
||
console.log('parentDimensions', structuredClone(parentDimensions)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove console.log statements from production code.
console.log('parentDimensions', structuredClone(parentDimensions)); | |
Copilot is powered by AI, so mistakes are possible. Review output carefully before use.
|
||
while (iterationCount <= ITERATION_LIMIT) { | ||
const childDimensions = getElementDimensions(childElement); | ||
console.log({ childDimensions }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove console.log statements from production code.
console.log({ childDimensions }); | |
// console.log({ childDimensions }); |
Copilot is powered by AI, so mistakes are possible. Review output carefully before use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 8
🧹 Outside diff range and nitpick comments (15)
packages/ui/primitives/document-flow/show-field-item.tsx (1)
50-52
: Consider improving class organization and text readability.While the responsive sizing using
clamp()
is good, consider these improvements:
- Split the long className into multiple lines for better maintainability
- Consider adding a minimum line-height for better readability at small sizes
className={cn( - 'text-muted-foreground/50 flex h-full w-full flex-col items-center justify-center p-0 text-[clamp(0.575rem,1.8cqw,1.2rem)] leading-none', + 'flex h-full w-full flex-col items-center justify-center p-0', + 'text-muted-foreground/50', + 'text-[clamp(0.575rem,1.8cqw,1.2rem)]', + 'leading-[1.2]', // Instead of leading-none field.type === FieldType.SIGNATURE && fontCaveat.className, )}packages/tailwind-config/index.cjs (1)
142-146
: Consider documenting container queries usage.Since container queries are a powerful but relatively new feature, consider adding documentation or code examples to help other developers effectively use this capability for field sizing.
Would you like me to help draft documentation about container queries usage in the project?
apps/web/src/app/(signing)/sign/[token]/name-field.tsx (2)
175-177
: Text sizing adjustment aligns with PR objectivesThe modification to use
text-[clamp(0.425rem,25cqw,0.825rem)]
effectively:
- Reduces the minimum text size to support smaller fields
- Increases the scaling factor for better responsiveness
- Maintains readability with the same maximum size
However, consider adding a comment explaining the chosen values for future maintainability.
- <p className="text-muted-foreground dark:text-background/80 text-[clamp(0.425rem,25cqw,0.825rem)] duration-200"> + {/* Minimum size reduced to 0.425rem to support smaller fields while maintaining readability */} + <p className="text-muted-foreground dark:text-background/80 text-[clamp(0.425rem,25cqw,0.825rem)] duration-200">
Line range hint
152-154
: Consider responsive sizing for the loaderTo maintain consistency with the improved field sizing, consider making the loader size responsive using similar clamp() values or relative units instead of fixed sizes.
- <Loader className="text-primary h-5 w-5 animate-spin md:h-8 md:w-8" /> + <Loader className="text-primary h-[clamp(1.25rem,4cqw,2rem)] w-[clamp(1.25rem,4cqw,2rem)] animate-spin" />packages/ui/primitives/document-flow/field-item.tsx (1)
Line range hint
38-76
: Consider splitting the component for better maintainabilityThe
FieldItem
component currently handles multiple concerns:
- Field positioning
- Size management
- Content rendering
- Interactive controls
Consider splitting this into smaller, more focused components to improve maintainability and make future sizing improvements easier:
FieldPositioner
: Handle drag & drop positioningFieldSizer
: Manage dimensions and resizingFieldContent
: Render the actual field contentThis would make it easier to:
- Implement the planned drag-and-drop system refactor
- Add more sophisticated sizing logic
- Test each concern independently
Would you like me to provide a detailed proposal for this refactoring?
apps/web/src/app/(signing)/sign/[token]/number-field.tsx (1)
Line range hint
1-350
: Consider extracting validation logic and error renderingThe component could benefit from two refactoring opportunities:
- Extract the validation logic into a custom hook for better reusability
- Create a reusable error component to reduce repetition in error rendering
Example implementation for error component:
type ErrorMessageProps = { errors: ValidationErrors; }; const ErrorMessages: React.FC<ErrorMessageProps> = ({ errors }) => ( <div> {Object.entries(errors).map(([type, messages]) => messages.map((error, index) => ( <p key={`${type}-${index}`} className="mt-2 text-sm text-red-500"> {error} </p> )) )} </div> );This would simplify the error rendering section of the dialog.
packages/ui/primitives/document-flow/add-fields.tsx (1)
600-600
: Improve text sizing implementation with CSS custom propertyThe text sizing implementation using
clamp()
is good for responsiveness, but consider extracting the clamp values to a CSS custom property for better maintainability and reuse across components.- <span className="text-[clamp(0.425rem,25cqw,0.825rem)]"> + <span className="text-[var(--field-text-size,clamp(0.425rem,25cqw,0.825rem))]">Also applies to: 615-617
packages/lib/translations/en/common.po (3)
412-416
: Maintain consistent capitalization in button labelsThe translations "Add Myself" and "Add Placeholder Recipient" use title case, which differs from other similar action buttons in the file that use sentence case (e.g., "Add a document", "Add text").
Consider using sentence case for consistency:
-msgstr "Add Myself" +msgstr "Add myself" -msgstr "Add Placeholder Recipient" +msgstr "Add placeholder recipient"
1558-1559
: Improve clarity of the restriction messageThe message could be more concise while maintaining its meaning.
Consider this alternative wording:
-msgstr "This document has already been sent to this recipient. You can no longer edit this recipient." +msgstr "This recipient cannot be edited as the document has already been sent to them."
1626-1627
: Improve clarity of the validation messageThe current translation uses a placeholder {0} which might be confusing in the context.
Consider this alternative wording:
-msgstr "To proceed further, please set at least one value for the {0} field." +msgstr "Please set at least one value for the {0} field to continue."packages/lib/translations/fr/common.po (1)
446-447
: Consider a more natural translation for "Advanced settings".While "Paramètres avancés" is technically correct, consider "Options avancées" for consistency with line 272 where "Advanced Options" is translated as "Options avancées".
-msgid "Advanced settings" -msgstr "Paramètres avancés" +msgid "Advanced settings" +msgstr "Options avancées"packages/lib/translations/de/common.po (2)
1023-1030
: Inconsistent quotation marks in translationsThe translations use a mix of straight quotes (") and German quotation marks („"). For consistency with German language standards, use German quotation marks throughout.
Example fix for one instance:
msgid "Name" -msgstr "Name" +msgstr „Name"
1594-1602
: Improve clarity of technical terms in translationsThe translations of technical terms could be improved for better understanding by German users. Consider adding explanatory terms where appropriate.
msgid "This field cannot be modified or deleted." -msgstr "Dieses Feld kann nicht geändert oder gelöscht werden." +msgstr "Dieses Eingabefeld kann nicht bearbeitet oder entfernt werden."packages/ui/primitives/auto-sized-text.tsx (2)
73-74
: SimplifytargetHeight
calculation usingMath.min
To enhance readability and conciseness, you can simplify the
targetHeight
calculation by usingMath.min
.Apply this diff to simplify:
-const targetHeight = - maxHeight && maxHeight < parentDimensions.height ? maxHeight : parentDimensions.height; +const targetHeight = maxHeight ? Math.min(maxHeight, parentDimensions.height) : parentDimensions.height;Also applies to: 142-143
79-84
: Removeconsole.log
statements from production codeMultiple
console.log
statements are present in the code, which are useful for debugging but should be removed or replaced with a proper logging mechanism in production to avoid unnecessary console output and potential performance issues.Apply this diff to remove the
console.log
statements:console.log({ fontSizeLowerBound: fontSizeLowerBound.current, fontSizeUpperBound: fontSizeUpperBound.current, fontSize: fontSize.current, }); // ... console.log({ currentFontSize: fontSize.current, newFontSize, targetHeight, currentHeight: childDimensions.height, parentHeight: parentDimensions.height, }); // ... -console.log('parentDimensions', structuredClone(parentDimensions)); // ... -console.log({ childDimensions });Also applies to: 98-105, 134-134, 140-141
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
⛔ Files ignored due to path filters (1)
package-lock.json
is excluded by!**/package-lock.json
📒 Files selected for processing (24)
apps/web/src/app/(signing)/sign/[token]/date-field.tsx
(1 hunks)apps/web/src/app/(signing)/sign/[token]/dropdown-field.tsx
(3 hunks)apps/web/src/app/(signing)/sign/[token]/email-field.tsx
(1 hunks)apps/web/src/app/(signing)/sign/[token]/initials-field.tsx
(1 hunks)apps/web/src/app/(signing)/sign/[token]/name-field.tsx
(1 hunks)apps/web/src/app/(signing)/sign/[token]/number-field.tsx
(1 hunks)apps/web/src/app/(signing)/sign/[token]/signature-field.tsx
(1 hunks)apps/web/src/app/(signing)/sign/[token]/text-field.tsx
(1 hunks)packages/lib/translations/de/common.po
(21 hunks)packages/lib/translations/de/web.po
(7 hunks)packages/lib/translations/en/common.po
(21 hunks)packages/lib/translations/en/web.po
(7 hunks)packages/lib/translations/es/common.po
(21 hunks)packages/lib/translations/es/web.po
(7 hunks)packages/lib/translations/fr/common.po
(21 hunks)packages/lib/translations/fr/web.po
(7 hunks)packages/tailwind-config/index.cjs
(1 hunks)packages/tailwind-config/package.json
(1 hunks)packages/ui/primitives/auto-sized-text.tsx
(1 hunks)packages/ui/primitives/document-flow/add-fields.tsx
(5 hunks)packages/ui/primitives/document-flow/field-icon.tsx
(2 hunks)packages/ui/primitives/document-flow/field-item.tsx
(3 hunks)packages/ui/primitives/document-flow/show-field-item.tsx
(1 hunks)packages/ui/primitives/template-flow/add-template-fields.tsx
(5 hunks)
✅ Files skipped from review due to trivial changes (6)
- apps/web/src/app/(signing)/sign/[token]/date-field.tsx
- apps/web/src/app/(signing)/sign/[token]/dropdown-field.tsx
- apps/web/src/app/(signing)/sign/[token]/email-field.tsx
- apps/web/src/app/(signing)/sign/[token]/initials-field.tsx
- apps/web/src/app/(signing)/sign/[token]/signature-field.tsx
- packages/lib/translations/en/web.po
🔇 Additional comments (49)
packages/tailwind-config/package.json (2)
10-11
: LGTM! Dependencies are properly structured.
The addition of container queries plugin aligns well with the PR's objective of improving field sizing, and moving typography from devDependencies to dependencies is appropriate if it's required at runtime.
10-11
: Consider updating to latest stable versions.
Please verify if newer stable versions are available for:
- @tailwindcss/container-queries (current: ^0.1.1)
- @tailwindcss/typography (current: ^0.5.9)
packages/ui/primitives/document-flow/show-field-item.tsx (2)
47-47
: LGTM! Good use of CSS container queries.
The addition of [container-type:size]
enables size-based container queries, providing a solid foundation for responsive field sizing.
Ensure your target browsers support CSS Container Queries (supported in all modern browsers since late 2022).
56-58
: Remove commented code and verify UX impact.
The email display has been commented out rather than removed. This change seems unrelated to the field sizing improvements and might affect user experience.
- If the email display is no longer needed, remove the commented code entirely
- If this is temporary, please add a TODO comment explaining why
Please confirm if removing the email display was intentional and doesn't negatively impact user experience.
packages/ui/primitives/document-flow/field-icon.tsx (1)
48-48
: Verify text scaling behavior
Please test the text scaling behavior across different viewport widths to ensure:
- Text remains readable at all sizes
- Scaling is smooth and consistent
- Text doesn't become disproportionately large at certain breakpoints
Also applies to: 74-75
packages/tailwind-config/index.cjs (1)
142-146
: LGTM! Good choice adding container queries support.
The addition of @tailwindcss/container-queries
plugin aligns well with the PR's objective of improving field sizing. Container queries will provide more granular control over component sizing based on their container rather than viewport size.
packages/ui/primitives/document-flow/field-item.tsx (3)
38-39
: LGTM: Type definitions for default dimensions
The addition of optional defaultHeight
and defaultWidth
props aligns well with the PR's objective of improving field sizing capabilities.
58-59
: LGTM: Props destructuring
The destructuring of the new default dimension props is properly implemented and follows the established pattern.
75-76
: 🛠️ Refactor suggestion
Consider enhancing dimension handling
The current implementation has several points that could be improved:
- Falling back to 0 when no default dimensions are provided could result in invisible fields
- There's no validation to ensure positive dimensions
- The relationship between min and default dimensions isn't enforced (default could be smaller than min)
Consider implementing these improvements:
- pageHeight: defaultHeight || 0,
- pageWidth: defaultWidth || 0,
+ pageHeight: Math.max(defaultHeight ?? minHeight ?? 50, minHeight ?? 0),
+ pageWidth: Math.max(defaultWidth ?? minWidth ?? 50, minWidth ?? 0),
Please verify:
- The default fallback values are appropriate for your use case
- The field remains visible and usable when no dimensions are provided
apps/web/src/app/(signing)/sign/[token]/number-field.tsx (3)
255-257
: Well-implemented responsive sizing!
The use of clamp()
for both the icon and text provides smooth scaling between viewport sizes while maintaining readability. The chosen values create a good balance between minimum and maximum sizes.
263-263
: Good styling consistency!
The text sizing maintains consistency with the non-inserted state, and the dark mode consideration is a nice touch.
Line range hint 1-350
: Verify security measures for document signing
The authentication and validation appear well-implemented, but please verify:
- The
executeActionAuthProcedure
provides sufficient protection against unauthorized field modifications - The number validation adequately prevents injection attacks through the number field input
apps/web/src/app/(signing)/sign/[token]/text-field.tsx (1)
255-258
: 🛠️ Refactor suggestion
Consider increasing the minimum text size for better readability
While the responsive sizing using clamp()
is a good approach, the minimum text size of 0.425rem
(≈6.8px) might be too small for comfortable reading. Consider increasing it to at least 0.625rem
(10px) to ensure better readability across all viewport sizes.
- <span className="text-[clamp(0.425rem,25cqw,0.825rem)]">
+ <span className="text-[clamp(0.625rem,25cqw,0.825rem)]">
Please verify browser compatibility for the Container Query Width (cqw) unit, as it's a relatively new CSS feature.
packages/ui/primitives/template-flow/add-template-fields.tsx (3)
70-74
: LGTM! Verify field dimensions across different field types.
The new minimum and default dimensions look good. The 3:1 width-to-height ratio and 2.5x multiplier for default sizes are reasonable choices.
Please ensure these dimensions work well across all field types, particularly for:
- Signature fields which might need more height
- Text fields which might need more width
- Checkbox/Radio fields which might need equal height and width
431-431
: LGTM! Responsive text sizing implementation.
Good use of modern CSS features:
- CSS
clamp()
for responsive text sizing - Appropriate text size range for small fields
- Prevention of text selection with
pointer-events-none
Also applies to: 445-447
460-463
: LGTM! Field dimension properties properly implemented.
Good implementation of field dimension controls:
- Minimum dimensions prevent fields from becoming too small
- Default dimensions provide a good starting size
- Properties align with the defined constants
packages/ui/primitives/document-flow/add-fields.tsx (2)
79-83
: LGTM: Well-defined field dimension constants
The constants are well-structured with clear relationships between minimum and default sizes. The 2.5x multiplier for default sizes provides a good balance between usability and space efficiency.
638-641
: LGTM: Consistent field dimension props
The field dimensions are properly passed to the FieldItem component, maintaining consistency between minimum and default sizes.
packages/lib/translations/en/common.po (2)
441-442
: LGTM!
The translation "Advanced settings" is consistent with other similar UI elements in the application.
1589-1590
: LGTM!
The translation clearly explains the direct link template field functionality and its implications.
packages/lib/translations/fr/common.po (8)
417-421
: LGTM! Clear and natural translations.
The translations for "Add Myself" and "Add Placeholder Recipient" are accurate and maintain a consistent tone with the rest of the application.
592-593
: LGTM! Accurate field configuration translations.
The translations for configuring fields and date elements are clear and maintain proper French grammar.
Also applies to: 654-656
673-673
: LGTM! Well-translated field types and UI elements.
The translations for field types (Dropdown, Date, Email) and related UI elements are accurate and natural in French.
Also applies to: 795-812
832-832
: LGTM! Clear action-related translations.
The translations for empty field states and signing options are accurate and maintain proper French context.
Also applies to: 841-841, 845-845
1023-1030
: LGTM! Well-structured recipient-related messages.
The translations for recipient-related messages and validation texts are clear and maintain proper French grammar and tone.
Also applies to: 1046-1047, 1055-1056
1084-1086
: LGTM! Consistent translations for form elements.
The translations for number fields, radio buttons, and template-related actions are accurate and maintain consistency with the application's terminology.
Also applies to: 1178-1178, 1258-1258, 1290-1290
1363-1363
: LGTM! Clear advanced settings translations.
The translations for advanced settings and signature-related elements are well-structured and natural in French.
Also applies to: 1379-1383
1563-1563
: LGTM! Accurate validation message translations.
The translations for validation messages and recipient status updates are clear and maintain proper French grammar and context.
Also applies to: 1594-1594, 1602-1602, 1631-1632
packages/lib/translations/es/common.po (7)
417-418
: LGTM: Translation maintains consistency
The translation "Agregame" for "Add Myself" maintains consistency with the application's Spanish language style and is grammatically correct.
421-422
: LGTM: Clear and accurate translation
The translation "Agregar destinatario de marcador de posición" accurately conveys the meaning of "Add Placeholder Recipient" while maintaining natural Spanish phrasing.
446-448
: LGTM: Consistent terminology
The translation "Configuraciones avanzadas" for "Advanced settings" maintains consistency with other similar terms in the application.
592-594
: LGTM: Proper placeholder handling
The translation correctly maintains the {0} placeholder while providing a natural Spanish translation for "Configure the {0} field" → "Configurar el campo {0}".
1594-1595
: LGTM: Clear and comprehensive translation
The translation effectively conveys the complex message about direct link template field behavior while maintaining natural Spanish language flow.
1602-1603
: LGTM: Accurate translation of technical concept
The translation correctly conveys the technical concept of recipient modification restrictions after signing or completing a document.
1631-1633
: LGTM: Proper placeholder handling and clear message
The translation maintains the {0} placeholder while clearly conveying the requirement for setting at least one field value.
packages/lib/translations/de/common.po (1)
417-421
:
Missing translation for "Checkbox" field type
The translation for "Checkbox" at line 417 is missing. All UI elements should be translated to maintain a consistent German interface.
#: packages/ui/primitives/document-flow/types.ts:58
msgid "Checkbox"
-msgstr ""
+msgstr "Kontrollkästchen"
Likely invalid or redundant comment.
packages/lib/translations/es/web.po (1)
833-837
: LGTM! New field translations look good.
The translations for text and number fields are accurate and maintain consistency with the rest of the interface.
packages/lib/translations/fr/web.po (5)
65-65
: LGTM! Plural forms handled correctly.
The French translation correctly handles the plural forms while maintaining a natural flow.
127-128
: LGTM! Variables and plural forms preserved.
The translation maintains all placeholders and correctly handles plural forms in French.
833-837
: LGTM! Natural translation.
The French translation is accurate and reads naturally.
1796-1796
: LGTM! Accurate translation.
The translation "Numéro" is the correct French equivalent for "Number".
3047-3048
: LGTM! Common UI translation.
"Sauvegarder" is the standard French translation for "Save" in user interfaces.
packages/lib/translations/de/web.po (6)
65-66
: LGTM! Accurate plural form handling
The translation correctly implements the German plural forms for the character count message while maintaining natural language flow.
833-837
: LGTM! Consistent field translations
The translations for text and number fields are accurate and maintain consistency with the application's terminology.
1796-1796
: LGTM! Natural placeholder text
The German translation for the text field placeholder is accurate and follows common UI patterns.
2484-2485
: LGTM! Concise field label
The translation "Nummer" for "Number" is appropriate and consistent with German form field conventions.
3047-3048
: LGTM! Standard button text
The translation "Speichern" is the standard German equivalent for "Save" and is consistently used throughout the UI.
3668-3669
: LGTM! Clear field label
The translation "Text" is appropriate and maintains consistency with other form field labels.
packages/ui/primitives/auto-sized-text.tsx (1)
134-134
: Ensure compatibility of structuredClone
or use alternative
The structuredClone
function may not be supported in all browsers or environments. To maintain compatibility, consider using a polyfill, a library like lodash.cloneDeep
, or avoiding deep cloning if not necessary.
Apply this diff to replace structuredClone
:
-console.log('parentDimensions', structuredClone(parentDimensions));
+console.log('parentDimensions', { ...parentDimensions });
Or remove it if logging is no longer needed.
@@ -45,7 +45,7 @@ export const FieldIcon = ({ | |||
return ( | |||
<div | |||
className={cn( | |||
'text-field-card-foreground flex items-center justify-center gap-x-1 text-[clamp(0.875rem,1.8cqw,1.2rem)]', | |||
'text-field-card-foreground flex items-center justify-center gap-x-1 text-[clamp(0.575rem,25cqw,1.2rem)]', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review text sizing for accessibility concerns
While the responsive sizing approach using clamp()
is good, the minimum text sizes (0.575rem ≈ 7.67px for signatures, 0.425rem ≈ 5.67px for other fields) might be too small for accessibility. Consider increasing these values to maintain readability.
Additionally, the large multiplier (25cqw) in the middle value could cause text to scale too aggressively across different viewport widths.
Consider adjusting the values to:
-'text-[clamp(0.575rem,25cqw,1.2rem)]'
+'text-[clamp(0.75rem,10cqw,1.2rem)]'
-'text-[clamp(0.425rem,25cqw,0.825rem)]'
+'text-[clamp(0.625rem,10cqw,0.825rem)]'
Also applies to: 74-75
<p className="text-muted-foreground dark:text-background/80 flex items-center justify-center gap-x-1 text-[clamp(0.425rem,25cqw,0.825rem)] duration-200"> | ||
{field.customText.length < 20 | ||
? field.customText | ||
: field.customText.substring(0, 15) + '...'} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Multiple styling improvements recommended
- The minimum text size should be increased for better readability, similar to the previous suggestion.
- Consider using a more semantic approach for text truncation instead of hardcoding character limits.
- <p className="text-muted-foreground dark:text-background/80 flex items-center justify-center gap-x-1 text-[clamp(0.425rem,25cqw,0.825rem)] duration-200">
+ <p className="text-muted-foreground dark:text-muted-foreground flex items-center justify-center gap-x-1 text-[clamp(0.625rem,25cqw,0.825rem)] truncate max-w-full duration-200">
- {field.customText.length < 20
- ? field.customText
- : field.customText.substring(0, 15) + '...'}
+ {field.customText}
The changes:
- Increase minimum text size for better readability
- Use CSS
truncate
utility for text overflow - Replace manual string truncation with CSS
- Use semantic dark mode color instead of background opacity
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
<p className="text-muted-foreground dark:text-background/80 flex items-center justify-center gap-x-1 text-[clamp(0.425rem,25cqw,0.825rem)] duration-200"> | |
{field.customText.length < 20 | |
? field.customText | |
: field.customText.substring(0, 15) + '...'} | |
<p className="text-muted-foreground dark:text-muted-foreground flex items-center justify-center gap-x-1 text-[clamp(0.625rem,25cqw,0.825rem)] truncate max-w-full duration-200"> | |
{field.customText} |
#: apps/web/src/app/(signing)/sign/[token]/number-field.tsx:337 | ||
#: apps/web/src/app/(signing)/sign/[token]/text-field.tsx:344 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Inconsistent translation for "Save" button.
The translation for "Save" appears multiple times in the file with different contexts. For consistency, use "Guardar" across all instances.
#: apps/web/src/app/(signing)/sign/[token]/number-field.tsx:337
#: apps/web/src/app/(signing)/sign/[token]/text-field.tsx:344
msgid "Save"
-msgstr "Save"
+msgstr "Guardar"
Committable suggestion skipped: line range outside the PR's diff.
#: apps/web/src/app/(signing)/sign/[token]/text-field.tsx:257 | ||
#: apps/web/src/app/(signing)/sign/[token]/text-field.tsx:274 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Inconsistent translation for text field labels.
The translation for text field labels should be consistent throughout the application.
#: apps/web/src/app/(signing)/sign/[token]/text-field.tsx:257
#: apps/web/src/app/(signing)/sign/[token]/text-field.tsx:274
msgid "Text"
-msgstr "Text"
+msgstr "Texto"
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
#: apps/web/src/app/(signing)/sign/[token]/text-field.tsx:257 | |
#: apps/web/src/app/(signing)/sign/[token]/text-field.tsx:274 | |
#: apps/web/src/app/(signing)/sign/[token]/text-field.tsx:257 | |
#: apps/web/src/app/(signing)/sign/[token]/text-field.tsx:274 | |
msgid "Text" | |
msgstr "Texto" |
@@ -1793,7 +1793,7 @@ | |||
msgid "Enter your name" | |||
msgstr "Ingresa tu nombre" | |||
|
|||
#: apps/web/src/app/(signing)/sign/[token]/text-field.tsx:278 | |||
#: apps/web/src/app/(signing)/sign/[token]/text-field.tsx:280 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing translation for auto-sign functionality.
The translation for "Enter your text here" is correct, but there are several auto-sign related strings that need translation:
#: apps/web/src/app/(signing)/sign/[token]/auto-sign.tsx:196
msgid "An error occurred while auto-signing the document, some fields may not be signed. Please review and manually sign any remaining fields."
-msgstr ""
+msgstr "Se produjo un error al firmar automáticamente el documento, es posible que algunos campos no se hayan firmado. Por favor, revise y firme manualmente los campos restantes."
#: apps/web/src/app/(signing)/sign/[token]/auto-sign.tsx:183
msgid "When you sign a document, we can automatically fill in and sign the following fields using information that has already been provided. You can also manually sign or remove any automatically signed fields afterwards if you desire."
-msgstr ""
+msgstr "Cuando firma un documento, podemos completar y firmar automáticamente los siguientes campos utilizando la información que ya se ha proporcionado. También puede firmar manualmente o eliminar cualquier campo firmado automáticamente después si lo desea."
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
#: apps/web/src/app/(signing)/sign/[token]/text-field.tsx:280 | |
#: apps/web/src/app/(signing)/sign/[token]/text-field.tsx:280 | |
#: apps/web/src/app/(signing)/sign/[token]/auto-sign.tsx:196 | |
msgid "An error occurred while auto-signing the document, some fields may not be signed. Please review and manually sign any remaining fields." | |
msgstr "Se produjo un error al firmar automáticamente el documento, es posible que algunos campos no se hayan firmado. Por favor, revise y firme manualmente los campos restantes." | |
#: apps/web/src/app/(signing)/sign/[token]/auto-sign.tsx:183 | |
msgid "When you sign a document, we can automatically fill in and sign the following fields using information that has already been provided. You can also manually sign or remove any automatically signed fields afterwards if you desire." | |
msgstr "Cuando firma un documento, podemos completar y firmar automáticamente los siguientes campos utilizando la información que ya se ha proporcionado. También puede firmar manualmente o eliminar cualquier campo firmado automáticamente después si lo desea." |
const fontSize = useRef<number>(0); | ||
const fontSizeLowerBound = useRef<number>(0); | ||
const fontSizeUpperBound = useRef<number>(0); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initialize fontSize.current
to a meaningful starting value
Currently, fontSize.current
is initialized to 0
, which may lead to unintended behavior in the font size calculations. Starting with a 0
font size could cause the text to not render visibly or lead to division by zero errors in subsequent calculations. Consider initializing fontSize.current
to a reasonable default, such as parentDimensions.height
or a typical font size like 16
.
// Reset iteration parameters | ||
fontSizeLowerBound.current = 0; | ||
fontSizeUpperBound.current = parentDimensions.height; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initialize fontSize.current
before starting the iteration
Before entering the iteration loop, fontSize.current
should be initialized to a starting value to ensure proper convergence. Without initialization, fontSize.current
remains at 0
, which may cause the first adjustment to be incorrect. Consider setting fontSize.current
to fontSizeUpperBound.current
or an average of the upper and lower bounds.
Apply this diff to initialize fontSize.current
:
// Reset iteration parameters
fontSizeLowerBound.current = 0;
fontSizeUpperBound.current = parentDimensions.height;
+fontSize.current = (fontSizeLowerBound.current + fontSizeUpperBound.current) / 2;
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
// Reset iteration parameters | |
fontSizeLowerBound.current = 0; | |
fontSizeUpperBound.current = parentDimensions.height; | |
// Reset iteration parameters | |
fontSizeLowerBound.current = 0; | |
fontSizeUpperBound.current = parentDimensions.height; | |
fontSize.current = (fontSizeLowerBound.current + fontSizeUpperBound.current) / 2; |
const adjustFontSize = (childDimensions: Dimensions, parentDimensions: Dimensions) => { | ||
const childElement = childRef.current; | ||
|
||
if (!childElement) { | ||
return; | ||
} | ||
|
||
let newFontSize: number; | ||
|
||
const targetHeight = | ||
maxHeight && maxHeight < parentDimensions.height ? maxHeight : parentDimensions.height; | ||
|
||
const isElementTooBig = | ||
childDimensions.width > parentDimensions.width || childDimensions.height > targetHeight; | ||
|
||
console.log({ | ||
fontSizeLowerBound: fontSizeLowerBound.current, | ||
fontSizeUpperBound: fontSizeUpperBound.current, | ||
fontSize: fontSize.current, | ||
}); | ||
|
||
if (isElementTooBig) { | ||
// Scale down if element is bigger than target | ||
newFontSize = (fontSizeLowerBound.current + fontSize.current) / 2; | ||
fontSizeUpperBound.current = fontSize.current; | ||
} else if ( | ||
childDimensions.width < parentDimensions.width || | ||
childDimensions.height < parentDimensions.height | ||
) { | ||
// Scale up if element is smaller than target | ||
newFontSize = (fontSizeUpperBound.current + fontSize.current) / 2; | ||
fontSizeLowerBound.current = fontSize.current; | ||
} | ||
|
||
console.log({ | ||
currentFontSize: fontSize.current, | ||
newFontSize, | ||
targetHeight, | ||
currentHeight: childDimensions.height, | ||
parentHeight: parentDimensions.height, | ||
}); | ||
|
||
fontSize.current = newFontSize; | ||
|
||
// Convert to rem if useRem is true | ||
const displayFontSize = useRem ? `${pxToRem(newFontSize)}rem` : `${newFontSize}px`; | ||
childElement.style.fontSize = displayFontSize; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct the binary search logic in adjustFontSize
function
The binary search implementation in the adjustFontSize
function may not correctly converge toward the optimal font size due to miscalculations of newFontSize
. Specifically:
- When scaling down (element is too big), the new font size should be calculated using the upper and lower bounds:
newFontSize = (fontSizeLowerBound.current + fontSizeUpperBound.current) / 2;
- When scaling up (element is too small), the calculation should be the same:
newFontSize = (fontSizeLowerBound.current + fontSizeUpperBound.current) / 2;
Updating fontSize.current
directly without properly adjusting the bounds may prevent the algorithm from converging. Adjust the calculations to ensure that the font size correctly approaches the optimal value within the iteration limit.
Apply this diff to correct the calculations:
function adjustFontSize(childDimensions: Dimensions, parentDimensions: Dimensions) {
// ...
if (isElementTooBig) {
// Scale down if element is bigger than target
- newFontSize = (fontSizeLowerBound.current + fontSize.current) / 2;
+ fontSizeUpperBound.current = fontSize.current;
+ newFontSize = (fontSizeLowerBound.current + fontSizeUpperBound.current) / 2;
- fontSizeUpperBound.current = fontSize.current;
} else if (/* scaling up condition */) {
// Scale up if element is smaller than target
- newFontSize = (fontSizeUpperBound.current + fontSize.current) / 2;
+ fontSizeLowerBound.current = fontSize.current;
+ newFontSize = (fontSizeLowerBound.current + fontSizeUpperBound.current) / 2;
- fontSizeLowerBound.current = fontSize.current;
}
// ...
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
const adjustFontSize = (childDimensions: Dimensions, parentDimensions: Dimensions) => { | |
const childElement = childRef.current; | |
if (!childElement) { | |
return; | |
} | |
let newFontSize: number; | |
const targetHeight = | |
maxHeight && maxHeight < parentDimensions.height ? maxHeight : parentDimensions.height; | |
const isElementTooBig = | |
childDimensions.width > parentDimensions.width || childDimensions.height > targetHeight; | |
console.log({ | |
fontSizeLowerBound: fontSizeLowerBound.current, | |
fontSizeUpperBound: fontSizeUpperBound.current, | |
fontSize: fontSize.current, | |
}); | |
if (isElementTooBig) { | |
// Scale down if element is bigger than target | |
newFontSize = (fontSizeLowerBound.current + fontSize.current) / 2; | |
fontSizeUpperBound.current = fontSize.current; | |
} else if ( | |
childDimensions.width < parentDimensions.width || | |
childDimensions.height < parentDimensions.height | |
) { | |
// Scale up if element is smaller than target | |
newFontSize = (fontSizeUpperBound.current + fontSize.current) / 2; | |
fontSizeLowerBound.current = fontSize.current; | |
} | |
console.log({ | |
currentFontSize: fontSize.current, | |
newFontSize, | |
targetHeight, | |
currentHeight: childDimensions.height, | |
parentHeight: parentDimensions.height, | |
}); | |
fontSize.current = newFontSize; | |
// Convert to rem if useRem is true | |
const displayFontSize = useRem ? `${pxToRem(newFontSize)}rem` : `${newFontSize}px`; | |
childElement.style.fontSize = displayFontSize; | |
}; | |
const adjustFontSize = (childDimensions: Dimensions, parentDimensions: Dimensions) => { | |
const childElement = childRef.current; | |
if (!childElement) { | |
return; | |
} | |
let newFontSize: number; | |
const targetHeight = | |
maxHeight && maxHeight < parentDimensions.height ? maxHeight : parentDimensions.height; | |
const isElementTooBig = | |
childDimensions.width > parentDimensions.width || childDimensions.height > targetHeight; | |
console.log({ | |
fontSizeLowerBound: fontSizeLowerBound.current, | |
fontSizeUpperBound: fontSizeUpperBound.current, | |
fontSize: fontSize.current, | |
}); | |
if (isElementTooBig) { | |
// Scale down if element is bigger than target | |
fontSizeUpperBound.current = fontSize.current; | |
newFontSize = (fontSizeLowerBound.current + fontSizeUpperBound.current) / 2; | |
} else if ( | |
childDimensions.width < parentDimensions.width || | |
childDimensions.height < parentDimensions.height | |
) { | |
// Scale up if element is smaller than target | |
fontSizeLowerBound.current = fontSize.current; | |
newFontSize = (fontSizeLowerBound.current + fontSizeUpperBound.current) / 2; | |
} | |
console.log({ | |
currentFontSize: fontSize.current, | |
newFontSize, | |
targetHeight, | |
currentHeight: childDimensions.height, | |
parentHeight: parentDimensions.height, | |
}); | |
fontSize.current = newFontSize; | |
// Convert to rem if useRem is true | |
const displayFontSize = useRem ? `${pxToRem(newFontSize)}rem` : `${newFontSize}px`; | |
childElement.style.fontSize = displayFontSize; | |
}; |
This PR sounds like it's meant to address #886 . |
Description
Allows for smaller field sizing in addition to improving our styling when displaying labels on smaller fields.
This is the minimum currently supported field size until we perform a more extensive refactor of our current drag and drop system.
Related Issue
Reported via support channels
Changes Made
clamp()
method for dynamic sizing.Summary by CodeRabbit
Release Notes
New Features
AutoSizedText
component for dynamic font size adjustment based on parent dimensions.UI Enhancements
FieldIcon
andShowFieldItem
components.Localization
Bug Fixes
StackAvatar
component to streamline rendering.