X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/c72c1ba8048825f15d864753dd247080e29f227b..247b312a502ac3fdcc915a2e6e858a0eea8c0c5b:/src/components/chips-input/chips-input.tsx diff --git a/src/components/chips-input/chips-input.tsx b/src/components/chips-input/chips-input.tsx index 96e7b70a..fc5fda01 100644 --- a/src/components/chips-input/chips-input.tsx +++ b/src/components/chips-input/chips-input.tsx @@ -4,31 +4,36 @@ import * as React from 'react'; import { Chips } from '~/components/chips/chips'; -import { Input, withStyles, WithStyles } from '@material-ui/core'; +import { Input as MuiInput, withStyles, WithStyles } from '@material-ui/core'; import { StyleRulesCallback } from '@material-ui/core/styles'; +import { InputProps } from '@material-ui/core/Input'; interface ChipsInputProps { - values: Value[]; + value: Value[]; getLabel?: (value: Value) => string; onChange: (value: Value[]) => void; createNewValue: (value: string) => Value; + inputComponent?: React.ComponentType; + inputProps?: InputProps; + deletable?: boolean; + orderable?: boolean; } type CssRules = 'chips' | 'input' | 'inputContainer'; -const styles: StyleRulesCallback = () => ({ +const styles: StyleRulesCallback = ({ spacing }) => ({ chips: { - minHeight: '40px', + minHeight: spacing.unit * 5, zIndex: 1, position: 'relative', }, input: { - position: 'relative', - top: '-5px', zIndex: 1, + marginBottom: 8, + position: 'relative', }, inputContainer: { - top: '-24px', + marginTop: -34 }, }); @@ -58,13 +63,13 @@ export const ChipsInput = withStyles(styles)( if (this.state.text) { const newValue = this.props.createNewValue(this.state.text); this.setState({ text: '' }); - this.props.onChange([...this.props.values, newValue]); + this.props.onChange([...this.props.value, newValue]); } } deleteLastValue = () => { - if (this.state.text.length === 0 && this.props.values.length > 0) { - this.props.onChange(this.props.values.slice(0, -1)); + if (this.state.text.length === 0 && this.props.value.length > 0) { + this.props.onChange(this.props.value.slice(0, -1)); } } @@ -77,7 +82,7 @@ export const ChipsInput = withStyles(styles)( getInputStyles = (): React.CSSProperties => ({ width: this.filler.current - ? this.filler.current.offsetWidth + 8 + ? this.filler.current.offsetWidth : '100%', right: this.filler.current ? `calc(${this.filler.current.offsetWidth}px - 100%)` @@ -91,27 +96,40 @@ export const ChipsInput = withStyles(styles)( render() { return <> -
- } - /> -
- + {this.renderChips()} + {this.renderInput()} ; } + renderChips() { + const { classes, value, ...props } = this.props; + return
+ } + /> +
; + } + + renderInput() { + const { inputProps: InputProps, inputComponent: Input = MuiInput, classes } = this.props; + return ; + } + componentDidUpdate(prevProps: ChipsInputProps) { - if (prevProps.values !== this.props.values) { + if (prevProps.value !== this.props.value) { this.updateCursorPosition(); } }