mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-01-10 02:55:41 +00:00
f5b6a49463
* Updated all translations, moved into their own folders. * Switch translations to use Markdown component. * Remove markup tests, since were using a module now. * Fix flow errors, render react elements instead of dangerouslysetinnerhtml. * Make translate a connected component, so it updates with Redux. * Fix flow errors * First pass at returning raw when needed for placeholder. * Added aria test. * Fixed flow errors and linter warnings. * Move settimeout to saga. * Change reload to 250 ms from 1500 ms
53 lines
1.4 KiB
JavaScript
53 lines
1.4 KiB
JavaScript
// @flow
|
|
// import React from 'react';
|
|
import type { Element } from 'react';
|
|
import { renderToString } from 'react-dom/server';
|
|
|
|
type PrintOptions = {
|
|
styles?: string,
|
|
printTimeout?: number,
|
|
popupFeatures?: Object
|
|
};
|
|
|
|
export default function(element: Element<*>, opts: PrintOptions = {}) {
|
|
const options = {
|
|
styles: '',
|
|
printTimeout: 500,
|
|
popupFeatures: {},
|
|
...opts
|
|
};
|
|
|
|
// Convert popupFeatures into a key=value,key=value string. See
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/Window/open#Window_features
|
|
// for more information.
|
|
const featuresStr = Object.keys(options.popupFeatures)
|
|
.map(key => `${key}=${options.popupFeatures[key]}`)
|
|
.join(',');
|
|
|
|
const popup = window.open('about:blank', 'printWindow', featuresStr);
|
|
popup.document.open();
|
|
popup.document.write(`
|
|
<html>
|
|
<head>
|
|
<style>${options.styles}</style>
|
|
<script>
|
|
setTimeout(function() {
|
|
window.print();
|
|
}, ${options.printTimeout});
|
|
</script>
|
|
</head>
|
|
<body>
|
|
${renderToString(element)}
|
|
<script>
|
|
// FIXME consider if we REALLY want it
|
|
var width = document.body.children[0].offsetWidth;
|
|
var height = document.body.children[0].offsetHeight;
|
|
window.moveTo(0, 0);
|
|
// FIXME Chrome could be larger (i guess?)
|
|
window.resizeTo(width + 60, height + 60);
|
|
</script>
|
|
</body>
|
|
</html>
|
|
`);
|
|
}
|