UNPKG

@macrostrat/column-components

Version:

React rendering primitives for stratigraphic columns

63 lines (62 loc) 1.47 kB
import h from "@macrostrat/hyper"; import classNames from "classnames"; import { Component } from "react"; class PickerControl extends Component { constructor(props) { super(props); this.onUpdate = this.onUpdate.bind(this); } static defaultProps = { states: [ { label: "State 1", value: "state1" }, { label: "State 2", value: "state2" } ], vertical: true, isNullable: false }; render() { const { states, activeState, vertical } = this.props; let className = classNames("bp6-button-group", "bp6-fill", { "bp6-vertical": vertical, "bp6-align-left": vertical }); return h("div.picker-control", [ h( "div", { className }, states.map((d) => { className = classNames("bp6-button", { "bp6-active": this.props.activeState === d.value }); return h( "button", { type: "button", className, onClick: this.onUpdate(d.value) }, d.label ); }) ) ]); } onUpdate(value) { return () => { if (value === this.props.activeState) { if (!this.props.isNullable) { return; } value = null; } if (this.props.onUpdate == null) { return; } return this.props.onUpdate(value); }; } } export { PickerControl }; //# sourceMappingURL=picker-base.js.map