diff options
author | Fred Carlsen <fred@sjelfull.no> | 2018-12-18 02:25:51 +0800 |
---|---|---|
committer | Fred Carlsen <fred@sjelfull.no> | 2018-12-18 02:26:04 +0800 |
commit | 31bbb0696ccfe8f8b671ac2b2c3f18ec956cd46d (patch) | |
tree | 5abb8caa7e5af50f9f4e7a3630905f3aef4835d8 /packages/website/ts/@next/components/modals/input.tsx | |
parent | 6ab8415198cee93bf1aea06f5190ab4d19167f14 (diff) | |
download | dexon-sol-tools-31bbb0696ccfe8f8b671ac2b2c3f18ec956cd46d.tar.gz dexon-sol-tools-31bbb0696ccfe8f8b671ac2b2c3f18ec956cd46d.tar.zst dexon-sol-tools-31bbb0696ccfe8f8b671ac2b2c3f18ec956cd46d.zip |
Show errors from serverside
Diffstat (limited to 'packages/website/ts/@next/components/modals/input.tsx')
-rw-r--r-- | packages/website/ts/@next/components/modals/input.tsx | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/packages/website/ts/@next/components/modals/input.tsx b/packages/website/ts/@next/components/modals/input.tsx index 61663d906..d4d9206a2 100644 --- a/packages/website/ts/@next/components/modals/input.tsx +++ b/packages/website/ts/@next/components/modals/input.tsx @@ -11,27 +11,37 @@ interface InputProps { width?: InputWidth; label: string; type?: string; + errors?: ErrorProps; + isErrors?: boolean; } interface LabelProps { string: boolean; } +interface ErrorProps { + [key: string]: string; +} + export const Input = React.forwardRef((props: InputProps, ref?: React.Ref<HTMLInputElement>) => { - const { name, label, type } = props; + const { name, label, type, errors } = props; const id = `input-${name}`; const componentType = type === 'textarea' ? 'textarea' : 'input'; + const isErrors = errors.hasOwnProperty(name) && errors[name] !== null; + const errorMessage = isErrors ? errors[name] : null; return ( <InputWrapper {...props}> <Label htmlFor={id}>{label}</Label> - <StyledInput as={componentType} ref={ref} id={id} placeholder={label} {...props} /> + <StyledInput as={componentType} ref={ref} id={id} placeholder={label} isErrors={isErrors} {...props} /> + {isErrors && <Error>{errorMessage}</Error>} </InputWrapper> ); }); Input.defaultProps = { width: InputWidth.Full, + errors: {}, }; const StyledInput = styled.input` @@ -45,6 +55,9 @@ const StyledInput = styled.input` width: 100%; min-height: ${props => props.type === 'textarea' && `120px`}; + background-color: ${(props: InputProps) => props.isErrors && `#FDEDED`}; + border-color: ${(props: InputProps) => props.isErrors && `#FD0000`}; + &::placeholder { color: #C3C3C3; } @@ -68,3 +81,15 @@ const Label = styled.label` margin-bottom: 10px; display: inline-block; `; + +const Error = styled.span` + color: #FD0000; + font-size: .833333333rem; + line-height: 1em; + display: inline-block; + position: absolute; + bottom: 0; + left: 0; + width: 100%; + transform: translateY(24px); +`; |