insomnia/packages/insomnia-app/app/ui/components/base/mailto.js

35 lines
806 B
JavaScript
Raw Normal View History

// @flow
import * as React from 'react';
import autobind from 'autobind-decorator';
2018-10-17 16:42:33 +00:00
import { buildQueryStringFromParams, joinUrlAndQueryString } from 'insomnia-url';
import Link from './link';
type Props = {|
email: string,
children?: React.Node,
subject?: string,
body?: string,
|};
@autobind
class Mailto extends React.PureComponent<Props> {
2018-06-25 17:42:50 +00:00
render() {
const { email, body, subject, children } = this.props;
const params = [];
if (subject) {
2018-06-25 17:42:50 +00:00
params.push({ name: 'subject', value: subject });
}
if (body) {
2018-06-25 17:42:50 +00:00
params.push({ name: 'body', value: body });
}
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>;
}
}
export default Mailto;