Skip to content

Commit

Permalink
Merge branch 'tailwind/search-input' into merged-3965-4004
Browse files Browse the repository at this point in the history
  • Loading branch information
rithviknishad committed Nov 9, 2022
2 parents 85804a7 + 6c95dfd commit c05c7cf
Show file tree
Hide file tree
Showing 19 changed files with 306 additions and 199 deletions.
10 changes: 5 additions & 5 deletions src/Components/Assets/AssetsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import React, { useState, useCallback, useEffect } from "react";
import { navigate, useQueryParams } from "raviger";
import loadable from "@loadable/component";
import Pagination from "../Common/Pagination";
import { InputSearchBox } from "../Common/SearchBox";
import { make as SlideOver } from "../Common/SlideOver.gen";
import CircularProgress from "@material-ui/core/CircularProgress";
import AssetFilter from "./AssetFilter";
import AdvancedFilterButton from "../Common/AdvancedFilterButton";
import { parseQueryParams } from "../../Utils/primitives";
import Chip from "../../CAREUI/display/Chip";
import SearchInput from "../Form/SearchInput";

const Loading = loadable(() => import("../Common/Loading"));

Expand Down Expand Up @@ -321,11 +321,11 @@ const AssetsList = () => {
</div>
</div>
<div className="flex-1">
<InputSearchBox
<SearchInput
name="search"
value={qParams.search}
search={onSearchSuspects}
placeholder="Search by Asset Name"
errors=""
onChange={({ value }) => onSearchSuspects(value)}
placeholder="Search assets"
/>
</div>
<div className="flex flex-col md:flex-row lg:ml-2 justify-start items-start gap-2">
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Common/DateInputV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ const DateInputV2: React.FC<Props> = ({
<input
type="text"
readOnly
className={`form-input ${className}`}
className={`text-sm block py-3 px-4 w-full rounded placeholder:text-gray-500 focus:bg-white border-2 focus:border-primary-400 outline-none !ring-0 transition-all duration-200 ease-in-out ${className}`}
placeholder={placeholder ? placeholder : "Select date"}
value={value && format(value, "yyyy-MM-dd")}
/>
Expand Down
67 changes: 0 additions & 67 deletions src/Components/Common/SearchBox.tsx

This file was deleted.

23 changes: 10 additions & 13 deletions src/Components/ExternalResult/ResultList.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import loadable from "@loadable/component";
import Grid from "@material-ui/core/Grid";
import { Button } from "@material-ui/core";
import CircularProgress from "@material-ui/core/CircularProgress";
import { navigate, useQueryParams } from "raviger";
import React, { useEffect, useState } from "react";
import { useDispatch } from "react-redux";
import { externalResultList } from "../../Redux/actions";
import Pagination from "../Common/Pagination";
import { InputSearchBox } from "../Common/SearchBox";
import { make as SlideOver } from "../Common/SlideOver.gen";
import ListFilter from "./ListFilter";
import moment from "moment";
Expand All @@ -18,6 +16,7 @@ import { FacilityModel } from "../Facility/models";
import clsx from "clsx";
import { PhoneNumberField } from "../Common/HelperInputFields";
import parsePhoneNumberFromString from "libphonenumber-js";
import SearchInput from "../Form/SearchInput";
const Loading = loadable(() => import("../Common/Loading"));
const PageTitle = loadable(() => import("../Common/PageTitle"));

Expand Down Expand Up @@ -364,17 +363,15 @@ export default function ResultList() {
</div>
</div>
<div className="mt-2">
<div>
<div className="text-sm font-semibold mb-2">Search by Name</div>
<InputSearchBox
search={searchByName}
value={qParams.name || ""}
placeholder="Search by Patient Name"
errors=""
/>
</div>
<div className="text-sm font-semibold my-2">Search by number</div>
<div className="w-full">
<SearchInput
label="Search by name"
name="name"
onChange={({ value }) => searchByName(value)}
value={qParams.name}
placeholder="Search patient"
/>
<div className="text-sm font-medium my-2">Search by number</div>
<div className="w-full max-w-sm">
<PhoneNumberField
value={qParams.mobile_number || "+91"}
onChange={(value: string) => searchByPhone(value)}
Expand Down
16 changes: 7 additions & 9 deletions src/Components/Facility/HospitalList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import loadable from "@loadable/component";
import { InputLabel, TextField } from "@material-ui/core";
import Pagination from "../Common/Pagination";
import { FacilityModel } from "./models";
import { InputSearchBox } from "../Common/SearchBox";
import { CSVLink } from "react-csv";
import moment from "moment";
import { Theme, createStyles, makeStyles } from "@material-ui/core/styles";
Expand All @@ -40,6 +39,7 @@ import * as Notification from "../../Utils/Notifications.js";
import { Modal } from "@material-ui/core";
import SelectMenu from "../Common/components/SelectMenu";
import AccordionV2 from "../Common/components/AccordionV2";
import SearchInput from "../Form/SearchInput";
const Loading = loadable(() => import("../Common/Loading"));
const PageTitle = loadable(() => import("../Common/PageTitle"));

Expand Down Expand Up @@ -656,14 +656,12 @@ export const HospitalList = (props: any) => {
</div>
</div>
<div className="flex my-4 gap-2 flex-col md:flex-row justify-between flex-grow">
<div className="w-full md:w-72">
<InputSearchBox
value={qParams.search}
search={onSearchSuspects}
placeholder={t("facility_search_placeholder")}
errors=""
/>
</div>
<SearchInput
name="search"
value={qParams.search}
onChange={({ value }) => onSearchSuspects(value)}
placeholder={t("facility_search_placeholder")}
/>

<div className="flex items-start mb-2 w-full md:w-auto">
<button
Expand Down
8 changes: 5 additions & 3 deletions src/Components/Form/FormFields/FormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ const FormField = (props: {

return (
<div className={className}>
<FieldLabel htmlFor={id} required={required} className={labelClassName}>
{label}
</FieldLabel>
{label && (
<FieldLabel htmlFor={id} required={required} className={labelClassName}>
{label}
</FieldLabel>
)}
{props.children}
<FieldErrorText
error={resolveFormFieldError(props.props)}
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Form/FormFields/TextAreaFormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const TextAreaFormField = ({ rows = 3, ...props }: TextAreaFormFieldProps) => {
<FormField props={props}>
<textarea
id={props.id}
className={`form-textarea ${bgColor} ${borderColor}`}
className={`text-sm block py-3 px-4 w-full rounded placeholder:text-gray-500 focus:bg-white border-2 focus:border-primary-400 outline-none ring-0 transition-all duration-200 ease-in-out resize-none ${bgColor} ${borderColor}`}
disabled={props.disabled}
rows={rows}
placeholder={props.placeholder}
Expand Down
105 changes: 80 additions & 25 deletions src/Components/Form/FormFields/TextFormField.tsx
Original file line number Diff line number Diff line change
@@ -1,45 +1,100 @@
import React from "react";
import FormField from "./FormField";
import {
FormFieldBaseProps,
resolveFormFieldChangeEventHandler,
resolveFormFieldError,
} from "./Utils";

type Props = FormFieldBaseProps<string> & {
export type TextFormFieldProps = FormFieldBaseProps<string> & {
placeholder?: string;
value?: string | number;
autoComplete?: string;
type?: "email" | "password" | "search" | "text";
// prefixIcon?: React.ReactNode;
// suffixIcon?: React.ReactNode;
className?: string | undefined;
removeDefaultClasses?: true | undefined;
leading?: React.ReactNode | undefined;
trailing?: React.ReactNode | undefined;
leadingFocused?: React.ReactNode | undefined;
trailingFocused?: React.ReactNode | undefined;
};

const TextFormField = (props: Props) => {
const TextFormField = React.forwardRef((props: TextFormFieldProps, ref) => {
const handleChange = resolveFormFieldChangeEventHandler(props);
const error = resolveFormFieldError(props);

const bgColor = error ? "bg-red-50" : "bg-gray-200";
const borderColor = error ? "border-red-500" : "border-gray-200";

return (
<FormField props={props}>
<input
id={props.id}
className={`form-input ${bgColor} ${borderColor}`}
disabled={props.disabled}
type={props.type || "text"}
placeholder={props.placeholder}
name={props.name}
value={props.value}
autoComplete={props.autoComplete}
required={props.required}
onChange={(event) => {
event.preventDefault();
handleChange(event.target);
}}
/>
</FormField>
const { leading, trailing } = props;
const leadingFocused = props.leadingFocused || props.leading;
const trailingFocused = props.trailingFocused || props.trailing;
const hasIcon = !!(leading || trailing || leadingFocused || trailingFocused);
const padding = `py-3 ${hasIcon ? "px-8" : "px-3"}`;

let child = (
<input
ref={ref as any}
id={props.id}
className={
props.removeDefaultClasses
? props.className
: `peer text-sm block ${padding} w-full rounded placeholder:text-gray-500 bg-gray-200 focus:bg-white border-2 focus:border-primary-400 outline-none ring-0 transition-all duration-200 ease-in-out ${borderColor} ${props.className}`
}
disabled={props.disabled}
type={props.type || "text"}
placeholder={props.placeholder}
name={props.name}
value={props.value}
autoComplete={props.autoComplete}
required={props.required}
onChange={(event) => {
event.preventDefault();
handleChange(event.target);
}}
/>
);
};

if (hasIcon) {
const _leading =
leading === leadingFocused ? (
<div className="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3">
{leading}
</div>
) : (
<>
<div className="opacity-100 peer-focus:opacity-0 translate-y-0 peer-focus:translate-y-1 pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3 transition-all duration-500 delay-300 ease-in-out">
{leading}
</div>
<div className="opacity-0 peer-focus:opacity-100 -translate-y-1 peer-focus:translate-y-0 pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3 transition-all duration-500 delay-300 ease-in-out">
{leadingFocused}
</div>
</>
);
const _trailing =
trailing === trailingFocused ? (
<div className="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3">
{trailing}
</div>
) : (
<>
<div className="opacity-100 peer-focus:opacity-0 translate-y-0 peer-focus:translate-y-1 pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3 transition-all duration-500 delay-300 ease-in-out">
{trailing}
</div>
<div className="opacity-0 peer-focus:opacity-100 -translate-y-1 peer-focus:translate-y-0 pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3 transition-all duration-500 delay-300 ease-in-out">
{trailingFocused}
</div>
</>
);

child = (
<div className="relative">
{(leading || leadingFocused) && _leading}
{child}
{(trailing || trailingFocused) && _trailing}
</div>
);
}

return <FormField props={props}>{child}</FormField>;
});

export default TextFormField;
2 changes: 1 addition & 1 deletion src/Components/Form/FormFields/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type FieldChangeEventHandler<T> = (event: FieldChangeEvent<T>) => void;
export type FormFieldBaseProps<T> = {
id?: string;
name: string;
label: React.ReactNode;
label?: React.ReactNode;
disabled?: boolean;
className?: string;
required?: boolean;
Expand Down
Loading

0 comments on commit c05c7cf

Please sign in to comment.