This repository was archived by the owner on Oct 4, 2022. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathCard.js
More file actions
156 lines (136 loc) · 3.01 KB
/
Copy pathCard.js
File metadata and controls
156 lines (136 loc) · 3.01 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import React, { Fragment } from "react";
import PropTypes from "prop-types";
import styled from "styled-components";
/* Yoast dependencies */
import { colors } from "@yoast/style-guide";
import { makeOutboundLink } from "@yoast/helpers";
/* Internal dependencies */
import Banner from "./CardBanner";
const Container = styled.div`
position: relative;
display: flex;
flex-direction: column;
background-color: ${ colors.$color_white };
width: 100%;
box-shadow: 0 2px 4px 0 rgba(0,0,0,0.2);
`;
const HeaderImage = styled.img`
width: 100%;
vertical-align: bottom;
`;
const Content = styled.div`
padding: 12px 16px;
display: flex;
flex-direction: column;
flex-grow: 1;
`;
const HeaderLink = styled.a`
text-decoration: none;
color: ${ colors.$color_pink_dark };
/* IE11 bug header image height see https://github.com/philipwalton/flexbugs#flexbug-5 */
overflow: hidden;
&:hover,
&:focus,
&:active {
text-decoration: underline;
color: ${ colors.$color_pink_dark };
}
&:focus,
&:active {
box-shadow: none;
}
`;
const HeaderTitle = styled.h2`
margin: 16px 16px 0 16px;
font-weight: 400;
font-size: 1.5em;
line-height: 1.2;
color: currentColor;
`;
const OutboundHeaderLink = makeOutboundLink( HeaderLink );
/**
* Card component.
*/
class Card extends React.Component {
/**
* Returns the header image and title, with a link if provided.
*
* @returns {React.Component} The header image.
*/
getHeader() {
if ( ! this.props.header ) {
return null;
}
if ( this.props.header.link ) {
return (
<OutboundHeaderLink href={ this.props.header.link }>
<HeaderImage src={ this.props.header.image } alt="" />
<HeaderTitle>{ this.props.header.title }</HeaderTitle>
</OutboundHeaderLink>
);
}
return (
<Fragment>
<HeaderImage src={ this.props.header.image } alt="" />;
<HeaderTitle>{ this.props.header.title }</HeaderTitle>
</Fragment>
);
}
/**
* Gets the banner if a banner text is provided.
*
* @returns {React.Component} The banner or null.
*/
getBanner() {
if ( ! this.props.banner ) {
return null;
}
return (
<Banner { ...this.props.banner }>
{ this.props.banner.text }
</Banner>
);
}
/**
* Renders the component.
*
* @returns {ReactElement} The rendered component.
*/
render() {
return (
<Container className={ this.props.className } id={ this.props.id }>
{ this.getHeader() }
{ this.getBanner() }
<Content>
{ this.props.children }
</Content>
</Container>
);
}
}
export default Card;
export const FullHeightCard = styled( Card )`
height: 100%;
`;
Card.propTypes = {
className: PropTypes.string,
id: PropTypes.string,
header: PropTypes.shape( {
title: PropTypes.string,
image: PropTypes.string.isRequired,
link: PropTypes.string,
} ),
banner: PropTypes.shape( {
text: PropTypes.string.isRequired,
textColor: PropTypes.string,
backgroundColor: PropTypes.string,
} ),
children: PropTypes.any,
};
Card.defaultProps = {
className: "",
id: "",
header: null,
banner: null,
children: null,
};