Line data Source code
1 : /*
2 : * Copyright (C) 2019 Red Hat, Inc.
3 : * SPDX-License-Identifier: LGPL-2.1-or-later
4 : */
5 :
6 708 : 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 223 : export const EmptyStatePanel = ({
17 223 : title,
18 223 : paragraph,
19 223 : loading = false,
20 223 : icon,
21 223 : action,
22 223 : isActionInProgress = false,
23 223 : onAction,
24 223 : actionVariant = "primary",
25 223 : secondary,
26 223 : headingLevel = "h1"
27 223 : }: {
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 223 : }) => {
39 51 : const slimType = title || paragraph ? "" : "slim";
40 75 : const emptyStateHeaderIcon = loading ? Spinner : icon;
41 :
42 223 : return (
43 223 : <EmptyState headingLevel={headingLevel} titleText={title} variant={EmptyStateVariant.full} {...emptyStateHeaderIcon && { icon: emptyStateHeaderIcon }}>
44 223 : <EmptyStateBody>
45 223 : {paragraph}
46 223 : </EmptyStateBody>
47 210 : {(action || secondary) &&
48 81 : <EmptyStateFooter>
49 71 : { action && (typeof action == "string"
50 50 : ? <Button variant={actionVariant} className={slimType}
51 50 : isLoading={isActionInProgress}
52 50 : isDisabled={isActionInProgress}
53 50 : onClick={onAction}>
54 50 : {action}
55 50 : </Button>
56 54 : : action)}
57 44 : { secondary && <EmptyStateActions>{secondary}</EmptyStateActions> }
58 81 : </EmptyStateFooter>}
59 223 : </EmptyState>
60 : );
61 223 : };
|