diff --git a/app/components/UI/FormFieldMessage.js b/app/components/UI/FormFieldMessage.js new file mode 100644 index 00000000..abdc21d0 --- /dev/null +++ b/app/components/UI/FormFieldMessage.js @@ -0,0 +1,43 @@ +import React from 'react' +import PropTypes from 'prop-types' +import { Box, Flex } from 'rebass' +import SystemSuccess from 'components/Icon/SystemSuccess' +import SystemWarning from 'components/Icon/SystemWarning' +import SystemError from 'components/Icon/SystemError' + +import styled from 'styled-components' +import { variant } from 'styled-system' + +const messageStyle = variant({ key: 'messages' }) +const Message = styled(Flex)(messageStyle) + +/** + * @render react + * @name FormFieldMessage + * @example + * + */ +class FormFieldMessage extends React.Component { + static displayName = 'FormFieldMessage' + + static propTypes = { + variant: PropTypes.string, + children: PropTypes.node + } + + render() { + const { children, variant } = this.props + return ( + + + {variant === 'success' && } + {variant === 'warning' && } + {variant === 'error' && } + + {children} + + ) + } +} + +export default FormFieldMessage diff --git a/app/components/UI/Input.js b/app/components/UI/Input.js new file mode 100644 index 00000000..003cbc61 --- /dev/null +++ b/app/components/UI/Input.js @@ -0,0 +1,90 @@ +import React from 'react' +import { asField } from 'informed' +import { Input as Base } from 'styled-system-html' +import { withTheme } from 'styled-components' +import { Flex } from 'rebass' +import FormFieldMessage from 'components/UI/FormFieldMessage' + +/** + * @render react + * @name Input + * @example + * + */ +class Input extends React.PureComponent { + static displayName = 'Input' + + render() { + const { + onChange, + onBlur, + initialValue, + field, + forwardedRef, + theme, + fieldApi, + fieldState, + justifyContent, + ...rest + } = this.props + const { setValue, setTouched } = fieldApi + const { value } = fieldState + + let borderColor + + if (fieldState.touched) { + if (fieldState.error) { + borderColor = theme.colors.superRed + } else if (value && !fieldState.error) { + borderColor = theme.colors.superGreen + } + } + + return ( + + { + setValue(e.target.value) + if (onChange) { + onChange(e) + } + }} + onBlur={e => { + setTouched() + if (onBlur) { + onBlur(e) + } + }} + error={fieldState.error} + /> + {fieldState.error && ( + + {fieldState.error} + + )} + + ) + } +} + +export default asField(withTheme(Input)) diff --git a/app/components/UI/Label.js b/app/components/UI/Label.js new file mode 100644 index 00000000..33f8c999 --- /dev/null +++ b/app/components/UI/Label.js @@ -0,0 +1,20 @@ +import React from 'react' +import { Label as Base } from 'styled-system-html' + +/** + * @render react + * @name Label + * @example + *