Skip to content

Commit 43ff672

Browse files
committed
Fix search modal
1 parent 82cf070 commit 43ff672

File tree

6 files changed

+27
-25
lines changed

6 files changed

+27
-25
lines changed

resources/scripts/components/dashboard/search/SearchContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default () => {
1919
<>
2020
{visible &&
2121
<SearchModal
22-
appear={true}
22+
appear
2323
visible={visible}
2424
onDismissed={() => setVisible(false)}
2525
/>

resources/scripts/components/dashboard/search/SearchModal.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { httpErrorToHuman } from '@/api/http';
1313
import { Link } from 'react-router-dom';
1414
import styled from 'styled-components/macro';
1515
import tw from 'twin.macro';
16+
import Input from '@/components/elements/Input';
1617

1718
type Props = RequiredModalProps;
1819

@@ -94,11 +95,7 @@ export default ({ ...props }: Props) => {
9495
>
9596
<SearchWatcher/>
9697
<InputSpinner visible={loading}>
97-
<Field
98-
innerRef={ref}
99-
name={'term'}
100-
className={'input-dark'}
101-
/>
98+
<Field as={Input} innerRef={ref} name={'term'}/>
10299
</InputSpinner>
103100
</FormikFieldWrapper>
104101
</Form>

resources/scripts/components/elements/Field.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { forwardRef } from 'react';
22
import { Field as FormikField, FieldProps } from 'formik';
33
import Input from '@/components/elements/Input';
44
import Label from '@/components/elements/Label';
@@ -13,8 +13,8 @@ interface OwnProps {
1313

1414
type Props = OwnProps & Omit<React.InputHTMLAttributes<HTMLInputElement>, 'name'>;
1515

16-
const Field = ({ id, name, light = false, label, description, validate, className, ...props }: Props) => (
17-
<FormikField name={name} validate={validate}>
16+
const Field = forwardRef<HTMLInputElement, Props>(({ id, name, light = false, label, description, validate, className, ...props }, ref) => (
17+
<FormikField innerRef={ref} name={name} validate={validate}>
1818
{
1919
({ field, form: { errors, touched } }: FieldProps) => (
2020
<React.Fragment>
@@ -39,6 +39,7 @@ const Field = ({ id, name, light = false, label, description, validate, classNam
3939
)
4040
}
4141
</FormikField>
42-
);
42+
));
43+
Field.displayName = 'Field';
4344

4445
export default Field;

resources/scripts/components/elements/FormikFieldWrapper.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import React from 'react';
22
import { Field, FieldProps } from 'formik';
33
import classNames from 'classnames';
44
import InputError from '@/components/elements/InputError';
5+
import Label from '@/components/elements/Label';
6+
import tw from 'twin.macro';
57

68
interface Props {
79
id?: string;
@@ -18,10 +20,10 @@ const FormikFieldWrapper = ({ id, name, label, className, description, validate,
1820
{
1921
({ field, form: { errors, touched } }: FieldProps) => (
2022
<div className={classNames(className, { 'has-error': touched[field.name] && errors[field.name] })}>
21-
{label && <label htmlFor={id} className={'input-dark-label'}>{label}</label>}
23+
{label && <Label htmlFor={id}>{label}</Label>}
2224
{children}
2325
<InputError errors={errors} touched={touched} name={field.name}>
24-
{description ? <p className={'input-help'}>{description}</p> : null}
26+
{description || null}
2527
</InputError>
2628
</div>
2729
)
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
import React from 'react';
22
import capitalize from 'lodash-es/capitalize';
33
import { FormikErrors, FormikTouched } from 'formik';
4+
import tw from 'twin.macro';
45

56
interface Props {
67
errors: FormikErrors<any>;
78
touched: FormikTouched<any>;
89
name: string;
9-
children?: React.ReactNode;
10+
children?: string | number | null | undefined;
1011
}
1112

1213
const InputError = ({ errors, touched, name, children }: Props) => (
1314
touched[name] && errors[name] ?
14-
<p className={'input-help error'}>
15+
<p css={tw`text-xs text-red-400 pt-2`}>
1516
{typeof errors[name] === 'string' ?
1617
capitalize(errors[name] as string)
1718
:
1819
capitalize((errors[name] as unknown as string[])[0])
1920
}
2021
</p>
2122
:
22-
<React.Fragment>
23-
{children}
24-
</React.Fragment>
23+
<>
24+
{children ? <p css={tw`text-xs text-neutral-400 pt-2`}>{children}</p> : null}
25+
</>
2526
);
2627

2728
export default InputError;

resources/scripts/components/elements/InputSpinner.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import React from 'react';
22
import Spinner from '@/components/elements/Spinner';
33
import { CSSTransition } from 'react-transition-group';
4+
import Fade from '@/components/elements/Fade';
5+
import tw from 'twin.macro';
46

57
const InputSpinner = ({ visible, children }: { visible: boolean, children: React.ReactNode }) => (
6-
<div className={'relative'}>
7-
<CSSTransition
8-
timeout={250}
8+
<div css={tw`relative`}>
9+
<Fade
10+
appear
11+
unmountOnExit
912
in={visible}
10-
unmountOnExit={true}
11-
appear={true}
12-
classNames={'fade'}
13+
timeout={250}
1314
>
14-
<div className={'absolute right-0 h-full flex items-center justify-end pr-3'}>
15+
<div css={tw`absolute right-0 h-full flex items-center justify-end pr-3`}>
1516
<Spinner size={'small'}/>
1617
</div>
17-
</CSSTransition>
18+
</Fade>
1819
{children}
1920
</div>
2021
);

0 commit comments

Comments
 (0)