Skip to content

Commit a25066d

Browse files
committed
🔧
1 parent 5843d9e commit a25066d

File tree

8 files changed

+1761
-0
lines changed

8 files changed

+1761
-0
lines changed

Diff for: .gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#IDEs
2+
.idea
3+
14
# Logs
25
logs
36
*.log
@@ -35,3 +38,6 @@ jspm_packages
3538

3639
# Optional REPL history
3740
.node_repl_history
41+
42+
# Typescript
43+
build

Diff for: .idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: circle.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
machine:
2+
node:
3+
version: 6.9.1
4+
deployment:
5+
release:
6+
branch: master
7+
commands:
8+
- npm run release || true

Diff for: package.json

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "react-progressive-image",
3+
"version": "0.0.0-development",
4+
"description": "Progressively load images using a blur effect. Edit",
5+
"main": "build/index.js",
6+
"scripts": {
7+
"lint": "tslint --project tsconfig.json",
8+
"build": "tsc --pretty",
9+
"watch": "tsc --watch --pretty",
10+
"test": "npm run lint && npm run build",
11+
"release": "semantic-release pre && npm publish && semantic-release post"
12+
},
13+
"files": [
14+
"build"
15+
],
16+
"repository": {
17+
"type": "git",
18+
"url": "git+https://github.com/wcandillon/react-progressive-image.git"
19+
},
20+
"keywords": [
21+
"react",
22+
"image",
23+
"progressive",
24+
"image",
25+
"loading"
26+
],
27+
"author": "William Candillon",
28+
"license": "Apache-2.0",
29+
"bugs": {
30+
"url": "https://github.com/wcandillon/react-progressive-image/issues"
31+
},
32+
"homepage": "https://github.com/wcandillon/react-progressive-image#readme",
33+
"devDependencies": {
34+
"@types/react": "^15.0.23",
35+
"condition-circle": "^1.5.0",
36+
"semantic-release": "^6.3.2",
37+
"ts-npm-lint": "^0.1.0",
38+
"tslint": "^5.1.0",
39+
"typescript": "^2.3.2"
40+
}
41+
}

Diff for: src/index.tsx

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import * as React from "react";
2+
3+
interface ProgressiveImageProps extends React.HTMLProps<HTMLDivElement> {
4+
preview: string;
5+
src: string;
6+
background?: boolean;
7+
}
8+
9+
interface ProgressiveImageState {
10+
src: string;
11+
blur: number;
12+
}
13+
14+
class ProgressiveImage extends React.Component<ProgressiveImageProps, ProgressiveImageState> {
15+
16+
private clonedProps: React.HTMLProps<HTMLDivElement> = {};
17+
18+
componentWillMount() {
19+
const {src, preview} = this.props;
20+
this.setState({ src: preview, blur: 10 });
21+
this.cloneProps();
22+
fetch(src).then(() => this.setState({ src, blur: 0 }));
23+
}
24+
25+
render() {
26+
const {style} = this.props;
27+
return (
28+
<div>
29+
<style>{`
30+
@-webkit-keyframes blur {
31+
0% { -webkit-filter: blur(10px); }
32+
100% { -webkit-filter: blur(0); }
33+
}
34+
`}</style>
35+
<div style={Object.assign(this.getStyle(), style)} {...this.clonedProps} />
36+
</div>
37+
);
38+
}
39+
40+
private cloneProps() {
41+
Object.keys(this.props)
42+
.filter(prop => ["style", "src", "preview", "background"].indexOf(prop) === -1)
43+
.forEach(prop => this.clonedProps[prop] = this.props[prop]);
44+
}
45+
46+
private getStyle() {
47+
const {src, blur} = this.state;
48+
return {
49+
backgroundImage: `url(${src})`,
50+
filter: `blur(${blur}px)`,
51+
animation: "blur 400ms",
52+
animationTimingFunction: "ease"
53+
};
54+
}
55+
}

Diff for: tsconfig.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es6",
4+
"module": "es6",
5+
"moduleResolution": "node",
6+
"jsx": "react",
7+
"outDir": "build",
8+
"rootDir": "src",
9+
"allowSyntheticDefaultImports": true,
10+
"noImplicitAny": true,
11+
"experimentalDecorators": true,
12+
"preserveConstEnums": true,
13+
"sourceMap": true,
14+
"strictNullChecks": true,
15+
"declaration": true
16+
},
17+
"filesGlob": [
18+
"src/**/*.ts",
19+
"src/**/*.tsx"
20+
],
21+
"exclude": [
22+
"build",
23+
"node_modules"
24+
],
25+
"compileOnSave": false
26+
}

Diff for: tslint.json

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"rules": {
3+
"class-name": true,
4+
"comment-format": [
5+
true,
6+
"check-space"
7+
],
8+
"indent": [
9+
true,
10+
"spaces"
11+
],
12+
"no-unused-variable": [true, {"ignore-pattern": "React"}],
13+
"no-duplicate-variable": true,
14+
"no-eval": true,
15+
"no-internal-module": true,
16+
"no-trailing-whitespace": true,
17+
"no-unsafe-finally": true,
18+
"no-var-keyword": true,
19+
"one-line": [
20+
true,
21+
"check-open-brace",
22+
"check-whitespace"
23+
],
24+
"quotemark": [
25+
true,
26+
"double"
27+
],
28+
"semicolon": [
29+
true,
30+
"always"
31+
],
32+
"triple-equals": [
33+
true,
34+
"allow-null-check"
35+
],
36+
"typedef-whitespace": [
37+
true,
38+
{
39+
"call-signature": "nospace",
40+
"index-signature": "nospace",
41+
"parameter": "nospace",
42+
"property-declaration": "nospace",
43+
"variable-declaration": "nospace"
44+
}
45+
],
46+
"variable-name": [
47+
true,
48+
"ban-keywords"
49+
],
50+
"whitespace": [
51+
true,
52+
"check-branch",
53+
"check-decl",
54+
"check-operator",
55+
"check-separator",
56+
"check-type"
57+
]
58+
}
59+
}

0 commit comments

Comments
 (0)