Validate input fields
Summary: Adds basic non-empty validation to title and description. Reviewed By: mweststrate Differential Revision: D18762778 fbshipit-source-id: 4bdbb550f4e740d399fbeaa9fb8170b801fc500e
This commit is contained in:
committed by
Facebook Github Bot
parent
bb6a7c50cd
commit
d791814dfa
@@ -10,14 +10,19 @@
|
|||||||
import styled from 'react-emotion';
|
import styled from 'react-emotion';
|
||||||
import {colors} from './colors';
|
import {colors} from './colors';
|
||||||
|
|
||||||
export const inputStyle = (compact: boolean, readOnly: boolean) => ({
|
export const inputStyle = (props: {
|
||||||
border: `1px solid ${colors.light15}`,
|
compact: boolean;
|
||||||
|
valid: boolean;
|
||||||
|
readOnly: boolean;
|
||||||
|
}) => ({
|
||||||
|
border: `1px solid ${props.valid ? colors.light15 : colors.red}`,
|
||||||
borderRadius: 4,
|
borderRadius: 4,
|
||||||
font: 'inherit',
|
font: 'inherit',
|
||||||
fontSize: '1em',
|
fontSize: '1em',
|
||||||
height: compact ? '17px' : '28px',
|
|
||||||
lineHeight: compact ? '17px' : '28px',
|
height: props.compact ? '17px' : '28px',
|
||||||
backgroundColor: readOnly ? colors.light02 : undefined,
|
lineHeight: props.compact ? '17px' : '28px',
|
||||||
|
backgroundColor: props.readOnly ? colors.light02 : undefined,
|
||||||
'&:disabled': {
|
'&:disabled': {
|
||||||
backgroundColor: '#ddd',
|
backgroundColor: '#ddd',
|
||||||
borderColor: '#ccc',
|
borderColor: '#ccc',
|
||||||
@@ -26,8 +31,20 @@ export const inputStyle = (compact: boolean, readOnly: boolean) => ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const Input = styled('input')(
|
const Input = styled('input')(
|
||||||
({compact, readOnly}: {compact?: boolean; readOnly?: boolean}) => ({
|
({
|
||||||
...inputStyle(compact || false, readOnly || false),
|
compact,
|
||||||
|
valid,
|
||||||
|
readOnly,
|
||||||
|
}: {
|
||||||
|
compact?: boolean;
|
||||||
|
valid?: boolean;
|
||||||
|
readOnly?: boolean;
|
||||||
|
}) => ({
|
||||||
|
...inputStyle({
|
||||||
|
compact: compact || false,
|
||||||
|
valid: valid !== false,
|
||||||
|
readOnly: readOnly === true,
|
||||||
|
}),
|
||||||
padding: compact ? '0 5px' : '0 10px',
|
padding: compact ? '0 5px' : '0 10px',
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
import styled from 'react-emotion';
|
import styled from 'react-emotion';
|
||||||
import {colors} from './colors';
|
import {colors} from './colors';
|
||||||
|
|
||||||
export const multilineStyle = {
|
export const multilineStyle = (props: {valid: boolean}) => ({
|
||||||
border: `1px solid ${colors.light15}`,
|
border: `1px solid ${props.valid === false ? colors.red : colors.light15}`,
|
||||||
borderRadius: 4,
|
borderRadius: 4,
|
||||||
font: 'inherit',
|
font: 'inherit',
|
||||||
fontSize: '1em',
|
fontSize: '1em',
|
||||||
@@ -24,12 +24,12 @@ export const multilineStyle = {
|
|||||||
borderColor: '#ccc',
|
borderColor: '#ccc',
|
||||||
cursor: 'not-allowed',
|
cursor: 'not-allowed',
|
||||||
},
|
},
|
||||||
};
|
|
||||||
|
|
||||||
const MultiLineInput = styled('textarea')({
|
|
||||||
...multilineStyle,
|
|
||||||
padding: '0 10px',
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const MultiLineInput = styled('textarea')((props: {valid?: boolean}) => ({
|
||||||
|
...multilineStyle({valid: props.valid === undefined || props.valid}),
|
||||||
|
padding: '0 10px',
|
||||||
|
}));
|
||||||
MultiLineInput.displayName = 'MultiLineInput';
|
MultiLineInput.displayName = 'MultiLineInput';
|
||||||
|
|
||||||
export default MultiLineInput;
|
export default MultiLineInput;
|
||||||
|
|||||||
@@ -11,8 +11,20 @@ import styled from 'react-emotion';
|
|||||||
import {inputStyle} from './Input';
|
import {inputStyle} from './Input';
|
||||||
|
|
||||||
const Textarea = styled('textarea')(
|
const Textarea = styled('textarea')(
|
||||||
({compact, readOnly}: {compact?: boolean; readOnly?: boolean}) => ({
|
({
|
||||||
...inputStyle(compact || false, readOnly || false),
|
compact,
|
||||||
|
readOnly,
|
||||||
|
valid,
|
||||||
|
}: {
|
||||||
|
compact?: boolean;
|
||||||
|
readOnly?: boolean;
|
||||||
|
valid?: boolean;
|
||||||
|
}) => ({
|
||||||
|
...inputStyle({
|
||||||
|
compact: compact || false,
|
||||||
|
readOnly: readOnly || false,
|
||||||
|
valid: valid !== false,
|
||||||
|
}),
|
||||||
lineHeight: 'normal',
|
lineHeight: 'normal',
|
||||||
padding: compact ? '5px' : '8px',
|
padding: compact ? '5px' : '8px',
|
||||||
resize: 'none',
|
resize: 'none',
|
||||||
|
|||||||
Reference in New Issue
Block a user