x
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<form data-controller="midwest-form" action="#" accept-charset="UTF-8" method="get"> <div class="flex flex-col gap-4 max-w-sm"> <p class="text-sm text-theme-8">Select categories to assign:</p> <ul data-controller="midwest-tree-view" role="tree" class="midwest-tree-view"> <li role="treeitem" class="midwest-tree-node" style="--tree-depth: 0" aria-expanded="true" tabindex="-1"> <div class="tree-node-trigger"> <span class="tree-node-chevron" aria-hidden="true" data-action="click->midwest-tree-view#toggle"> <div class="midwest-icon "> <div class="midwest-icon-inner"> <svg xmlns="http://www.w3.org/2000/svg" class="Midwest-Icon__Svg" viewbox="0 0 512 512" focusable="false" role="img" aria-label="Chevron down"><title>Chevron down</title> <path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="48" d="M112 184l144 144 144-144"></path></svg> </div> </div> </span> <input type="checkbox" class="tree-node-checkbox" id="tree-node-12708" name="category_ids[]" value="1" data-action="change->midwest-tree-view#checkboxChanged" aria-hidden="true" tabindex="-1"> <span class="tree-node-label">Engineering</span> </div> <ul role="group" class="tree-node-children"> <li role="treeitem" class="midwest-tree-node" style="--tree-depth: 1" aria-expanded="false" tabindex="-1"> <div class="tree-node-trigger"> <span class="tree-node-chevron" aria-hidden="true" data-action="click->midwest-tree-view#toggle"> <div class="midwest-icon "> <div class="midwest-icon-inner"> <svg xmlns="http://www.w3.org/2000/svg" class="Midwest-Icon__Svg" viewbox="0 0 512 512" focusable="false" role="img" aria-label="Chevron down"><title>Chevron down</title> <path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="48" d="M112 184l144 144 144-144"></path></svg> </div> </div> </span> <input type="checkbox" class="tree-node-checkbox" id="tree-node-12718" name="category_ids[]" value="2" data-action="change->midwest-tree-view#checkboxChanged" aria-hidden="true" tabindex="-1"> <span class="tree-node-label">Frontend</span> </div> <ul role="group" class="tree-node-children"> <li role="treeitem" class="midwest-tree-node" style="--tree-depth: 2" tabindex="-1"> <div class="tree-node-trigger"> <span class="tree-node-spacer" aria-hidden="true"></span> <input type="checkbox" class="tree-node-checkbox" id="tree-node-12720" name="category_ids[]" value="3" data-action="change->midwest-tree-view#checkboxChanged" aria-hidden="true" tabindex="-1"> <span class="tree-node-label">React</span> </div> </li> <li role="treeitem" class="midwest-tree-node" style="--tree-depth: 2" tabindex="-1"> <div class="tree-node-trigger"> <span class="tree-node-spacer" aria-hidden="true"></span> <input type="checkbox" class="tree-node-checkbox" id="tree-node-12728" name="category_ids[]" value="4" data-action="change->midwest-tree-view#checkboxChanged" aria-hidden="true" tabindex="-1"> <span class="tree-node-label">Vue</span> </div> </li> </ul> </li> <li role="treeitem" class="midwest-tree-node" style="--tree-depth: 1" aria-expanded="false" tabindex="-1"> <div class="tree-node-trigger"> <span class="tree-node-chevron" aria-hidden="true" data-action="click->midwest-tree-view#toggle"> <div class="midwest-icon "> <div class="midwest-icon-inner"> <svg xmlns="http://www.w3.org/2000/svg" class="Midwest-Icon__Svg" viewbox="0 0 512 512" focusable="false" role="img" aria-label="Chevron down"><title>Chevron down</title> <path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="48" d="M112 184l144 144 144-144"></path></svg> </div> </div> </span> <input type="checkbox" class="tree-node-checkbox" id="tree-node-12730" name="category_ids[]" value="5" data-action="change->midwest-tree-view#checkboxChanged" aria-hidden="true" tabindex="-1"> <span class="tree-node-label">Backend</span> </div> <ul role="group" class="tree-node-children"> <li role="treeitem" class="midwest-tree-node" style="--tree-depth: 2" tabindex="-1"> <div class="tree-node-trigger"> <span class="tree-node-spacer" aria-hidden="true"></span> <input type="checkbox" class="tree-node-checkbox" id="tree-node-12738" name="category_ids[]" value="6" data-action="change->midwest-tree-view#checkboxChanged" aria-hidden="true" tabindex="-1"> <span class="tree-node-label">Ruby</span> </div> </li> <li role="treeitem" class="midwest-tree-node" style="--tree-depth: 2" tabindex="-1"> <div class="tree-node-trigger"> <span class="tree-node-spacer" aria-hidden="true"></span> <input type="checkbox" class="tree-node-checkbox" id="tree-node-12740" name="category_ids[]" value="7" data-action="change->midwest-tree-view#checkboxChanged" aria-hidden="true" tabindex="-1"> <span class="tree-node-label">Go</span> </div> </li> </ul> </li> </ul> </li> <li role="treeitem" class="midwest-tree-node" style="--tree-depth: 0" aria-expanded="false" tabindex="-1"> <div class="tree-node-trigger"> <span class="tree-node-chevron" aria-hidden="true" data-action="click->midwest-tree-view#toggle"> <div class="midwest-icon "> <div class="midwest-icon-inner"> <svg xmlns="http://www.w3.org/2000/svg" class="Midwest-Icon__Svg" viewbox="0 0 512 512" focusable="false" role="img" aria-label="Chevron down"><title>Chevron down</title> <path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="48" d="M112 184l144 144 144-144"></path></svg> </div> </div> </span> <input type="checkbox" class="tree-node-checkbox" id="tree-node-12748" name="category_ids[]" value="8" data-action="change->midwest-tree-view#checkboxChanged" aria-hidden="true" tabindex="-1"> <span class="tree-node-label">Design</span> </div> <ul role="group" class="tree-node-children"> <li role="treeitem" class="midwest-tree-node" style="--tree-depth: 1" tabindex="-1"> <div class="tree-node-trigger"> <span class="tree-node-spacer" aria-hidden="true"></span> <input type="checkbox" class="tree-node-checkbox" id="tree-node-12750" name="category_ids[]" value="9" data-action="change->midwest-tree-view#checkboxChanged" aria-hidden="true" tabindex="-1"> <span class="tree-node-label">UI</span> </div> </li> <li role="treeitem" class="midwest-tree-node" style="--tree-depth: 1" tabindex="-1"> <div class="tree-node-trigger"> <span class="tree-node-spacer" aria-hidden="true"></span> <input type="checkbox" class="tree-node-checkbox" id="tree-node-12758" name="category_ids[]" value="10" data-action="change->midwest-tree-view#checkboxChanged" aria-hidden="true" tabindex="-1"> <span class="tree-node-label">UX</span> </div> </li> </ul> </li> </ul> <button type="submit" class="midwest-button variant-default size-default theme-primary" name="submit"> <span class="midwest-button-content">Save</span> <div class="midwest-loading-icon" role="img" aria-label="Loading" aria-hidden="true" style="display: none"> <div class="midwest-loading-icon-inner"> <!-- By Sam Herbert (@sherb), for everyone. More @ http://goo.gl/7AJzbL --> <svg viewbox="0 0 120 30" xmlns="http://www.w3.org/2000/svg" fill="currentColor" class="Midwest-LoadingIcon__Svg" focusable="false" aria-hidden="true"> <circle cx="15" cy="15" r="15"> <animate attributename="r" from="15" to="15" begin="0s" dur="0.8s" values="15;9;15" calcmode="linear" repeatcount="indefinite"></animate> <animate attributename="fill-opacity" from="1" to="1" begin="0s" dur="0.8s" values="1;.5;1" calcmode="linear" repeatcount="indefinite"></animate> </circle> <circle cx="60" cy="15" r="9" fill-opacity="0.3"> <animate attributename="r" from="9" to="9" begin="0s" dur="0.8s" values="9;15;9" calcmode="linear" repeatcount="indefinite"></animate> <animate attributename="fill-opacity" from="0.5" to="0.5" begin="0s" dur="0.8s" values=".5;1;.5" calcmode="linear" repeatcount="indefinite"></animate> </circle> <circle cx="105" cy="15" r="15"> <animate attributename="r" from="15" to="15" begin="0s" dur="0.8s" values="15;9;15" calcmode="linear" repeatcount="indefinite"></animate> <animate attributename="fill-opacity" from="1" to="1" begin="0s" dur="0.8s" values="1;.5;1" calcmode="linear" repeatcount="indefinite"></animate> </circle> </svg> </div> </div> </button> </div></form>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<%= midwest_form_with(url: "#", method: :get) do |form| %> <div class="flex flex-col gap-4 max-w-sm"> <p class="text-sm text-theme-8">Select categories to assign:</p> <%= form.tree_view(:category_ids) do |tree| %> <% tree.with_node("Engineering", value: "1", expanded: true) do |eng| %> <% eng.with_node("Frontend", value: "2") do |fe| %> <% fe.with_node("React", value: "3") %> <% fe.with_node("Vue", value: "4") %> <% end %> <% eng.with_node("Backend", value: "5") do |be| %> <% be.with_node("Ruby", value: "6") %> <% be.with_node("Go", value: "7") %> <% end %> <% end %> <% tree.with_node("Design", value: "8") do |design| %> <% design.with_node("UI", value: "9") %> <% design.with_node("UX", value: "10") %> <% end %> <% end %> <%= form.submit "Save" %> </div><% end %>Form Builder
Inside a midwest_form_with block, use form.tree_view(:attribute)
to render a selectable tree that submits checked values as an array.
No params configured.
No assets to display.
Add a .js or .css file alongside the component to see it here.
Figma embed for Tree View/form_builder
Annotate a preview to embed its Figma design here:
@figma "https://figma.com/..."