-
Notifications
You must be signed in to change notification settings - Fork 936
Commit
* Also add this support to InfoBox as well * Only one child is supported inside <InfoWindow> or <InfoBox> * Closes #69 and thanks to @thetiby
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { | ||
default as React, | ||
Children, | ||
} from "react"; | ||
|
||
function renderElement ( | ||
contentElement, | ||
prevContent | ||
) { | ||
if ("[object HTMLDivElement]" !== Object.prototype.toString.call(prevContent)) { | ||
prevContent = document.createElement("div"); | ||
} | ||
|
||
React.render(contentElement, prevContent); | ||
return prevContent; | ||
} | ||
|
||
export default function setContentForOptionalReactElement ( | ||
contentOptionalReactElement, | ||
infoWindowLikeInstance | ||
) { | ||
if (React.isValidElement(contentOptionalReactElement)) { | ||
const contentElement = Children.only(contentOptionalReactElement); | ||
const prevContent = infoWindowLikeInstance.getContent(); | ||
|
||
const domEl = renderElement(contentOptionalReactElement, prevContent); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
tomchentw
Author
Owner
|
||
infoWindowLikeInstance.setContent(domEl); | ||
|
||
} else { | ||
infoWindowLikeInstance.setContent(contentOptionalReactElement); | ||
} | ||
} |
@tomchentw thank you so much for including this functionality in the main repo!
Did you keep the functionality of setting a class name on the DOM element where the infoWindow/infoBox child is mounted? I love your new code structure, but I think it's important to also have this in. (because there most likely will be the need to style the parent element of whatever content I put into the InfoBox, given that the parent element can be an empty div with no css class to reference it by)
For reference, I used to do that here. Thanks!