Update Input
* Add fieldsetClasses prop * Fallback to an empty string if value is undefined * Fix focus ring to be consistent with our other custom focus rings * Fix placeholder color
This commit is contained in:
parent
e8d1da58d5
commit
9f890ae253
2 changed files with 39 additions and 18 deletions
|
|
@ -1,7 +1,3 @@
|
||||||
.full {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.fieldset {
|
.fieldset {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|
@ -11,6 +7,10 @@
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.full {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
.error {
|
.error {
|
||||||
color: $error;
|
color: $error;
|
||||||
font-size: $font-small;
|
font-size: $font-small;
|
||||||
|
|
@ -23,8 +23,8 @@
|
||||||
.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-radius: $input-corner;
|
border-radius: $input-corner;
|
||||||
|
border: none;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
color: var(--text-primary);
|
color: var(--text-primary);
|
||||||
display: block;
|
display: block;
|
||||||
|
|
@ -34,7 +34,7 @@
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
||||||
&:not(.wrapper) {
|
&:not(.wrapper) {
|
||||||
padding: $unit * 1.5 $unit-2x;
|
padding: ($unit * 1.5) $unit-2x;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.accessory {
|
&.accessory {
|
||||||
|
|
@ -43,7 +43,6 @@
|
||||||
align-items: center;
|
align-items: center;
|
||||||
background: var(--input-bg);
|
background: var(--input-bg);
|
||||||
border-radius: $input-corner;
|
border-radius: $input-corner;
|
||||||
border: $offset solid transparent;
|
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|
||||||
|
|
@ -60,11 +59,16 @@
|
||||||
input {
|
input {
|
||||||
background: transparent;
|
background: transparent;
|
||||||
border-radius: $input-corner;
|
border-radius: $input-corner;
|
||||||
border: none;
|
border: 2px solid transparent;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
color: var(--text-primary);
|
color: var(--text-primary);
|
||||||
padding: ($unit * 1.75) $unit-2x;
|
padding: ($unit * 1.75) $unit-2x;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
||||||
|
&:focus {
|
||||||
|
border: 2px solid $blue;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -72,11 +76,6 @@
|
||||||
-webkit-appearance: none;
|
-webkit-appearance: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
&:focus {
|
|
||||||
border: 2px solid $blue;
|
|
||||||
outline: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.bound {
|
&.bound {
|
||||||
background-color: var(--input-bound-bg);
|
background-color: var(--input-bound-bg);
|
||||||
|
|
||||||
|
|
@ -124,6 +123,6 @@
|
||||||
|
|
||||||
.input::placeholder,
|
.input::placeholder,
|
||||||
.input > input::placeholder {
|
.input > input::placeholder {
|
||||||
color: var(--text-secondary);
|
color: var(--text-tertiary);
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ interface Props extends React.ComponentProps<'input'> {
|
||||||
bound?: boolean
|
bound?: boolean
|
||||||
error?: string
|
error?: string
|
||||||
label?: string
|
label?: string
|
||||||
|
fieldsetClassName?: String
|
||||||
|
wrapperClassName?: string
|
||||||
hide1Password?: boolean
|
hide1Password?: boolean
|
||||||
showCounter?: boolean
|
showCounter?: boolean
|
||||||
}
|
}
|
||||||
|
|
@ -17,7 +19,16 @@ const defaultProps = {
|
||||||
}
|
}
|
||||||
|
|
||||||
const Input = React.forwardRef<HTMLInputElement, Props>(function input(
|
const Input = React.forwardRef<HTMLInputElement, Props>(function input(
|
||||||
{ value: initialValue, bound, label, error, showCounter, ...props }: Props,
|
{
|
||||||
|
value: initialValue,
|
||||||
|
bound,
|
||||||
|
label,
|
||||||
|
error,
|
||||||
|
showCounter,
|
||||||
|
fieldsetClassName,
|
||||||
|
wrapperClassName,
|
||||||
|
...props
|
||||||
|
}: Props,
|
||||||
forwardedRef
|
forwardedRef
|
||||||
) {
|
) {
|
||||||
// States
|
// States
|
||||||
|
|
@ -26,7 +37,18 @@ const Input = React.forwardRef<HTMLInputElement, Props>(function input(
|
||||||
props.maxLength ? props.maxLength - (`${value}` || '').length : 0
|
props.maxLength ? props.maxLength - (`${value}` || '').length : 0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setValue(initialValue)
|
||||||
|
}, [initialValue])
|
||||||
|
|
||||||
// Classes
|
// Classes
|
||||||
|
const fieldsetClasses = classNames(
|
||||||
|
{
|
||||||
|
[styles.fieldset]: true,
|
||||||
|
},
|
||||||
|
fieldsetClassName?.split(' ').map((className) => styles[className])
|
||||||
|
)
|
||||||
|
|
||||||
const inputWrapperClasses = classNames(
|
const inputWrapperClasses = classNames(
|
||||||
{
|
{
|
||||||
[styles.wrapper]: true,
|
[styles.wrapper]: true,
|
||||||
|
|
@ -34,7 +56,7 @@ const Input = React.forwardRef<HTMLInputElement, Props>(function input(
|
||||||
[styles.input]: showCounter,
|
[styles.input]: showCounter,
|
||||||
[styles.bound]: showCounter && bound,
|
[styles.bound]: showCounter && bound,
|
||||||
},
|
},
|
||||||
props.className?.split(' ').map((className) => styles[className])
|
wrapperClassName?.split(' ').map((className) => styles[className])
|
||||||
)
|
)
|
||||||
|
|
||||||
const inputClasses = classNames(
|
const inputClasses = classNames(
|
||||||
|
|
@ -70,7 +92,7 @@ const Input = React.forwardRef<HTMLInputElement, Props>(function input(
|
||||||
type={props.type}
|
type={props.type}
|
||||||
name={props.name}
|
name={props.name}
|
||||||
placeholder={props.placeholder}
|
placeholder={props.placeholder}
|
||||||
value={value}
|
value={value || ''}
|
||||||
onBlur={props.onBlur}
|
onBlur={props.onBlur}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
maxLength={props.maxLength}
|
maxLength={props.maxLength}
|
||||||
|
|
@ -82,7 +104,7 @@ const Input = React.forwardRef<HTMLInputElement, Props>(function input(
|
||||||
)
|
)
|
||||||
|
|
||||||
const fieldset = (
|
const fieldset = (
|
||||||
<fieldset className={styles.fieldset}>
|
<fieldset className={fieldsetClasses}>
|
||||||
{label && <legend className={styles.legend}>{label}</legend>}
|
{label && <legend className={styles.legend}>{label}</legend>}
|
||||||
{input}
|
{input}
|
||||||
{error && <span className={styles.error}>{error}</span>}
|
{error && <span className={styles.error}>{error}</span>}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue