forked from webpack/webpack.js.org
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPrint.js
46 lines (41 loc) · 1.04 KB
/
Print.js
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
import React from 'react';
// Load Styling
import './Print.scss';
import icon from '../../assets/icon-print.svg';
import BarIcon from '../../styles/icons/vertical-bar.svg';
const PRINTABLE_SECTIONS = [
'api',
'concepts',
'configuration',
'contribute',
'guides',
'loaders',
'migrate',
'plugins'
];
export default function Print (props) {
const { url } = props;
const printUrl = _printPageUrlFromUrl(url);
// not in a printable section
if (!printUrl) {
return null;
}
return (
<div className="sidebar-item sidebar-item--disabled`">
<BarIcon className="sidebar-item__toggle" width={15} fill='#175d96' />
<a className="sidebar-item__title sidebar-link__print"
href={printUrl}
rel="nofollow"
alt="Print"
title="Print"
target="_blank">
Print Section
<img src={icon} />
</a>
</div>
);
}
function _printPageUrlFromUrl(urlRaw) {
let urlSplit = urlRaw.split('/');
return PRINTABLE_SECTIONS.includes(urlSplit[1]) ? `/${urlSplit[1]}/printable/` : false;
}