-
-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename ChunkSize to PxToPercent for clarity
- Loading branch information
David Cetinkaya
committed
Feb 21, 2020
1 parent
142bf73
commit f2820de
Showing
10 changed files
with
58 additions
and
57 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,16 @@ | ||
import { PxToPercent } from '../components/pxToPercent' | ||
|
||
const itemSize = 25 | ||
const wiewInPx = 1000 | ||
const pxToPercent = PxToPercent(wiewInPx) | ||
|
||
describe('PxToPercent', () => { | ||
test('Exposes correct totalPercent', () => { | ||
expect(pxToPercent.totalPercent).toBe(100) | ||
}) | ||
|
||
test('Converts given pixels to percentage of view', () => { | ||
const measure = pxToPercent.measure(itemSize) | ||
expect(measure).toBe(2.5) | ||
}) | ||
}) |
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 was deleted.
Oops, something went wrong.
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 @@ | ||
export type PxToPercent = { | ||
measure: (n: number) => number | ||
totalPercent: number | ||
} | ||
|
||
export function PxToPercent(viewInPx: number): PxToPercent { | ||
const totalPercent = 100 | ||
|
||
function measure(n: number): number { | ||
return (n / viewInPx) * totalPercent | ||
} | ||
|
||
const self: PxToPercent = { | ||
measure, | ||
totalPercent, | ||
} | ||
return Object.freeze(self) | ||
} |
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