forked from diegomura/react-pdf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: specifying ids on elements (named destinations) (diegomura#2549)
- Loading branch information
1 parent
5f970f5
commit 9b4d66b
Showing
4 changed files
with
47 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@react-pdf/pdfkit': patch | ||
--- | ||
|
||
Fix named destinations (id attribute with string value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
/* | ||
PDFNumberTree - represents a number tree object | ||
PDFNameTree - represents a name tree object | ||
*/ | ||
|
||
import PDFTree from './tree'; | ||
import PDFTree from "./tree"; | ||
|
||
class PDFNumberTree extends PDFTree { | ||
class PDFNameTree extends PDFTree { | ||
_compareKeys(a, b) { | ||
return parseInt(a) - parseInt(b); | ||
return a.localeCompare(b); | ||
} | ||
|
||
_keysName() { | ||
return 'Nums'; | ||
return 'Names'; | ||
} | ||
|
||
_dataForKey(k) { | ||
return parseInt(k); | ||
return new String(k); | ||
} | ||
} | ||
|
||
export default PDFNumberTree; | ||
export default PDFNameTree; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* eslint-disable react/no-array-index-key */ | ||
import { Document, Font, Link, Page, Text, View } from '@react-pdf/renderer'; | ||
import renderToImage from './renderComponent'; | ||
|
||
Font.register({ | ||
family: 'Lato', | ||
src: 'https://fonts.gstatic.com/s/lato/v16/S6uyw4BMUTPHjx4wWw.ttf', | ||
}); | ||
|
||
const Doc = () => ( | ||
<Document> | ||
<Page | ||
orientation="landscape" | ||
size="A4" | ||
style={{ padding: 30, fontSize: 24, fontFamily: 'Lato' }} | ||
> | ||
<View> | ||
<Link href="#nameddestination"> | ||
<Text>Click me to get to the named destination</Text> | ||
</Link> | ||
</View> | ||
<View id="nameddestination" break> | ||
<Text>Here is the named destination</Text> | ||
</View> | ||
</Page> | ||
</Document> | ||
); | ||
|
||
describe('named destinations', () => { | ||
test('should visually match snapshot', async () => { | ||
const image = await renderToImage(<Doc />); | ||
|
||
expect(image).toMatchImageSnapshot(); | ||
}); | ||
}); |
Binary file added
BIN
+19.9 KB
...stinations-test-js-named-destinations-should-visually-match-snapshot-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.