mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-28 03:08:30 +00:00
Change textarea style based on its state prop
This commit is contained in:
parent
34a02ee537
commit
7d4ca8eeed
@ -15,10 +15,11 @@ const disabledColor = colors.TEXT_PRIMARY;
|
|||||||
|
|
||||||
const TextArea = styled.textarea`
|
const TextArea = styled.textarea`
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
min-height: 85px;
|
||||||
|
margin-bottom: 10px;
|
||||||
padding: 6px 12px;
|
padding: 6px 12px;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
min-height: 25px;
|
border: 1px solid ${props => (props.borderColor ? props.borderColor : colors.DIVIDER)};
|
||||||
border: ${props => (props.isError ? `1px solid ${colors.ERROR_PRIMARY}` : `1px solid ${colors.DIVIDER}`)};
|
|
||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
resize: none;
|
resize: none;
|
||||||
outline: none;
|
outline: none;
|
||||||
@ -87,6 +88,23 @@ const TopLabel = styled.span`
|
|||||||
color: ${colors.TEXT_SECONDARY};
|
color: ${colors.TEXT_SECONDARY};
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
const BottomText = styled.span`
|
||||||
|
font-size: ${FONT_SIZE.SMALLER};
|
||||||
|
color: ${props => (props.color ? props.color : colors.TEXT_SECONDARY)};
|
||||||
|
`;
|
||||||
|
|
||||||
|
const getColor = (inputState) => {
|
||||||
|
let color = '';
|
||||||
|
if (inputState === 'success') {
|
||||||
|
color = colors.SUCCESS_PRIMARY;
|
||||||
|
} else if (inputState === 'warning') {
|
||||||
|
color = colors.WARNING_PRIMARY;
|
||||||
|
} else if (inputState === 'error') {
|
||||||
|
color = colors.ERROR_PRIMARY;
|
||||||
|
}
|
||||||
|
return color;
|
||||||
|
};
|
||||||
|
|
||||||
const Textarea = ({
|
const Textarea = ({
|
||||||
className,
|
className,
|
||||||
placeholder = '',
|
placeholder = '',
|
||||||
@ -96,15 +114,17 @@ const Textarea = ({
|
|||||||
onBlur,
|
onBlur,
|
||||||
isDisabled,
|
isDisabled,
|
||||||
onChange,
|
onChange,
|
||||||
isError,
|
|
||||||
topLabel,
|
topLabel,
|
||||||
|
state = '',
|
||||||
|
bottomText = '',
|
||||||
}) => (
|
}) => (
|
||||||
<Wrapper>
|
<Wrapper
|
||||||
|
className={className}
|
||||||
|
>
|
||||||
{topLabel && (
|
{topLabel && (
|
||||||
<TopLabel>{topLabel}</TopLabel>
|
<TopLabel>{topLabel}</TopLabel>
|
||||||
)}
|
)}
|
||||||
<TextArea
|
<TextArea
|
||||||
className={className}
|
|
||||||
disabled={isDisabled}
|
disabled={isDisabled}
|
||||||
style={customStyle}
|
style={customStyle}
|
||||||
onFocus={onFocus}
|
onFocus={onFocus}
|
||||||
@ -112,14 +132,20 @@ const Textarea = ({
|
|||||||
value={value}
|
value={value}
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
isError={isError}
|
borderColor={getColor(state)}
|
||||||
/>
|
/>
|
||||||
|
{bottomText && (
|
||||||
|
<BottomText
|
||||||
|
color={getColor(state)}
|
||||||
|
>
|
||||||
|
{bottomText}
|
||||||
|
</BottomText>
|
||||||
|
)}
|
||||||
</Wrapper>
|
</Wrapper>
|
||||||
);
|
);
|
||||||
|
|
||||||
Textarea.propTypes = {
|
Textarea.propTypes = {
|
||||||
className: PropTypes.string,
|
className: PropTypes.string,
|
||||||
isError: PropTypes.bool,
|
|
||||||
onFocus: PropTypes.func,
|
onFocus: PropTypes.func,
|
||||||
onBlur: PropTypes.func,
|
onBlur: PropTypes.func,
|
||||||
onChange: PropTypes.func,
|
onChange: PropTypes.func,
|
||||||
@ -128,6 +154,8 @@ Textarea.propTypes = {
|
|||||||
value: PropTypes.string,
|
value: PropTypes.string,
|
||||||
isDisabled: PropTypes.bool,
|
isDisabled: PropTypes.bool,
|
||||||
topLabel: PropTypes.node,
|
topLabel: PropTypes.node,
|
||||||
|
state: PropTypes.string,
|
||||||
|
bottomText: PropTypes.string,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Textarea;
|
export default Textarea;
|
||||||
|
@ -65,7 +65,7 @@ const GasInput = styled(Input)`
|
|||||||
|
|
||||||
const StyledTextarea = styled(Textarea)`
|
const StyledTextarea = styled(Textarea)`
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
height: 80px;
|
min-height: 80px;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const AdvancedSettingsSendButtonWrapper = styled.div`
|
const AdvancedSettingsSendButtonWrapper = styled.div`
|
||||||
@ -96,6 +96,17 @@ const getGasPriceInputState = (gasPriceErrors: string, gasPriceWarnings: string)
|
|||||||
return state;
|
return state;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getDataTextareaState = (dataError: string, dataWarning: string): string => {
|
||||||
|
let state = '';
|
||||||
|
if (dataWarning) {
|
||||||
|
state = 'warning';
|
||||||
|
}
|
||||||
|
if (dataError) {
|
||||||
|
state = 'error';
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
};
|
||||||
|
|
||||||
// stateless component
|
// stateless component
|
||||||
const AdvancedForm = (props: Props) => {
|
const AdvancedForm = (props: Props) => {
|
||||||
const {
|
const {
|
||||||
@ -221,6 +232,7 @@ const AdvancedForm = (props: Props) => {
|
|||||||
</Tooltip>
|
</Tooltip>
|
||||||
</InputLabelWrapper>
|
</InputLabelWrapper>
|
||||||
)}
|
)}
|
||||||
|
state={getDataTextareaState(errors.data, warnings.data)}
|
||||||
bottomText={errors.data || warnings.data || infos.data}
|
bottomText={errors.data || warnings.data || infos.data}
|
||||||
isDisabled={networkSymbol !== currency}
|
isDisabled={networkSymbol !== currency}
|
||||||
value={networkSymbol !== currency ? '' : data}
|
value={networkSymbol !== currency ? '' : data}
|
||||||
|
Loading…
Reference in New Issue
Block a user