Skip to content
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

Merged
merged 2 commits into from
Nov 20, 2024
Merged

fix: improve field sizing #1486

merged 2 commits into from
Nov 20, 2024

Conversation

Mythie
Copy link
Collaborator

@Mythie Mythie commented Nov 20, 2024

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

  • Updated our minimum size constraints
  • Attempted to add a general autosizing component for text and failed
  • Updated styling in a bunch of places to use the css clamp() method for dynamic sizing.

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced responsive text sizing across various input fields (Date, Dropdown, Email, Initials, Name, Number, Signature, Text).
    • Added a new AutoSizedText component for dynamic font size adjustment based on parent dimensions.
  • UI Enhancements

    • Improved responsiveness and adaptability of text and icon sizes in the FieldIcon and ShowFieldItem components.
    • Updated constants for field dimensions to enhance UI layout and responsiveness.
  • Localization

    • Updated and refined translations in German, English, Spanish, and French for improved clarity and accuracy in user notifications and document actions.
  • Bug Fixes

    • Enhanced error handling and validation prompts for field completion requirements in templates and document flows.
    • Removed unnecessary console logging in the StackAvatar component to streamline rendering.

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.
Copy link

vercel bot commented Nov 20, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
prd-openpage-api ❌ Failed (Inspect) Nov 20, 2024 11:43am
stg-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 20, 2024 11:43am
stg-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 20, 2024 11:43am
stg-marketing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 20, 2024 11:43am
3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
prd-app ⬜️ Ignored (Inspect) Nov 20, 2024 11:43am
prd-docs ⬜️ Ignored (Inspect) Visit Preview Nov 20, 2024 11:43am
prd-marketing ⬜️ Ignored (Inspect) Nov 20, 2024 11:43am

@Mythie Mythie requested a review from Copilot November 20, 2024 11:18
Copy link
Contributor

coderabbitai bot commented Nov 20, 2024

Walkthrough

The 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

File Path Change Summary
apps/web/src/app/(signing)/sign/[token]/date-field.tsx Updated class names for <p> elements to adjust text size using text-[clamp(...)] utility.
apps/web/src/app/(signing)/sign/[token]/dropdown-field.tsx Adjusted class names for SelectValue and paragraph elements for responsive text sizing.
apps/web/src/app/(signing)/sign/[token]/email-field.tsx Updated class names for <p> elements to enhance responsive text sizing.
apps/web/src/app/(signing)/sign/[token]/initials-field.tsx Modified class names for <p> elements to improve responsive text sizing.
apps/web/src/app/(signing)/sign/[token]/name-field.tsx Adjusted class name for a paragraph element to change text size for inserted state.
apps/web/src/app/(signing)/sign/[token]/number-field.tsx Updated rendering logic and styling for responsive text size; streamlined functions for clarity.
apps/web/src/app/(signing)/sign/[token]/signature-field.tsx Changed class name for "Signature" text to use responsive sizing with clamp function.
apps/web/src/app/(signing)/sign/[token]/text-field.tsx Modified field display name and custom text for better responsiveness and readability.
packages/lib/translations/de/common.po Updated German translations, adding, modifying, and removing strings for clarity and accuracy.
packages/lib/translations/de/web.po Updated German translations for clarity and consistency across messages.
packages/lib/translations/en/common.po Added and modified English translation strings for document actions and notifications.
packages/lib/translations/en/web.po Updated English translations for document management and user interactions.
packages/lib/translations/es/common.po Added and refined Spanish translations for document actions and user notifications.
packages/lib/translations/es/web.po Updated Spanish translations for document management and user interactions.
packages/lib/translations/fr/common.po Added and modified French translations for various UI elements and notifications.
packages/lib/translations/fr/web.po Updated French translations for clarity and grammatical correctness.
packages/tailwind-config/index.cjs Added @tailwindcss/container-queries plugin to Tailwind CSS configuration.
packages/tailwind-config/package.json Added new dependencies for Tailwind CSS plugins and cleared devDependencies.
packages/ui/primitives/auto-sized-text.tsx Introduced AutoSizedText component for dynamic font size adjustment based on parent dimensions.
packages/ui/primitives/document-flow/add-fields.tsx Updated constants for field dimensions and modified rendering logic for responsive design.
packages/ui/primitives/document-flow/field-icon.tsx Adjusted CSS classes for text size and icon dimensions for responsiveness.
packages/ui/primitives/document-flow/field-item.tsx Added new optional properties for default dimensions in FieldItemProps.
packages/ui/primitives/document-flow/show-field-item.tsx Modified JSX structure for responsiveness and removed signer email display.
packages/ui/primitives/template-flow/add-template-fields.tsx Updated constants for field dimensions and improved error handling for form validation.

