Skip to content

Commit

Permalink
fix: correct typing for itemSize
Browse files Browse the repository at this point in the history
Closes #724
Reverts #688 - the PR was incorrect, and I misled the contributor.
  • Loading branch information
petyosi committed Aug 16, 2022
1 parent f6454b4 commit aab06cf
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
GridRootProps,
FlatIndexLocationWithAlign,
FlatScrollIntoViewLocation,
SizeFunction,
} from './interfaces'
import { List } from './List'
import { Grid } from './Grid'
Expand Down Expand Up @@ -121,7 +122,7 @@ export interface VirtuosoProps<D, C> extends ListRootProps {
*
* The default implementation reads `el.getBoundingClientRect().height` and `el.getBoundingClientRect().width`.
*/
itemSize?: (el: HTMLElement, dimension: 'height' | 'width') => number
itemSize?: SizeFunction

/**
* Can be used to improve performance if the rendered items are of known size.
Expand Down Expand Up @@ -349,7 +350,7 @@ export interface TableVirtuosoProps<D, C> extends Omit<VirtuosoProps<D, C>, 'com
*
* The default implementation reads `el.getBoundingClientRect().height` and `el.getBoundingClientRect().width`.
*/
itemSize?: (el: HTMLElement, dimension: 'height' | 'width') => number
itemSize?: SizeFunction

/**
* Can be used to improve performance if the rendered items are of known size.
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useChangedChildSizes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Log, LogLevel } from '../loggerSystem'
import { SizeFunction, SizeRange } from '../sizeSystem'
import { SizeRange } from '../sizeSystem'
import { useSizeWithElRef } from './useSize'
import { ScrollContainerState } from '../interfaces'
import { SizeFunction, ScrollContainerState } from '../interfaces'
export default function useChangedListContentsSizes(
callback: (ranges: SizeRange[]) => void,
itemSize: SizeFunction,
Expand Down
3 changes: 3 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,6 @@ export interface ScrollContainerState {
scrollTop: number
viewportHeight: number
}

/** Calculates the height of `el`, which will be the `Item` element in the DOM. */
export type SizeFunction = (el: HTMLElement, field: 'offsetHeight' | 'offsetWidth') => number
4 changes: 1 addition & 3 deletions src/sizeSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as arrayBinarySearch from './utils/binaryArraySearch'
import { correctItemSize } from './utils/correctItemSize'
import { loggerSystem, Log, LogLevel } from './loggerSystem'
import { recalcSystem } from './recalcSystem'
import { SizeFunction } from './interfaces'

export interface SizeRange {
startIndex: number
Expand Down Expand Up @@ -273,9 +274,6 @@ const SIZE_MAP = {
offsetWidth: 'width',
} as const

/** Calculates the height of `el`, which will be the `Item` element in the DOM. */
export type SizeFunction = (el: HTMLElement, field: 'offsetHeight' | 'offsetWidth') => number

export const sizeSystem = u.system(
([{ log }, { recalcInProgress }]) => {
const sizeRanges = u.stream<SizeRange[]>()
Expand Down

0 comments on commit aab06cf

Please sign in to comment.