-
-
Notifications
You must be signed in to change notification settings - Fork 211
/
input.tsx
63 lines (54 loc) · 1.86 KB
/
input.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import React from 'react'
import cx from 'classnames'
import styles from './input.css'
import { HighlightButton } from 'components/common/button'
import { t } from 'locale'
import { copyToClipboard } from 'utils/clipboard'
interface ITextInputProps extends React.HTMLProps<HTMLInputElement> {
theRef?: (e: HTMLInputElement | null) => void
className?: string
defaultValue?: string
}
export const TextInput: React.SFC<ITextInputProps> = props => {
const { theRef, ...rest } = props
return <input ref={theRef} type="text" {...rest} className={cx(styles.text, props.className)} />
}
interface ITextAreaProps extends React.HTMLProps<HTMLTextAreaElement> {
theRef?: (e: HTMLTextAreaElement | null) => void
className?: string
}
export const TextAreaInput: React.SFC<ITextAreaProps> = props => {
const { theRef, ...rest } = props
return <textarea ref={theRef} {...rest} className={cx(styles.text, props.className)} />
}
export const InputGroup: React.SFC<ITextInputProps> = props => {
return <div className={styles.inputGroup}>{props.children}</div>
}
interface IClipboardTextInputProps extends ITextInputProps {
inputClassName?: string
}
export class ClipboardTextInput extends React.Component<IClipboardTextInputProps> {
private input: HTMLInputElement | null = null
render() {
return (
<div className={cx(styles.textContainer, this.props.className)}>
<input
ref={e => (this.input = e)}
className={cx(this.props.inputClassName, styles.textInput)}
type="text"
defaultValue={this.props.defaultValue}
disabled={this.props.disabled}
/>
<HighlightButton icon="clipboard" onClick={this.copy} highlight>
{t('copy')}
</HighlightButton>
</div>
)
}
private copy = () => {
if (this.input) {
const { value } = this.input
copyToClipboard(value)
}
}
}