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

feat(useMeasure): support custom measurers in order to support border-box and others #1603

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

m-kolomoyets
Copy link

What is the current behavior, and the steps to reproduce the issue?

Current implementation of the useMeasure hook calculates the element bounds based on content-box model only.

It is a little unexpected behavior when the project and all the layout is based on border-box model and trying to calculate measures of the element has paddings.

Thus, current hook ignores paddings calculating element's width and height.

What is the expected behavior?

Giving the possibility to define custom measure matcher model to take the values needed.

How does this PR fix the problem?

By adding the additional optional function argument receives the ResizeObserverEntry value and returns the new measures should be applied or null. If function returns null, the default behavior is applied and content-box measures will be returned.

Checklist

  • Have you read contribution guideline?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Is there an existing issue for this PR?
  • Have the files been linted and formatted?
  • Have the docs been updated to match the changes in the PR?
  • Have the tests been updated to match the changes in the PR?
  • Have you run the tests locally to confirm they pass?

src/useMeasure/__docs__/story.mdx Outdated Show resolved Hide resolved
src/useMeasure/index.ts Outdated Show resolved Hide resolved
@xobotyi
Copy link
Contributor

xobotyi commented Jan 30, 2025

Thanks for contribution!

@m-kolomoyets m-kolomoyets requested a review from xobotyi January 30, 2025 14:51
Copy link
Contributor

@xobotyi xobotyi left a comment

Choose a reason for hiding this comment

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

LGTM

@xobotyi xobotyi changed the title feat(useMeasure): extend hook with optional ResizeObserverEntry matcher callback feat(useMeasure): support custom measurers in order to support border-box and others Jan 30, 2025
Copy link

codecov bot commented Jan 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.80%. Comparing base (95de481) to head (34b5df0).
Report is 16 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1603      +/-   ##
==========================================
+ Coverage   97.60%   97.80%   +0.19%     
==========================================
  Files          63       63              
  Lines        1714     1868     +154     
  Branches      481      483       +2     
==========================================
+ Hits         1673     1827     +154     
  Misses         39       39              
  Partials        2        2              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants