mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
added text input
This commit is contained in:
parent
5aca2508ea
commit
578b37716b
7 changed files with 527 additions and 0 deletions
24
src/components/input/Icon/index.tsx
Normal file
24
src/components/input/Icon/index.tsx
Normal file
|
@ -0,0 +1,24 @@
|
|||
import React, { FC } from 'react';
|
||||
import { IIcon } from '~/redux/types';
|
||||
|
||||
type IProps = React.SVGAttributes<SVGElement> & {
|
||||
size?: number;
|
||||
icon: IIcon;
|
||||
};
|
||||
|
||||
export const Icon: FC<IProps> = ({
|
||||
size = 20,
|
||||
icon,
|
||||
...props
|
||||
}) => (
|
||||
<svg
|
||||
width={size}
|
||||
height={size}
|
||||
viewBox={`0 0 24 24`}
|
||||
preserveAspectRatio="xMidYMid slice"
|
||||
{...props}
|
||||
style={{ ...props.style, outline: 'none' }}
|
||||
>
|
||||
<use xlinkHref={`#${icon}`} />
|
||||
</svg>
|
||||
);
|
91
src/components/input/InputText/index.tsx
Normal file
91
src/components/input/InputText/index.tsx
Normal file
|
@ -0,0 +1,91 @@
|
|||
import React, {
|
||||
FC,
|
||||
ChangeEvent,
|
||||
useCallback,
|
||||
useState, useEffect,
|
||||
} from 'react';
|
||||
import * as styles from '~/styles/inputs.scss';
|
||||
import classNames from 'classnames';
|
||||
import { Icon } from '~/components/input/Icon';
|
||||
import { IInputTextProps } from '~/redux/types';
|
||||
import { LoaderCircle } from '~/components/input/LoaderCircle';
|
||||
|
||||
const InputText: FC<IInputTextProps> = ({
|
||||
wrapperClassName,
|
||||
className = '',
|
||||
handler,
|
||||
required = false,
|
||||
status,
|
||||
title,
|
||||
error,
|
||||
value = '',
|
||||
onRef,
|
||||
is_loading,
|
||||
...props
|
||||
}) => {
|
||||
const [focused, setFocused] = useState(false);
|
||||
const [inner_ref, setInnerRef] = useState();
|
||||
|
||||
const onInput = useCallback(
|
||||
({ target }: ChangeEvent<HTMLInputElement>) => handler(target.value),
|
||||
[handler],
|
||||
);
|
||||
|
||||
const onFocus = useCallback(() => setFocused(true), [focused]);
|
||||
const onBlur = useCallback(() => setFocused(false), [focused]);
|
||||
|
||||
useEffect(() => {
|
||||
if (onRef) onRef(inner_ref);
|
||||
}, [inner_ref, onRef]);
|
||||
|
||||
return (
|
||||
<div className={classNames(
|
||||
styles.input_text_wrapper,
|
||||
wrapperClassName,
|
||||
{
|
||||
[styles.required]: required,
|
||||
[styles.focused]: focused,
|
||||
[styles.has_status]: !!status || !!error,
|
||||
[styles.has_value]: !!value,
|
||||
[styles.has_error]: !!error,
|
||||
[styles.has_loader]: is_loading,
|
||||
},
|
||||
)}>
|
||||
<div className={styles.input}>
|
||||
<input
|
||||
type="text"
|
||||
onChange={onInput}
|
||||
className={classNames(styles.input_text, className)}
|
||||
onFocus={onFocus}
|
||||
onBlur={onBlur}
|
||||
value={value || ''}
|
||||
ref={setInnerRef}
|
||||
{...props}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className={styles.status}>
|
||||
<div className={classNames(styles.success_icon, { active: status === 'success' })}>
|
||||
<Icon icon="check" size={20} />
|
||||
</div>
|
||||
<div className={classNames(styles.error_icon, { active: status === 'error' || !!error })}>
|
||||
<Icon icon="close" size={20} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className={styles.loader}>
|
||||
<div className={classNames({ active: is_loading })}>
|
||||
<LoaderCircle size={20} />
|
||||
</div>
|
||||
</div>
|
||||
{
|
||||
title && <div className={styles.title}><span>{title}</span></div>
|
||||
}
|
||||
{
|
||||
error && <div className={styles.error}><span>{error}</span></div>
|
||||
}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export { InputText };
|
37
src/components/input/LoaderCircle/index.tsx
Normal file
37
src/components/input/LoaderCircle/index.tsx
Normal file
|
@ -0,0 +1,37 @@
|
|||
import React, { FC } from 'react';
|
||||
import * as styles from './styles.scss';
|
||||
|
||||
interface IProps {
|
||||
size?: number;
|
||||
}
|
||||
|
||||
export const LoaderCircle: FC<IProps> = ({ size = 24 }) => (
|
||||
<div className={styles.wrap}>
|
||||
<svg width={size} height={size} viewBox="0 0 24 24">
|
||||
<g strokeWidth={0.5}>
|
||||
{
|
||||
[...new Array(8)].map((el, i) => (
|
||||
<path
|
||||
d="M11,2 L11,6 C11,6.55228475 11.4477153,7 12,7 C12.5522847,7 13,6.55228475 13,6 L13,2 C13,1.44771525 12.5522847,1 12,1 C11.4477153,1 11,1.44771525 11,2 Z"
|
||||
opacity={0.125 * (8 - i)}
|
||||
transform={`rotate(${Math.floor(45 * i)} 12 12)`}
|
||||
// style={{
|
||||
// animationDelay: `${-100 * (8 - i)}ms`,
|
||||
// }}
|
||||
key={i}
|
||||
/>
|
||||
))
|
||||
}
|
||||
</g>
|
||||
</svg>
|
||||
</div>
|
||||
);
|
||||
|
||||
/*
|
||||
<div className={styles.wrap}>
|
||||
<svg className={styles.icon} width={size} height={size}>
|
||||
<path d={describeArc(size / 2, size / 2, size / 2, 0, 90)} />
|
||||
<path d={describeArc(size / 2, size / 2, size / 2, 180, 270)} />
|
||||
</svg>
|
||||
</div>
|
||||
*/
|
19
src/components/input/LoaderCircle/styles.scss
Normal file
19
src/components/input/LoaderCircle/styles.scss
Normal file
|
@ -0,0 +1,19 @@
|
|||
.icon {
|
||||
fill: transparentize(black, 0.6);
|
||||
stroke: none;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
0% { transform: rotate(0); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
@keyframes fade {
|
||||
0% { opacity: 1; transform: scale(1); }
|
||||
100% { opacity: 0.1; transform: scale(4); }
|
||||
}
|
||||
|
||||
.wrap {
|
||||
animation: spin infinite steps(9, end) 1s;
|
||||
display: inline-flex;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue