diff --git a/app/assets/stylesheets/inputs.css b/app/assets/stylesheets/inputs.css index 252ef2835..573bb5e38 100644 --- a/app/assets/stylesheets/inputs.css +++ b/app/assets/stylesheets/inputs.css @@ -57,18 +57,12 @@ } } - .input--file { + .input--file, + .input--upload { cursor: pointer; - display: grid; - inline-size: auto; - place-items: center; - > * { - grid-area: 1 / 1; - } - - img { - border-radius: 0.4em; + &:has(input[type="file"]:focus-visible) { + outline: 0.15rem solid var(--color-selected-dark); } input[type="file"] { @@ -88,10 +82,19 @@ opacity: 0; } } + } - &:has(input[type="file"]:focus), - &:has(input[type="file"]:focus-visible) { - outline: 0.15rem solid var(--color-selected-dark); + .input--file { + display: grid; + inline-size: auto; + place-items: center; + + > * { + grid-area: 1 / 1; + } + + img { + border-radius: 0.4em; } &:is(.avatar) { @@ -101,6 +104,24 @@ } } + .input--upload { + --btn-border-color: var(--color-ink); + + border-style: dashed; + position: relative; + + input[type="file"] { + inset: 0; + outline: none; + position: absolute; + } + + &:has([data-upload-preview-target="fileName"]:not([hidden])) { + --btn-border-color: var(--color-positive); + --btn-color: var(--color-positive); + } + } + .input--select { --input-border-radius: 2em; --input-padding: 0.5em 1.8em 0.5em 1.2em; diff --git a/app/javascript/controllers/upload_preview_controller.js b/app/javascript/controllers/upload_preview_controller.js index 14cc5bfee..d7b0bd478 100644 --- a/app/javascript/controllers/upload_preview_controller.js +++ b/app/javascript/controllers/upload_preview_controller.js @@ -1,14 +1,31 @@ import { Controller } from "@hotwired/stimulus" export default class extends Controller { - static targets = [ "image", "input" ] + static targets = [ "image", "input", "fileName", "placeholder" ] previewImage() { - const file = this.inputTarget.files[0] - - if (file) { - this.imageTarget.src = URL.createObjectURL(file) + if (this.#file) { + this.imageTarget.src = URL.createObjectURL(this.#file) this.imageTarget.onload = () => URL.revokeObjectURL(this.imageTarget.src) } } + + previewFileName() { + this.#file ? this.#showFileName() : this.#showPlaceholder() + } + + #showFileName() { + this.fileNameTarget.innerHTML = this.#file.name + this.fileNameTarget.removeAttribute("hidden") + this.placeholderTarget.setAttribute("hidden", true) + } + + #showPlaceholder() { + this.placeholderTarget.removeAttribute("hidden") + this.fileNameTarget.setAttribute("hidden", true) + } + + get #file() { + return this.inputTarget.files[0] + } } diff --git a/app/views/imports/new.html.erb b/app/views/imports/new.html.erb index 138be6758..d1acb4dd2 100644 --- a/app/views/imports/new.html.erb +++ b/app/views/imports/new.html.erb @@ -1,17 +1,21 @@ <% @page_title = "Import an account" %> -
Upload the .zip file from your Fizzy export.
-Your import is in progress. This may take a while for large accounts.
-This page will refresh automatically.
+This page will refresh automatically.
<% when "completed" %>Your import has completed successfully!