Line data Source code
1 : /*
2 : * Copyright (C) 2019 Red Hat, Inc.
3 : * SPDX-License-Identifier: LGPL-2.1-or-later
4 : */
5 :
6 709 : import React from "react";
7 : import { Button } from "@patternfly/react-core/dist/esm/components/Button/index.js";
8 : import type { ButtonProps } from "@patternfly/react-core/dist/esm/components/Button/index.js";
9 : import {
10 : EmptyStateActions, EmptyState, EmptyStateBody, EmptyStateFooter, EmptyStateVariant
11 : } from "@patternfly/react-core/dist/esm/components/EmptyState/index.js";
12 : import type { EmptyStateProps } from "@patternfly/react-core/dist/esm/components/EmptyState/index.js";
13 : import { Spinner } from "@patternfly/react-core/dist/esm/components/Spinner/index.js";
14 : import "./cockpit-components-empty-state.css";
15 :
16 252 : export const EmptyStatePanel = ({
17 252 : title,
18 252 : paragraph,
19 252 : loading = false,
20 252 : icon,
21 252 : action,
22 252 : isActionInProgress = false,
23 252 : onAction,
24 252 : actionVariant = "primary",
25 252 : secondary,
26 252 : headingLevel = "h1"
27 252 : }: {
28 : title?: EmptyStateProps["titleText"],
29 : paragraph?: React.ReactNode,
30 : loading?: boolean,
31 : icon?: EmptyStateProps["icon"],
32 : action?: React.ReactNode | string,
33 : isActionInProgress?: boolean,
34 : onAction?: ButtonProps["onClick"],
35 : actionVariant?: ButtonProps["variant"],
36 : secondary?: React.ReactNode,
37 : headingLevel?: EmptyStateProps['headingLevel'],
38 252 : }) => {
39 52 : const slimType = title || paragraph ? "" : "slim";
40 77 : const emptyStateHeaderIcon = loading ? Spinner : icon;
41 :
42 252 : return (
43 252 : <EmptyState headingLevel={headingLevel} titleText={title} variant={EmptyStateVariant.full} {...emptyStateHeaderIcon && { icon: emptyStateHeaderIcon }}>
44 252 : <EmptyStateBody>
45 252 : {paragraph}
46 252 : </EmptyStateBody>
47 239 : {(action || secondary) &&
48 83 : <EmptyStateFooter>
49 73 : { action && (typeof action == "string"
50 51 : ? <Button variant={actionVariant} className={slimType}
51 51 : isLoading={isActionInProgress}
52 51 : isDisabled={isActionInProgress}
53 51 : onClick={onAction}>
54 51 : {action}
55 51 : </Button>
56 56 : : action)}
57 45 : { secondary && <EmptyStateActions>{secondary}</EmptyStateActions> }
58 83 : </EmptyStateFooter>}
59 252 : </EmptyState>
60 : );
61 252 : };
|