DioxusLabs / dioxus

Fullstack GUI library for web, desktop, mobile, and more.
https://dioxuslabs.com
Apache License 2.0
18.5k stars 704 forks source link

Error `defs` found for struct `dioxus::dioxus_html::svg` #2315

Closed katopz closed 2 weeks ago

katopz commented 2 weeks ago

Problem

Try to use defs in svg

<svg viewBox="0 0 120 120" xmlns="http://www.w3.org/2000/svg">
  <defs>
    <marker
      id="triangle"
      viewBox="0 0 10 10"
      refX="1"
      refY="5"
      markerUnits="strokeWidth"
      markerWidth="10"
      markerHeight="10"
      orient="auto">
      <path d="M 0 0 L 10 5 L 0 10 z" fill="#f00" />
    </marker>
  </defs>
  <polyline
    fill="none"
    stroke="black"
    points="20,100 40,60 70,80 100,20"
    marker-end="url(#triangle)" />
</svg>

Steps To Reproduce

#![allow(non_snake_case)]
use dioxus::prelude::*;

fn main() {
    launch(App);
}

fn App() -> Element {
    rsx! {
        svg {
            view_box: "0 0 120 120",
            defs: {
                marker {
                    // path: {
                    //     d:"M 0 0 L 10 5 L 0 10 z",
                    //     fill:"#f00"
                    // }
                }
            },
        }
    }
}

Expected behavior

Able to use defs

Screenshots

If applicable, add screenshots to help explain your problem.

Environment:

Seem like we not support defs yet am I right?

ealmloff commented 2 weeks ago

In your code, you use defs: {...} and path: {...} which is the syntax for attributes, not elements. This code compiles:

#![allow(non_snake_case)]
use dioxus::prelude::*;

fn main() {
    launch(App);
}

fn App() -> Element {
    rsx! {
        svg {
            view_box: "0 0 120 120",
            defs {
                marker {
                    path {
                        d: "M 0 0 L 10 5 L 0 10 z",
                        fill:"#f00"
                    }
                }
            },
        }
    }
}