Skip to content

Commit ee7a999

Browse files
authored
fix(component): Minor improvements
Minor improvements
2 parents 2ffcc48 + 5ff46bc commit ee7a999

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,12 @@ You can also customize the transition time and the timing function used for that
3333
transitionFunction="ease"
3434
/>
3535
```
36+
37+
In case of `background=true`, it is possible to add some layers on top of the background image, for instance:
38+
39+
```jsx
40+
<ProgressiveImage
41+
preview="/images/tiny-preview.png" src="/images/preview.png" background={true}
42+
backgroundImages={["linear-gradient(to top, rgba(31,31,31,0.3), rgba(31,31,31,0.3))"]}
43+
/>
44+
```

src/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export interface ProgressiveImageProps {
77
preview: string;
88
src: string;
99
background?: boolean;
10+
backgroundImages?: string[];
1011
transitionTime?: number;
1112
timingFunction?: string;
1213
}
@@ -53,7 +54,7 @@ export class ProgressiveImage extends React.Component<ProgressiveImageProps & Di
5354

5455
private cloneProps() {
5556
Object.keys(this.props)
56-
.filter(prop => ["style", "src", "preview", "background", "transitionTime", "timingFunction"].indexOf(prop) === -1)
57+
.filter(prop => ["style", "src", "preview", "background", "transitionTime", "timingFunction", "backgroundImages", "children"].indexOf(prop) === -1)
5758
.forEach(prop => this.clonedProps[prop] = this.props[prop]);
5859
}
5960

@@ -68,8 +69,9 @@ export class ProgressiveImage extends React.Component<ProgressiveImageProps & Di
6869

6970
private getBackgroundStyle() {
7071
const {src} = this.state;
72+
const {backgroundImages} = this.props;
7173
const style = {
72-
backgroundImage: `url(${src})`
74+
backgroundImage: `${backgroundImages ? `${backgroundImages.join(",")},` : ""}url(${src})`
7375
};
7476
return Object.assign(style, this.getStyle());
7577
}

0 commit comments

Comments
 (0)