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: Create new Graphic component #3049

Open
alanbsmith opened this issue Nov 12, 2024 · 3 comments
Open

feat: Create new Graphic component #3049

alanbsmith opened this issue Nov 12, 2024 · 3 comments
Labels
11.x 12.x new-component New Component Implementation

Comments

@alanbsmith
Copy link
Member

🚀 Feature Proposal

Create a new Graphic component that pulls SVGs from a URL instead of injecting the graphic as inner HTML within the component.

Motivation

  1. Allow our consumers to pull assets from a CDN instead of our graphics package
  2. Assets can be cached by the browser and are only pulled in on request instead of bloating their app bundle
  3. Move away from using __dangerouslySetInnerHTML
  4. Opens the option to easily support PNGs

We could also refactor the existing Graphic component, but I think it's a better idea to add this to canvas-kit-preview-react and allow consumers to adjust over time. Adding a new component would also allow us to roll this out to teams sooner.

Example

The API could look something like this:

<Graphic imageName="empty-state-critical" />

🗒️ We would still need to figure out how to elegantly handle setting the base URL for various consumers and environments.

Under the hood, we would use set the imageName as a CSS var in our stencil and pass it along to the backgroundImage.

base: ({ imageName }) => ({
  backgroundImage: `${baseUrl}/${imageName}.svg`,
})

🤔 Maybe there should be a warning if the image is not found or is invalid?

Open to discussion on this. 😄

@alanbsmith alanbsmith added new-component New Component Implementation 12.x labels Nov 12, 2024
@github-project-automation github-project-automation bot moved this to 🆕 New in Canvas Kit Nov 12, 2024
@vibdev
Copy link
Contributor

vibdev commented Nov 12, 2024

We would still need to figure out how to elegantly handle setting the base URL for various consumers and environments

If we assumed the base URL was always the same it could go in the CKR provider.


One downside with background images is you don't get the same callbacks you get with <img> tag. e.g. onerror and onload

@alanbsmith
Copy link
Member Author

@vibdev Yeah, it could be an img tag and use src instead. 🤔

@vibdev
Copy link
Contributor

vibdev commented Nov 15, 2024

Is there any desire to make it a <Picture /> element so we could serve different graphics depending on media queries?

Also one other thought is, this might be a really good use case for web components, there is no reactivity so might fit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
11.x 12.x new-component New Component Implementation
Projects
Status: 🆕 New
Development

No branches or pull requests

3 participants