-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
💄 [#1309] Added upload script and upload file-input styles
- Loading branch information
1 parent
8b69321
commit 9f12f73
Showing
5 changed files
with
189 additions
and
4 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
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,56 @@ | ||
// class UploadDocument { | ||
// constructor(node) { | ||
// this.node = node | ||
// this.node.addEventListener('click', this.toggleOpen.bind(this)) | ||
// } | ||
// | ||
// toggleOpen(event) { | ||
// event.preventDefault() | ||
// this.node.parentElement.parentElement.classList.toggle('upload--open') | ||
// } | ||
// } | ||
// | ||
// const uploadButtons = document.querySelectorAll('.upload__button .button') | ||
// ;[...uploadButtons].forEach((uploadButton) => new UploadDocument(uploadButton)) | ||
|
||
const fileEle = document.getElementById('id_file') | ||
const sizeEle = document.getElementById('upload-size') | ||
const nameEle = document.getElementById('upload-name') | ||
const closeUpload = document.getElementById('closeUpload') | ||
|
||
fileEle.addEventListener('change', function (e) { | ||
const files = e.target.files | ||
if (files.length === 0) { | ||
// Hide the size element if user doesn't choose any file | ||
sizeEle.innerHTML = '' | ||
sizeEle.style.display = 'none' | ||
nameEle.innerHTML = '' | ||
nameEle.style.display = 'none' | ||
} else { | ||
// Convert the file size to a readable format | ||
const formatFileSize = function (bytes) { | ||
const sufixes = ['B', 'kB', 'MB', 'GB', 'TB'] | ||
const i = Math.floor(Math.log(bytes) / Math.log(1024)) | ||
return `${(bytes / Math.pow(1024, i)).toFixed(2)} ${sufixes[i]}` | ||
} | ||
// File size in bytes | ||
sizeEle.innerHTML = formatFileSize(files[0].size) | ||
nameEle.innerHTML = `${files[0].name}` | ||
|
||
// Display it | ||
sizeEle.style.display = 'block' | ||
nameEle.style.display = 'block' | ||
} | ||
}) | ||
|
||
closeUpload.onclick = function (e, fileEle, sizeEle, nameEle) { | ||
const files = e.target.files | ||
document.getElementById('id_file').value = null | ||
sizeEle.innerHTML = "null" | ||
nameEle.innerHTML = "null" | ||
|
||
// Display it | ||
sizeEle.style.display = 'block' | ||
nameEle.style.display = 'block' | ||
console.log('close button clicked') | ||
} |
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,94 @@ | ||
/// | ||
/// Toggle upload. | ||
/// | ||
|
||
#document-upload { | ||
input[type='file'] { | ||
border: 0; | ||
clip: rect(0 0 0 0); | ||
height: 20px; | ||
margin: 0 -100px 0 0; | ||
overflow: hidden; | ||
padding: 0 -100px 0 0; | ||
//position: absolute; | ||
width: 100%; | ||
} | ||
//::-webkit-file-upload-button { | ||
// color: white; | ||
// background-color: var(--color-primary); | ||
// font-family: 'Lato', sans-serif; | ||
// text-transform: uppercase; | ||
// border: 0; | ||
// border-radius: 2px; | ||
// font-size: 12px; | ||
// line-height: 32px; | ||
// height: 32px; | ||
// font-weight: normal; | ||
// text-align: center; | ||
// vertical-align: middle; | ||
// cursor: pointer; | ||
// white-space: nowrap; | ||
// padding: 0 12px; | ||
//} | ||
.id_file { | ||
background-color: coral; | ||
border: 1px solid green; | ||
display: inline-block; | ||
width: 100%; | ||
} | ||
|
||
.fieldset-container { | ||
display: flex; | ||
flex-direction: row; | ||
border: 1px solid grey; | ||
overflow: hidden; | ||
} | ||
|
||
.upload { | ||
display: flex; | ||
flex-direction: column; | ||
&--open { | ||
.upload__container { | ||
display: grid; | ||
grid-template-columns: 1fr; | ||
} | ||
} | ||
} | ||
|
||
.upload__container { | ||
align-items: center; | ||
border-bottom: 1px solid var(--color-white); | ||
display: grid; | ||
gap: var(--spacing-medium); | ||
grid-template-columns: 1fr; | ||
margin-bottom: var(--spacing-medium); | ||
padding: 8px; | ||
|
||
.form__control { | ||
& *[class*='icon'] { | ||
position: static; | ||
transform: none; | ||
} | ||
.label { | ||
flex-direction: column; | ||
position: static; | ||
} | ||
} | ||
|
||
.input { | ||
min-width: 300px; | ||
} | ||
} | ||
} | ||
|
||
#document-upload | ||
.upload__container.container | ||
.form__actions | ||
.button | ||
*[class*='icon'], | ||
#document-upload .upload__container.container .form__actions .button, | ||
#document-upload > div > div.upload__button .button *[class*='icon'], | ||
#document-upload > div > div.upload__button .button { | ||
position: static; | ||
transform: none; | ||
} |
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