mirror of
https://github.com/hazemKrimi/crimson-quirks-ui.git
synced 2026-05-01 18:20:28 +00:00
Update input component
This commit is contained in:
@@ -1,24 +1,62 @@
|
|||||||
|
import { Text } from '..';
|
||||||
|
import { Upload } from '../../assets';
|
||||||
import { Wrapper } from './styles';
|
import { Wrapper } from './styles';
|
||||||
|
|
||||||
type InputProps = {
|
type InputProps = {
|
||||||
className?: string;
|
className?: string;
|
||||||
color?: 'client' | 'productOwner' | 'developer' | 'admin' | string;
|
color?:
|
||||||
|
| 'client'
|
||||||
|
| 'productOwner'
|
||||||
|
| 'developer'
|
||||||
|
| 'admin'
|
||||||
|
| 'success'
|
||||||
|
| 'warning'
|
||||||
|
| 'error'
|
||||||
|
| 'black'
|
||||||
|
| 'white';
|
||||||
error?: boolean;
|
error?: boolean;
|
||||||
errorMessage?: string;
|
errorMessage?: string;
|
||||||
value: string;
|
value: string;
|
||||||
label: string;
|
label: string;
|
||||||
type: 'text' | 'email' | 'password' | 'file' | 'number';
|
type?: 'text' | 'email' | 'password' | 'file' | 'number';
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
fullWidth?: boolean;
|
fullWidth?: boolean;
|
||||||
multiline?: boolean;
|
multiline?: boolean;
|
||||||
iconLeft?: React.SVGProps<SVGSVGElement>;
|
|
||||||
onChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
|
onChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const Input = ({ type, value, ...props }: InputProps) => {
|
const Input = ({
|
||||||
|
type = 'text',
|
||||||
|
color = 'client',
|
||||||
|
label,
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
error,
|
||||||
|
errorMessage,
|
||||||
|
...props
|
||||||
|
}: InputProps) => {
|
||||||
return (
|
return (
|
||||||
<Wrapper {...props}>
|
<Wrapper label={label} error={error} type={type} color={color} {...props}>
|
||||||
<input type={type} value={value} />
|
<div className='info'>
|
||||||
|
{label && (
|
||||||
|
<Text variant='body' weight='bold' className='label'>
|
||||||
|
{label}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
{error && errorMessage && (
|
||||||
|
<Text variant='body' color='error' className='error-message'>
|
||||||
|
{errorMessage}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className='input'>
|
||||||
|
{type === 'file' && (
|
||||||
|
<span className='icon left'>
|
||||||
|
<Upload />
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
<input type={type} value={value} onChange={onChange} accept='image/*' />
|
||||||
|
</div>
|
||||||
</Wrapper>
|
</Wrapper>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
+219
-17
@@ -1,74 +1,276 @@
|
|||||||
import styled, { css } from 'styled-components';
|
import styled, { css } from 'styled-components';
|
||||||
|
|
||||||
type WrapperProps = {
|
type WrapperProps = {
|
||||||
color?: 'client' | 'productOwner' | 'developer' | 'admin' | string;
|
color?:
|
||||||
|
| 'client'
|
||||||
|
| 'productOwner'
|
||||||
|
| 'developer'
|
||||||
|
| 'admin'
|
||||||
|
| 'success'
|
||||||
|
| 'warning'
|
||||||
|
| 'error'
|
||||||
|
| 'black'
|
||||||
|
| 'gray'
|
||||||
|
| 'white';
|
||||||
error?: boolean;
|
error?: boolean;
|
||||||
errorMessage?: string;
|
errorMessage?: string;
|
||||||
|
type?: 'text' | 'email' | 'password' | 'file' | 'number';
|
||||||
|
label: string;
|
||||||
fullWidth?: boolean;
|
fullWidth?: boolean;
|
||||||
multiline?: boolean;
|
|
||||||
iconLeft?: React.SVGProps<SVGSVGElement>;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Wrapper = styled.div<WrapperProps>`
|
export const Wrapper = styled.div<WrapperProps>`
|
||||||
display: inline;
|
.input {
|
||||||
|
width: inherit;
|
||||||
|
height: inherit;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
|
padding: 1rem;
|
||||||
|
position: relative;
|
||||||
color: ${({ theme }) => theme.colors.black.main};
|
color: ${({ theme }) => theme.colors.black.main};
|
||||||
|
background: ${({ theme }) => theme.colors.white.main};
|
||||||
|
background-clip: padding-box;
|
||||||
|
border: 2px solid transparent;
|
||||||
|
|
||||||
|
&:before {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
width: inherit;
|
||||||
|
height: inherit;
|
||||||
|
z-index: -1;
|
||||||
|
margin: -2px;
|
||||||
|
border-radius: inherit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.info {
|
||||||
|
margin-bottom: 5px;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(2, 1fr);
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
p {
|
||||||
|
background: ${({ theme }) => theme.colors.gray.dark};
|
||||||
|
-webkit-background-clip: text;
|
||||||
|
-webkit-text-fill-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.label {
|
||||||
|
justify-self: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-message {
|
||||||
|
justify-self: flex-end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
input {
|
input {
|
||||||
|
width: 100%;
|
||||||
background: none;
|
background: none;
|
||||||
border: none;
|
border: none;
|
||||||
color: ${({ theme }) => theme.colors.black.main};
|
color: ${({ theme }) => theme.colors.black.main};
|
||||||
}
|
}
|
||||||
|
|
||||||
${({ color, theme }) => {
|
input[type='file'] {
|
||||||
if (!color)
|
cursor: pointer;
|
||||||
|
|
||||||
|
&::-webkit-file-upload-button {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
${({ type }) => {
|
||||||
|
if (type === 'file')
|
||||||
return css`
|
return css`
|
||||||
border: 2px solid ${theme.colors.client.light};
|
.input {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
|
return '';
|
||||||
|
}}
|
||||||
|
|
||||||
|
.icon {
|
||||||
|
${({ type }) => type === 'file' && `cursor: pointer`};
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon.left {
|
||||||
|
margin-right: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
${({ color, theme }) => {
|
||||||
switch (color) {
|
switch (color) {
|
||||||
case 'client':
|
case 'client':
|
||||||
return css`
|
return css`
|
||||||
border: 2px solid ${theme.colors.client.light};
|
.input:before {
|
||||||
|
background: ${theme.colors.client.light};
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type='file'] {
|
||||||
|
color: ${theme.colors.client.main};
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon svg path {
|
||||||
|
stroke: ${theme.colors.client.main};
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
case 'productOwner':
|
case 'productOwner':
|
||||||
return css`
|
return css`
|
||||||
border: 2px solid ${theme.colors.productOwner.light};
|
.input:before {
|
||||||
|
background: ${theme.colors.productOwner.light};
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type='file'] {
|
||||||
|
color: ${theme.colors.productOwner.main};
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon svg path {
|
||||||
|
stroke: ${theme.colors.productOwner.main};
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
case 'developer':
|
case 'developer':
|
||||||
return css`
|
return css`
|
||||||
border: 2px solid ${theme.colors.developer.light};
|
.input:before {
|
||||||
|
background: ${theme.colors.developer.light};
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type='file'] {
|
||||||
|
color: ${theme.colors.developer.main};
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon svg path {
|
||||||
|
stroke: ${theme.colors.developer.main};
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
case 'admin':
|
case 'admin':
|
||||||
return css`
|
return css`
|
||||||
border: 2px solid ${theme.colors.admin.light};
|
.input:before {
|
||||||
|
background: ${theme.colors.admin.light};
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type='file'] {
|
||||||
|
color: ${theme.colors.admin.main};
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon svg path {
|
||||||
|
stroke: ${theme.colors.admin.main};
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
case 'success':
|
case 'success':
|
||||||
return css`
|
return css`
|
||||||
border: 2px solid ${theme.colors.success.main};
|
.input:before {
|
||||||
|
background: ${theme.colors.success.main};
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type='file'] {
|
||||||
|
color: ${theme.colors.success.main};
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon svg path {
|
||||||
|
stroke: ${theme.colors.success.main};
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
case 'warning':
|
case 'warning':
|
||||||
return css`
|
return css`
|
||||||
border: 2px solid ${theme.colors.warning.main};
|
.input:before {
|
||||||
|
background: ${theme.colors.warning.main};
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type='file'] {
|
||||||
|
color: ${theme.colors.warning.main};
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon svg path {
|
||||||
|
stroke: ${theme.colors.warning.main};
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
case 'error':
|
case 'error':
|
||||||
return css`
|
return css`
|
||||||
border: 2px solid ${theme.colors.error.main};
|
.input:before {
|
||||||
|
background: ${theme.colors.error.main};
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type='file'] {
|
||||||
|
color: ${theme.colors.error.main};
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon svg path {
|
||||||
|
stroke: ${theme.colors.error.main};
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
case 'black':
|
case 'black':
|
||||||
return css`
|
return css`
|
||||||
border: 2px solid ${theme.colors.black.main};
|
.input:before {
|
||||||
|
background: ${theme.colors.black.main};
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type='file'] {
|
||||||
|
color: ${theme.colors.black.main};
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon svg path {
|
||||||
|
stroke: ${theme.colors.black.main};
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
case 'white':
|
case 'white':
|
||||||
return css`
|
return css`
|
||||||
border: 2px solid ${theme.colors.white.main};
|
.input:before {
|
||||||
|
background: ${theme.colors.white.main};
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type='file'] {
|
||||||
|
color: ${theme.colors.white.main};
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon svg path {
|
||||||
|
stroke: ${theme.colors.white.main};
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
default:
|
default:
|
||||||
return css`
|
return css`
|
||||||
border: 2px solid ${color};
|
.input:before {
|
||||||
|
background: ${theme.colors.client.light};
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type='file'] {
|
||||||
|
color: ${theme.colors.client.main};
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon svg path {
|
||||||
|
stroke: ${theme.colors.client.main};
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
${({ error, theme }) =>
|
||||||
|
error &&
|
||||||
|
css`
|
||||||
|
.info p {
|
||||||
|
background: ${theme.colors.error.main};
|
||||||
|
-webkit-background-clip: text;
|
||||||
|
-webkit-text-fill-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input:before {
|
||||||
|
background: ${theme.colors.error.main};
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type='file'] {
|
||||||
|
color: ${theme.colors.error.main};
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon svg path {
|
||||||
|
stroke: ${theme.colors.error.main};
|
||||||
|
}
|
||||||
|
`}
|
||||||
|
|
||||||
${({ fullWidth }) =>
|
${({ fullWidth }) =>
|
||||||
fullWidth &&
|
fullWidth &&
|
||||||
css`
|
css`
|
||||||
|
|||||||
Reference in New Issue
Block a user