2021-02-02 22:23:42 +00:00
|
|
|
import { autoBindMethodsForReact } from 'class-autobind-decorator';
|
2018-10-17 16:42:33 +00:00
|
|
|
import { buildQueryStringFromParams, joinUrlAndQueryString } from 'insomnia-url';
|
2021-07-22 23:04:56 +00:00
|
|
|
import React, { PureComponent, ReactNode } from 'react';
|
|
|
|
|
|
|
|
import { AUTOBIND_CFG } from '../../../common/constants';
|
2021-09-27 13:47:22 +00:00
|
|
|
import { Link } from './link';
|
2017-10-13 13:01:27 +00:00
|
|
|
|
2021-05-12 06:35:00 +00:00
|
|
|
interface Props {
|
|
|
|
email: string;
|
|
|
|
children?: ReactNode;
|
|
|
|
subject?: string;
|
|
|
|
body?: string;
|
|
|
|
}
|
2017-10-13 13:01:27 +00:00
|
|
|
|
2021-02-02 22:23:42 +00:00
|
|
|
@autoBindMethodsForReact(AUTOBIND_CFG)
|
2021-09-27 13:47:22 +00:00
|
|
|
export class Mailto extends PureComponent<Props> {
|
2018-06-25 17:42:50 +00:00
|
|
|
render() {
|
|
|
|
const { email, body, subject, children } = this.props;
|
2021-05-18 20:32:18 +00:00
|
|
|
const params: {name: string; value: string}[] = [];
|
2017-10-13 13:01:27 +00:00
|
|
|
|
|
|
|
if (subject) {
|
2021-05-12 06:35:00 +00:00
|
|
|
params.push({
|
|
|
|
name: 'subject',
|
|
|
|
value: subject,
|
|
|
|
});
|
2017-10-13 13:01:27 +00:00
|
|
|
}
|
2021-05-12 06:35:00 +00:00
|
|
|
|
2017-10-13 13:01:27 +00:00
|
|
|
if (body) {
|
2021-05-12 06:35:00 +00:00
|
|
|
params.push({
|
|
|
|
name: 'body',
|
|
|
|
value: body,
|
|
|
|
});
|
2017-10-13 13:01:27 +00:00
|
|
|
}
|
|
|
|
|
2017-11-26 20:45:40 +00:00
|
|
|
const qs = buildQueryStringFromParams(params);
|
|
|
|
const href = joinUrlAndQueryString(`mailto:${email}`, qs);
|
2018-06-25 17:42:50 +00:00
|
|
|
return <Link href={href}>{children || email}</Link>;
|
2017-10-13 13:01:27 +00:00
|
|
|
}
|
|
|
|
}
|