The code powering m.abunchtell.com https://m.abunchtell.com
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

84 linhas
2.4 KiB

  1. import React from 'react';
  2. import IconButton from '../../../components/icon_button';
  3. import PropTypes from 'prop-types';
  4. import { defineMessages, injectIntl } from 'react-intl';
  5. import { connect } from 'react-redux';
  6. import ImmutablePureComponent from 'react-immutable-pure-component';
  7. import ImmutablePropTypes from 'react-immutable-proptypes';
  8. const messages = defineMessages({
  9. upload: { id: 'upload_button.label', defaultMessage: 'Add media ({formats})' },
  10. });
  11. const SUPPORTED_FORMATS = 'JPEG, PNG, GIF, WebM, MP4, MOV, OGG, WAV, MP3, FLAC';
  12. const makeMapStateToProps = () => {
  13. const mapStateToProps = state => ({
  14. acceptContentTypes: state.getIn(['media_attachments', 'accept_content_types']),
  15. });
  16. return mapStateToProps;
  17. };
  18. const iconStyle = {
  19. height: null,
  20. lineHeight: '27px',
  21. };
  22. export default @connect(makeMapStateToProps)
  23. @injectIntl
  24. class UploadButton extends ImmutablePureComponent {
  25. static propTypes = {
  26. disabled: PropTypes.bool,
  27. unavailable: PropTypes.bool,
  28. onSelectFile: PropTypes.func.isRequired,
  29. style: PropTypes.object,
  30. resetFileKey: PropTypes.number,
  31. acceptContentTypes: ImmutablePropTypes.listOf(PropTypes.string).isRequired,
  32. intl: PropTypes.object.isRequired,
  33. };
  34. handleChange = (e) => {
  35. if (e.target.files.length > 0) {
  36. this.props.onSelectFile(e.target.files);
  37. }
  38. }
  39. handleClick = () => {
  40. this.fileElement.click();
  41. }
  42. setRef = (c) => {
  43. this.fileElement = c;
  44. }
  45. render () {
  46. const { intl, resetFileKey, unavailable, disabled, acceptContentTypes } = this.props;
  47. if (unavailable) {
  48. return null;
  49. }
  50. return (
  51. <div className='compose-form__upload-button'>
  52. <IconButton icon='paperclip' title={intl.formatMessage(messages.upload, { formats: SUPPORTED_FORMATS })} disabled={disabled} onClick={this.handleClick} className='compose-form__upload-button-icon' size={18} inverted style={iconStyle} />
  53. <label>
  54. <span style={{ display: 'none' }}>{intl.formatMessage(messages.upload, { formats: SUPPORTED_FORMATS })}</span>
  55. <input
  56. key={resetFileKey}
  57. ref={this.setRef}
  58. type='file'
  59. multiple
  60. accept={acceptContentTypes.toArray().join(',')}
  61. onChange={this.handleChange}
  62. disabled={disabled}
  63. style={{ display: 'none' }}
  64. />
  65. </label>
  66. </div>
  67. );
  68. }
  69. }