mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 15:05:44 +01:00
use reflow to migrate from flow to typescript
This commit is contained in:
56
scm-ui/ui-components/src/forms/Textarea.tsx
Normal file
56
scm-ui/ui-components/src/forms/Textarea.tsx
Normal file
@@ -0,0 +1,56 @@
|
||||
import React from 'react';
|
||||
import LabelWithHelpIcon from './LabelWithHelpIcon';
|
||||
|
||||
export type SelectItem = {
|
||||
value: string;
|
||||
label: string;
|
||||
};
|
||||
|
||||
type Props = {
|
||||
name?: string;
|
||||
label?: string;
|
||||
placeholder?: SelectItem[];
|
||||
value?: string;
|
||||
autofocus?: boolean;
|
||||
onChange: (value: string, name?: string) => void;
|
||||
helpText?: string;
|
||||
disabled?: boolean;
|
||||
};
|
||||
|
||||
class Textarea extends React.Component<Props> {
|
||||
field: HTMLTextAreaElement | null | undefined;
|
||||
|
||||
componentDidMount() {
|
||||
if (this.props.autofocus && this.field) {
|
||||
this.field.focus();
|
||||
}
|
||||
}
|
||||
|
||||
handleInput = (event: SyntheticInputEvent<HTMLTextAreaElement>) => {
|
||||
this.props.onChange(event.target.value, this.props.name);
|
||||
};
|
||||
|
||||
render() {
|
||||
const { placeholder, value, label, helpText, disabled } = this.props;
|
||||
|
||||
return (
|
||||
<div className="field">
|
||||
<LabelWithHelpIcon label={label} helpText={helpText} />
|
||||
<div className="control">
|
||||
<textarea
|
||||
className="textarea"
|
||||
ref={input => {
|
||||
this.field = input;
|
||||
}}
|
||||
placeholder={placeholder}
|
||||
onChange={this.handleInput}
|
||||
value={value}
|
||||
disabled={!!disabled}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default Textarea;
|
||||
Reference in New Issue
Block a user