From 10576fbdc388696df358b88a1881b7d441cb5635 Mon Sep 17 00:00:00 2001 From: Malar Kannan Date: Tue, 18 Jul 2017 12:02:59 +0530 Subject: [PATCH] refactored single input components from lexedit --- src/LexEdit.tsx | 46 +++++++---------------------------- src/LexEditor.tsx | 2 ++ src/LexSingleInput.tsx | 55 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 65 insertions(+), 38 deletions(-) diff --git a/src/LexEdit.tsx b/src/LexEdit.tsx index 357917c..7911286 100644 --- a/src/LexEdit.tsx +++ b/src/LexEdit.tsx @@ -1,9 +1,11 @@ import * as React from 'react'; import * as _ from 'lodash'; -import LexSingleInput from './LexSingleInput'; import { - Image, - Input, + textInput, + selectInput, + imagePreview +} from './LexSingleInput'; +import { Card, Button } from 'semantic-ui-react'; @@ -22,48 +24,18 @@ export class LexEdit extends React.Component { let lexFields = _.keys(this.props.fieldMetaMap).map(field => { let lens = this.props.fieldMetaMap[field].lens; let defaultText = _.get(li, lens, ''); + let options = this.props.fieldMetaMap[field].options; let sh = (e: any) => { let eventData = {}; eventData[field] = e.target.value; this.handleOnChange(eventData); }; if (this.props.fieldMetaMap[field].type === 'text') { - return ( - - - - ); + return textInput({field,sh,defaultText,options,langSelOpts}); } else if (this.props.fieldMetaMap[field].type === 'select') { - let staticOpts = this.props.fieldMetaMap[field].options; - let fieldOpts = _.get(langSelOpts, field, []); - let selOpts = staticOpts ? staticOpts : fieldOpts; - return ( - - - - ); + return selectInput({field,sh,defaultText,options,langSelOpts}); } else if (this.props.fieldMetaMap[field].type === 'preview' && defaultText !== '') { - let imageSrc = this.imageRoot + defaultText; - return ( - - - - ); + return imagePreview({field,sh,defaultText,options,langSelOpts}); } else { return null; } diff --git a/src/LexEditor.tsx b/src/LexEditor.tsx index fc8eac8..b6d9085 100644 --- a/src/LexEditor.tsx +++ b/src/LexEditor.tsx @@ -86,6 +86,7 @@ function LexMatches(params: any) { key={uniqueKey} lexItem={mObj} selectionMeta={props.selectionMeta} + new_entry={false} /> ); }); @@ -97,6 +98,7 @@ function LexMatches(params: any) { key={props.searchText} lexItem={addProps} selectionMeta={props.selectionMeta} + new_entry={true} /> ); editEntries.push(addEntry); diff --git a/src/LexSingleInput.tsx b/src/LexSingleInput.tsx index 7820b3d..8644849 100644 --- a/src/LexSingleInput.tsx +++ b/src/LexSingleInput.tsx @@ -1,8 +1,13 @@ import * as React from 'react'; +import * as _ from 'lodash'; import { Label, Form } from 'semantic-ui-react'; const { Flex, Box } = require('reflexbox'); +import { + Input, + Image +} from 'semantic-ui-react'; -export default class LexSingleInput extends React.Component { +class LexSingleInput extends React.Component { public render() { return (
@@ -24,3 +29,51 @@ export default class LexSingleInput extends React.Component { ); } } + +const imageRoot = '/png/'; + +export function textInput(params: any) { + let {field,sh,defaultText} = params; + return ( + + + + ); +} + +export function selectInput(params: any) { + let {field,sh,defaultText,options,langSelOpts} = params; + let staticOpts = options; + let fieldOpts = _.get(langSelOpts, field, []); + let selOpts = staticOpts ? staticOpts : fieldOpts; + return ( + + + + ); +} + +export function imagePreview(params: any) { + let {field,defaultText} = params; + let imageSrc = imageRoot + defaultText; + return ( + + + + ); +}