Fix input styles
This commit is contained in:
parent
23f35fc35f
commit
625031974d
2 changed files with 16 additions and 11 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
.Input {
|
.input {
|
||||||
-webkit-font-smoothing: antialiased;
|
-webkit-font-smoothing: antialiased;
|
||||||
background-color: var(--input-bg);
|
background-color: var(--input-bg);
|
||||||
border: 2px solid transparent;
|
border: 2px solid transparent;
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
outline: none;
|
outline: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.Bound {
|
&.bound {
|
||||||
background-color: var(--input-bound-bg);
|
background-color: var(--input-bound-bg);
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
|
|
@ -39,7 +39,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.InputError {
|
.inputError {
|
||||||
color: $error;
|
color: $error;
|
||||||
font-size: $font-tiny;
|
font-size: $font-tiny;
|
||||||
margin: $unit 0;
|
margin: $unit 0;
|
||||||
|
|
@ -48,7 +48,7 @@
|
||||||
width: 0;
|
width: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.Input::placeholder {
|
.input::placeholder {
|
||||||
/* Chrome, Firefox, Opera, Safari 10.1+ */
|
/* Chrome, Firefox, Opera, Safari 10.1+ */
|
||||||
color: var(--text-secondary);
|
color: var(--text-secondary);
|
||||||
opacity: 1; /* Firefox */
|
opacity: 1; /* Firefox */
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ interface Props
|
||||||
React.InputHTMLAttributes<HTMLInputElement>,
|
React.InputHTMLAttributes<HTMLInputElement>,
|
||||||
HTMLInputElement
|
HTMLInputElement
|
||||||
> {
|
> {
|
||||||
|
bound?: boolean
|
||||||
visible?: string
|
visible?: string
|
||||||
error?: string
|
error?: string
|
||||||
label?: string
|
label?: string
|
||||||
|
|
@ -18,20 +19,26 @@ const defaultProps = {
|
||||||
}
|
}
|
||||||
|
|
||||||
const Input = React.forwardRef<HTMLInputElement, Props>(function Input(
|
const Input = React.forwardRef<HTMLInputElement, Props>(function Input(
|
||||||
props: Props,
|
{ value, visible, bound, error, label, ...props }: Props,
|
||||||
forwardedRef
|
forwardedRef
|
||||||
) {
|
) {
|
||||||
// States
|
// States
|
||||||
const [inputValue, setInputValue] = useState('')
|
const [inputValue, setInputValue] = useState('')
|
||||||
|
|
||||||
// Classes
|
// Classes
|
||||||
const classes = classNames({ Input: true }, props.className)
|
const classes = classNames(
|
||||||
|
{
|
||||||
|
[styles.input]: true,
|
||||||
|
[styles.bound]: bound,
|
||||||
|
},
|
||||||
|
props.className
|
||||||
|
)
|
||||||
const { defaultValue, ...inputProps } = props
|
const { defaultValue, ...inputProps } = props
|
||||||
|
|
||||||
// Change value when prop updates
|
// Change value when prop updates
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (props.value) setInputValue(`${props.value}`)
|
if (value) setInputValue(`${value}`)
|
||||||
}, [props.value])
|
}, [value])
|
||||||
|
|
||||||
function handleChange(event: React.ChangeEvent<HTMLInputElement>) {
|
function handleChange(event: React.ChangeEvent<HTMLInputElement>) {
|
||||||
setInputValue(event.target.value)
|
setInputValue(event.target.value)
|
||||||
|
|
@ -49,9 +56,7 @@ const Input = React.forwardRef<HTMLInputElement, Props>(function Input(
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
formNoValidate
|
formNoValidate
|
||||||
/>
|
/>
|
||||||
{props.error && props.error.length > 0 && (
|
{error && error.length > 0 && <p className="InputError">{error}</p>}
|
||||||
<p className="InputError">{props.error}</p>
|
|
||||||
)}
|
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue