Skip to content

Commit

Permalink
Blur range
Browse files Browse the repository at this point in the history
  • Loading branch information
psmyrdek committed Nov 8, 2017
1 parent f50b71c commit 595f16b
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 6 deletions.
37 changes: 37 additions & 0 deletions src/components/blur-range/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { h, Component } from 'preact';

export default class BlurRange extends Component {

constructor(props) {
super(props);
this.state = {
blurValue: 0
}
}

onRangeChange(value) {
this.setState(prevState => {
return {
...prevState,
blurValue: value
}
});
this.props.onChange(value);
}

render() {
return (
<div>
<p class="controlPanelTitle">Blur</p>
<input
type="range"
min="0"
max="20"
step="1"
value={this.state.blurValue}
onChange={(e) => this.onRangeChange(e.srcElement.value)}
/>
</div>
)
}
}
18 changes: 15 additions & 3 deletions src/components/generator-container/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { h, Component } from 'preact';
import ImagePreview from '../../components/image-preview';
import GradientPicker from '../../components/gradient-picker';
import BlurRange from '../../components/blur-range';
import style from './style';

export default class GeneratorContainer extends Component {
Expand All @@ -9,7 +10,8 @@ export default class GeneratorContainer extends Component {
super();
this.state = {
imageUrl: '',
gradientUrl: ''
gradientUrl: '',
blurValue: 0
};
}

Expand All @@ -31,6 +33,15 @@ export default class GeneratorContainer extends Component {
});
}

onBlurChange(blurValue) {
this.setState(prevState => {
return {
...prevState,
blurValue: blurValue
}
});
}

render() {

return (
Expand All @@ -43,13 +54,14 @@ export default class GeneratorContainer extends Component {
value={this.state.imageUrl}
onChange={e => this.updateImageUrl(e)}
/>
<div style="position: relative">
<ImagePreview imageUrl={this.state.imageUrl} />
<div class={style.imagePreviewContainer}>
<ImagePreview imageUrl={this.state.imageUrl} blurValue={this.state.blurValue} />
<img src={this.state.gradientUrl} style="position: absolute; top: 0" />
</div>
</div>
<div class={style.controlPanel}>
<GradientPicker onChange={this.onGradientChange.bind(this)} />
<BlurRange onChange={this.onBlurChange.bind(this)} />
</div>
</div>
)
Expand Down
5 changes: 5 additions & 0 deletions src/components/generator-container/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@
width: 100%;
margin-top: 10px;
padding: 0 5px;
}

.imagePreviewContainer {
position: relative;
overflow: hidden;
}
3 changes: 2 additions & 1 deletion src/components/gradient-picker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import style from './style';

export default (props) => {
return (
<div>
<div class={style.gradientPickerContainer}>
<p class="controlPanelTitle">Gradient</p>
<select class={style.gradientSelect} onChange={(e) => props.onChange(e.srcElement.value)}>
<option value="">Pick gradient style</option>
<option value="/assets/gradients/1.png">Style 1</option>
Expand Down
4 changes: 4 additions & 0 deletions src/components/gradient-picker/style.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.gradientSelect {
width: 100%;
}

.gradientPickerContainer {
margin-bottom: 20px;
}
4 changes: 2 additions & 2 deletions src/components/image-preview/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { h, Component } from 'preact';
import appConfig from '../../common/appConfig';

export default class GeneratorContainer extends Component {

Expand All @@ -15,7 +14,8 @@ export default class GeneratorContainer extends Component {

render(props, state) {
const previewStyle = Object.assign({}, this.imgPreviewStyle, {
'background-image': `url('${this.props.imageUrl}')`
'background-image': `url('${this.props.imageUrl}')`,
'filter': `blur(${this.props.blurValue}px)`
});

return (
Expand Down
6 changes: 6 additions & 0 deletions src/style/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@ html, body {

#app {
height: 100%;
}

.controlPanelTitle {
font-size: 10px;
margin: 0 0 10px 0;
padding: 0;
}

0 comments on commit 595f16b

Please sign in to comment.