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

Request to add <image> element under the <svg> element (https://developer.mozilla.org/fr/docs/Web/SVG/Element/image) #1981

Closed
fdgStilla opened this issue Feb 26, 2024 · 4 comments · Fixed by #1985
Labels
good first issue Good for newcomers html Related to the html crate

Comments

@fdgStilla
Copy link
Contributor

Specific Demand

It is not possible to add an image element under a svg element.

Also is there any way to make it work with the 0.4.3? I could not find any example on how to create a custom element:

@ealmloff ealmloff added good first issue Good for newcomers html Related to the html crate labels Feb 26, 2024
@ealmloff
Copy link
Member

It looks like an image component existed at one point but is currently commented out:

// /// Build a
// /// [`<image>`](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/image)
// /// element.
// image "http://www.w3.org/2000/svg" {};

@fdgStilla
Copy link
Contributor Author

Ok I tried to uncomment the element and it works. It posted the PR on main but I am still interested in learning how to workaround this issue with the 0.4.3.

@ealmloff
Copy link
Member

To work around this issue in 0.4.3, you can create your own dioxus_elements mod like this:

use dioxus::prelude::*;

#[component]
fn SvgImage<'a>(cx: Scope<'a>) -> Element<'a> {
    mod dioxus_elements {
        pub struct image;

        impl image {
            pub const TAG_NAME: &'static str = "image";
            pub const NAME_SPACE: Option<&'static str> = Some("http://www.w3.org/2000/svg");
            // Tuple: (attribute name, namespace, volatile)
            pub const href: (&'static str, Option<&'static str>, bool) = (stringify!($fil), None, false);
        }
        impl dioxus::prelude::SvgAttributes for image {}
    }
    render! {
        image {
            href: "https://www.rust-lang.org/logos/rust-logo-512x512.png",
        }
    }
}

fn main(){}

@fdgStilla
Copy link
Contributor Author

I tried to use it but I could not make it work:

fn main() {
    dioxus_desktop::launch(App);
}

fn App(cx: Scope) -> Element {
    cx.render(rsx!(
        // both the following create an empty main div
        svg{SvgImage{}}
        SvgImage{}
        // some other combination with image{} tag do not compile
    ))
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers html Related to the html crate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants