import React from 'react'; import { BasicConfig } from 'react-awesome-query-builder'; import { ButtonGroup, TextField, Icon, MenuItem, Button, IconButton, Slider } from '../'; // type to color const typeToColor = { addRule : 'success', delRule : 'error', addGroup : 'success', delGroup : 'error', }; // create select field const SelectField = (props) => { // return jsx return ( props.setField(e.target.value) } > { (props.items || []).map((opt) => { // return jsx return ( { opt.label } ); }) } ); }; // settings const settings = { ...BasicConfig.settings, // selects renderFunc : SelectField, renderField : SelectField, renderOperator : SelectField, // buttons renderButton : (props) => { // return jsx return props.type.includes('del') ? ( ) : ( ); }, renderButtonGroup : (props) => , // conjunctions renderConjs : (props) => { // null if disabled if (props.disabled) return null; // get conjunction const conjunction = props.selectedConjunction || 'AND'; // return group return ( { props.showNot && ( ) } { Object.keys(props.conjunctionOptions || {}).map((key) => { // get opt const opt = props.conjunctionOptions[key]; // return jsx return ( ); }) } ); }, }; // widgets const widgets = { ...BasicConfig.widgets, text : { ...BasicConfig.widgets.text, factory : (props) => { // check operator const { value, label, setValue } = props; // return control return ( setValue(e.target.value) } /> ); }, }, number : { ...BasicConfig.widgets.number, factory : (props) => { // check operator const { value, label, setValue } = props; // return control return ( setValue(parseFloat(e.target.value)) } /> ); }, }, select : { ...BasicConfig.widgets.select, factory : (props) => { // check operator const { value, setValue, listValues } = props; // return value return ( setValue(e.target.value) } > { (listValues || []).map((opt) => { // return jsx return ( { opt.title } ); }) } ); }, }, multiselect : { ...BasicConfig.widgets.multiselect, factory : (props) => { // check operator const { value, setValue, listValues } = props; // return value return ( v) } onChange={ (e) => setValue(e.target.value) } SelectProps={ { multiple : true, } } > { (listValues || []).map((opt) => { // return jsx return ( { opt.title } ); }) } ); }, }, boolean : { ...BasicConfig.widgets.boolean, factory : (props) => { // check operator const { value, setValue, labelYes, labelNo } = props; // value const values = [{ label : labelYes, value : 'true', }, { label : labelNo, value : 'false', }]; // return value return ( setValue(e.target.value === 'true') } > { (values || []).map((opt) => { // return jsx return ( { opt.label } ); }) } ); }, }, slider : { ...BasicConfig.widgets.slider, factory : (props) => { // check operator const { setValue, value = 0, label, min, max } = props; // return control return (
setValue(parseFloat(e.target.value)) } InputProps={ { min, max, } } /> setValue(parseFloat(e.target.value)) } />
); } }, /* date: { ...BasicConfig.widgets.date, factory: (props) => , }, time: { ...BasicConfig.widgets.time, factory: (props) => , }, datetime: { ...BasicConfig.widgets.datetime, factory: (props) => , }, */ }; // types const types = { ...BasicConfig.types, }; // export default export default { ...BasicConfig, types, widgets, settings, };