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

Suggestion: FileAttachment(...).image({ width: 500 }) #268

Closed
yurivish opened this issue Oct 17, 2021 · 10 comments
Closed

Suggestion: FileAttachment(...).image({ width: 500 }) #268

yurivish opened this issue Oct 17, 2021 · 10 comments

Comments

@yurivish
Copy link

Is your feature request related to a problem? Please describe.
I'd like to be able to easily load an image into an <img> element with a specific width.

Describe the solution you'd like
Some syntax like

FileAttachment(...).image({ width: 500 })

Describe alternatives you've considered
A chained promise that manually sets the width property and returns the image, but is verbose to write.

@CobusT
Copy link
Collaborator

CobusT commented Oct 17, 2021

Looks like there is an issue logged in the standard library for this. Good idea.

@CobusT
Copy link
Collaborator

CobusT commented Nov 4, 2021

The new standard library is now released and has this feature! We pass all the attributes through to the image, so you can use:
FileAttachment(...).image({ width: 500 })
or even:
FileAttachment(...).image({ width: 500, style: "border: 20px solid red" })

@CobusT CobusT closed this as completed Nov 4, 2021
@yurivish
Copy link
Author

yurivish commented Nov 4, 2021

Woot, that’s great, thank you Cobus!

@triptych
Copy link

triptych commented Nov 4, 2021

@triptych
Copy link

triptych commented Nov 4, 2021

Is the list of attributes whitelisted?
I can pass {
title: "foo",
}
but not {
onclick: "bar"
}

@triptych
Copy link

triptych commented Nov 4, 2021

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Img

some other attributes like "crossorigin" don't seem to be passed either

@mbostock
Copy link
Member

mbostock commented Nov 4, 2021

The onclick property takes a function, not a string, so try onclick: () => console.log("click").

@mbostock
Copy link
Member

mbostock commented Nov 4, 2021

You need to use “crossOrigin” rather than “crossorigin”. https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/crossOrigin

@triptych
Copy link

triptych commented Nov 4, 2021

I see, so you're passing the javascript properties , because HTML attributes are not case sensitive --> https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Img#attr-crossorigin

@triptych
Copy link

triptych commented Nov 4, 2021

So cool! Thanks @mbostock for the tips! I updated my notebook with more examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants