File size: 2,306 Bytes
1e92f2d | 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 | import { Dialog, FormLabel } from '@automattic/components';
import { localize } from 'i18n-calypso';
import PropTypes from 'prop-types';
import { Component } from 'react';
import FormFieldset from 'calypso/components/forms/form-fieldset';
import FormTextInput from 'calypso/components/forms/form-text-input';
export class AddImageDialog extends Component {
static propTypes = {
onClose: PropTypes.func,
onInsert: PropTypes.func,
shouldDisplay: PropTypes.bool,
translate: PropTypes.func,
};
state = {
imageAlt: '',
imageTitle: '',
imageUrl: '',
};
setImageAlt = ( event ) => this.setState( { imageAlt: event.target.value } );
setImageTitle = ( event ) => this.setState( { imageTitle: event.target.value } );
setImageUrl = ( event ) => this.setState( { imageUrl: event.target.value } );
closeDialog = () =>
this.setState(
{
imageAlt: '',
imageTitle: '',
imageUrl: '',
},
this.props.onClose
);
insertImgTag = () => {
const { imageAlt: alt, imageTitle: title, imageUrl: src } = this.state;
this.props.onInsert( { alt, src, title } );
this.closeDialog();
};
render() {
const { shouldDisplay, translate } = this.props;
const { imageAlt, imageTitle, imageUrl } = this.state;
const buttons = [
{
action: 'cancel',
label: translate( 'Cancel' ),
},
{
action: 'add-image',
isPrimary: true,
label: translate( 'Add Image' ),
onClick: this.insertImgTag,
},
];
return (
<Dialog
isVisible={ shouldDisplay }
buttons={ buttons }
onClose={ this.closeDialog }
additionalClassNames="comment-html-editor__dialog"
>
<FormFieldset>
<FormLabel htmlFor="image_url">{ translate( 'URL' ) }</FormLabel>
<FormTextInput name="image_url" onChange={ this.setImageUrl } value={ imageUrl } />
</FormFieldset>
<FormFieldset>
<FormLabel htmlFor="image_title">{ translate( 'Title' ) }</FormLabel>
<FormTextInput name="image_title" onChange={ this.setImageTitle } value={ imageTitle } />
</FormFieldset>
<FormFieldset>
<FormLabel htmlFor="image_alt">{ translate( 'Alt Text' ) }</FormLabel>
<FormTextInput name="image_alt" onChange={ this.setImageAlt } value={ imageAlt } />
</FormFieldset>
</Dialog>
);
}
}
export default localize( AddImageDialog );
|