fs-walle-react-ts/src/LexSingleInput.tsx

80 lines
2.0 KiB
TypeScript
Raw Normal View History

2017-06-21 12:37:48 +00:00
import * as React from 'react';
import * as _ from 'lodash';
2017-06-22 11:34:06 +00:00
import { Label, Form } from 'semantic-ui-react';
const { Flex, Box } = require('reflexbox');
import {
Input,
Image
} from 'semantic-ui-react';
2017-06-21 12:37:48 +00:00
class LexSingleInput extends React.Component<any, any> {
2017-06-21 12:37:48 +00:00
public render() {
return (
2017-06-22 11:34:06 +00:00
<div>
<Form>
<Form.Group as={Flex} inline={true} style={{ margin: '0 0 5px 5px' }}>
<Form.Field as={Box} w={2 / 5} style={{ textAlign: 'right' }}>
<Label
pointing="right"
>
{this.props.labelText}
</Label>
</Form.Field>
<Form.Field as={Box} w={3 / 5} >
{this.props.children}
</Form.Field>
</Form.Group>
</Form>
2017-06-21 12:37:48 +00:00
</div>
);
}
}
const imageRoot = '/png/';
export function textInput(params: any) {
let {field,sh,defaultText} = params;
return (
<LexSingleInput key={field} labelText={_.capitalize(field)}>
<Input
onChange={sh}
defaultValue={defaultText}
placeholder={field}
type="text"
dir="auto"
style={{ width: '10em' }}
/>
</LexSingleInput>
);
}
export function selectInput(params: any) {
let {field,sh,defaultText,options,langSelOpts} = params;
let staticOpts = options;
let fieldOpts = _.get<any>(langSelOpts, field, []);
let selOpts = staticOpts ? staticOpts : fieldOpts;
return (
<LexSingleInput key={field} labelText={_.capitalize(field)}>
<select
onChange={sh}
style={{ width: '10em' }}
defaultValue={defaultText}
>
{selOpts.map((k: any, i: any, c: any) => {
return <option key={i} value={k}> {k}</option>;
})}
</select>
</LexSingleInput>
);
}
export function imagePreview(params: any) {
let {field,defaultText} = params;
let imageSrc = imageRoot + defaultText;
return (
<LexSingleInput key={field} labelText={_.capitalize(field)}>
<Image src={imageSrc} size="tiny" bordered={true} />
</LexSingleInput>
);
}