import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { withTheme } from 'styled-components';
import { Row, Col } from 'react-styled-flexboxgrid';
import { Field } from 'redux-form';
import styled from 'styled-components';
import remcalc from 'remcalc';
import titleCase from 'title-case';
import { Padding } from 'styled-components-spacing';
import Flex, { FlexItem } from 'styled-flex-component';
import Editor from 'joyent-ui-toolkit/dist/es/editor';
import {
Message,
MessageDescription,
H4,
MessageTitle,
Card,
CardHeader,
CardHeaderMeta,
CardOutlet,
FormGroup,
FormLabel,
Input,
FormMeta,
Button,
Textarea,
Divider,
DeleteIcon
} from 'joyent-ui-toolkit';
const CollapsedKeyValue = styled.span`
word-break: break-all;
line-height: 1.5;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
display: block;
`;
class ValueTextareaField extends PureComponent {
render() {
const { input = {}, submitting } = this.props;
return input.value === 'user-script' ? (
) : (
);
}
}
const TextareaKeyValue = ({ type, submitting }) => [
{titleCase(type)} key
,
{titleCase(type)} value
];
const InputKeyValue = ({ type, submitting }) => (
{titleCase(type)} key
{titleCase(type)} value
);
export const KeyValue = ({
input = 'input',
type = 'metadata',
method = 'add',
error = null,
expanded = true,
submitting = false,
pristine = true,
removing = false,
handleSubmit,
onToggleExpanded = () => null,
onCancel = () => null,
onRemove = () => null,
theme = {}
}) => {
const handleHeaderClick = method === 'edit' && onToggleExpanded;
return (
{method === 'add' ? (
{`${titleCase(method)} ${type}`}
) : (
!expanded ? `${input.value}: ` : {`${input.value}: `}
}
/>
{input.value}}
/>
)}
{expanded ? (
{error && !submitting ? (
Ooops!
{error}
) : null}
{input === 'input' ? (
) : (
)}
) : null}
);
};
KeyValue.propTypes = {
input: PropTypes.oneOf(['input', 'textarea']).isRequired,
type: PropTypes.string.isRequired,
method: PropTypes.oneOf(['add', 'edit']).isRequired,
removing: PropTypes.bool.isRequired,
expanded: PropTypes.bool.isRequired,
onToggleExpanded: PropTypes.func,
onCancel: PropTypes.func,
onRemove: PropTypes.func
};
export default withTheme(({ handleSubmit, ...rest }) => (
));