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

chore: overflow utility initial commit #18644

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

Conversation

devadula-nandan
Copy link
Contributor

@devadula-nandan devadula-nandan commented Feb 20, 2025

Closes #6883 on ibm-products

adds framework agonistic overflow utility, to the utility package.

Changelog

New

  • adds overflow utility to utilities package
  • adds tests to it

Testing / Reviewing

automated tests written in the test file

existing ibm-products actionbar and tagset example
https://stackblitz.com/edit/github-yxe1kwrz?file=src%2FExample%2FExample.jsx

Iteration 1
React usage example of this utility
Lit usage example of this utility

iteration 2
React usage example of this utility
Lit usage example of this utility

Copy link

netlify bot commented Feb 20, 2025

Deploy Preview for v11-carbon-web-components ready!

Name Link
🔨 Latest commit 69dd4dc
🔍 Latest deploy log https://app.netlify.com/sites/v11-carbon-web-components/deploys/67c852c690090e00087455be
😎 Deploy Preview https://deploy-preview-18644--v11-carbon-web-components.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Feb 20, 2025

Deploy Preview for carbon-elements ready!

Name Link
🔨 Latest commit 69dd4dc
🔍 Latest deploy log https://app.netlify.com/sites/carbon-elements/deploys/67c852c679d58b0008b061b3
😎 Deploy Preview https://deploy-preview-18644--carbon-elements.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Feb 20, 2025

Deploy Preview for v11-carbon-react ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 69dd4dc
🔍 Latest deploy log https://app.netlify.com/sites/v11-carbon-react/deploys/67c852c6fb9fcd0008b21caa
😎 Deploy Preview https://deploy-preview-18644--v11-carbon-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codecov bot commented Feb 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.28%. Comparing base (95b053a) to head (69dd4dc).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #18644   +/-   ##
=======================================
  Coverage   84.28%   84.28%           
=======================================
  Files         409      409           
  Lines       14702    14702           
  Branches     4846     4842    -4     
=======================================
  Hits        12392    12392           
- Misses       2146     2147    +1     
+ Partials      164      163    -1     

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

@devadula-nandan devadula-nandan marked this pull request as ready for review February 25, 2025 10:01
@devadula-nandan devadula-nandan requested review from a team as code owners February 25, 2025 10:01
Copy link
Member

@tay1orjones tay1orjones left a comment

Choose a reason for hiding this comment

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

This is awesome! 🔥

Some pieces of the react usage example have me wondering if the abstractions you have here could be modified to improve performance and usage.

An entirely new overflowHandler is created anytime the actions change. actions may be unlikely to change, but it seems like we should be able to reuse the one we already have. The container isn't changing, none of the other "props" are changing, the existing resize observer doesn't need to be destroyed, etc.

Also the amount of boilerplate stood out to me. It would be best if the consumer didn't have to bear that burden.

If the internal functions (getDimension, update, etc) were available by themselves in addition to createOverflowHandlder, we could make a useOverflowHandler hook for react users that uses these internally. It would streamlines the usage for consumers while also giving us a chance to make it more performant. We could memoize the actions and the container, contain the hiddenItems state, selectively provide return values if they were to need them, etc.

It might even be that we could avoid handling the requestAnimationFrame ourselves and use useLayoutEffect in the hook.

You've maybe considered all this though 😅 if so, we can divert to a new issue. Either way I'm curious to hear what you think

/**
* Maximum number of visible items. If provided, only this number of items will be shown.
*/
maxVisible?: number;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
maxVisible?: number;
maxVisibleItems?: number;

@devadula-nandan
Copy link
Contributor Author

devadula-nandan commented Mar 3, 2025

hey @tay1orjones , i like to do some more changes to this, to reduce the boilerplate, i see some potential for it, and yes, actionbar example doesnt need any memoization, i just copy pasted the example from tagset and forgot to clean up, since these are just vague examples and we are yet to build proper usage examples on lit and react. which is going to be a seperate issue.

we are destroying and recreating the overflowHandler on tagset overflow tag width changes which usually happens at number 9->10, 99->100.
i am also making use of data-hidden and data-offset and data-fixed attributes in the next iteration which we can use to do custom styling through pure css, and dropping onVisible and onHidden callbacks, we can still access them in onChange callback.

ill move getDimension (will change this to getSize) outside the handler and export it for reusability, i should also add a note to it, not to call it in any loop or update function, as they are expensive and could clog the memory usage, it could be better to call it once per instance, and revoke and recall the instance if we want to recalculate it.

ill move this to draft and will open with new changes soon. thanks for the review, it enabled few more insights to this.

@devadula-nandan
Copy link
Contributor Author

Hi @tay1orjones ,

this is done, and open for re-review

iteration 2 change log

  1. seperated internal functions getSize , updateOverflowHandler and exported (interfaces as well)
  2. removed onVisible, onHidden callbacks, instead we are setting data-hidden attributes, which we use to style with plain css. we can still access hidden and visible items from onChange callback
  3. added data-offset attribute for the offset element and removed offsetSize prop
  4. removed items prop, since we can construct this array from children
  5. introduced data-fixed attribute. any item that has data-fixed attribute, doesn't participate in any overflowing activity
  6. added interface docs at most places
  7. stackblitz examples updated

@devadula-nandan devadula-nandan marked this pull request as ready for review March 5, 2025 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rewrite useOverflowItems utility as vanilla JS
2 participants