您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

SharedVideoDialog.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // @flow
  2. import { FieldTextStateless } from '@atlaskit/field-text';
  3. import React from 'react';
  4. import { Dialog } from '../../../base/dialog';
  5. import { translate } from '../../../base/i18n';
  6. import { getFieldValue } from '../../../base/react';
  7. import { connect } from '../../../base/redux';
  8. import { defaultSharedVideoLink } from '../../constants';
  9. import { getYoutubeLink } from '../../functions';
  10. import AbstractSharedVideoDialog from '../AbstractSharedVideoDialog';
  11. /**
  12. * Component that renders the video share dialog.
  13. *
  14. * @returns {React$Element<any>}
  15. */
  16. class SharedVideoDialog extends AbstractSharedVideoDialog<*> {
  17. /**
  18. * Instantiates a new component.
  19. *
  20. * @inheritdoc
  21. */
  22. constructor(props) {
  23. super(props);
  24. this.state = {
  25. value: '',
  26. okDisabled: true
  27. };
  28. this._onChange = this._onChange.bind(this);
  29. this._onSubmitValue = this._onSubmitValue.bind(this);
  30. }
  31. _onChange: Object => void;
  32. /**
  33. * Callback for the onChange event of the field.
  34. *
  35. * @param {Object} evt - The static event.
  36. * @returns {void}
  37. */
  38. _onChange(evt: Object) {
  39. const linkValue = getFieldValue(evt);
  40. this.setState({
  41. value: linkValue,
  42. okDisabled: !getYoutubeLink(linkValue)
  43. });
  44. }
  45. _onSubmitValue: () => boolean;
  46. /**
  47. * Callback to be invoked when the value of the link input is submitted.
  48. *
  49. * @returns {boolean}
  50. */
  51. _onSubmitValue() {
  52. return this._onSetVideoLink(this.state.value);
  53. }
  54. /**
  55. * Implements React's {@link Component#render()}.
  56. *
  57. * @inheritdoc
  58. */
  59. render() {
  60. const { t } = this.props;
  61. return (
  62. <Dialog
  63. hideCancelButton = { false }
  64. okDisabled = { this.state.okDisabled }
  65. okKey = { t('dialog.Share') }
  66. onSubmit = { this._onSubmitValue }
  67. titleKey = { t('dialog.shareVideoTitle') }
  68. width = { 'small' }>
  69. <FieldTextStateless
  70. autoFocus = { true }
  71. className = 'input-control'
  72. compact = { false }
  73. label = { t('dialog.videoLink') }
  74. name = 'sharedVideoUrl'
  75. onChange = { this._onChange }
  76. placeholder = { defaultSharedVideoLink }
  77. shouldFitContainer = { true }
  78. type = 'text'
  79. value = { this.state.value } />
  80. </Dialog>
  81. );
  82. }
  83. _onSetVideoLink: string => boolean;
  84. _onChange: Object => void;
  85. }
  86. export default translate(connect()(SharedVideoDialog));