@figlinq/react-chart-editor
Version:
plotly.js chart editor react component UI
2 lines • 3.54 kB
JavaScript
function ownKeys(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,o)}return t}function _objectSpread(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?ownKeys(Object(t),!0).forEach(function(r){_defineProperty(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}function _defineProperty(e,r,t){return(r=_toPropertyKey(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function _toPropertyKey(t){var i=_toPrimitive(t,"string");return"symbol"==typeof i?i:i+""}function _toPrimitive(t,r){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,r||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}import{Component}from"react";import PropTypes from"prop-types";import{connectToContainer}from"../../lib";import{MULTI_VALUED_PLACEHOLDER}from"../../lib/constants";import Field from"./Field";import DropdownWidget from"../widgets/Dropdown";import Text from"./Text";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export class UnconnectedDropdownCustom extends Component{constructor(props,context){super(props,context);this.setValue=this.setValue.bind(this);this.setLocals=this.setLocals.bind(this);this.setLocals(props);this.state={custom:this.value===props.customOpt||!this.props.options.map(o=>o.value).includes(this.value)}}UNSAFE_componentWillReceiveProps(props){this.setLocals(props)}setLocals(props){this.value=props.fullValue===undefined||props.fullValue===MULTI_VALUED_PLACEHOLDER?this.props.defaultOpt:props.fullValue}setValue(value){let custom=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;this.value=value;const customOpt=this.props.customOpt;this.setState({custom:(custom||value===customOpt)&&value!==""});this.props.updateContainer({[this.props.attr]:value===customOpt&&!custom?customOpt:value})}render(){const{options,attr,customOpt}=this.props;const value=(this.value===""||!options.map(o=>o.value).includes(this.value))&&this.state.custom?customOpt:this.value;return _jsxs(Field,_objectSpread(_objectSpread({},this.props),{},{children:[_jsx(DropdownWidget,{backgroundDark:this.props.backgroundDark,options:options,value:value,onChange:this.setValue,clearable:this.props.clearable,components:this.props.components,placeholder:this.props.placeholder}),this.state.custom&&_jsx(Text,{attr:attr,updatePlot:value=>this.setValue(value,true),onChange:value=>{if(value){this.setValue(value,true)}}})]}))}}UnconnectedDropdownCustom.propTypes=_objectSpread({backgroundDark:PropTypes.bool,fullValue:PropTypes.any,updatePlot:PropTypes.func,clearable:PropTypes.bool,components:PropTypes.object,placeholder:PropTypes.any,defaultOpt:PropTypes.oneOfType([PropTypes.number,PropTypes.bool,PropTypes.string]),customOpt:PropTypes.oneOfType([PropTypes.number,PropTypes.bool,PropTypes.string]),label:PropTypes.string,attr:PropTypes.string},Field.propTypes);UnconnectedDropdownCustom.contextTypes={updateContainer:PropTypes.func};UnconnectedDropdownCustom.displayName="UnconnectedDropdownCustom";export default connectToContainer(UnconnectedDropdownCustom);
//# sourceMappingURL=DropdownCustom.js.map