Skip to content

Instantly share code, notes, and snippets.

@iazel
Created July 13, 2019 13:49
Show Gist options
  • Save iazel/18e6567768e206593b1999fcc6beb007 to your computer and use it in GitHub Desktop.
Save iazel/18e6567768e206593b1999fcc6beb007 to your computer and use it in GitHub Desktop.
Composable Reactive UI / Filter
import { h, ctext, onClick } from '@crui/core'
import { map, RW$B } from '@crui/reactive/rx/box'
import { $props } from '@crui/reactive/setups/props'
const Filter = (
$vis: RW$B<Visibility>,
filterVis: Visibility,
label: string
) => {
const className = map($vis, (v) => (
'filter ' + (v === vis ? 'active' : '')
))
return h('button', sc([
ctext(label),
$props({ className }),
onClick((e) => {
e.preventDefault()
$vis.set(filterVis)
})
]))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment