X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/3acc51716153bb950a2f2363363549eb0fdb9787..40d96a9dafd0db3497a997a48ee223509de05de0:/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 210feae9..790d49eb 100644 --- a/src/components/chips-input/chips-input.tsx +++ b/src/components/chips-input/chips-input.tsx @@ -4,31 +4,37 @@ 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[]; getLabel?: (value: Value) => string; onChange: (value: Value[]) => void; createNewValue: (value: string) => Value; + inputComponent?: React.ComponentType; + inputProps?: InputProps; + deletable?: boolean; + orderable?: boolean; + disabled?: 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 }, }); @@ -72,35 +78,64 @@ export const ChipsInput = withStyles(styles)( if (this.timeout) { clearTimeout(this.timeout); } - this.timeout = setTimeout(() => this.forceUpdate()); - } - - render() { - this.updateCursorPosition(); - return <> -
- } /> -
- - ; + this.timeout = setTimeout(() => this.setState({ ...this.state })); } 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%)` : 0, }) + + componentDidMount() { + this.updateCursorPosition(); + } + + render() { + return <> + {this.renderChips()} + {this.renderInput()} + ; + } + + renderChips() { + const { classes, ...props } = this.props; + return
+ } + /> +
; + } + + renderInput() { + const { inputProps: InputProps, inputComponent: Input = MuiInput, classes } = this.props; + return ; + } + + componentDidUpdate(prevProps: ChipsInputProps) { + if (prevProps.values !== this.props.values) { + this.updateCursorPosition(); + } + } + componentWillUnmount() { + clearTimeout(this.timeout); + } });