Skip to content

Commit 027547c

Browse files
authored
fix layout of notifications (#135)
1 parent 105fa99 commit 027547c

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/output.jl

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -175,25 +175,31 @@ Display elements of `v` inside notification boxes that can be closed with a clos
175175
The elements are laid out according to `layout`.
176176
`observe` on this widget returns the observable of the list of elements that have not bein deleted.
177177
"""
178-
function notifications(::WidgetTheme, v=[]; container = div, wrap = identity,
179-
layout = (v...)->container((wrap(el) for el in v)...), className = "")
180-
178+
function notifications(::WidgetTheme, v=[]; container = node(:div),
179+
wrap = identity,
180+
layout = (v...)->container((wrap(el) for el in v)...),
181+
className = "")
182+
scope = Scope()
181183
output = Observable{Any}(v)
184+
to_delete = Observable(scope, "to_delete", 0)
185+
on(to_delete) do ind
186+
v = output[]
187+
deleteat!(v, ind)
188+
output[] = v
189+
end
182190
className = mergeclasses(className, "notification")
183191
list = map(output) do t
184192
function create_item(ind, el)
185-
btn = button(className = "delete")
186-
on(observe(btn)) do x
187-
deleteat!(t, ind)
188-
output[] = output[]
189-
end
190-
div(btn, className = className, el)
193+
btn = node(:button, className = "delete", events = Dict("click" =>
194+
@js event -> $to_delete[] = $ind))
195+
node(:div, btn, el, className = className)
191196
end
192197
[create_item(ind, el) for (ind, el) in enumerate(t)]
193198
end
194-
scope = Scope()
195-
slap_design!(scope)
199+
196200
scope.dom = map(v -> layout(v...), list)
201+
slap_design!(scope)
202+
197203
Widget{:notifications}([:list => list]; output = output, scope = scope,
198204
layout = _ -> node(:div, scope, className="interact-widget"))
199205
end

test/test_observables.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ end
266266
list = children(f.scope.dom[])[1]
267267

268268
@test begin
269-
observe(children(list)[1])[] += 1
269+
Widgets.scope(f)[:to_delete][] = 1
270270
sleep(0.1)
271271
observe(f)[] == []
272272
end

0 commit comments

Comments
 (0)