GitHub

@@ -1,6 +1,6 @@

11

import { get } from './index'

223-

function hasDescription(item: any, descriptionKey: string): boolean {

3+

function itemHasDescription(item: any, descriptionKey: string): boolean {

44

if (typeof item !== 'object' || item === null) {

55

return false

66

}

@@ -30,18 +30,22 @@ function getSize(size: 'xs' | 'sm' | 'md' | 'lg' | 'xl', hasDescription: boolean

30303131

/**

3232

* Get estimate size for virtualizers that checks each item individually

33-

* NOTE: This requires Reka UI to support functions for estimateSize (https://github.com/unovue/reka-ui/pull/2288)

34-

* Until then, we check if ANY item has a description and use that for all items

3533

*/

36-

export function getEstimateSize(items: any[], size: 'xs' | 'sm' | 'md' | 'lg' | 'xl', descriptionKey?: string): number {

37-

// TODO: Once Reka UI supports functions, uncomment and change return type to: number | ((index: number) => number)

38-

// return (index: number) => {

39-

// const item = items[index]

40-

// const hasDescription = descriptionKey ? hasDescription(item, descriptionKey) : false

41-

// return getSize(size, hasDescription)

42-

// }

34+

export function getEstimateSize(items: any[], size: 'xs' | 'sm' | 'md' | 'lg' | 'xl', descriptionKey?: string, hasDescriptionSlot?: boolean): (index: number) => number {

35+

const sizeWithDescription = getSize(size, true)

36+

const sizeWithoutDescription = getSize(size, false)

433744-

// For now, check if ANY item has a description and use a static size

45-

const anyHasDescription = descriptionKey ? items.some(item => hasDescription(item, descriptionKey)) : false

46-

return getSize(size, anyHasDescription)

38+

// If description slot is used, all items get the larger size

39+

if (hasDescriptionSlot) {

40+

return () => sizeWithDescription

41+

}

42+43+

// If no descriptionKey, all items get the smaller size

44+

if (!descriptionKey) {

45+

return () => sizeWithoutDescription

46+

}

47+48+

return (index: number) => {

49+

return itemHasDescription(items[index], descriptionKey) ? sizeWithDescription : sizeWithoutDescription

50+

}

4751

}

Read the original on github.com ↗