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

Add "embed this chart" modal to map tiles #4782

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

Conversation

juliawu
Copy link
Contributor

@juliawu juliawu commented Dec 9, 2024

This PR adds an "embed this chart" modal to the footer of the map tile that gives users HTML they can use to embed that chart as a web component.

Screenshots:

Screenshot 2024-12-09 at 3 42 21 PM

Screenshot 2024-12-10 at 9 50 43 AM

More concretely, this PR:

  • Adds a new modal to show web component HTML
  • Adds helper function and test to generate the web component source code for map tiles
  • Adds the "material symbols outlined" fonts to web component shadow and light roots so that the code icon can be used, and DRYs the logic used
  • Updates the styling of the icon buttons so we can have an emphasized (blue) and default (white) style
  • Updates the styling of modal textareas to match figma mocks

@miss-o-soup
Copy link

This is looking good, thank you!
Some small nit-picks are that the blue "Close" button should not have a hairline/border, or if keeping should be the same color as the blue button. Same for the modal dialog box, there shouldn't be a border/hairline, or if keeping it should be white.
Wondering if this button implementation and dialog can be generalized to be re-used as a component. Thank you!

@juliawu
Copy link
Contributor Author

juliawu commented Dec 10, 2024

This is looking good, thank you! Some small nit-picks are that the blue "Close" button should not have a hairline/border, or if keeping should be the same color as the blue button. Same for the modal dialog box, there shouldn't be a border/hairline, or if keeping it should be white. Wondering if this button implementation and dialog can be generalized to be re-used as a component. Thank you!

Updated to remove the border on the blue button and modal dialog box. Screenshot also updated.

Button impelmentation is already a re-usable component! Styling for the modal is also shared (I inherited a lot from the work @beets did for the "see metadata" modal). Getting the download modal styling to match is a future fix-it friday item.

mapChartData && getReplacementStrings(props, mapChartData);
const header = getChartTitle(props.title, replacementStrings);

let sourceCode = `<script src="https://datacommons.org/datacommons.js"></script>
Copy link
Contributor

Choose a reason for hiding this comment

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

Use the apiRoot value here for the hostname if set. This way the functionality will work on https://unstats.un.org/UNSDWebsite/undatacommons/sdgs

return layer.variable;
})
.filter((variable) => {
return variable?.denom == "Count_Person";
Copy link
Contributor

Choose a reason for hiding this comment

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

Use DEFAULT_PER_CAPITA_DENOM here

sourceCode += `\n\tplaceNameProp="${props.placeNameProp}"`;
}
if (props.sources) {
sourceCode += `\n\tplaceNameProp="${props.sources.join(" ")}"`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be \n\tsources=.. ?

<datacommons-map
\theader="${header}"
\tchildPlaceTypes="${enclosedPlaceTypes}"
\tparentPlaces="${places}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you use childPlaceType & parentPlace (singular) if there's only a single parent place? Right now i dont think we actually use multiple parent places anywhere, and using multiple places isn't documented in the web component map api

readOnly
value={props.sourceCode}
>
{props.sourceCode}
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it work to just set value and not the innerHTML here?

</ModalHeader>
<div className="modal-subtitle">
Use the following code to embed this chart on your website. For{" "}
documentation, see our{" "}
Copy link
Contributor

Choose a reason for hiding this comment

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

how about this alternate wording?

"Embed this chart on your website using the code below. For instructions and customization options, see our Web Component Documentation."

googleSansEl.rel = "stylesheet";
const materialIconsEl = document.createElement("link");
materialIconsEl.href =
"https://fonts.googleapis.com/icon?family=Material+Icons&display=block";
Copy link
Contributor

Choose a reason for hiding this comment

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

Does dropping &display=block here & in the sheet below have any side effects?

.
</div>
<ModalBody>
<textarea
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you combine this with the textarea in chart_embed.tsx to a reusable component?

border: $border;
display: flex;
font-family: monospace;
font-family: "Google Sans Text", sans-serif;
Copy link
Contributor

Choose a reason for hiding this comment

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

Use css variable here - might need to verify which one, but maybe font-family: var(--dc-font-family, base.$font-family-sans-serif);

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.

3 participants