UNPKG

@macrostrat/column-components

Version:

React rendering primitives for stratigraphic columns

111 lines (110 loc) 3.48 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const React = require("react"); const h$1 = require("@macrostrat/hyper"); const util = require("./util.cjs"); const core = require("@blueprintjs/core"); const index = require("../lithology/index.cjs"); const main_module = require("./main.module.scss.cjs"); const lithology = require("../context/lithology.cjs"); const patterns = require("../lithology/patterns.cjs"); const _interopDefault = (e) => e && e.__esModule ? e : { default: e }; const h__default = /* @__PURE__ */ _interopDefault(h$1); const h = h__default.default.styled(main_module.default); const LithologySwatch = function({ symbolID, style, ...rest }) { const { resolvePattern } = React.useContext(patterns.GeologicPatternContext); const src = resolvePattern(symbolID); if (style == null) { style = {}; } style.backgroundImage = `url("${src}")`; return h("div.lithology-swatch", { style, ...rest }); }; const LithologyItem = function(props) { const { symbol, lithology: lithology2 } = props; return h("span.facies-picker-row", [ h(LithologySwatch, { symbolID: symbol }), h("span.facies-picker-name", lithology2) ]); }; const LithologyPicker = (props) => { const { interval, onChange } = props; const { lithologies } = React.useContext(lithology.LithologyContext); console.log("lithologies", lithologies, interval); let options = []; for (let item of lithologies) { const { id, pattern } = item; const symbol = index.symbolIndex[pattern]; options.push({ value: id, label: h(LithologyItem, { lithology: id, symbol }) }); } let value = options.find((d) => d.value === interval.lithology_id); return h(util.RaisedSelect, { id: "lithology-select", options, value, isClearable: true, onChange(res) { const f = res != null ? res.value : null; return onChange(f); } }); }; const SymbolPickerInner = function(props) { let symbol; const { interval, onClose, style } = props; let text = "No pattern set"; if (interval.pattern != null) { symbol = interval.pattern; text = `Symbol ${symbol}`; } if (interval.lithology != null) { symbol = index.symbolIndex[interval.lithology]; text = "Default for lithology"; } return h("div.lithology-symbol-picker-inner", { style }, [ h.if(symbol != null)(LithologySwatch, { symbolID: symbol }), h("div.picker-label.text", text), h.if(onClose != null)( core.Button, { small: true, icon: "cross", intent: core.Intent.DANGER, minimal: true, onClick: onClose }, "Clear override" ) ]); }; const LithologySymbolPicker = function(props) { const { interval, updatePattern } = props; const [isExpanded, setIsExpanded] = React.useState(false); const className = isExpanded ? "expanded" : "hidden"; return h("div.lithology-symbol-picker", { className }, [ h( core.Button, { className: "expand-button", onClick() { setIsExpanded(true); }, minimal: true, small: true, intent: core.Intent.WARNING }, "Override lithology pattern" ), h(SymbolPickerInner, { interval, onClose: () => setIsExpanded(false), updatePattern }) ]); }; exports.LithologyPicker = LithologyPicker; exports.LithologySymbolPicker = LithologySymbolPicker; //# sourceMappingURL=lithology-picker.cjs.map