-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #462 from dump-hr/Andrea/input-component
New input component (2)
- Loading branch information
Showing
6 changed files
with
182 additions
and
7 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
.container { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: flex-start; | ||
gap: 6px; | ||
font-family: 'Inter', sans-serif; | ||
transition: gap 0.3s ease-in-out; | ||
width: 100%; | ||
|
||
&:has(.error) { | ||
gap: 4px; | ||
} | ||
} | ||
|
||
.inputWrapper { | ||
position: relative; | ||
width: 100%; | ||
background-color: aqua; | ||
} | ||
|
||
.input { | ||
width: 100%; | ||
border: none; | ||
background: transparent; | ||
border-bottom: 1.5px solid transparent; | ||
outline: none; | ||
@include paragraph-16; | ||
color: $primary-black; | ||
padding: 5px 0 2px 0; | ||
transition: opacity 0.3s ease-out; | ||
transition: padding-top 0.3s ease-out; | ||
|
||
&.error { | ||
border-bottom-color: $error-light; | ||
} | ||
|
||
&.active { | ||
border-bottom-color: $primary-black; | ||
} | ||
|
||
&.floating { | ||
padding-top: 25px; | ||
} | ||
} | ||
|
||
.placeholder { | ||
position: absolute; | ||
left: 0; | ||
bottom: 8px; | ||
@include paragraph-16; | ||
color: $black-70; | ||
transition: all 0.3s ease-out; | ||
pointer-events: none; | ||
|
||
&.floating { | ||
transform: translateY(-25px); | ||
@include paragraph-14; | ||
} | ||
} | ||
|
||
.dots { | ||
position: absolute; | ||
bottom: 0; | ||
left: 0; | ||
@include dottedBreak($primary-black); | ||
} | ||
|
||
.errorText { | ||
@include paragraph-14; | ||
color: $error-light; | ||
transition: gap 0.3s ease-in; | ||
} | ||
|
||
.togglePassword { | ||
position: absolute; | ||
right: 0px; | ||
top: 50%; | ||
transform: translateY(-50%); | ||
background: transparent; | ||
border: none; | ||
cursor: pointer; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import React, { useState } from 'react'; | ||
import c from './Input.module.scss'; | ||
import clsx from 'clsx'; | ||
import EyeIcon from '../../assets/icons/Eye open.svg'; | ||
import EyeClosedIcon from '../../assets/icons/Eye closed.svg'; | ||
|
||
type InputProps = { | ||
value: string; | ||
placeholder: string; | ||
onChange: (e: React.ChangeEvent<HTMLInputElement>) => void; | ||
error?: string; | ||
type?: 'text' | 'password'; | ||
} & Omit<React.HTMLProps<HTMLInputElement>, 'onChange'>; | ||
|
||
export const Input = ({ | ||
value, | ||
placeholder, | ||
onChange, | ||
error, | ||
type = 'text', | ||
...props | ||
}: InputProps) => { | ||
const [isPasswordVisible, setPasswordToBeVisible] = useState(false); | ||
const [isFocused, setItIsFocus] = useState(false); | ||
const isActive = value && !error; | ||
const showLabel = isFocused || value; | ||
|
||
const passwordVisibility = () => { | ||
setPasswordToBeVisible((prev) => !prev); | ||
}; | ||
|
||
const inputType = | ||
type === 'password' && !isPasswordVisible ? 'password' : 'text'; | ||
|
||
return ( | ||
<div className={c.container} style={props.style}> | ||
<div className={c.inputWrapper}> | ||
<input | ||
type={inputType} | ||
value={value} | ||
onChange={onChange} | ||
onFocus={() => setItIsFocus(true)} | ||
onBlur={() => setItIsFocus(false)} | ||
placeholder='' | ||
className={clsx( | ||
c.input, | ||
error && c.error, | ||
isActive && c.active, | ||
{ | ||
[c.floating]: showLabel, | ||
}, | ||
props.className, | ||
)} | ||
{...props} | ||
/> | ||
|
||
<label | ||
className={clsx(c.placeholder, { | ||
[c.floating]: showLabel, | ||
[c.error]: error, | ||
[c.active]: isActive, | ||
})}> | ||
{placeholder} | ||
</label> | ||
|
||
{!value && !error && <div className={c.dots}></div>} | ||
|
||
{type === 'password' && ( | ||
<button | ||
type='button' | ||
onClick={passwordVisibility} | ||
className={c.togglePassword}> | ||
<img src={isPasswordVisible ? EyeIcon : EyeClosedIcon} /> | ||
</button> | ||
)} | ||
</div> | ||
|
||
{error && ( | ||
<span className={clsx(c.errorText, { visible: !!error })}>{error}</span> | ||
)} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './Input'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters