-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
EmptyState.tsx
106 lines (95 loc) · 2.83 KB
/
EmptyState.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import * as React from 'react';
import {classNames} from '@shopify/css-utilities';
import {Action} from '../../types';
import Image from '../Image';
import {buttonFrom} from '../Button';
import Stack from '../Stack';
import TextContainer from '../TextContainer';
import DisplayText from '../DisplayText';
import styles from './EmptyState.scss';
export interface Props {
/** The empty state heading */
heading?: string;
/** The image to use for small screens */
image: string;
/** The image to use for large screens */
largeImage?: string;
/** The image to use for large screens */
imageContained?: boolean;
/** Elements to display inside empty state */
children?: React.ReactNode;
/** Primary action for empty state */
action: Action;
/** Secondary action for empty state */
secondaryAction?: Action;
/** Secondary elements to display below empty state actions */
footerContent?: React.ReactNode;
}
export default class EmptyState extends React.PureComponent<Props, never> {
render() {
const {
children,
heading,
image,
largeImage,
imageContained,
action,
secondaryAction,
footerContent,
} = this.props;
const className = classNames(
styles.EmptyState,
imageContained && styles.imageContained,
);
const imageMarkup = largeImage ? (
<Image
alt=""
role="presentation"
className={styles.Image}
source={largeImage}
sourceSet={[
{source: image, descriptor: '568w'},
{source: largeImage, descriptor: '1136w'},
]}
sizes="(max-width: 568px) 60vw"
/>
) : (
<Image
role="presentation"
alt=""
className={styles.Image}
source={image}
/>
);
const secondaryActionMarkup = secondaryAction
? buttonFrom(secondaryAction, {plain: true})
: null;
const footerContentMarkup = footerContent ? (
<div className={styles.FooterContent}>
<TextContainer>{footerContent}</TextContainer>
</div>
) : null;
return (
<div className={className}>
<div className={styles.Section}>
<div className={styles.DetailsContainer}>
<div className={styles.Details}>
<TextContainer>
<DisplayText size="medium">{heading}</DisplayText>
<div className={styles.Content}>{children}</div>
</TextContainer>
<div className={styles.Actions}>
<Stack alignment="center">
{buttonFrom(action, {primary: true, size: 'large'})}
{secondaryActionMarkup}
</Stack>
</div>
{footerContentMarkup}
</div>
</div>
<div className={styles.ImageContainer}>{imageMarkup}</div>
</div>
</div>
);
}
}