1
1
import * as React from 'react'
2
- import styled , { css } from 'styled-components'
2
+ import styled , { css , InterpolationValue } from 'styled-components'
3
3
import Icon from './icon'
4
4
import { MarginPadding , GlobalSizes } from '../commons'
5
5
import * as CSS from 'csstype'
6
6
7
+ type OverlayType = 'gradient' | 'dark'
8
+
9
+ const OverlayStyle : { [ key in OverlayType ] : InterpolationValue [ ] } = {
10
+ gradient : css `
11
+ background-color : rgba (0 , 0 , 0 , 0.8 );
12
+ ` ,
13
+ dark : css `
14
+ background-image : linear-gradient (
15
+ to bottom,
16
+ rgba (0 , 0 , 0 , 0.6 ),
17
+ rgba (0 , 0 , 0 , 0 )
18
+ );
19
+ ` ,
20
+ }
21
+
7
22
const IMAGE_HEIGHT_OPTIONS : Partial < Record < GlobalSizes , string > > = {
8
23
mini : '80px' ,
9
24
small : '110px' ,
@@ -52,20 +67,19 @@ const SourceUrl = styled.div`
52
67
const ImageOverlay = styled . div < {
53
68
borderRadius ?: number
54
69
overlayPadding ?: MarginPadding
70
+ overlayType ?: OverlayType
55
71
} > `
56
72
box-sizing: border-box;
57
73
position: absolute;
58
74
top: 0;
59
75
width: 100%;
60
76
height: 100%;
61
- background-image: linear-gradient(
62
- to bottom,
63
- rgba(0, 0, 0, 0.6),
64
- rgba(0, 0, 0, 0)
65
- );
77
+
66
78
border-radius: ${ ( { borderRadius } ) =>
67
79
borderRadius === 0 ? 0 : borderRadius || 6 } px;
68
80
81
+ ${ ( { overlayType = 'gradient' } ) => OverlayStyle [ overlayType ] }
82
+
69
83
${ ( { overlayPadding } ) =>
70
84
overlayPadding &&
71
85
css `
@@ -91,14 +105,16 @@ const ImageFrameContent = ({
91
105
ImageSource,
92
106
overlay,
93
107
overlayPadding,
108
+ overlayType,
94
109
withLinkIndicator,
95
110
} : {
96
111
imageUrl ?: string
97
112
borderRadius ?: number
98
113
sourceUrl ?: string
99
114
ImageSource ?: any
100
- overlay ?: boolean
115
+ overlay ?: React . ReactNode
101
116
overlayPadding ?: MarginPadding
117
+ overlayType ?: OverlayType
102
118
withLinkIndicator ?: boolean
103
119
} ) => (
104
120
< >
@@ -115,7 +131,11 @@ const ImageFrameContent = ({
115
131
</ SourceUrl >
116
132
) }
117
133
{ overlay && (
118
- < ImageOverlay borderRadius = { borderRadius } overlayPadding = { overlayPadding } >
134
+ < ImageOverlay
135
+ borderRadius = { borderRadius }
136
+ overlayPadding = { overlayPadding }
137
+ overlayType = { overlayType }
138
+ >
119
139
{ overlay }
120
140
</ ImageOverlay >
121
141
) }
@@ -208,6 +228,7 @@ function Image({
208
228
ImageSource,
209
229
overlay,
210
230
overlayPadding,
231
+ overlayType,
211
232
withLinkIndicator,
212
233
onClick,
213
234
floated,
@@ -223,8 +244,9 @@ function Image({
223
244
frame ?: GlobalSizes
224
245
size ?: GlobalSizes
225
246
ImageSource ?: any
226
- overlay ?: boolean
247
+ overlay ?: React . ReactNode
227
248
overlayPadding ?: MarginPadding
249
+ overlayType ?: OverlayType
228
250
withLinkIndicator ?: boolean
229
251
onClick ?: ( e ?: React . SyntheticEvent ) => any
230
252
floated ?: CSS . FloatProperty
@@ -278,6 +300,7 @@ function Image({
278
300
ImageSource = { ImageSource }
279
301
overlay = { overlay }
280
302
overlayPadding = { overlayPadding }
303
+ overlayType = { overlayType }
281
304
withLinkIndicator = { withLinkIndicator }
282
305
/>
283
306
) }
0 commit comments