2020-10-16 13:16:01 +00:00
|
|
|
import React from "react";
|
2021-03-07 11:57:26 +00:00
|
|
|
import AvatarEditorComponent from "./";
|
2021-03-02 10:08:26 +00:00
|
|
|
import Avatar from "../avatar";
|
|
|
|
|
|
|
|
export default {
|
|
|
|
title: "Components/AvatarEditor",
|
2021-03-07 11:57:26 +00:00
|
|
|
component: AvatarEditorComponent,
|
2021-03-02 10:08:26 +00:00
|
|
|
argTypes: {
|
|
|
|
openEditor: { action: "onOpen", table: { disable: true } },
|
|
|
|
closeEditor: { action: "onClose", table: { disable: true } },
|
|
|
|
onSave: { action: "onSave", table: { disable: true } },
|
|
|
|
onLoadFile: { action: "onLoadFile", table: { disable: true } },
|
|
|
|
onImageChange: { action: "onImageChange", table: { disable: true } },
|
|
|
|
onDeleteImage: { action: "onDeleteImage", table: { disable: true } },
|
|
|
|
},
|
|
|
|
parameters: {
|
|
|
|
docs: {
|
|
|
|
description: {
|
|
|
|
component: "Used to display user avatar editor on page.",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-03-07 11:57:26 +00:00
|
|
|
class AvatarEditor extends React.Component {
|
2021-03-02 10:08:26 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
isOpen: false,
|
|
|
|
userImage: null,
|
|
|
|
};
|
|
|
|
|
|
|
|
this.openEditor = this.openEditor.bind(this);
|
|
|
|
this.onClose = this.onClose.bind(this);
|
|
|
|
this.onSave = this.onSave.bind(this);
|
|
|
|
this.onLoadFile = this.onLoadFile.bind(this);
|
|
|
|
this.onImageChange = this.onImageChange.bind(this);
|
|
|
|
this.onDeleteImage = this.onDeleteImage.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
onDeleteImage() {
|
|
|
|
this.props.onDeleteImage();
|
|
|
|
}
|
|
|
|
onImageChange(img) {
|
|
|
|
this.props.onImageChange(img);
|
|
|
|
this.setState({
|
|
|
|
userImage: img,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
onLoadFile(file) {
|
|
|
|
this.props.onLoadFile(file);
|
|
|
|
}
|
|
|
|
onSave(isUpdate, data) {
|
|
|
|
this.props.onSave(isUpdate, data);
|
|
|
|
this.setState({
|
|
|
|
isOpen: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
openEditor(e) {
|
|
|
|
this.props.openEditor(e);
|
|
|
|
this.setState({
|
|
|
|
isOpen: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
onClose() {
|
|
|
|
this.props.closeEditor();
|
|
|
|
this.setState({
|
|
|
|
isOpen: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
unknownError,
|
|
|
|
unknownTypeError,
|
|
|
|
saveButtonLoading,
|
|
|
|
maxSizeFileError,
|
|
|
|
} = this.props;
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Avatar
|
|
|
|
size="max"
|
|
|
|
role="user"
|
|
|
|
source={this.state.userImage}
|
|
|
|
editing={true}
|
|
|
|
editAction={this.openEditor}
|
|
|
|
/>
|
|
|
|
{this.props.children}
|
2021-03-07 11:57:26 +00:00
|
|
|
<AvatarEditorComponent
|
2021-03-02 10:08:26 +00:00
|
|
|
{...this.props}
|
|
|
|
visible={this.state.isOpen || this.props.visible}
|
|
|
|
onClose={this.onClose}
|
|
|
|
onSave={this.onSave}
|
|
|
|
onDeleteImage={this.onDeleteImage}
|
|
|
|
onImageChange={this.onImageChange}
|
|
|
|
onLoadFile={this.onLoadFile}
|
|
|
|
chooseFileLabel={"Drop files here, or click to select files"}
|
|
|
|
chooseMobileFileLabel={"Click to select files"}
|
|
|
|
saveButtonLoading={saveButtonLoading}
|
|
|
|
maxSizeFileError={maxSizeFileError || "Maximum file size exceeded"}
|
|
|
|
unknownTypeError={unknownTypeError || "Unknown image file type"}
|
|
|
|
unknownError={unknownError || "Error"}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const Template = (args) => {
|
2021-03-07 11:57:26 +00:00
|
|
|
return <AvatarEditor {...args} />;
|
2021-03-02 10:08:26 +00:00
|
|
|
};
|
|
|
|
export const Default = Template.bind({});
|