2017-06-21 12:37:48 +00:00
|
|
|
import * as React from 'react';
|
2017-07-18 06:32:59 +00:00
|
|
|
import * as _ from 'lodash';
|
2017-06-22 11:34:06 +00:00
|
|
|
import { Label, Form } from 'semantic-ui-react';
|
|
|
|
|
const { Flex, Box } = require('reflexbox');
|
2017-07-18 06:32:59 +00:00
|
|
|
import {
|
|
|
|
|
Input,
|
|
|
|
|
Image
|
|
|
|
|
} from 'semantic-ui-react';
|
2017-07-19 13:40:56 +00:00
|
|
|
// import {
|
|
|
|
|
// SortableContainer,
|
|
|
|
|
// SortableElement
|
|
|
|
|
// } from 'react-sortable-hoc';
|
2017-06-21 12:37:48 +00:00
|
|
|
|
2017-07-18 06:32:59 +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' }}>
|
2017-07-18 08:04:02 +00:00
|
|
|
{this.props.label}
|
2017-06-22 11:34:06 +00:00
|
|
|
</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>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-18 06:32:59 +00:00
|
|
|
|
2017-07-18 08:04:02 +00:00
|
|
|
function changedLabel(changed: boolean, text: string) {
|
|
|
|
|
let labelClass = changed ? 'olive' : '';
|
|
|
|
|
return (
|
|
|
|
|
<Label
|
|
|
|
|
pointing="right"
|
|
|
|
|
className={labelClass}
|
|
|
|
|
>
|
|
|
|
|
{text}
|
|
|
|
|
</Label>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-18 06:32:59 +00:00
|
|
|
const imageRoot = '/png/';
|
|
|
|
|
|
|
|
|
|
export function textInput(params: any) {
|
2017-07-18 08:04:02 +00:00
|
|
|
let { field, sh, defaultText, changed } = params;
|
2017-07-18 06:32:59 +00:00
|
|
|
return (
|
2017-07-18 08:04:02 +00:00
|
|
|
<LexSingleInput
|
|
|
|
|
label={changedLabel(changed, field)}
|
|
|
|
|
key={field}
|
|
|
|
|
>
|
2017-07-18 06:32:59 +00:00
|
|
|
<Input
|
|
|
|
|
onChange={sh}
|
2017-07-18 08:04:02 +00:00
|
|
|
value={defaultText}
|
2017-07-18 06:32:59 +00:00
|
|
|
placeholder={field}
|
|
|
|
|
type="text"
|
|
|
|
|
dir="auto"
|
|
|
|
|
style={{ width: '10em' }}
|
|
|
|
|
/>
|
|
|
|
|
</LexSingleInput>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function selectInput(params: any) {
|
2017-07-18 08:04:02 +00:00
|
|
|
let { field, sh, defaultText, options, langSelOpts, changed } = params;
|
2017-07-18 06:32:59 +00:00
|
|
|
let staticOpts = options;
|
|
|
|
|
let fieldOpts = _.get<any>(langSelOpts, field, []);
|
|
|
|
|
let selOpts = staticOpts ? staticOpts : fieldOpts;
|
|
|
|
|
return (
|
2017-07-18 08:04:02 +00:00
|
|
|
<LexSingleInput key={field} label={changedLabel(changed, field)}>
|
2017-07-18 06:32:59 +00:00
|
|
|
<select
|
|
|
|
|
onChange={sh}
|
|
|
|
|
style={{ width: '10em' }}
|
2017-07-18 08:04:02 +00:00
|
|
|
value={defaultText}
|
2017-07-18 06:32:59 +00:00
|
|
|
>
|
|
|
|
|
{selOpts.map((k: any, i: any, c: any) => {
|
|
|
|
|
return <option key={i} value={k}> {k}</option>;
|
|
|
|
|
})}
|
|
|
|
|
</select>
|
|
|
|
|
</LexSingleInput>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function imagePreview(params: any) {
|
2017-07-18 08:04:02 +00:00
|
|
|
let { field, defaultText, changed } = params;
|
2017-07-18 06:32:59 +00:00
|
|
|
let imageSrc = imageRoot + defaultText;
|
2017-07-19 11:23:24 +00:00
|
|
|
return defaultText !== '' ? (
|
2017-07-18 08:04:02 +00:00
|
|
|
<LexSingleInput key={field} label={changedLabel(changed, field)}>
|
2017-07-18 06:32:59 +00:00
|
|
|
<Image src={imageSrc} size="tiny" bordered={true} />
|
|
|
|
|
</LexSingleInput>
|
2017-07-19 12:32:46 +00:00
|
|
|
) : textInput(params);
|
2017-07-18 06:32:59 +00:00
|
|
|
}
|
2017-07-19 13:40:56 +00:00
|
|
|
|
|
|
|
|
// const SortableItem = SortableElement(({ value }) =>
|
|
|
|
|
// <li>{value}</li>
|
|
|
|
|
// );
|
|
|
|
|
//
|
|
|
|
|
// const SortableList = SortableContainer(({ items }) => {
|
|
|
|
|
// return (
|
|
|
|
|
// <ul>
|
|
|
|
|
// {items.map((value: any, index: any) => (
|
|
|
|
|
// <SortableItem key={`item-${index}`} index={index} value={value} />
|
|
|
|
|
// ))}
|
|
|
|
|
// </ul>
|
|
|
|
|
// );
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
export function listInput(params: any) {
|
|
|
|
|
let { field, defaultText, changed } = params;
|
|
|
|
|
let imageSrc = imageRoot + defaultText;
|
|
|
|
|
return (
|
|
|
|
|
<LexSingleInput key={field} label={changedLabel(changed, field)}>
|
|
|
|
|
<Image src={imageSrc} size="tiny" bordered={true} />
|
|
|
|
|
</LexSingleInput>
|
|
|
|
|
);
|
|
|
|
|
}
|