| 1 |
import { css } from '@patternfly/react-styles'; |
| 2 |
import styles from '@patternfly/react-styles/css/components/EmptyState/empty-state'; |
| 3 |
import { EmptyStateHeader } from './EmptyStateHeader'; |
| 4 |
import { statusIcons } from '../../helpers'; |
| 5 |
|
| 6 |
export enum EmptyStateVariant { |
| 7 |
'xs' = 'xs', |
| 8 |
sm = 'sm', |
| 9 |
lg = 'lg', |
| 10 |
'xl' = 'xl', |
| 11 |
full = 'full' |
| 12 |
} |
| 13 |
|
| 14 |
export enum EmptyStateStatus { |
| 15 |
danger = 'danger', |
| 16 |
warning = 'warning', |
| 17 |
success = 'success', |
| 18 |
info = 'info', |
| 19 |
custom = 'custom' |
| 20 |
} |
| 21 |
|
| 22 |
export interface EmptyStateProps extends React.HTMLProps<HTMLDivElement> { |
| 23 |
/** Additional classes added to the empty state */ |
| 24 |
className?: string; |
| 25 |
/** Content rendered inside the empty state */ |
| 26 |
children?: React.ReactNode; |
| 27 |
/** Modifies empty state max-width and sizes of icon, title and body */ |
| 28 |
variant?: 'xs' | 'sm' | 'lg' | 'xl' | 'full'; |
| 29 |
/** Cause component to consume the available height of its container */ |
| 30 |
isFullHeight?: boolean; |
| 31 |
/** Status of the empty state, will set a default status icon and color. Icon can be overwritten using the icon prop */ |
| 32 |
status?: 'danger' | 'warning' | 'success' | 'info' | 'custom'; |
| 33 |
/** Additional class names to apply to the empty state header */ |
| 34 |
headerClassName?: string; |
| 35 |
/** Additional classes added to the title inside empty state header */ |
| 36 |
titleClassName?: string; |
| 37 |
/** Text of the title inside empty state header, will be wrapped in headingLevel */ |
| 38 |
titleText?: React.ReactNode; |
| 39 |
/** Empty state icon element to be rendered. Can also be a spinner component */ |
| 40 |
icon?: React.ComponentType<any>; |
| 41 |
/** The heading level to use, default is h1 */ |
| 42 |
headingLevel?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'; |
| 43 |
} |
| 44 |
|
| 45 |
export const EmptyState: React.FunctionComponent<EmptyStateProps> = ({ |
| 46 |
children, |
| 47 |
className, |
| 48 |
variant = EmptyStateVariant.full, |
| 49 |
isFullHeight, |
| 50 |
status, |
| 51 |
icon: customIcon, |
| 52 |
titleText, |
| 53 |
titleClassName, |
| 54 |
headerClassName, |
| 55 |
headingLevel, |
| 56 |
...props |
| 57 |
}: EmptyStateProps) => { |
| 58 |
const statusIcon = status && statusIcons[status]; |
| 59 |
const icon = customIcon || statusIcon; |
| 60 |
|
| 61 |
return ( |
| 62 |
<div |
| 63 |
className={css( |
| 64 |
styles.emptyState, |
| 65 |
variant !== 'full' && styles.modifiers[variant], |
| 66 |
isFullHeight && styles.modifiers.fullHeight, |
| 67 |
status && styles.modifiers[status], |
| 68 |
className |
| 69 |
)} |
| 70 |
{...props} |
| 71 |
> |
| 72 |
<div className={css(styles.emptyStateContent)}> |
| 73 |
<EmptyStateHeader |
| 74 |
icon={icon} |
| 75 |
titleText={titleText} |
| 76 |
titleClassName={titleClassName} |
| 77 |
className={headerClassName} |
| 78 |
headingLevel={headingLevel} |
| 79 |
/> |
| 80 |
{children} |
| 81 |
</div> |
| 82 |
</div> |
| 83 |
); |
| 84 |
}; |
| 85 |
EmptyState.displayName = 'EmptyState'; |