Files
OpenBB/frontend-components/tables/src/components/Table/DebouncedInput.tsx
jose-donato dbd466d381 New table design (#4485)
* fix: new table design

* fix: added trillions

* fixing some raw data

* fix: trying to fix global+resize

* feat: improving design

* fix: new styling and lot of reorganizing

* title fix

* feat: new html

* fix: bottom bar

* fix: table dates

* fix: table html

* fix: new filtering

* fix: new filtering

* fix: long

* Lint

* Lint again

* fix: beautiful james suggestions

* fix: some more fixes

* fix: typo

* fix economy bug

* feat: added toast to notify user and some more cleanup

* fix: more issues

* tests

* fix: james updates

* fix: added banner to charts as well

* fixing title

* better fix

* feat: added column resizing and any number of columns

* auto column width - poc

* feat: added colors toggle, support to display source, fixed some more issues

* fix: table deploy

* fix: table issue

* fix header

* fix: some fixes

* fix: remember pagination and default pagination to 30

* mypy

* Colins tests

* Fix economy test

---------

Co-authored-by: James Maslek <jmaslek11@gmail.com>
Co-authored-by: teh_coderer <me@tehcoderer.com>
Co-authored-by: andrewkenreich <andrew.kenreich@gmail.com>
2023-03-23 16:45:46 +00:00

62 lines
1.5 KiB
TypeScript
Vendored

import { FC, useEffect, useState } from "react";
type Props = {
value: string | number;
onChange: (value: string | number) => void;
debounce?: number;
} & Omit<React.InputHTMLAttributes<HTMLInputElement>, "onChange">;
const DebouncedInput: FC<Props> = ({
value: initialValue,
onChange,
debounce = 500,
...props
}) => {
const [value, setValue] = useState<number | string>(initialValue);
const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) =>
setValue(event.target.value);
useEffect(() => {
setValue(initialValue);
}, [initialValue]);
useEffect(() => {
const timeout = setTimeout(() => {
onChange(value);
}, debounce);
return () => clearTimeout(timeout);
}, [value]);
return (
<div className="relative group">
<div className="absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none">
<svg
aria-hidden="true"
className="w-5 h-5 text-grey-600"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"
></path>
</svg>
</div>
<input
{...props}
className="bg-grey-900 h-[36px] border-[1.5px] border-grey-700 rounded p-3 pl-10 max-w-[216px]"
value={value}
onChange={handleInputChange}
/>
</div>
);
};
export default DebouncedInput;