Fix search modal
This commit is contained in:
parent
82cf070c06
commit
43ff67238c
|
@ -19,7 +19,7 @@ export default () => {
|
||||||
<>
|
<>
|
||||||
{visible &&
|
{visible &&
|
||||||
<SearchModal
|
<SearchModal
|
||||||
appear={true}
|
appear
|
||||||
visible={visible}
|
visible={visible}
|
||||||
onDismissed={() => setVisible(false)}
|
onDismissed={() => setVisible(false)}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -13,6 +13,7 @@ import { httpErrorToHuman } from '@/api/http';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import styled from 'styled-components/macro';
|
import styled from 'styled-components/macro';
|
||||||
import tw from 'twin.macro';
|
import tw from 'twin.macro';
|
||||||
|
import Input from '@/components/elements/Input';
|
||||||
|
|
||||||
type Props = RequiredModalProps;
|
type Props = RequiredModalProps;
|
||||||
|
|
||||||
|
@ -94,11 +95,7 @@ export default ({ ...props }: Props) => {
|
||||||
>
|
>
|
||||||
<SearchWatcher/>
|
<SearchWatcher/>
|
||||||
<InputSpinner visible={loading}>
|
<InputSpinner visible={loading}>
|
||||||
<Field
|
<Field as={Input} innerRef={ref} name={'term'}/>
|
||||||
innerRef={ref}
|
|
||||||
name={'term'}
|
|
||||||
className={'input-dark'}
|
|
||||||
/>
|
|
||||||
</InputSpinner>
|
</InputSpinner>
|
||||||
</FormikFieldWrapper>
|
</FormikFieldWrapper>
|
||||||
</Form>
|
</Form>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import React from 'react';
|
import React, { forwardRef } from 'react';
|
||||||
import { Field as FormikField, FieldProps } from 'formik';
|
import { Field as FormikField, FieldProps } from 'formik';
|
||||||
import Input from '@/components/elements/Input';
|
import Input from '@/components/elements/Input';
|
||||||
import Label from '@/components/elements/Label';
|
import Label from '@/components/elements/Label';
|
||||||
|
@ -13,8 +13,8 @@ interface OwnProps {
|
||||||
|
|
||||||
type Props = OwnProps & Omit<React.InputHTMLAttributes<HTMLInputElement>, 'name'>;
|
type Props = OwnProps & Omit<React.InputHTMLAttributes<HTMLInputElement>, 'name'>;
|
||||||
|
|
||||||
const Field = ({ id, name, light = false, label, description, validate, className, ...props }: Props) => (
|
const Field = forwardRef<HTMLInputElement, Props>(({ id, name, light = false, label, description, validate, className, ...props }, ref) => (
|
||||||
<FormikField name={name} validate={validate}>
|
<FormikField innerRef={ref} name={name} validate={validate}>
|
||||||
{
|
{
|
||||||
({ field, form: { errors, touched } }: FieldProps) => (
|
({ field, form: { errors, touched } }: FieldProps) => (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
|
@ -39,6 +39,7 @@ const Field = ({ id, name, light = false, label, description, validate, classNam
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
</FormikField>
|
</FormikField>
|
||||||
);
|
));
|
||||||
|
Field.displayName = 'Field';
|
||||||
|
|
||||||
export default Field;
|
export default Field;
|
||||||
|
|
|
@ -2,6 +2,8 @@ import React from 'react';
|
||||||
import { Field, FieldProps } from 'formik';
|
import { Field, FieldProps } from 'formik';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import InputError from '@/components/elements/InputError';
|
import InputError from '@/components/elements/InputError';
|
||||||
|
import Label from '@/components/elements/Label';
|
||||||
|
import tw from 'twin.macro';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
id?: string;
|
id?: string;
|
||||||
|
@ -18,10 +20,10 @@ const FormikFieldWrapper = ({ id, name, label, className, description, validate,
|
||||||
{
|
{
|
||||||
({ field, form: { errors, touched } }: FieldProps) => (
|
({ field, form: { errors, touched } }: FieldProps) => (
|
||||||
<div className={classNames(className, { 'has-error': touched[field.name] && errors[field.name] })}>
|
<div className={classNames(className, { 'has-error': touched[field.name] && errors[field.name] })}>
|
||||||
{label && <label htmlFor={id} className={'input-dark-label'}>{label}</label>}
|
{label && <Label htmlFor={id}>{label}</Label>}
|
||||||
{children}
|
{children}
|
||||||
<InputError errors={errors} touched={touched} name={field.name}>
|
<InputError errors={errors} touched={touched} name={field.name}>
|
||||||
{description ? <p className={'input-help'}>{description}</p> : null}
|
{description || null}
|
||||||
</InputError>
|
</InputError>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,17 +1,18 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import capitalize from 'lodash-es/capitalize';
|
import capitalize from 'lodash-es/capitalize';
|
||||||
import { FormikErrors, FormikTouched } from 'formik';
|
import { FormikErrors, FormikTouched } from 'formik';
|
||||||
|
import tw from 'twin.macro';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
errors: FormikErrors<any>;
|
errors: FormikErrors<any>;
|
||||||
touched: FormikTouched<any>;
|
touched: FormikTouched<any>;
|
||||||
name: string;
|
name: string;
|
||||||
children?: React.ReactNode;
|
children?: string | number | null | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const InputError = ({ errors, touched, name, children }: Props) => (
|
const InputError = ({ errors, touched, name, children }: Props) => (
|
||||||
touched[name] && errors[name] ?
|
touched[name] && errors[name] ?
|
||||||
<p className={'input-help error'}>
|
<p css={tw`text-xs text-red-400 pt-2`}>
|
||||||
{typeof errors[name] === 'string' ?
|
{typeof errors[name] === 'string' ?
|
||||||
capitalize(errors[name] as string)
|
capitalize(errors[name] as string)
|
||||||
:
|
:
|
||||||
|
@ -19,9 +20,9 @@ const InputError = ({ errors, touched, name, children }: Props) => (
|
||||||
}
|
}
|
||||||
</p>
|
</p>
|
||||||
:
|
:
|
||||||
<React.Fragment>
|
<>
|
||||||
{children}
|
{children ? <p css={tw`text-xs text-neutral-400 pt-2`}>{children}</p> : null}
|
||||||
</React.Fragment>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
export default InputError;
|
export default InputError;
|
||||||
|
|
|
@ -1,20 +1,21 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import Spinner from '@/components/elements/Spinner';
|
import Spinner from '@/components/elements/Spinner';
|
||||||
import { CSSTransition } from 'react-transition-group';
|
import { CSSTransition } from 'react-transition-group';
|
||||||
|
import Fade from '@/components/elements/Fade';
|
||||||
|
import tw from 'twin.macro';
|
||||||
|
|
||||||
const InputSpinner = ({ visible, children }: { visible: boolean, children: React.ReactNode }) => (
|
const InputSpinner = ({ visible, children }: { visible: boolean, children: React.ReactNode }) => (
|
||||||
<div className={'relative'}>
|
<div css={tw`relative`}>
|
||||||
<CSSTransition
|
<Fade
|
||||||
timeout={250}
|
appear
|
||||||
|
unmountOnExit
|
||||||
in={visible}
|
in={visible}
|
||||||
unmountOnExit={true}
|
timeout={250}
|
||||||
appear={true}
|
|
||||||
classNames={'fade'}
|
|
||||||
>
|
>
|
||||||
<div className={'absolute right-0 h-full flex items-center justify-end pr-3'}>
|
<div css={tw`absolute right-0 h-full flex items-center justify-end pr-3`}>
|
||||||
<Spinner size={'small'}/>
|
<Spinner size={'small'}/>
|
||||||
</div>
|
</div>
|
||||||
</CSSTransition>
|
</Fade>
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue