Skip to content

Commit 0047710

Browse files
author
Diyor Khaydarov
committed
fix: side filter
1 parent 64b9d7a commit 0047710

File tree

6 files changed

+153
-121
lines changed

6 files changed

+153
-121
lines changed

Diff for: components/scaffold/filters/filters.templ

+29
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,32 @@ templ (t *TableFilter) Component() {
132132
}
133133
}
134134
}
135+
136+
templ (t *TableFilter) AsSideFilter() {
137+
<div class="space-y-3">
138+
<div>
139+
@input.Checkbox(&input.CheckboxProps{
140+
Label: "Select All",
141+
ID: "all-users-checkbox",
142+
Attrs: templ.Attributes{
143+
"class": "parent",
144+
"x-ref": "parent",
145+
"@change": "onParentChange",
146+
},
147+
})
148+
</div>
149+
<hr class="my-3 border-t border-surface-400"/>
150+
<div class="space-y-3">
151+
for _, opt := range t.options {
152+
@input.Checkbox(&input.CheckboxProps{
153+
Label: opt.Label,
154+
Attrs: templ.Attributes{
155+
"name": t.Name,
156+
"value": opt.Value,
157+
"@change": "onChange",
158+
},
159+
})
160+
}
161+
</div>
162+
</div>
163+
}

Diff for: components/scaffold/filters/filters_templ.go

+62
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: components/scaffold/helpers.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package scaffold
22

33
import (
44
"github.com/a-h/templ"
5-
"github.com/iota-uz/iota-sdk/components/scaffold/filters"
65
)
76

87
// --- Interfaces ---
@@ -55,7 +54,7 @@ func WithClass(classes string) ColumnOpt {
5554
type TableConfig struct {
5655
Title string
5756
DataURL string
58-
Filters []*filters.TableFilter
57+
Filters []templ.Component
5958
Columns []TableColumn
6059
Rows []TableRow
6160
SideFilter templ.Component
@@ -66,7 +65,7 @@ func NewTableConfig(title, dataURL string) *TableConfig {
6665
Title: title,
6766
DataURL: dataURL,
6867
Columns: []TableColumn{},
69-
Filters: []*filters.TableFilter{},
68+
Filters: []templ.Component{},
7069
Rows: []TableRow{},
7170
}
7271
}
@@ -91,7 +90,7 @@ func (c *TableConfig) AddCols(cols ...TableColumn) *TableConfig {
9190
return c
9291
}
9392

94-
func (c *TableConfig) AddFilters(filters ...*filters.TableFilter) *TableConfig {
93+
func (c *TableConfig) AddFilters(filters ...templ.Component) *TableConfig {
9594
c.Filters = append(c.Filters, filters...)
9695
return c
9796
}

Diff for: components/scaffold/scaffold.templ

+16-20
Original file line numberDiff line numberDiff line change
@@ -99,29 +99,14 @@ templ TableContent(config *TableConfig) {
9999
</div>
100100
<div class="hidden md:flex gap-3 h-full">
101101
for _, filter := range config.Filters {
102-
@filter.Component()
102+
@filter
103103
}
104104
</div>
105105
</form>
106106
@Table(config)
107107
</div>
108108
}
109109

110-
templ SideFilter() {
111-
<div class="bg-surface-600 border border-primary rounded-lg p-4 mb-4">
112-
<form
113-
hx-get="/users"
114-
hx-target="#table-body"
115-
hx-swap="innerHTML"
116-
hx-push-url="true"
117-
hx-indicator="#table-body"
118-
hx-trigger="change"
119-
>
120-
{ children... }
121-
</form>
122-
</div>
123-
}
124-
125110
// Content renders the complete scaffold page content with filters and table
126111
templ Content(config *TableConfig) {
127112
{{ pageCtx := composables.UsePageCtx(ctx) }}
@@ -130,7 +115,7 @@ templ Content(config *TableConfig) {
130115
Action: "open-filters",
131116
}) {
132117
for _, filter := range config.Filters {
133-
@filter.Component()
118+
@filter
134119
}
135120
}
136121
<div class="m-6">
@@ -154,9 +139,20 @@ templ Content(config *TableConfig) {
154139
<div class="mt-5 flex gap-5">
155140
<!-- Left sidebar with filters -->
156141
<div class="hidden md:block w-64 flex-shrink-0">
157-
@SideFilter() {
158-
@config.SideFilter
159-
}
142+
<div class="bg-surface-600 border border-primary rounded-lg p-4 mb-4">
143+
<form
144+
hx-get={ config.DataURL }
145+
hx-target="#table-body"
146+
hx-swap="innerHTML"
147+
hx-push-url="true"
148+
hx-indicator="#table-body"
149+
hx-trigger="change"
150+
x-data="checkboxes"
151+
x-init="init"
152+
>
153+
@config.SideFilter
154+
</form>
155+
</div>
160156
</div>
161157
<!-- Main content area with table -->
162158
<div class="flex-1">

0 commit comments

Comments
 (0)