From b17f03247b51d89eebae732488bbddcb00b32bf2 Mon Sep 17 00:00:00 2001 From: Florian Scholdei Date: Tue, 26 Nov 2019 15:59:38 +0100 Subject: [PATCH] Change AddEntryTo... to single-line component, add className prop to InputField and Autocomplete --- scm-ui/ui-components/src/Autocomplete.tsx | 7 ++- .../src/forms/AddEntryToTableField.tsx | 55 +++++++++++++------ .../AutocompleteAddEntryToTableField.tsx | 42 +++++++++----- scm-ui/ui-components/src/forms/InputField.tsx | 15 ++++- scm-ui/ui-components/src/layout/Level.tsx | 9 ++- 5 files changed, 90 insertions(+), 38 deletions(-) diff --git a/scm-ui/ui-components/src/Autocomplete.tsx b/scm-ui/ui-components/src/Autocomplete.tsx index 7618464b57..814be20aa2 100644 --- a/scm-ui/ui-components/src/Autocomplete.tsx +++ b/scm-ui/ui-components/src/Autocomplete.tsx @@ -1,4 +1,5 @@ import React from "react"; +import classNames from "classnames"; import { Async, AsyncCreatable } from "react-select"; import { SelectValue } from "@scm-manager/ui-types"; import LabelWithHelpIcon from "./forms/LabelWithHelpIcon"; @@ -14,6 +15,7 @@ type Props = { loadingMessage: string; noOptionsMessage: string; creatable?: boolean; + className?: string; }; type State = {}; @@ -53,10 +55,11 @@ class Autocomplete extends React.Component { loadingMessage, noOptionsMessage, loadSuggestions, - creatable + creatable, + className } = this.props; return ( -
+
{creatable ? ( diff --git a/scm-ui/ui-components/src/forms/AddEntryToTableField.tsx b/scm-ui/ui-components/src/forms/AddEntryToTableField.tsx index 8f76956c47..3e18674244 100644 --- a/scm-ui/ui-components/src/forms/AddEntryToTableField.tsx +++ b/scm-ui/ui-components/src/forms/AddEntryToTableField.tsx @@ -1,7 +1,8 @@ import React, { MouseEvent } from "react"; -import InputField from "./InputField"; +import styled from "styled-components"; import Level from "../layout/Level"; -import { AddButton } from "../buttons"; +import InputField from "./InputField"; +import AddButton from "../buttons/AddButton"; type Props = { addEntry: (p: string) => void; @@ -17,6 +18,22 @@ type State = { entryToAdd: string; }; +const StyledLevel = styled(Level)` + align-items: stretch; + margin-bottom: 1rem !important; // same margin as field +`; + +const StyledInputField = styled(InputField)` + width: 100%; + margin-right: 1.5rem; +`; + +const StyledField = styled.div.attrs(props => ({ + className: "field" +}))` + align-self: flex-end; +`; + class AddEntryToTableField extends React.Component { constructor(props: Props) { super(props); @@ -37,27 +54,29 @@ class AddEntryToTableField extends React.Component { render() { const { disabled, buttonLabel, fieldLabel, errorMessage, helpText } = this.props; return ( - <> - - + } + right={ + - } - /> - + + } + /> ); } diff --git a/scm-ui/ui-components/src/forms/AutocompleteAddEntryToTableField.tsx b/scm-ui/ui-components/src/forms/AutocompleteAddEntryToTableField.tsx index 19042bb2ac..8287249858 100644 --- a/scm-ui/ui-components/src/forms/AutocompleteAddEntryToTableField.tsx +++ b/scm-ui/ui-components/src/forms/AutocompleteAddEntryToTableField.tsx @@ -1,7 +1,8 @@ import React, { MouseEvent } from "react"; +import styled from "styled-components"; import { SelectValue } from "@scm-manager/ui-types"; -import Autocomplete from "../Autocomplete"; import Level from "../layout/Level"; +import Autocomplete from "../Autocomplete"; import AddButton from "../buttons/AddButton"; type Props = { @@ -20,6 +21,11 @@ type State = { selectedValue?: SelectValue; }; +const StyledAutocomplete = styled(Autocomplete)` + width: 100%; + margin-right: 1.5rem; +`; + class AutocompleteAddEntryToTableField extends React.Component { constructor(props: Props) { super(props); @@ -41,20 +47,26 @@ class AutocompleteAddEntryToTableField extends React.Component { const { selectedValue } = this.state; return ( -
- - } /> -
+ + } + right={ +
+ +
+ } + /> ); } diff --git a/scm-ui/ui-components/src/forms/InputField.tsx b/scm-ui/ui-components/src/forms/InputField.tsx index a0fd1c631c..d832d8a7d6 100644 --- a/scm-ui/ui-components/src/forms/InputField.tsx +++ b/scm-ui/ui-components/src/forms/InputField.tsx @@ -15,6 +15,7 @@ type Props = { errorMessage?: string; disabled?: boolean; helpText?: string; + className?: string; }; class InputField extends React.Component { @@ -47,11 +48,21 @@ class InputField extends React.Component { }; render() { - const { type, placeholder, value, validationError, errorMessage, disabled, label, helpText } = this.props; + const { + type, + placeholder, + value, + validationError, + errorMessage, + disabled, + label, + helpText, + className + } = this.props; const errorView = validationError ? "is-danger" : ""; const helper = validationError ?

{errorMessage}

: ""; return ( -
+
{ render() { - const { className, left, right } = this.props; + const { className, left, children, right } = this.props; + let child = null; + if (children) { + child =
{children}
; + } + return (
{left}
+ {child}
{right}
);