• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

terrestris / react-geo / 21403141555

27 Jan 2026 03:27PM UTC coverage: 68.058% (+0.1%) from 67.962%
21403141555

Pull #4474

github

web-flow
Merge 4ae47bc43 into 546b57526
Pull Request #4474: fix print button typing

682 of 1086 branches covered (62.8%)

Branch coverage included in aggregate %.

5 of 8 new or added lines in 1 file covered. (62.5%)

2 existing lines in 1 file now uncovered.

1259 of 1766 relevant lines covered (71.29%)

14.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

69.7
/src/Button/PrintButton/PrintButton.tsx
1
import React, {
2
  useState
3
} from 'react';
4

5
import useMap from '@terrestris/react-util/dist/Hooks/useMap/useMap';
6
import { PdfPrintSpec, PngPrintSpec, PrintSpec, PrintUtil } from '@terrestris/react-util/dist/Util/PrintUtil';
7

8
import SimpleButton, {
9
  SimpleButtonProps
10
} from '../SimpleButton/SimpleButton';
11

12
type BaseProps = Omit<PrintSpec, 'map'> & SimpleButtonProps;
13

14
type PngProps = Omit<PngPrintSpec, 'map' | 'format'> & {
15
  format?: 'png';
16
};
17

18
type PdfProps = Omit<PdfPrintSpec, 'map' | 'format' | 'pdfPrintFunc'> & {
19
  format: 'pdf';
20
  pdfPrintFunc: PdfPrintSpec['pdfPrintFunc'];
21
};
22

23
export type PrintButtonProps = BaseProps & (PngProps | PdfProps);
24

25
export const PrintButton: React.FC<PrintButtonProps> = (props) => {
1✔
26
  const {
27
    attributions = 'bottom-right',
7✔
28
    dpi = 120,
7✔
29
    extent,
30
    extentPadding,
31
    format, // plese note: setting a default here breaks the typing
32
    legendTitle = 'Legend',
7✔
33
    mapSize,
34
    northArrow = 'top-right',
7✔
35
    onProgressChange,
36
    outputFileName = 'react-geo-image',
7✔
37
    scaleBar = {
7✔
38
      position: 'bottom-left',
39
      units: 'metric'
40
    },
41
    title = 'Print',
7✔
42
    ...passThroughProps
43
  } = props;
7✔
44

45
  const [loading, setLoading] = useState<boolean>(false);
7✔
46
  const map = useMap();
7✔
47

48
  const onPrintClick = async () => {
7✔
49
    if (!map) {
2!
50
      return;
×
51
    }
52
    if (format === 'pdf') {
2!
NEW
53
      const { pdfPrintFunc } = props;
×
UNCOV
54
      setLoading(true);
×
NEW
55
      const pdfPrintSpec: PdfPrintSpec = {
×
56
        dpi,
57
        extent,
58
        extentPadding,
59
        format,
60
        legendTitle,
61
        map,
62
        mapSize,
63
        northArrow,
64
        onProgressChange,
65
        outputFileName,
66
        pdfPrintFunc,
67
        scaleBar,
68
        title
69
      };
NEW
70
      await PrintUtil.printPdf(pdfPrintSpec);
×
UNCOV
71
      setLoading(false);
×
72
    } else {
73
      // format = "png" or undefined -> "png"
74
      setLoading(true);
2✔
75
      const pngPrintSpec: PngPrintSpec = {
2✔
76
        attributions,
77
        dpi,
78
        extent,
79
        extentPadding,
80
        format: 'png',
81
        map,
82
        mapSize,
83
        onProgressChange,
84
        outputFileName,
85
        scaleBar
86
      };
87
      await PrintUtil.printPng(pngPrintSpec);
2✔
88
      setLoading(false);
2✔
89
    }
90
  };
91

92
  if (!map) {
7!
93
    return null;
×
94
  }
95

96
  return (
7✔
97
    <SimpleButton
98
      loading={loading}
99
      onClick={onPrintClick}
100
      {...passThroughProps}
101
    />
102
  );
103

104
};
105

106
export default PrintButton;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc