Skip to content

Commit

Permalink
Merge pull request #462 from dump-hr/Andrea/input-component
Browse files Browse the repository at this point in the history
New input component (2)
  • Loading branch information
lovretomic authored Jan 6, 2025
2 parents 78b34d9 + 6fded19 commit 6d9bdb9
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 7 deletions.
7 changes: 7 additions & 0 deletions apps/app/src/assets/icons/Eye closed.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions apps/app/src/assets/icons/Eye open.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
82 changes: 82 additions & 0 deletions apps/app/src/components/Input/Input.module.scss
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;
}
83 changes: 83 additions & 0 deletions apps/app/src/components/Input/Input.tsx
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>
);
};
1 change: 1 addition & 0 deletions apps/app/src/components/Input/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Input';
12 changes: 5 additions & 7 deletions apps/app/src/styles/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,13 @@
letter-spacing: 0%;
}

@mixin dottedBreak($color: rgba(23, 22, 21, 0.3), $dot-size: 0.8px) {
@mixin dottedBreak($color: rgba(23, 22, 21, 0.3)) {
width: 100%;
height: 2px;
background-image: radial-gradient(
circle,
$color $dot-size,
transparent calc($dot-size + 0.3px)
);
background-size: calc($dot-size * 10) 2px;
background-image: radial-gradient(circle, $color 0.8px, transparent 0.3px);
background-size: 8px 2px;
background-repeat: repeat-x;
background-color: transparent;
white-space: nowrap;
overflow: hidden;
}

0 comments on commit 6d9bdb9

Please sign in to comment.