Skip to content

Commit

Permalink
Merge pull request #1490 from PrefectHQ/virtual-scroller-exports-and-…
Browse files Browse the repository at this point in the history
…types

Export `getVirtualScroller` utility and fix `makeItemVisible` return type`
  • Loading branch information
pleek91 authored Oct 28, 2024
2 parents 54956ed + 95d35e5 commit ffdae6e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/components/VirtualScroller/utilities.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const scrollers = new Map<string, UseVirtualScroller>()
const noop = (): void => {}

type UseVirtualScroller = {
makeItemVisible: (itemKey: unknown) => void,
makeItemVisible: (itemKey: unknown) => () => void,
scrollItemIntoView: (itemKey: unknown, options?: ScrollIntoViewOptions) => void,
}

Expand All @@ -17,8 +18,9 @@ export function getVirtualScroller(name: string): UseVirtualScroller {

const makeItemVisible: UseVirtualScroller['makeItemVisible'] = (itemKey) => {
const scroller = scrollers.get(name)
const callback = scroller?.makeItemVisible(itemKey)

return scroller?.makeItemVisible(itemKey)
return callback ?? noop
}

const scrollItemIntoView: UseVirtualScroller['scrollItemIntoView'] = (itemKey, options) => {
Expand Down
6 changes: 5 additions & 1 deletion src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ import { PToggle, install as installPToggle } from '@/components/Toggle'
import { PTooltip, PTooltipContent, PTooltipProvider, PTooltipRoot, PTooltipTrigger, install as installPTooltip } from '@/components/Tooltip'
import { PTypeAhead, install as installPTypeAhead } from '@/components/TypeAhead'
import { PUnwrap, install as installPUnwrap } from '@/components/Unwrap'
import { PVirtualScroller, install as installPVirtualScroller } from '@/components/VirtualScroller'
import { PVirtualScroller, install as installPVirtualScroller, getVirtualScroller } from '@/components/VirtualScroller'
import { PWindow, install as installPWindow } from '@/components/Window'
import { PWizard, install as installPWizard } from '@/components/Wizard'

Expand Down Expand Up @@ -220,6 +220,10 @@ export {
PWizard
}

export {
getVirtualScroller
}

export const installs = [
installPAccordion,
installPAutoHeightTransition,
Expand Down

0 comments on commit ffdae6e

Please sign in to comment.