Skip to content

Commit

Permalink
allow avatar removal
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Dec 15, 2018
1 parent 31190ec commit 405ce75
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 6 deletions.
14 changes: 14 additions & 0 deletions css/base.css
Expand Up @@ -868,6 +868,7 @@ i.search {
/* Styling of avatar upload control */
.avatar-upload {
display: flex;
position: relative;
flex-direction: column;
flex-shrink: 0;
width: 7rem;
Expand All @@ -877,6 +878,19 @@ i.search {
padding: 0;
}

.avatar-upload .clear-avatar {
position: absolute;
font-size: 1rem;
top: 0;
right: 0;
opacity: 0;
background-image: radial-gradient(#fff 40%, transparent 75%);
}

.avatar-upload:hover .clear-avatar {
opacity: 1;
}

.avatar-upload .avatar-box {
position: relative;
width: 7rem;
Expand Down
2 changes: 1 addition & 1 deletion css/base.min.css

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions src/widgets/avatar-upload.jsx
Expand Up @@ -14,6 +14,7 @@ export default class AvatarUpload extends React.Component {
};

this.handleFileUpload = this.handleFileUpload.bind(this);
this.handleClear = this.handleClear.bind(this);
}

static getDerivedStateFromProps(nextProps, prevState) {
Expand Down Expand Up @@ -41,12 +42,21 @@ export default class AvatarUpload extends React.Component {
e.target.value = '';
}

handleClear() {
this.props.onImageChanged(null);
}

render() {
// Randomize id value in case more than one AvatarUpload is shown
// at the same time.
var randId = "file-input-avatar-" + (Math.random() + '').substr(2);
return (
<div className="avatar-upload">
{this.props.readOnly || !this.state.dataUrl ?
null :
<a href="javascript:;" className="clear-avatar" onClick={this.handleClear}>
<i className="material-icons">clear</i>
</a>}
{this.state.dataUrl ?
<img src={this.state.dataUrl} className="preview" /> :
this.props.readOnly && this.props.uid ?
Expand Down
16 changes: 14 additions & 2 deletions umd/index.dev.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion umd/index.dev.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion umd/index.prod.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion umd/index.prod.js.map

Large diffs are not rendered by default.

0 comments on commit 405ce75

Please sign in to comment.