@@ -70,20 +70,6 @@ Functions and macros below are a part of `solid.core` namespace:
7070($ button {:on-click #(prn :pressed )} " press" )
7171```
7272
73- #### Child nodes
74-
75- ``` clj
76- ; ; ✅ bound
77- (let [title " the label"
78- input ($ :input ) ]
79- ($ :label title input))
80-
81- ; ; ✅ or explicit
82- ($ :label " the label" ($ :input )))
83-
84- ; ; <label> the label <input> </label>
85- ```
86-
8773### Attributes
8874
8975The ` :class ` attribute supports multiple formats:
@@ -102,50 +88,45 @@ The `:class` attribute supports multiple formats:
10288{:class {:active @is-active?
10389 :disabled @is-disabled?}}
10490```
105-
106- #### Bound Attributes
107-
108- Given a component declared with ` defui ` :
91+ #### Passing attributes and child nodes
10992
11093``` clj
11194(defui custom-label [{:keys [input-name children]} attrs]
11295 ($ :label {:for input-name} children))
113- ```
11496
115- It would be called like this:
116-
117- ``` clj
97+ ; ; ✅ Pass the attribute map as a literal
11898($ custom-label {:input-name " my-input" } " the label title" )
119- ```
12099
121- However, to pass bound variables for the ` defui ` component,
122100
123- ``` clj
124- ; ; ❌ Using a bound variable for attributes, `attrs` is
125- ; ; indistinguishable from passing multiple child nodes for the `$` macro
126101(let [attrs {:input-name " my-input" }
127102 children " the label title" ]
128- ($ custom-label attrs children))
129-
130- ; ; ✅ Wrapping the attribute variable with a vector, `[attrs]`
131- ; ; signals the macro that it should be treated as an attribute map
132- (let [attrs {:input-name " my-input" }
133- children " the label title" ]
134- ($ custom-label [attrs] children))
103+ ($ :<> ; ; Fragment component
104+ ($ custom-label attrs children) ; ; ✅ Pass the attribute map as a bound variable
105+ ($ custom-label children) ; ; ✅ Attribute map is optional, it may be elided entirely
106+ ($ custom-label) ; ; also valid
107+ ($ custom-label attrs))) ; ; also valid
135108```
136109
137110Do not use bound variables for keyword tags:
138111
139112``` clj
140113; ; ❌ Not supported for keyword tags,
141114; ; Only supported for `defui` tags
142- (let [attrs {:class " my-div" } ]
143- ($ :div [attrs] children))
115+ (let [attrs {:class " my-div" }
116+ title ($ " the label" )
117+ input ($ :input )]
118+ ($ :label attrs title input))
144119
145120; ; ✅ Be explicit with a map literal
146- ($ :div {:class " my-div" } children))
121+ (let [attrs
122+ title ($ " the label" )
123+ input ($ :input )]
124+ ($ :label {:class " my-label" } title input))
125+ ; ; <label class="my-label"> the label <input> </label>
147126```
148127
128+
129+
149130### Rendering
150131
151132Conditional rendering with ` if ` and ` when ` , via [ <Show > component] ( https://docs.solidjs.com/reference/components/show )
0 commit comments