diff --git a/gradle/changelog/file_input_component.yaml b/gradle/changelog/file_input_component.yaml new file mode 100644 index 0000000000..d02e3abfb0 --- /dev/null +++ b/gradle/changelog/file_input_component.yaml @@ -0,0 +1,2 @@ +- type: fixed + description: Harmonize FileInput component with styleguide ([#1693](https://github.com/scm-manager/scm-manager/pull/1693)) diff --git a/scm-ui/ui-components/src/__snapshots__/storyshots.test.ts.snap b/scm-ui/ui-components/src/__snapshots__/storyshots.test.ts.snap index 8485602fbd..6fa4ee4174 100644 --- a/scm-ui/ui-components/src/__snapshots__/storyshots.test.ts.snap +++ b/scm-ui/ui-components/src/__snapshots__/storyshots.test.ts.snap @@ -46984,6 +46984,91 @@ exports[`Storyshots Forms|DropDown With Translation 1`] = ` `; +exports[`Storyshots Forms|FileInput Default 1`] = ` +
+
+
+ +
+ +
+
+
+
+
+ +
+
+ +
+`; + exports[`Storyshots Forms|InputField AutoFocus 1`] = `
{ + const { register, handleSubmit } = useForm(); + const [stored, setStored] = useState(); + + const onSubmit = (settings: Settings) => { + setStored(settings); + }; + + return ( + <> +
+ + Submit} /> + + {stored ? ( +
+
+            {JSON.stringify(stored, null, 2)}
+          
+
+ ) : null} + + ); +}; + +storiesOf("Forms|FileInput", module) + .addDecorator((storyFn) => {storyFn()}) + .addDecorator((storyFn) => {storyFn()}) + .add("Default", () => ); diff --git a/scm-ui/ui-components/src/forms/FileInput.tsx b/scm-ui/ui-components/src/forms/FileInput.tsx index f57e42c3d0..d257bef7d8 100644 --- a/scm-ui/ui-components/src/forms/FileInput.tsx +++ b/scm-ui/ui-components/src/forms/FileInput.tsx @@ -21,13 +21,16 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -import React, { ChangeEvent, FC, FocusEvent } from "react"; +import React, { ChangeEvent, FC, FocusEvent, useState } from "react"; +import { useTranslation } from "react-i18next"; import classNames from "classnames"; -import LabelWithHelpIcon from "./LabelWithHelpIcon"; +import { File } from "@scm-manager/ui-types"; import { createAttributesForTesting } from "../devBuild"; +import LabelWithHelpIcon from "./LabelWithHelpIcon"; type Props = { name?: string; + filenamePlaceholder?: string; className?: string; label?: string; placeholder?: string; @@ -41,6 +44,7 @@ type Props = { const FileInput: FC = ({ name, + filenamePlaceholder, testId, helpText, placeholder, @@ -49,9 +53,16 @@ const FileInput: FC = ({ className, ref, onBlur, - onChange + onChange, }) => { + const [t] = useTranslation("commons"); + const [file, setFile] = useState(null); + const handleChange = (event: ChangeEvent) => { + const uploadedFile = event?.target?.files![0]; + // @ts-ignore the uploaded file doesn't match our types + setFile(uploadedFile); + if (onChange && event.target.files) { onChange(event); } @@ -66,18 +77,33 @@ const FileInput: FC = ({ return (
-
- +
+
); diff --git a/scm-ui/ui-styles/src/scm.scss b/scm-ui/ui-styles/src/scm.scss index c6bd5cafab..b5b1b25485 100644 --- a/scm-ui/ui-styles/src/scm.scss +++ b/scm-ui/ui-styles/src/scm.scss @@ -664,8 +664,9 @@ form .field:not(.is-grouped) { margin-bottom: 1rem; } .input, -.textarea { - /*background-color: whitesmoke;*/ +.select select, +.textarea, +.file-name { border-color: $blue-light; box-shadow: none; } diff --git a/scm-ui/ui-webapp/public/locales/de/commons.json b/scm-ui/ui-webapp/public/locales/de/commons.json index 48a8a37e4e..58eed0b2dc 100644 --- a/scm-ui/ui-webapp/public/locales/de/commons.json +++ b/scm-ui/ui-webapp/public/locales/de/commons.json @@ -122,6 +122,10 @@ "fileUpload": { "label": "Datei auswählen" }, + "fileInput": { + "label": "Datei auswählen", + "noFileChosen": "Keine Datei ausgewählt" + }, "importLog": { "title": "Importprotokoll" }, diff --git a/scm-ui/ui-webapp/public/locales/en/commons.json b/scm-ui/ui-webapp/public/locales/en/commons.json index 9eceddd829..47fbba6a71 100644 --- a/scm-ui/ui-webapp/public/locales/en/commons.json +++ b/scm-ui/ui-webapp/public/locales/en/commons.json @@ -123,6 +123,10 @@ "fileUpload": { "label": "Select File" }, + "fileInput": { + "label": "Select File", + "noFileChosen": "No file chosen" + }, "importLog": { "title": "Import Log" },