-
Notifications
You must be signed in to change notification settings - Fork 122
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
#98
Comments
If this is something this library wants to support, I could take a look at implementing this myself (based on the way |
You're probably right. I never thought that would actually be useful, but you're proving me wrong :) If you find the time to implement this, that would be awesome. I can assist you when needed. Here's a couple of thoughts on the topic:
|
If its alright with you, I'll just start a PR draft with basic functionality working where we can discuss implementation and other details over there so we have actual code to reference. Some thoughts on what you mentioned:
|
That would be great. For development, I would recommend you clone the repository and update the example in
absolutely, but in this case there needs to be an extra element. I don't see a problem with that right now, but we'll probably have to see. As for the "both children and glyph specified" case, I think we should at least log an error in that case (you can use the
That's an interesting Idea, maybe something like export type PinProps =
| PropsWithChildren<Omit<google.maps.marker.PinElementOptions, "glyph">>
| google.maps.marker.PinElementOptions will already do the trick?! |
Thanks, I'll take a look and see if I can get it working! As for the type thing, I looked into it for a bit, but unfortunately, it seems to be a limitation of typescript/tsx types, where Components don't error for wrong types even if the prop type is "correct" on paper. We can still use your type for DX, but even with using that type, doing something like: <Pin glyph={"a"}>
<div/>
</Pin> does not show a type error unfortunately. I think we should still use the type for better maintainability, but there does not seem to be a way for TS to show users problems with using the component before runtime. |
Quick question, how can i rebuild the main source library/use the updated (maybe my changes also just did not work, but after suspecting my changes were not applied, I put a console.error/log/logErrorOnce at the start of I tried npm build, build:examples, prepack, start and npm build in the example dir, any help would be appreciated. |
You have to use the |
thank you!! I must have mixed up your command with the one i saw in the example readme, but using |
Target Use Case
Currently, the only way pass a glyph thats an
HTMLElement
to a<Pin>
element (as far as i can tell) is to create the element inline in a react component and pass that to the pin like in the following example:This also causes unexpected issues when trying to render multiple markers using
Array.prototype.map()
, where defining the element just once in the component will only render it out on the lastAdvancedMarker
, since the native DOM and reacts virtual DOM have some conflicts when usingdocument.createElement()
. The workaround is to move thedocument.createElement()
part down into map, but still not a clean way to interact with react.Instead, I think it would be much nicer if we could pass a glyph via react
children
, similar to how<MapControl>
currently functions, which renders the children to appropriateHTMLElements
to be used with the google maps api. As this is a react wrapper, removing the need to manually create DOM elements directly would be inline with what this library is trying to achieve.This would increase code maintainability, decrease weird "non-react-like" code and decrease bug encounters when trying to interface with native DOM Elements and reacts virtual DOM when using this library (as well as just making the API easier to use).
Proposal
Ideally, when trying to pass a glyph thats an HTMLElement to a
<Pin>
, we could do something like this:Where
<Pin>
interpretschildren
that get passed as glyphs of typeElement
(according to types here) and gets rendered out appropriately.The text was updated successfully, but these errors were encountered: