You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -4,53 +4,167 @@ Use the ``RootRegistry`` protocol to define how custom modifiers in the DOM are
4
4
5
5
## Overview
6
6
7
-
If you don't already have one, create a type that conforms to the ``RootRegistry``protocol and provide it as the eneric type paramter to your ``LiveViewCoordinator``.
7
+
If you don't already have one, create a type that uses the ``Addon()``macro, and include it in the list of `addons` on your ``LiveView``.
8
8
9
9
```swift
10
-
structMyRegistry: RootRegistry {
10
+
publicextensionAddons {
11
+
@Addon
12
+
structMyAddon<Root: RootRegistry> {
13
+
// ...
14
+
}
11
15
}
12
16
```
13
17
14
-
Then, add an enum called `AttributeName` that has strings for raw values and conforms to `Equatable`. The framework will use this type to check if your registry supports a particular attribute name. All of the string values should be lowercase, otherwise the framework will not use them.
18
+
```swift
19
+
#LiveView(
20
+
.localhost,
21
+
addons: [.myAddon]
22
+
)
23
+
```
24
+
25
+
Then, add an enum called `CustomModifier` that has cases for each modifier to include.
26
+
The framework uses this type to parse modifiers in a stylesheet.
27
+
28
+
Use the ``CustomModifierGroupParser`` to include multiple modifiers.
To define the view modifier for this attributes, implement the ``CustomRegistry/decodeModifier(_:from:)-9gliz`` method. This method is automatically treated as a ``ViewModifierBuilder``, so simply construct your modifier rather than returning it.
56
+
## Parseable Modifiers
57
+
58
+
Each modifier should conform to ``LiveViewNativeStylesheet/ParseableModifierValue``.
59
+
You can use the ``LiveViewNativeStylesheet/ParseableExpression()`` macro to synthesize this conformance.
60
+
61
+
The macro will synthesize a parser for each `init` clause.
25
62
26
-
In the following example, a modifier like `{"type": "my_font", "size": 22}` could be used to apply the custom font named "My Font" with a fixed size of 22pt.
63
+
Any type conforming to ``LiveViewNativeStylesheet/ParseableModifierValue`` can be used as an argument in an `init` clause.
Because an enum is used for the attribute name, do not include a `default` branch in your `switch` statement so that Swift will check if for exhaustiveness.
125
+
```elixir
126
+
"my-background"do
127
+
myBackground(:my_content)
128
+
end
129
+
```
130
+
131
+
```html
132
+
<Elementclass="my-background">
133
+
<Texttemplate="my_content">Nested Content</Text>
134
+
</Element>
135
+
```
136
+
137
+
### Attribute References
138
+
Any type that conforms to ``AttributeDecodable`` can be wrapped with ``AttributeReference``.
44
139
45
-
Then, implement the `MyFontModifier` struct. By conforming to the `Decodable` protocol, the `init(from:)`initializer that handles decoding the modifier from JSON can be synthesized automatically. The `body(content:)` method modifies the `content` view it receives based on whatever values were decoded.
140
+
This will make it usable with the `attr(<name>)`helper in a stylesheet.
0 commit comments