Skip to content

Commit e3001d0

Browse files
authored
Adjust styling recipe (#44)
1 parent 3cd82f9 commit e3001d0

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

hugo/content/docs/recipes/styling.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,20 @@ When dealing with diagrams with different types of nodes, ports, edges, or label
4747

4848
By convention, Sprotty uses the `type` property, which is a string of the shape `main-type:sub-type`, to distinguish between different types of diagram elements. For example, a node of type `node:my-node` has the main type `node` and the sub-type `my-node`.
4949

50-
Using this convention, you can add a CSS class for each diagram element sub-type. For example:
50+
Using this convention, you can add a CSS class for each diagram element sub-type. The `CssClassPostprocessor`, which is included by default in Sprotty, automatically extracts the sub-type from the element's type and adds it as a CSS class to the element's wrapper.
51+
52+
For example:
5153

5254
* A node of type `node:my-node` using the `RectangularNodeView` would have the following CSS classes: `sprotty-node` and `my-node`.
5355
* A node of type `node:my-other-node` using the `RectangularNodeView` would have the following CSS classes: `sprotty-node` and `my-other-node`.
5456

55-
This allows for more control over the styling of your diagram elements.
57+
The `CssClassPostprocessor` works by:
58+
59+
1. Extracting the sub-type from the element's type (the part after the colon)
60+
2. Adding this sub-type as a CSS class to the element's wrapper `<g>` element
61+
3. Allowing you to target elements using descendant selectors like `.my-node .sprotty-node`
62+
63+
This allows for more control over the styling of your diagram elements without requiring manual class management.
5664

5765
## Styling on a Per-Element Basis
5866

0 commit comments

Comments
 (0)