Possibly related PRs

Suggested labels

pkg: ee changes

Suggested reviewers

  • dguyen

🐰 "In fields of code, we hop and play,
With text that shrinks and grows each day.
Responsive sizes, a joyful sight,
Enhancing views, making things right!
So let us cheer for changes bright,
In our web world, all feels just right!" 🐇✨

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/ui/primitives/auto-sized-text.tsx

Oops! 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 details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6dd2674 and 8cc2929.

📒 Files selected for processing (2)
  • apps/web/src/components/(dashboard)/avatar/stack-avatar.tsx (0 hunks)
  • packages/ui/primitives/auto-sized-text.tsx (1 hunks)
💤 Files with no reviewable changes (1)
  • apps/web/src/components/(dashboard)/avatar/stack-avatar.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/ui/primitives/auto-sized-text.tsx

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added apps: web Issues related to the webapp version bump 👀 labels Nov 20, 2024
Copy link

@Copilot Copilot AI left a 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({
Copy link
Preview

Copilot AI Nov 20, 2024

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.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
fontSizeLowerBound.current = fontSize.current;
}

console.log({
Copy link
Preview

Copilot AI Nov 20, 2024

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.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
fontSizeLowerBound.current = 0;
fontSizeUpperBound.current = parentDimensions.height;

console.log('parentDimensions', structuredClone(parentDimensions));
Copy link
Preview

Copilot AI Nov 20, 2024

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.

Suggested change
console.log('parentDimensions', structuredClone(parentDimensions));

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options

while (iterationCount <= ITERATION_LIMIT) {
const childDimensions = getElementDimensions(childElement);
console.log({ childDimensions });
Copy link
Preview

Copilot AI Nov 20, 2024

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.

Suggested change
console.log({ childDimensions });
// console.log({ childDimensions });

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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:

  1. Split the long className into multiple lines for better maintainability
  2. 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 objectives

The 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 loader

To 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 maintainability

The 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:

  1. FieldPositioner: Handle drag & drop positioning
  2. FieldSizer: Manage dimensions and resizing
  3. FieldContent: Render the actual field content

This 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 rendering

The component could benefit from two refactoring opportunities:

  1. Extract the validation logic into a custom hook for better reusability
  2. 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 property

The 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 labels

The 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 message

The 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 message

The 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 translations

The 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 translations

The 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: Simplify targetHeight calculation using Math.min

To enhance readability and conciseness, you can simplify the targetHeight calculation by using Math.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: Remove console.log statements from production code

Multiple 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

📥 Commits

Reviewing files that changed from the base of the PR and between 9ef8b1f and 6dd2674.

⛔ 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.

  1. If the email display is no longer needed, remove the commented code entirely
  2. 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:

  1. Text remains readable at all sizes
  2. Scaling is smooth and consistent
  3. 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:

  1. Falling back to 0 when no default dimensions are provided could result in invisible fields
  2. There's no validation to ensure positive dimensions
  3. 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:

  1. The executeActionAuthProcedure provides sufficient protection against unauthorized field modifications
  2. 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: ⚠️ Potential issue

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)]',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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

Comment on lines +264 to 267
<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) + '...'}
Copy link
Contributor

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

  1. The minimum text size should be increased for better readability, similar to the previous suggestion.
  2. 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.

Suggested change
<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}

Comment on lines +3047 to +3048
#: apps/web/src/app/(signing)/sign/[token]/number-field.tsx:337
#: apps/web/src/app/(signing)/sign/[token]/text-field.tsx:344
Copy link
Contributor

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.

Comment on lines +3668 to +3669
#: apps/web/src/app/(signing)/sign/[token]/text-field.tsx:257
#: apps/web/src/app/(signing)/sign/[token]/text-field.tsx:274
Copy link
Contributor

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.

Suggested change
#: 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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.

Suggested change
#: 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."

Comment on lines +60 to +63
const fontSize = useRef<number>(0);
const fontSizeLowerBound = useRef<number>(0);
const fontSizeUpperBound = useRef<number>(0);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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.

Comment on lines +130 to +133
// Reset iteration parameters
fontSizeLowerBound.current = 0;
fontSizeUpperBound.current = parentDimensions.height;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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.

Suggested change
// 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;

Comment on lines 64 to 111
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;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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.

Suggested change
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;
};

@chrisirhc
Copy link

This PR sounds like it's meant to address #886 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apps: web Issues related to the webapp version bump 👀
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants