-
Notifications
You must be signed in to change notification settings - Fork 442
/
ViewSwitcherToggle.tsx
57 lines (45 loc) · 1.35 KB
/
ViewSwitcherToggle.tsx
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
import {
SearchkitComponent,
SearchkitComponentProps,
ViewOptionsAccessor,
RenderComponentType,
RenderComponentPropType,
renderComponent
} from "../../../core"
import {Toggle, ListProps} from "../../ui"
const defaults = require("lodash/defaults")
export interface ViewSwitcherProps extends SearchkitComponentProps {
listComponent?:RenderComponentType<ListProps>
}
export class ViewSwitcherToggle extends SearchkitComponent<ViewSwitcherProps, any> {
static defaultProps = {
listComponent:Toggle
}
static propTypes = defaults({
listComponent:RenderComponentPropType
}, SearchkitComponent.propTypes)
getViewOptionsSwitcherAccessor(){
return this.searchkit.getAccessorByType(ViewOptionsAccessor)
}
setView(view){
this.getViewOptionsSwitcherAccessor().setView(view)
}
render() {
let viewOptionsAccessor = this.getViewOptionsSwitcherAccessor()
if(viewOptionsAccessor){
let options = viewOptionsAccessor.options
let selectedOption = viewOptionsAccessor.getSelectedOption().key
return renderComponent(this.props.listComponent, {
mod:this.props.mod,
className:this.props.className,
disabled:!this.hasHits(),
items:options,
selectedItems:[selectedOption],
toggleItem:this.setView.bind(this),
setItems: ([item]) => this.setView(item),
translate:this.translate
})
}
return null
}
}