import * as React from 'react'; import * as _ from 'lodash'; import { Label, Form } from 'semantic-ui-react'; const { Flex, Box } = require('reflexbox'); import { Input, Dropdown, Image, Modal, Button, } from 'semantic-ui-react'; class LexInputContainer extends React.Component { public render() { return (
{this.props.label} {this.props.children}
); } } function changedLabel(changed: boolean, text: string) { let labelClass = changed ? 'olive' : ''; return ( ); } function textInput(params: any) { let { field, sh, value, changed } = params; return ( { sh(d.value); }} value={value} placeholder={field} type="text" dir="auto" style={{ width: '10em' }} /> ); } function selectInput(params: any) { let { field, sh, value, options, langSelOpts, changed } = params; let staticOpts = options; let fieldOpts = _.get(langSelOpts, field, []); let selOpts = staticOpts ? staticOpts : fieldOpts; let dropOptions = selOpts.map((k: any, i: any, c: any) => { return { key: i, value: k, text: k }; }); return ( { sh(d.value); }} value={value} compact={true} selection={true} search={true} style={{ width: '10em' }} /> ); } function imagePreview(params: any) { let { field, value, changed } = params; let imageSrc = '/png/' + value; return value !== '' ? ( ) : textInput(params); } function listInput(params: any) { let { field, sh, langSelOpts, value, changed } = params; let fieldOpts = _.get(langSelOpts, field, []); let renderLabel = (label: any) => ({ content: `${label.value}`, }); let dropOptions = fieldOpts.map((k: any, i: any, c: any) => { return { key: i, value: k, text: k, }; }); return ( { sh(d.value); }} value={value} compact={true} selection={true} search={true} multiple={true} fluid={true} style={{ width: '10em' }} renderLabel={renderLabel} /> ); } function propListInput(params: any) { let { field, changed } = params; return ( ); } class PropListInput extends React.Component { constructor(props: any) { super(props); this.state = { modalOpen: false, exKey: '', exVal: '' }; } dropOptsForVal(value: any) { let { field, langSelOpts } = this.props.params; let fieldOpts = _.get(langSelOpts, field, []); function valueForKey(key: string) { let match = _.find(value, (v: any) => _.isEqual(v.key, key)); if (match) { return match; } else { return { key, value: '' }; } } return fieldOpts.map((k: any, i: any) => { return { key: i, value: valueForKey(k), text: k, }; }); } public render() { let { sh, value } = this.props.params; let dropOptions = this.dropOptsForVal(value); let renderLabel = (label: any) => ({ content: `${label.value.key}-${label.value.value}`, }); let onCloseModal = (e: any) => { let except = { key: this.state.exKey, value: this.state.exVal }; let ns = _.concat(value, except); this.setState({ modalOpen: false, exKey: '', exVal: '' }); sh(ns); }; let dropDownComp = ( { let newValue = d.value as any; let addedValue = _.difference(newValue, value) as any; let didAdd = _.size(addedValue) > 0; let exKey = didAdd ? addedValue[0].key : ''; this.setState({ exKey, modalOpen: didAdd }); if (!didAdd) { sh(newValue); } }} value={value} compact={true} selection={true} search={true} multiple={true} fluid={true} style={{ width: '10em' }} renderLabel={renderLabel} /> ); return ( Enter the exception for {this.state.exKey} { this.setState({ exVal: d.value }); }} /> ); } } export function componentForType(type: string, params: any) { switch (type) { case 'text': { return textInput(params); } case 'select': { return selectInput(params); } case 'preview': { return imagePreview(params); } case 'list': { return listInput(params); } case 'proplist': { return propListInput(params); } default: { console.log('type discarded :', type); return null; } } }