]> cat aescling's git repositories - mastodon.git/blob - app/javascript/mastodon/features/compose/components/upload.js
Remove unnecessary translateZ(0) when doing scale() (#5473)
[mastodon.git] / app / javascript / mastodon / features / compose / components / upload.js
1 import React from 'react';
2 import ImmutablePropTypes from 'react-immutable-proptypes';
3 import PropTypes from 'prop-types';
4 import IconButton from '../../../components/icon_button';
5 import Motion from '../../ui/util/optional_motion';
6 import spring from 'react-motion/lib/spring';
7 import ImmutablePureComponent from 'react-immutable-pure-component';
8 import { defineMessages, injectIntl } from 'react-intl';
9 import classNames from 'classnames';
10
11 const messages = defineMessages({
12 undo: { id: 'upload_form.undo', defaultMessage: 'Undo' },
13 description: { id: 'upload_form.description', defaultMessage: 'Describe for the visually impaired' },
14 });
15
16 @injectIntl
17 export default class Upload extends ImmutablePureComponent {
18
19 static propTypes = {
20 media: ImmutablePropTypes.map.isRequired,
21 intl: PropTypes.object.isRequired,
22 onUndo: PropTypes.func.isRequired,
23 onDescriptionChange: PropTypes.func.isRequired,
24 };
25
26 state = {
27 hovered: false,
28 focused: false,
29 dirtyDescription: null,
30 };
31
32 handleUndoClick = () => {
33 this.props.onUndo(this.props.media.get('id'));
34 }
35
36 handleInputChange = e => {
37 this.setState({ dirtyDescription: e.target.value });
38 }
39
40 handleMouseEnter = () => {
41 this.setState({ hovered: true });
42 }
43
44 handleMouseLeave = () => {
45 this.setState({ hovered: false });
46 }
47
48 handleInputFocus = () => {
49 this.setState({ focused: true });
50 }
51
52 handleInputBlur = () => {
53 const { dirtyDescription } = this.state;
54
55 this.setState({ focused: false, dirtyDescription: null });
56
57 if (dirtyDescription !== null) {
58 this.props.onDescriptionChange(this.props.media.get('id'), dirtyDescription);
59 }
60 }
61
62 render () {
63 const { intl, media } = this.props;
64 const active = this.state.hovered || this.state.focused;
65 const description = this.state.dirtyDescription || media.get('description') || '';
66
67 return (
68 <div className='compose-form__upload' onMouseEnter={this.handleMouseEnter} onMouseLeave={this.handleMouseLeave}>
69 <Motion defaultStyle={{ scale: 0.8 }} style={{ scale: spring(1, { stiffness: 180, damping: 12 }) }}>
70 {({ scale }) => (
71 <div className='compose-form__upload-thumbnail' style={{ transform: `scale(${scale})`, backgroundImage: `url(${media.get('preview_url')})` }}>
72 <IconButton icon='times' title={intl.formatMessage(messages.undo)} size={36} onClick={this.handleUndoClick} />
73
74 <div className={classNames('compose-form__upload-description', { active })}>
75 <label>
76 <span style={{ display: 'none' }}>{intl.formatMessage(messages.description)}</span>
77
78 <input
79 placeholder={intl.formatMessage(messages.description)}
80 type='text'
81 value={description}
82 maxLength={420}
83 onFocus={this.handleInputFocus}
84 onChange={this.handleInputChange}
85 onBlur={this.handleInputBlur}
86 />
87 </label>
88 </div>
89 </div>
90 )}
91 </Motion>
92 </div>
93 );
94 }
95
96 }
This page took 0.144847 seconds and 4 git commands to generate.