Skip to content

Commit

Permalink
✨ add disabled prop to the input
Browse files Browse the repository at this point in the history
  • Loading branch information
jarrisondev committed Jan 27, 2022
1 parent 8535ef3 commit 6803e0d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,23 @@ npm run build

## Props


`id` - *String*

Default: `file`

id to the input file

---

`disabled` - *Boolean*

Default: `false`

boolean for disabled input

---

`onChange(files)` - *Function*

Perform work on files added when submit is clicked.
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 18 additions & 13 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react'
import PropTypes from 'prop-types'

const mimeTypeRegexp = /^(application|audio|example|image|message|model|multipart|text|video)\/[a-z0-9\.\+\*-]+$/;
const extRegexp = /\.[a-zA-Z0-9]*$/;
const mimeTypeRegexp = /^(application|audio|example|image|message|model|multipart|text|video)\/[a-z0-9\.\+\*-]+$/
const extRegexp = /\.[a-zA-Z0-9]*$/

class Files extends React.Component {
constructor (props, context) {
Expand Down Expand Up @@ -101,7 +101,7 @@ class Files extends React.Component {
}

fileTypeAcceptable (file) {
let accepts = this.props.accepts;
let accepts = this.props.accepts
if (!accepts) {
return true
}
Expand All @@ -121,11 +121,11 @@ class Files extends React.Component {
}
}
} else if (file.extension && accept.match(extRegexp)) {
const ext = accept.substr(1);
return file.extension.toLowerCase() === ext.toLowerCase();
const ext = accept.substr(1)
return file.extension.toLowerCase() === ext.toLowerCase()
}
return false
});
})

if (!result) {
this.onError({
Expand Down Expand Up @@ -210,6 +210,8 @@ class Files extends React.Component {
accept: this.props.accepts ? this.props.accepts.join() : '',
multiple: this.props.multiple,
name: this.props.name,
id: this.props.id,
disabled: this.props.disabled,
style: { display: 'none' },
ref: (element) => {
this.inputElement = element
Expand All @@ -221,7 +223,6 @@ class Files extends React.Component {
<div>
<input
{...inputAttributes}
id={this.props.id || ''}
/>
<div
className={this.props.className}
Expand All @@ -230,10 +231,10 @@ class Files extends React.Component {
? this.openFileChooser
: null
}
onDrop={this.onDrop}
onDragOver={this.onDragOver}
onDragEnter={this.onDragEnter}
onDragLeave={this.onDragLeave}
onDrop={inputAttributes.disabled ? () => {} : this.onDrop}
onDragOver={inputAttributes.disabled ? () => {} : this.onDragOver}
onDragEnter={inputAttributes.disabled ? () => {} : this.onDragEnter}
onDragLeave={inputAttributes.disabled ? () => {} : this.onDragLeave}
ref={dropzone => { this.dropzone = dropzone }}
style={this.props.style}
>
Expand All @@ -260,7 +261,9 @@ Files.propTypes = {
minFileSize: PropTypes.number,
clickable: PropTypes.bool,
name: PropTypes.string,
style: PropTypes.object
style: PropTypes.object,
id: PropTypes.string,
disabled: PropTypes.bool
}

Files.defaultProps = {
Expand All @@ -278,7 +281,9 @@ Files.defaultProps = {
maxFileSize: Infinity,
minFileSize: 0,
name: 'file',
clickable: true
clickable: true,
id: 'file',
disabled: false
}

export default Files

0 comments on commit 6803e0d

Please sign in to comment.