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: Allow <Pin> glyphs to be passed as children (close #98) #99

Merged
merged 6 commits into from
Nov 28, 2023

Conversation

benschlegel
Copy link
Contributor

This PR allows the glyph property of to be passed via JSX children. Functionality is implemented like discussed in #98.

It uses a div container for the portal similar to (where the memo'd div wasn't added as a dependency to the useEffect, I assume that was intentional and also implemented it in this way for ).

I don't think theres any benefit to using a more detailed type for props to differentiate if children were passed or not, as those are inaccurate due to typescript/tsx limitations unfortunately, so I just wrapped the existing type with PropsWithChildren.

I took the code style of the other components as reference, but if there's anything to change im happy to do so :)

Copy link
Collaborator

@usefulthink usefulthink left a comment

Choose a reason for hiding this comment

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

Excellent work, thanks a lot!
Two minor changes, and we can merge it.

Did you see any problems with the extra div-element wrapping the content of the glyph or does it work as expected?

Comment on lines 54 to 57
/**
* Set glyph to glyph container if children are present (rendered via portal).
* If both props.glyph and props.children are present, props.children takes priority.
* */
Copy link
Collaborator

Choose a reason for hiding this comment

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

This shouldn't be using jsdoc-style comments.

Suggested change
/**
* Set glyph to glyph container if children are present (rendered via portal).
* If both props.glyph and props.children are present, props.children takes priority.
* */
// Set glyph to glyph container if children are present (rendered via portal).
// If both props.glyph and props.children are present, props.children takes priority.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in 0aa04d8

<Pin background={'#22ccff'} borderColor={'#1e89a1'} scale={1.4}>
{/* child gets rendered as 'glyph' element of pin */}
<img
src="https://www.svgrepo.com/show/522904/info-circle.svg"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would prefer it to have the svg-file in the example directory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, will change it, just did this as a suggestion as I wasn't sure about how you want to handle it in this repo. Any preference for what svg to choose for the example? I just picked a copyright free one from svgrepo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if you have a preference for where you want the svg file locally, I put it in an "assets" folder inside the example now in f4d79a0

@benschlegel
Copy link
Contributor Author

Tested with a few different configurations but did not see a problem with the extra div, I'm not sure what edge cases this could cause a problem in but I didn't run into them

@usefulthink
Copy link
Collaborator

That's fine with me then.

@usefulthink usefulthink merged commit 6374453 into visgl:main Nov 28, 2023
2 checks passed
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.

None yet

2 participants