From e567f0daa13834f980fc326faaed1eadeaebf34f Mon Sep 17 00:00:00 2001 From: Daniel Kos Date: Sun, 9 Sep 2018 21:35:56 +0200 Subject: [PATCH] Add file-upload focus indicator, add submit type for dialog default button Feature #14161 Arvados-DCO-1.1-Signed-off-by: Daniel Kos --- src/components/file-upload/file-upload.css | 67 +++++++++ src/components/file-upload/file-upload.tsx | 127 ++++++++++++------ src/components/form-dialog/form-dialog.tsx | 1 + src/components/text-field/text-field.tsx | 3 +- .../file-uploader/file-uploader.tsx | 6 +- .../form-fields/collection-form-fields.tsx | 3 +- 6 files changed, 165 insertions(+), 42 deletions(-) create mode 100644 src/components/file-upload/file-upload.css diff --git a/src/components/file-upload/file-upload.css b/src/components/file-upload/file-upload.css new file mode 100644 index 0000000000..0d74b897c0 --- /dev/null +++ b/src/components/file-upload/file-upload.css @@ -0,0 +1,67 @@ +.dropzone-border-left { + left: -1px; + top: -1px; + bottom: -1px; + width: 2px; + content: ""; + position: absolute; + transform: scaleY(0); + transition: transform 200ms cubic-bezier(0.0, 0, 0.2, 1) 0ms; + pointer-events: none; + background-color: #6a1b9a; +} + +.dropzone-border-right { + right: -1px; + top: -1px; + bottom: -1px; + width: 2px; + content: ""; + position: absolute; + transform: scaleY(0); + transition: transform 200ms cubic-bezier(0.0, 0, 0.2, 1) 0ms; + pointer-events: none; + background-color: #6a1b9a; +} + +.dropzone-border-top { + left: 0; + right: 0; + top: -1px; + height: 2px; + content: ""; + position: absolute; + transform: scaleX(0); + transition: transform 200ms cubic-bezier(0.0, 0, 0.2, 1) 0ms; + pointer-events: none; + background-color: #6a1b9a; +} + +.dropzone-border-bottom { + left: 0; + right: 0; + bottom: -1px; + height: 2px; + content: ""; + position: absolute; + transform: scaleX(0); + transition: transform 200ms cubic-bezier(0.0, 0, 0.2, 1) 0ms; + pointer-events: none; + background-color: #6a1b9a; +} + +.dropzone-border-left-active { + transform: scaleY(1); +} + +.dropzone-border-right-active { + transform: scaleY(1); +} + +.dropzone-border-top-active { + transform: scaleX(1); +} + +.dropzone-border-bottom-active { + transform: scaleX(1); +} diff --git a/src/components/file-upload/file-upload.tsx b/src/components/file-upload/file-upload.tsx index e7f402cdb2..0f87b1e9e3 100644 --- a/src/components/file-upload/file-upload.tsx +++ b/src/components/file-upload/file-upload.tsx @@ -3,6 +3,7 @@ // SPDX-License-Identifier: AGPL-3.0 import * as React from 'react'; +import * as classnames from 'classnames'; import { Grid, StyleRulesCallback, @@ -16,17 +17,24 @@ import { CloudUploadIcon } from "../icon/icon"; import { formatFileSize, formatProgress, formatUploadSpeed } from "~/common/formatters"; import { UploadFile } from '~/store/file-uploader/file-uploader-actions'; -type CssRules = "root" | "dropzone" | "container" | "uploadIcon"; +type CssRules = "root" | "dropzone" | "dropzoneWrapper" | "container" | "uploadIcon"; + +import './file-upload.css'; +import { DOMElement, RefObject } from "react"; const styles: StyleRulesCallback = theme => ({ root: { }, dropzone: { + width: "100%", + height: "100%", + overflow: "auto" + }, + dropzoneWrapper: { width: "100%", height: "200px", - overflow: "auto", - border: "1px dashed black", - borderRadius: "5px" + position: "relative", + border: "1px solid rgba(0, 0, 0, 0.42)" }, container: { height: "100%" @@ -36,44 +44,87 @@ const styles: StyleRulesCallback = theme => ({ } }); -export interface FileUploadProps { +interface FileUploadPropsData { files: UploadFile[]; disabled: boolean; onDrop: (files: File[]) => void; } +interface FileUploadState { + focused: boolean; +} + +export type FileUploadProps = FileUploadPropsData & WithStyles; + export const FileUpload = withStyles(styles)( - ({ classes, files, disabled, onDrop }: FileUploadProps & WithStyles) => - onDrop(files)} disabled={disabled}> - {files.length === 0 && - - - - Drag and drop data or click to browse - - - } - {files.length > 0 && - - - - File name - File size - Upload speed - Upload progress - - - - {files.map(f => - - {f.file.name} - {formatFileSize(f.file.size)} - {formatUploadSpeed(f.prevLoaded, f.loaded, f.prevTime, f.currentTime)} - {formatProgress(f.loaded, f.total)} - - )} - -
- } -
+ class extends React.Component { + constructor(props: FileUploadProps) { + super(props); + this.state = { + focused: false + }; + } + render() { + const { classes, onDrop, disabled, files } = this.props; + return
+
+
+
+
+ onDrop(files)} + onClick={(e) => { + const el = document.getElementsByClassName("file-upload-dropzone")[0]; + const inputs = el.getElementsByTagName("input"); + if (inputs.length > 0) { + inputs[0].focus(); + } + }} + disabled={disabled} + inputProps={{ + onFocus: () => { + this.setState({ + focused: true + }); + }, + onBlur: () => { + this.setState({ + focused: false + }); + } + }}> + {files.length === 0 && + + + + Drag and drop data or click to browse + + + } + {files.length > 0 && + + + + File name + File size + Upload speed + Upload progress + + + + {files.map(f => + + {f.file.name} + {formatFileSize(f.file.size)} + {formatUploadSpeed(f.prevLoaded, f.loaded, f.prevTime, f.currentTime)} + {formatProgress(f.loaded, f.total)} + + )} + +
+ } +
+
; + } + } ); diff --git a/src/components/form-dialog/form-dialog.tsx b/src/components/form-dialog/form-dialog.tsx index dd02813226..40050b7656 100644 --- a/src/components/form-dialog/form-dialog.tsx +++ b/src/components/form-dialog/form-dialog.tsx @@ -68,6 +68,7 @@ export const FormDialog = withStyles(styles)((props: DialogProjectProps) => {props.cancelLabel || 'Cancel'}