처음 디자인을 받고 placeholder가 움직이고... 비키는게 현실적으로 가능한가?
했는데 불가능은 없다 🤣
이 비현실적인 UI의 진실은 placeholder가 placeholder가 아니라는 것에 있다 😉
내가 작성한 코드를 자세히 보면 움직여야할 placeholder가 안보인다.CSS와 React의 useState를 활용하여 상태에 따라 라벨 위치를 변경하는 방식으로 구현을 진행했기 때문이다.
<InputContainer>
<FloatingLabel className={isFocused || employeeId ? "active" : ""}>아이디를 입력하세요</FloatingLabel>
<Input
type="text"
value={employeeId}
onChange={(e) => setEmployeeId(e.target.value)}
onFocus={() => setIsFocused(true)}
onBlur={() => setIsFocused(!!employeeId)}
required
/>
</InputContainer>
<InputContainer>
<FloatingLabel className={isPasswordFocused || password ? "active" : ""}>비밀번호를 입력하세요</FloatingLabel>
<Input
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
onFocus={() => setIsPasswordFocused(true)}
onBlur={() => setIsPasswordFocused(!!password)}
required
/>
</InputContainer>
*onFocus
: 클릭 되었을 때
**onBlur
: 클릭이 해제되었을 때
const FloatingLabel = styled.span`
position: absolute;
left: 14px;
top: 45%;
transform: translateY(-50%);
font-size: 16px;
color: var(--gray-600, #A6A5A5);
transition: all 0.2s ease-in-out;
pointer-events: none;
&.active {
top: 10px;
font-size: 12px;
color: var(--gray-500, #C0C0C0);
}
`;
const Input = styled.input`
width: 100%;
height: 44px;
padding: 10px 12px;
border-radius: 8px;
border: 2px solid var(--gray-600, #A6A5A5);
font-size: 14px;
background: transparent;
transition: all 0.2s ease-in-out;
max-width: 320px;
&:focus {
border: 2px solid var(--primary-main-200, #009857);
outline: none;
}
`;
[recoil] 그럼 Recoil은 언제 써야해요 ? (0) | 2025.02.21 |
---|---|
[Recoil]상태 관리 라이브러리 도전기 (0) | 2025.02.19 |
[React-Query] React-Query가 뭔데요? (0) | 2025.02.18 |