-
Notifications
You must be signed in to change notification settings - Fork 295
/
ReadOnlyInput.tsx
57 lines (50 loc) · 1.36 KB
/
ReadOnlyInput.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
// @flow
import React, { Component } from 'react';
import { observer } from 'mobx-react';
import classnames from 'classnames';
import { intlShape } from 'react-intl';
import { Input } from 'react-polymorph/lib/components/Input';
import { InputSkin } from 'react-polymorph/lib/skins/simple/InputSkin';
import globalMessages from '../../../i18n/global-messages';
import styles from './ReadOnlyInput.scss';
type Props = {
label: string,
value: string,
onClick?: Function,
isSet: boolean,
withButton?: boolean,
};
@observer
export default class ReadOnlyInput extends Component<Props> {
static contextTypes = {
intl: intlShape.isRequired,
};
render() {
const { label, value, onClick, isSet, withButton } = this.props;
const { intl } = this.context;
const buttonLabel = intl.formatMessage(
globalMessages[isSet ? 'change' : 'create']
);
const mainClasses = classnames([
styles.component,
isSet ? 'changeLabel' : 'createLabel',
]);
return (
<div className={mainClasses}>
<Input
themeOverrides={styles}
type="text"
label={label}
value={value}
disabled
skin={InputSkin}
/>
{withButton && (
<button className={styles.button} onClick={onClick}>
{buttonLabel}
</button>
)}
</div>
);
}
}