@macrostrat/column-components
Version:
React rendering primitives for stratigraphic columns
66 lines (65 loc) • 1.87 kB
JavaScript
;
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const h = require("@macrostrat/hyper");
const classNames = require("classnames");
const React = require("react");
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
const h__default = /* @__PURE__ */ _interopDefault(h);
const classNames__default = /* @__PURE__ */ _interopDefault(classNames);
class PickerControl extends React.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__default.default("bp6-button-group", "bp6-fill", {
"bp6-vertical": vertical,
"bp6-align-left": vertical
});
return h__default.default("div.picker-control", [
h__default.default(
"div",
{ className },
states.map((d) => {
className = classNames__default.default("bp6-button", {
"bp6-active": this.props.activeState === d.value
});
return h__default.default(
"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);
};
}
}
exports.PickerControl = PickerControl;
//# sourceMappingURL=picker-base.cjs.map