]>
cat aescling's git repositories - mastodon.git/blob - 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';
11 const messages
= defineMessages({
12 undo: { id: 'upload_form.undo', defaultMessage: 'Undo' },
13 description: { id: 'upload_form.description', defaultMessage: 'Describe for the visually impaired' },
17 export default class Upload
extends ImmutablePureComponent
{
20 media: ImmutablePropTypes
.map
.isRequired
,
21 intl: PropTypes
.object
.isRequired
,
22 onUndo: PropTypes
.func
.isRequired
,
23 onDescriptionChange: PropTypes
.func
.isRequired
,
29 dirtyDescription: null,
32 handleUndoClick
= () => {
33 this.props
.onUndo(this.props
.media
.get('id'));
36 handleInputChange
= e
=> {
37 this.setState({ dirtyDescription: e
.target
.value
});
40 handleMouseEnter
= () => {
41 this.setState({ hovered: true });
44 handleMouseLeave
= () => {
45 this.setState({ hovered: false });
48 handleInputFocus
= () => {
49 this.setState({ focused: true });
52 handleInputBlur
= () => {
53 const { dirtyDescription
} = this.state
;
55 this.setState({ focused: false, dirtyDescription: null });
57 if (dirtyDescription
!== null) {
58 this.props
.onDescriptionChange(this.props
.media
.get('id'), dirtyDescription
);
63 const { intl
, media
} = this.props
;
64 const active
= this.state
.hovered
|| this.state
.focused
;
65 const description
= this.state
.dirtyDescription
|| media
.get('description') || '';
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 }) }}>
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
} />
74 <div className
={classNames('compose-form__upload-description', { active
})}>
76 <span style
={{ display: 'none' }}>{intl
.formatMessage(messages
.description
)}</span
>
79 placeholder
={intl
.formatMessage(messages
.description
)}
83 onFocus
={this.handleInputFocus
}
84 onChange
={this.handleInputChange
}
85 onBlur
={this.handleInputBlur
}
This page took 0.144847 seconds and 4 git commands to generate.