diff --git a/doc/component.md b/doc/component.md index 257574b3..567c5fde 100644 --- a/doc/component.md +++ b/doc/component.md @@ -24,6 +24,7 @@ - [Asynchronous Rendering](#asynchronous-rendering) - [Error Handling](#error-handling) - [Functional Components](#functional-components) + - [SVG components](#svg-components) ## Overview @@ -1198,3 +1199,52 @@ class MyComponent extends Component { The way this works is that sub templates are inlined, and have access to the ambient context. They can therefore access `props`, and any other part of the caller component. + +### SVG Components + +Owl components can be used to generate dynamic SVG graphs: + +```js +class Node extends Component { + static template = xml` + + + + + + + + + + + + `; + static components = { Node }; +} + +class RootNode extends Component { + static template = xml` + + + + `; + static components = { Node }; + graph = { + label: "a", + children: [ + {label: "b"}, + {label: "c", children: [{label: "d"}, {label: "e"}]}, + {label: "f", children: [{label: "g"}]}, + ] + }; +} +``` + +This `RootNode` component will then display a live SVG representation of the +graph described by the `graph` property. Note that there is a recursive structure +here: the `Node` component uses itself as a subcomponent. + +Note that since SVG needs to be handled in a specific way (its namespace needs +to be properly set), there is a small constraint for Owl components: if an owl +component is supposed to be a part of an svg graph, then its root node needs to +be a `g` tag, so Owl can properly set the namespace. \ No newline at end of file