-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DIG-25624 Added the component, tests and setup
- Loading branch information
1 parent
0bef16e
commit d45319a
Showing
21 changed files
with
2,471 additions
and
446 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,6 @@ | |
"react" | ||
], | ||
"plugins": [ | ||
'transform-object-rest-spread' | ||
"transform-object-rest-spread" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,14 @@ | ||
{ | ||
"env": { | ||
"es6": true, | ||
"browser": true, | ||
"node": true | ||
}, | ||
"extends": "eslint-config-ffe", | ||
"parserOptions": { | ||
sourceType: "module", | ||
"ecmaFeatures": { | ||
"jsx": true | ||
} | ||
}, | ||
"extends": "ffe", | ||
"parser": "babel-eslint", | ||
"plugins": [ | ||
"react", | ||
"jsx-a11y" | ||
], | ||
|
||
"globals": { | ||
"describe": true, | ||
"it": true | ||
"it": true, | ||
"document": true, | ||
"window": true, | ||
"beforeEach": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# CHANGELOG | ||
|
||
## v1.0.0 | ||
* Initial version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import React from 'react'; | ||
import ReactDom from 'react-dom'; | ||
import FileUpload from '../src/file-upload.jsx'; | ||
import { getFileContent } from '../src/file-content'; | ||
import './index.less'; | ||
|
||
class Example extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
selectedFiles: [] | ||
}; | ||
this.onFilesSelected = this.onFilesSelected.bind(this); | ||
this.onFileDeleted = this.onFileDeleted.bind(this); | ||
} | ||
|
||
|
||
static async getContent(file) { | ||
return getFileContent(file); | ||
} | ||
|
||
async onFilesSelected(files) { | ||
for (let i = 0; i < files.length; i++) { | ||
const file = files[i]; | ||
if (file.type !== 'application/pdf') { | ||
this.setState({ | ||
...this.state, | ||
errorMessage: `"${file.name}" har feil filtype. PDF er påkrevd!` | ||
}); | ||
return; | ||
} | ||
|
||
const content = await Example.getContent(file); | ||
this.setState({ | ||
...this.state, | ||
errorMessage: undefined, | ||
selectedFiles: [ | ||
...this.state.selectedFiles, | ||
{ | ||
name: file.name, | ||
type: file.type, | ||
size: file.size, | ||
content: content | ||
} | ||
] | ||
}); | ||
} | ||
} | ||
|
||
onFileDeleted(file) { | ||
this.setState({ | ||
...this.state, | ||
selectedFiles: [ | ||
...this.state.selectedFiles.filter(currentFile => currentFile.name !== file.name) | ||
] | ||
}); | ||
} | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<h1 className="ffe-h1">ffe-file-upload-react</h1> | ||
<FileUpload | ||
label={'Velg fil'} | ||
selectedFiles={this.state.selectedFiles} | ||
onFilesSelected={ this.onFilesSelected } | ||
onFileDeleted={ this.onFileDeleted } | ||
selectedFilesHeaderLabel={'Du har lastet opp:'} | ||
errorMessage={this.state.errorMessage} | ||
/> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
|
||
ReactDom.render( | ||
<Example/>, | ||
document.getElementById('app') | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@import '~ffe-core/less/ffe.less'; | ||
@import '~ffe-form/less/form.less'; | ||
@import '~ffe-form/less/file-upload.less'; | ||
@font-url: "~ffe-core/fonts"; | ||
|
||
#app { | ||
max-width: 500px; | ||
width: auto; | ||
margin: 40px auto; | ||
margin-bottom: 80px; | ||
font-size: 16px; | ||
padding: 0 20px; | ||
font-family: "MuseoSansRounded-500",arial,sans-serif; | ||
text-align: left; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
export const getFileContent = (file) => { | ||
return new Promise(function(resolve, reject) { | ||
const reader = new window.FileReader(); | ||
reader.onload = event => resolve(event.target.result); | ||
reader.onerror = error => reject(error); | ||
reader.readAsDataURL(file); | ||
}); | ||
}; |
Oops, something went wrong.