-
Notifications
You must be signed in to change notification settings - Fork 295
/
InlineEditingDropdown.tsx
96 lines (88 loc) · 2.54 KB
/
InlineEditingDropdown.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// @flow
import React, { Component } from 'react';
import type { Node } from 'react';
import { observer } from 'mobx-react';
import { defineMessages, intlShape } from 'react-intl';
import { PopOver } from 'react-polymorph/lib/components/PopOver';
import SVGInline from 'react-svg-inline';
import classnames from 'classnames';
import { Select } from 'react-polymorph/lib/components/Select';
import { SelectSkin } from 'react-polymorph/lib/skins/simple/SelectSkin';
import styles from './InlineEditingDropdown.scss';
import questionMarkIcon from '../../../assets/images/question-mark.inline.svg';
const messages = defineMessages({
changesSaved: {
id: 'inline.editing.dropdown.changesSaved',
defaultMessage: '!!!Your changes have been saved',
description:
'Message "Your changes have been saved" for inline editing (eg. on Wallet Settings page).',
},
});
type Props = {
className?: string,
isActive: boolean,
label: string,
tooltip?: string | Node,
options: Array<{ value: number | string, label: string }>,
value: number | string,
onSubmit: Function,
onStartEditing: Function,
onStopEditing: Function,
successfullyUpdated: boolean,
};
@observer
export default class InlineEditingDropdown extends Component<Props> {
static contextTypes = {
intl: intlShape.isRequired,
};
onChange = (value: number | string) => {
this.props.onStartEditing();
this.props.onSubmit(value);
this.props.onStopEditing();
};
render() {
const { intl } = this.context;
const {
className,
isActive,
label,
tooltip,
options,
value,
successfullyUpdated,
} = this.props;
const componentClasses = classnames([className, styles.component]);
const dropdownStyles = classnames([
successfullyUpdated ? 'dropdown_animateSuccess' : null,
]);
const labelText = [
label,
!!tooltip && (
<PopOver content={tooltip} key="tooltip">
<SVGInline
svg={questionMarkIcon}
className={styles.questionMarkIcon}
/>
</PopOver>
),
];
return (
<div className={componentClasses}>
<Select
className={dropdownStyles}
label={labelText}
options={options}
value={value}
onChange={this.onChange}
disabled={!isActive}
skin={SelectSkin}
/>
{successfullyUpdated && (
<div className={styles.savingResultLabel}>
{intl.formatMessage(messages.changesSaved)}
</div>
)}
</div>
);
}
}