@quartic/bokehjs
Version:
Interactive, novel data visualization
53 lines (40 loc) • 1.45 kB
text/coffeescript
import "bootstrap/button"
import {input, label} from "core/dom"
import * as p from "core/properties"
import {uniqueId} from "core/util/string"
import {Widget, WidgetView} from "./widget"
import template from "./button_group_template"
export class RadioButtonGroupView extends WidgetView
events:
"change input": "change_input"
template: template
initialize: (options) ->
super(options)
render: () ->
super()
html = @template()
name = uniqueId("RadioButtonGroup")
active = @model.active
for text, i in @model.labels
inputEl = input({type: "radio", name: name, value: "#{i}", checked: i == active})
labelEl = label({class: ["bk-bs-btn", "bk-bs-btn-#{@model.button_type}"]}, inputEl, text)
if i == active then labelEl.classList.add("bk-bs-active")
return @
change_input: () ->
active = (i for radio, i in @$el.find("input") when radio.checked)
export class RadioButtonGroup extends Widget
type: "RadioButtonGroup"
default_view: RadioButtonGroupView
active: [ p.Any, null ] # TODO (bev) better type?
labels: [ p.Array, [] ]
button_type: [ p.String, "default" ]
callback: [ p.Instance ]
}