2020-11-24 20:11:13 +00:00
|
|
|
import React, {
|
|
|
|
FormEvent,
|
|
|
|
Fragment,
|
|
|
|
MouseEventHandler,
|
|
|
|
ReactNode,
|
|
|
|
} from "react";
|
2020-08-24 18:11:17 +00:00
|
|
|
import {
|
|
|
|
Toolbar,
|
|
|
|
ToolbarContent,
|
|
|
|
ToolbarItem,
|
|
|
|
InputGroup,
|
|
|
|
TextInput,
|
|
|
|
Button,
|
2020-09-28 15:58:03 +00:00
|
|
|
ButtonVariant,
|
2020-09-01 14:51:59 +00:00
|
|
|
} from "@patternfly/react-core";
|
|
|
|
import { SearchIcon } from "@patternfly/react-icons";
|
2020-09-28 15:58:03 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
2020-08-24 18:11:17 +00:00
|
|
|
|
|
|
|
type TableToolbarProps = {
|
2020-10-07 15:47:03 +00:00
|
|
|
toolbarItem?: ReactNode;
|
|
|
|
toolbarItemFooter?: ReactNode;
|
2020-11-24 20:11:13 +00:00
|
|
|
children: ReactNode;
|
|
|
|
searchTypeComponent?: ReactNode;
|
2020-09-28 15:58:03 +00:00
|
|
|
inputGroupName?: string;
|
|
|
|
inputGroupPlaceholder?: string;
|
|
|
|
inputGroupOnChange?: (
|
|
|
|
newInput: string,
|
2020-11-24 20:11:13 +00:00
|
|
|
event: FormEvent<HTMLInputElement>
|
2020-09-28 15:58:03 +00:00
|
|
|
) => void;
|
2020-10-05 18:13:23 +00:00
|
|
|
inputGroupOnClick?: MouseEventHandler;
|
2020-08-24 18:11:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const TableToolbar = ({
|
|
|
|
toolbarItem,
|
2020-10-07 15:47:03 +00:00
|
|
|
toolbarItemFooter,
|
2020-08-24 18:11:17 +00:00
|
|
|
children,
|
2020-11-24 20:11:13 +00:00
|
|
|
searchTypeComponent,
|
2020-09-28 15:58:03 +00:00
|
|
|
inputGroupName,
|
|
|
|
inputGroupPlaceholder,
|
|
|
|
inputGroupOnChange,
|
2020-10-05 18:13:23 +00:00
|
|
|
inputGroupOnClick,
|
2020-08-24 18:11:17 +00:00
|
|
|
}: TableToolbarProps) => {
|
2020-10-07 15:47:03 +00:00
|
|
|
const { t } = useTranslation();
|
2020-08-24 18:11:17 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Toolbar>
|
|
|
|
<ToolbarContent>
|
2020-11-24 20:11:13 +00:00
|
|
|
<Fragment>
|
2020-09-28 15:58:03 +00:00
|
|
|
{inputGroupName && (
|
|
|
|
<ToolbarItem>
|
|
|
|
<InputGroup>
|
2020-11-24 20:11:13 +00:00
|
|
|
{searchTypeComponent}
|
2020-09-28 15:58:03 +00:00
|
|
|
<TextInput
|
|
|
|
name={inputGroupName}
|
|
|
|
id={inputGroupName}
|
|
|
|
type="search"
|
2020-10-07 15:47:03 +00:00
|
|
|
aria-label={t("search")}
|
2020-09-28 15:58:03 +00:00
|
|
|
placeholder={inputGroupPlaceholder}
|
|
|
|
onChange={inputGroupOnChange}
|
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
variant={ButtonVariant.control}
|
2020-10-07 15:47:03 +00:00
|
|
|
aria-label={t("search")}
|
2020-10-05 18:13:23 +00:00
|
|
|
onClick={inputGroupOnClick}
|
2020-09-28 15:58:03 +00:00
|
|
|
>
|
|
|
|
<SearchIcon />
|
|
|
|
</Button>
|
|
|
|
</InputGroup>
|
|
|
|
</ToolbarItem>
|
|
|
|
)}
|
2020-11-24 20:11:13 +00:00
|
|
|
</Fragment>
|
2020-09-28 15:58:03 +00:00
|
|
|
{toolbarItem}
|
2020-08-24 18:11:17 +00:00
|
|
|
</ToolbarContent>
|
|
|
|
</Toolbar>
|
|
|
|
{children}
|
2020-10-07 15:47:03 +00:00
|
|
|
<Toolbar>{toolbarItemFooter}</Toolbar>
|
2020-08-24 18:11:17 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|