Skip to content
This repository has been archived by the owner on Jun 5, 2022. It is now read-only.

Add 'customIcon' parameter to allow for setting a custom icon. Needed… #244

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 25 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,30 +67,31 @@ export default App;
```
### Available Options

| parameter | type | default | description |
| :-------------: | :------: | :--------------------------------: | :------------------------------------------------------------ |
| className | String | - | Class name for the input. |
| onChange | Function | - | On change handler for the input. |
| buttonClassName | String | - | Class name for upload button. |
| buttonStyles | Object | - | Inline styles for upload button. |
| withPreview | Boolean | false | Show preview of selected images. |
| defaultImages | Array | ['imgUrl1', 'imgUrl2'] | Pre-populate with default images. |
| accept | String | "accept=image/\*" | Accept attribute for file input. |
| name | String | - | Input name. |
| withIcon | Boolean | true | If true, show upload icon on top |
| buttonText | String | 'Choose images' | The text that display in the button. |
| buttonType | String | 'submit' | The value of the button's "type" attribute. |
| withLabel | Boolean | true | Show instruction label |
| label | String | 'Max file size: 5mb, accepted: jpg, gif, png | Label text |
| labelStyles | Object | - | Inline styles for the label. |
| labelClass | string | - | Class name for the label |
| imgExtension | Array | ['.jpg', '.gif', '.png', '.gif'] | Supported image extension (will use in the image validation). |
| maxFileSize | Number | 5242880 | Max image size. |
| fileSizeError | String | " file size is too big" | Label for file size error message. |
| fileTypeError | String | " is not supported file extension" | Label for file extension error message. |
| errorClass | String | - | Class for error messages |
| errorStyle | Object | - | Inline styles for errors |
| singleImage | Boolean | false | Upload one single image |
| parameter | type | default | description |
| :-------------: | :------: | :--------------------------------: | :---------------------------------------------------------------|
| className | String | - | Class name for the input. |
| onChange | Function | - | On change handler for the input. |
| buttonClassName | String | - | Class name for upload button. |
| buttonStyles | Object | - | Inline styles for upload button. |
| withPreview | Boolean | false | Show preview of selected images. |
| defaultImages | Array | ['imgUrl1', 'imgUrl2'] | Pre-populate with default images. |
| accept | String | "accept=image/\*" | Accept attribute for file input. |
| name | String | - | Input name. |
| withIcon | Boolean | true | If true, show upload icon on top |
| customIcon | Object | - | Override default icon. e.g Dark-mode icon (included), or custom |
| buttonText | String | 'Choose images' | The text that display in the button. |
| buttonType | String | 'submit' | The value of the button's "type" attribute. |
| withLabel | Boolean | true | Show instruction label |
| label | String | 'Max file size: 5mb, accepted: jpg, gif, png | Label text |
| labelStyles | Object | - | Inline styles for the label. |
| labelClass | string | - | Class name for the label |
| imgExtension | Array | ['.jpg', '.gif', '.png', '.gif'] | Supported image extension (will use in the image validation). |
| maxFileSize | Number | 5242880 | Max image size. |
| fileSizeError | String | " file size is too big" | Label for file size error message. |
| fileTypeError | String | " is not supported file extension" | Label for file extension error message. |
| errorClass | String | - | Class for error messages |
| errorStyle | Object | - | Inline styles for errors |
| singleImage | Boolean | false | Upload one single image |

### Development

Expand Down
22 changes: 22 additions & 0 deletions src/component/UploadIconDarkMode.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/component/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface Props {
accept?: string
name?: string
withIcon?: boolean
customIcon?: object
buttonText?: string
withLabel?: boolean
label?: string
Expand Down
8 changes: 7 additions & 1 deletion src/component/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ReactImageUploadComponent extends React.Component {
}

/*
Load image at the beggining if defaultImage prop exists
Load image at the beginning if defaultImage prop exists
*/
componentWillReceiveProps(nextProps){
if(nextProps.defaultImages !== this.props.defaultImages){
Expand Down Expand Up @@ -162,6 +162,10 @@ class ReactImageUploadComponent extends React.Component {
Render the upload icon
*/
renderIcon() {
if (this.props.withIcon && Object.keys(this.props.customIcon).length !== 0) {
return <img src={this.props.customIcon} className="uploadIcon" alt="Upload Icon" />;
}

if (this.props.withIcon) {
return <img src={UploadIcon} className="uploadIcon" alt="Upload Icon" />;
}
Expand Down Expand Up @@ -253,6 +257,7 @@ ReactImageUploadComponent.defaultProps = {
accept: "image/*",
name: "",
withIcon: true,
customIcon: {},
buttonText: "Choose images",
buttonType: "button",
withLabel: true,
Expand Down Expand Up @@ -284,6 +289,7 @@ ReactImageUploadComponent.propTypes = {
accept: PropTypes.string,
name: PropTypes.string,
withIcon: PropTypes.bool,
customIcon: PropTypes.object,
buttonText: PropTypes.string,
withLabel: PropTypes.bool,
label: PropTypes.string,
Expand Down
Loading