-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support multiple line-height units
- Loading branch information
Showing
4 changed files
with
78 additions
and
8 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
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
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,18 @@ | ||
/* eslint-disable no-restricted-globals */ | ||
|
||
import { matchPercent } from '@react-pdf/fns'; | ||
|
||
const processLineHeight = (value, styles) => { | ||
if (value === '') return value; | ||
|
||
const { fontSize = 18 } = styles; | ||
|
||
// Percent values: use this number multiplied by the element's font size | ||
const { percent } = matchPercent(value) || {}; | ||
if (percent) return percent * fontSize; | ||
|
||
// Unitless values: use this number multiplied by the element's font size | ||
return isNaN(value) ? value : value * fontSize; | ||
}; | ||
|
||
export default processLineHeight; |
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