keycloak-scim/js/apps/admin-ui/src/components/keycloak-card/KeycloakCard.tsx

77 lines
1.7 KiB
TypeScript
Raw Normal View History

import {
Card,
CardActions,
CardBody,
CardFooter,
CardHeader,
CardTitle,
Dropdown,
2020-11-18 15:06:56 +00:00
Flex,
FlexItem,
KebabToggle,
Label,
} from "@patternfly/react-core";
import { ReactElement, useState } from "react";
import { Link, To } from "react-router-dom";
import "./keycloak-card.css";
export type KeycloakCardProps = {
title: string;
dropdownItems?: ReactElement[];
labelText?: string;
labelColor?: any;
footerText?: string;
to: To;
};
export const KeycloakCard = ({
title,
dropdownItems,
labelText,
labelColor,
footerText,
to,
}: KeycloakCardProps) => {
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
const onDropdownToggle = () => {
setIsDropdownOpen(!isDropdownOpen);
};
return (
<Card isSelectable>
<CardHeader>
<CardActions>
{dropdownItems && (
<Dropdown
2021-02-19 21:22:05 +00:00
data-testid={`${title}-dropdown`}
isPlain
position={"right"}
toggle={<KebabToggle onToggle={onDropdownToggle} />}
isOpen={isDropdownOpen}
dropdownItems={dropdownItems}
/>
)}
</CardActions>
<CardTitle data-testid="keycloak-card-title">
<Link to={to}>{title}</Link>
</CardTitle>
</CardHeader>
<CardBody />
<CardFooter>
2020-11-18 15:06:56 +00:00
<Flex>
<FlexItem className="keycloak--keycloak-card__footer">
{footerText && footerText}
</FlexItem>
<FlexItem>
{labelText && (
<Label color={labelColor || "gray"}>{labelText}</Label>
)}
</FlexItem>
</Flex>
</CardFooter>
</Card>
);
};