diff --git a/assets/js/shared-ui/upload.js b/assets/js/shared-ui/upload.js index 161ff61e..b1faf83f 100644 --- a/assets/js/shared-ui/upload.js +++ b/assets/js/shared-ui/upload.js @@ -17,16 +17,15 @@ if ( file ) { message.text( file.name ); } - }); // check whether element exist then execute js - if($( 'SUI_BODY_CLASS .sui-file-upload' ).length){ + if($( 'SUI_BODY_CLASS .sui-upload--file' ).length) { // This will trigger on file change. - $( 'SUI_BODY_CLASS .sui-file-browser input[type="file"]' ).on( 'change', function() { - var parent = $( this ).parent(); + $( 'SUI_BODY_CLASS .sui-upload--browser input[type="file"]' ).on( 'change', function() { + var parent = $( this ).closest( '.sui-upload' ); var filename = $( this ).val(); - var imageContainer = parent.find( '.sui-upload-image' ); + var imageContainer = parent.find( '.sui-upload__image' ); if(filename) { var lastIndex = filename.lastIndexOf( "\\" ); if ( lastIndex >= 0 ) { @@ -34,37 +33,37 @@ // To show uploaded file preview. if( imageContainer.length ){ var reader = new FileReader(); - var imagePreview = imageContainer.find( '.sui-image-preview' ); + var imagePreview = imageContainer.find( '.sui-upload__image--preview' ); reader.onload = function ( e ) { imagePreview.attr( 'style', 'background-image: url('+e.target.result+' );' ); } reader.readAsDataURL($( this )[0].files[0]); } - parent.find( '.sui-upload-file > span' ).text(filename); - parent.addClass( 'sui-has_file' ); + parent.find( '.sui-upload__file > span' ).text(filename); + parent.addClass( 'sui-upload--has-file' ); } } else { if( imageContainer.length ){ - var imagePreview = imageContainer.find( '.sui-image-preview' ); + var imagePreview = imageContainer.find( '.sui-upload__image--preview' ); imagePreview.attr( 'style', 'background-image: url();' ); } - parent.find( '.sui-upload-file > span' ).text( '' ); - parent.removeClass( 'sui-has_file' ); + parent.find( '.sui-upload__file > span' ).text( '' ); + parent.removeClass( 'sui-upload--has-file' ); } }); // This will trigger on click of upload button - $( 'SUI_BODY_CLASS .sui-file-browser .sui-upload-button' ).on( 'click', function(){ + $( 'SUI_BODY_CLASS .sui-upload--browser .sui-upload__button--upload' ).on( 'click', function(){ selectFile($( this )); }); // This will trigger when user wants to remove the selected upload file - $( 'SUI_BODY_CLASS .sui-file-upload [aria-label="Remove file"]' ).on( 'click', function(){ + $( 'SUI_BODY_CLASS .sui-upload--file [aria-label="Remove file"]' ).on( 'click', function(){ removeFile($( this )); }); // This will trigger reupload of file - $( 'SUI_BODY_CLASS .sui-file-browser .sui-upload-image' ).on( 'click', function(){ + $( 'SUI_BODY_CLASS .sui-upload--browser .sui-upload__image' ).on( 'click', function(){ selectFile($( this )); }); @@ -74,7 +73,7 @@ return (('draggable' in div) || ('ondragstart' in div && 'ondrop' in div)) && 'FormData' in window && 'FileReader' in window; }(); - var uploadArea = $( 'SUI_BODY_CLASS .sui-upload-button' ); + var uploadArea = $( 'SUI_BODY_CLASS .sui-upload__button' ); if(isAdvancedUpload){ var droppedFiles = false; @@ -98,18 +97,18 @@ // function to set uploaded file const uploadedFile = function (element, file, filename){ var parent = element.closest( '.sui-upload' ); - var imageContainer = parent.find( '.sui-upload-image' ); + var imageContainer = parent.find( '.sui-upload__image' ); if(filename) { if( imageContainer.length ){ var reader = new FileReader(); - var imagePreview = imageContainer.find( '.sui-image-preview' ); + var imagePreview = imageContainer.find( '.sui-upload__image--preview' ); reader.onload = function ( e ) { imagePreview.attr( 'style', 'background-image: url('+e.target.result+' );' ); } reader.readAsDataURL(file); } - parent.find( '.sui-upload-file > span' ).text(filename); - parent.addClass( 'sui-has_file' ); + parent.find( '.sui-upload__file > span' ).text(filename); + parent.addClass( 'sui-upload--has-file' ); } } diff --git a/assets/scss/shared-ui/_upload.scss b/assets/scss/shared-ui/_upload.scss index f24b2d62..9504c3ff 100644 --- a/assets/scss/shared-ui/_upload.scss +++ b/assets/scss/shared-ui/_upload.scss @@ -8,243 +8,231 @@ @extend %sui-screen-reader-text; } - button { - cursor: pointer; - display: block; - transition: 0.3s ease; - - &, - &:hover, - &:focus, - &:active { - outline: none; - box-shadow: none; - } + // Error and Multiple Uploads + + .sui-notice-error, + + .sui-upload { + margin-top: 10px; } + } - .sui-upload-image { - width: $file-upload--image-size; - height: $file-upload--image-size; - flex: 0 0 auto; - position: relative; - margin: 0; - padding: $file-upload--image-padding; - border: $file-upload--image-border-width $file-upload--image-border-style $file-upload--image-border-color; - border-radius: $border-radius; + .sui-upload__button { + cursor: pointer; + display: block; + transition: 0.3s ease; + + &, + &:hover, + &:focus, + &:active { + outline: none; + box-shadow: none; + } + } - [class*="sui-image-"] { - width: #{$file-upload--image-size - (($file-upload--image-border-width * 2) + ($file-upload--image-padding * 2))}; - height: #{$file-upload--image-size - (($file-upload--image-border-width * 2) + ($file-upload--image-padding * 2))}; - display: block; - border-radius: #{$border-radius - $file-upload--image-padding}; - } + // Image preview + .sui-upload__image { + width: $file-upload--image-size; + height: $file-upload--image-size; + flex: 0 0 auto; + position: relative; + margin: 0; + padding: $file-upload--image-padding; + border: $file-upload--image-border-width $file-upload--image-border-style $file-upload--image-border-color; + border-radius: $border-radius; + + ~ .sui-upload__file, + ~ .sui-upload__button { + margin-left: 5px; + } - .sui-image-mask { - background-color: $file-upload--image-mask-background; - background-image: linear-gradient(45deg, $white 25%, transparent 25%, transparent 75%, $white 75%, $white), linear-gradient(45deg, $white 25%, transparent 25%, transparent 75%, $white 75%, $white); - background-size: 12px 12px; - background-position: 0 0, 6px 6px; - } + ~ .sui-upload__file { + max-width: calc(100% - #{$file-upload--image-size + 5px}); + cursor: initial; + padding-left: 19px; - .sui-image-preview { - cursor: pointer; - display: none; - position: absolute; - top: $file-upload--image-padding; - left: $file-upload--image-padding; - background-color: transparent; - background-size: cover; - background-repeat: no-repeat; - background-position: center; - - @include icon(before, upload-cloud) { - opacity: 0; - display: flex; - align-items: center; - justify-content: center; - position: absolute; - top: 0; - right: 0; - bottom: 0; - left: 0; - border-radius: #{$border-radius - $file-upload--image-padding}; - color: $white; - font-size: 12px; - line-height: 12px; - background-color: $file-upload--image-preview-background; - transition: 0.2s ease; - } - - &, - &:hover, - &:focus, - &:active { - outline: none; - box-shadow: none; - } - - &:hover, - &:focus, - &:active { - - &:before { - opacity: 1; - } - } + &:before { + content: unset; } - ~ .sui-upload-button, - ~ .sui-upload-file { - margin-left: 5px; + &:hover, + &:active { + background-color: $file-upload--file-background; } + } + } - ~ .sui-upload-file { - max-width: calc(100% - #{$file-upload--image-size + 5px}); - cursor: initial; - padding-left: 19px; + [class*="sui-upload__image--"] { + width: #{$file-upload--image-size - (($file-upload--image-border-width * 2) + ($file-upload--image-padding * 2))}; + height: #{$file-upload--image-size - (($file-upload--image-border-width * 2) + ($file-upload--image-padding * 2))}; + display: block; + border-radius: #{$border-radius - $file-upload--image-padding}; + } - &:before { - content: unset; - } + .sui-upload__image--mask { + background-color: $file-upload--image-mask-background; + background-image: linear-gradient(45deg, $white 25%, transparent 25%, transparent 75%, $white 75%, $white), linear-gradient(45deg, $white 25%, transparent 25%, transparent 75%, $white 75%, $white); + background-size: 12px 12px; + background-position: 0 0, 6px 6px; + } - &:hover, - &:active { - background-color: $file-upload--file-background; - } - } + .sui-upload__image--preview { + cursor: pointer; + display: none; + position: absolute; + top: $file-upload--image-padding; + left: $file-upload--image-padding; + background-color: transparent; + background-size: cover; + background-repeat: no-repeat; + background-position: center; + + @include icon(before, upload-cloud) { + opacity: 0; + display: flex; + align-items: center; + justify-content: center; + position: absolute; + top: 0; + right: 0; + bottom: 0; + left: 0; + border-radius: #{$border-radius - $file-upload--image-padding}; + color: $white; + font-size: 12px; + line-height: 12px; + background-color: $file-upload--image-preview-background; + transition: 0.2s ease; } - .sui-upload-file { - max-width: 100%; - cursor: pointer; - flex: 0 0 auto; - display: none; - position: relative; - padding: 11px 61px 11px 41px; - border: 1px solid $file-upload--file-border-color; - border-radius: $border-radius; - background-color: $file-upload--file-background; - transition: 0.3s ease; - overflow-wrap: break-word; - - @include icon(before, page-pdf) { - width: 29px; - display: block; - position: absolute; - left: 14px; - font-size: 16px; - line-height: 16px; - text-align: center; - } + &, + &:hover, + &:focus, + &:active { + outline: none; + box-shadow: none; + } - span { - user-select: none; - display: block; - color: $file-upload--file-color; - font: $font--medium 12px/16px $font; - letter-spacing: $font--letter-spacing; - - &:focus { - outline: none; - box-shadow: none; - } - } + &:hover, + &:focus, + &:active { - button { - width: #{$file-upload--image-size - 1px}; - position: absolute; - top: 0; - right: 0; - bottom: 0; - border: 0 solid $file-upload--file-border-color; - border-left-width: 1px; - border-radius: 0 #{$border-radius - 1px} #{$border-radius - 1px} 0; - background-color: $file-upload--file-background; - font-size: 12px; - text-align: center; - - [class*="sui-icon-"] { - display: block; - - &:before { - display: block; - } - } - - &:hover, - &:focus, - &:active { - background-color: rgba(51, 51, 51, 0.04); - } + &:before { + opacity: 1; } + } + } - &:hover, - &:active { - background-color: $file-upload--file-hover-background; - } + // File upload + .sui-upload__file { + max-width: 100%; + cursor: pointer; + flex: 0 0 auto; + display: none; + position: relative; + padding: 11px 61px 11px 41px; + border: 1px solid $file-upload--file-border-color; + border-radius: $border-radius; + background-color: $file-upload--file-background; + transition: 0.3s ease; + overflow-wrap: break-word; + + @include icon(before, page-pdf) { + width: 29px; + display: block; + position: absolute; + left: 14px; + font-size: 16px; + line-height: 16px; + text-align: center; } - .sui-upload-button { - margin: 0; - padding: 11px 19px; - border: $file-upload--add-border-width $file-upload--add-border-style $file-upload--add-border-color; - border-radius: $border-radius; - background-color: $file-upload--add-background; - color: $file-upload--add-color; - font: $font--medium 12px/16px $font; - letter-spacing: $font--letter-spacing; + &:hover, + &:active { + background-color: $file-upload--file-hover-background; + } + } - &:hover, - &:focus, - &:active, - &.sui-is-dragover { - border-color: palette(silver, medium); - background-color: #FAFAFA; - } + .sui-upload__icon--upload, + .sui-upload__filename { + user-select: none; + color: $file-upload--file-color; + font: $font--medium 12px/16px $font; + letter-spacing: $font--letter-spacing; - [class*="sui-icon-"] { - width: 24px; - margin-left: -4px; - color: palette(gray, light); - font-size: 16px; - line-height: 16px; - vertical-align: bottom; - text-align: center; - - &:before { - display: block; - color: inherit; - } - } + &:focus { + outline: none; + box-shadow: none; } + } + + .sui-upload__filename { + display: block; + } - // STATUS: File uploaded - &.sui-has_file { + .sui-upload__button--remove { + width: #{$file-upload--image-size - 1px}; + position: absolute; + top: 0; + right: 0; + bottom: 0; + border: 0 solid $file-upload--file-border-color; + border-left-width: 1px; + border-radius: 0 #{$border-radius - 1px} #{$border-radius - 1px} 0; + background-color: $file-upload--file-background; + font-size: 12px; + text-align: center; + + &:hover, + &:focus, + &:active { + background-color: rgba(51, 51, 51, 0.04); + } + } - .sui-upload-image { + .sui-upload__button--upload { + margin: 0; + padding: 11px 19px; + border: $file-upload--add-border-width $file-upload--add-border-style $file-upload--add-border-color; + border-radius: $border-radius; + background-color: $file-upload--add-background; + color: $file-upload--add-color; + font: $font--medium 12px/16px $font; + letter-spacing: $font--letter-spacing; + + &:hover, + &:focus, + &:active, + &.sui-is-dragover { + border-color: palette(silver, medium); + background-color: #FAFAFA; + } - .sui-image-preview { - display: block; - } - } + [class*="sui-icon-"] { + width: 24px; + margin-left: -4px; + color: palette(gray, light); + font-size: 16px; + line-height: 16px; + vertical-align: bottom; + text-align: center; - .sui-upload-file { + &:before { display: block; - } - - .sui-upload-button { - display: none; + color: inherit; } } + } - // STATUS: Error - + .sui-notice { - margin-top: 10px; + // STATUS: File uploaded + .sui-upload--has-file { + + .sui-upload__image--preview, + .sui-upload__file { + display: block; } - // Multiple uploads - + .sui-upload { - margin-top: 10px; + .sui-upload__button--upload { + display: none; } } } \ No newline at end of file diff --git a/page-uploads-file.html b/page-uploads-file.html index e902e238..add42892 100644 --- a/page-uploads-file.html +++ b/page-uploads-file.html @@ -62,29 +62,30 @@
<div class="sui-form-field"> - <label class="sui-label">Field label</label> - - <div class="sui-upload sui-file-upload sui-file-browser"> + <label id="label-1" class="sui-label">Field label</label> - <input type="file" value="" readonly="readonly" /> + <div class="sui-upload sui-upload--file sui-upload--browser"> - <button class="sui-upload-button" - <span class="sui-icon-upload-cloud" aria-hidden="true"></span> - Upload file + <input type="file" value="" readonly="readonly" aria-labelledby="label-1" aria-describedby="unique-description-id" aria-controls="unique-file-id"/> + + <button class="sui-upload__button sui-upload__button--upload" tabindex="-1"> + <span class="sui-upload__icon--upload sui-icon-upload-cloud" aria-hidden="true"></span> Upload file </button> - <div class="sui-upload-file"> + <div class="sui-upload__file"> - <span></span> + <span class="sui-upload__filename" id="unique-file-id" tabindex="0"></span> - <button aria-label="Remove file"> - <span class="sui-icon-close" aria-hidden="true"></span> + <button class="sui-upload__button sui-upload__button--remove" + aria-label="Remove file"> + <span class="sui-upload__icon--remove sui-icon-close" aria-hidden="true"></span> </button> </div> </div> - <span class="sui-description">Element description.</span> - - <div class="sui-notice sui-notice-error" style="margin-top: 5px; display: none;"> - <p>Element error message.</p> - </div> + <span id="unique-description-id" class="sui-description">This is a description for files upload element.</span> </div>@@ -134,29 +131,30 @@
<div class="sui-form-field"> - <label class="sui-label">Field label</label> - - <div class="sui-upload sui-has_file"> + <label id="unique-label-id" class="sui-label">Upload file</label> - <input type="file" value="file-name.txt" readonly="readonly" /> + <div class="sui-upload sui-upload--file sui-upload--browser sui-upload--has-file"> - <button class="sui-upload-button" - <span class="sui-icon-upload-cloud" aria-hidden="true"></span> - Upload file + <input type="file" value="example-file.pdf" readonly="readonly" aria-labelledby="unique-label-id" aria-describedby="unique-description-id" aria-controls="unique-file-id"/> + + <button class="sui-upload__button sui-upload__button--upload" tabindex="-1"> + <span class="sui-upload__icon--upload sui-icon-upload-cloud" aria-hidden="true"></span> Upload file </button> - <div class="sui-upload-file"> + <div class="sui-upload__file"> - <span>file-name.txt</span> + <span class="sui-upload__filename" id="unique-file-id" tabindex="0">example-file.pdf</span> - <button aria-label="Remove file"> - <span class="sui-icon-close" aria-hidden="true"></span> + <button class="sui-upload__button sui-upload__button--remove" + aria-label="Remove file"> + <span class="sui-upload__icon--remove sui-icon-close" aria-hidden="true"></span> </button> </div> </div> - <span class="sui-description">Here goes field description.</span> - - <div class="sui-notice sui-notice-error" style="margin-top: 5px; display: none;"> - <p>Element error message.</p> - </div> + <span id="unique-description-id" class="sui-description">This is a description for files upload element.</span> </div>@@ -210,29 +204,30 @@
Whoops, only .pdf and .doc filetypes are allowed.
@@ -245,33 +240,33 @@<div class="sui-form-field"> - <label class="sui-label">Field label</label> - - <div class="sui-upload sui-has_file"> + <label id="unique-label-id" class="sui-label">Upload file</label> - <input type="file" value="file-name.txt" readonly="readonly" /> + <div class="sui-upload sui-upload--file sui-upload--browser"> - <button class="sui-upload-button" - <span class="sui-icon-upload-cloud" aria-hidden="true"></span> - Upload file + <input type="file" value="" readonly="readonly" aria-labelledby="unique-label-id" aria-describedby="unique-description-id" aria-controls="unique-file-id"/> + + <button class="sui-upload__button sui-upload__button--upload" tabindex="-1"> + <span class="sui-upload__icon--upload sui-icon-upload-cloud" aria-hidden="true"></span> Upload file </button> - <div class="sui-upload-file"> + <div class="sui-upload__file"> - <span>file-name.txt</span> + <span class="sui-upload__filename" id="unique-file-id" tabindex="0"></span> - <button aria-label="Remove file"> - <span class="sui-icon-close" aria-hidden="true"></span> + <button class="sui-upload__button sui-upload__button--remove" + aria-label="Remove file"> + <span class="sui-upload__icon--remove sui-icon-close" aria-hidden="true"></span> </button> </div> </div> - <span class="sui-description">Here goes field description.</span> + <span id="unique-description-id" class="sui-description">This is a description for files upload element.</span> <div class="sui-notice sui-notice-error" style="margin-top: 5px;"> - <p>Element error message.</p> + <p>Whoops, only .pdf and .doc filetypes are allowed.</p> </div> </div> @@ -318,34 +313,35 @@Single File
- + -+- - - @@ -356,34 +352,35 @@Single File
- + -+- - - @@ -394,34 +391,35 @@Single File
- - -+ - +-