Skip to content

Commit

Permalink
refactor(core): move ReferenceItemRefContext to singletons
Browse files Browse the repository at this point in the history
  • Loading branch information
binoy14 committed Apr 29, 2024
1 parent 6325629 commit a25a30b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* eslint-disable import/no-duplicates */
import type {MutableRefObject} from 'react'
import {createContext} from 'react'

/**
* @internal
*/
export interface ReferenceItemRef {
menuRef: MutableRefObject<HTMLDivElement | null>
containerRef: MutableRefObject<HTMLDivElement | null>
}

/**
* This is a way to store ref of the menu as well as the container of the ReferenceItem
* so it can be used down the tree for clickOutside handling
* @internal
*/
export const ReferenceItemRefContext = createContext<ReferenceItemRef | null>(null)
1 change: 1 addition & 0 deletions packages/sanity/src/_singletons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ export * from './form/inputs/arrays/ArrayOfObjectsInput/List/VirtualizerScrollIn
export * from './form/inputs/arrays/common/SortableItemIdContext'
export * from './form/inputs/PortableText/PortableTextMarkersContext'
export * from './form/inputs/PortableText/PortableTextMemberItemsContext'
export * from './form/inputs/ReferenceInput/ReferenceItemRefContext'
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {type ReactNode} from 'react'

import {type ReferenceItemRef, ReferenceItemRefContext} from './useReferenceItemRef'
import {type ReferenceItemRef, ReferenceItemRefContext} from 'sanity/_singletons'

/**
* @internal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
import {createContext, type MutableRefObject, useContext} from 'react'

/**
* @internal
*/
export interface ReferenceItemRef {
menuRef: MutableRefObject<HTMLDivElement | null>
containerRef: MutableRefObject<HTMLDivElement | null>
}

/**
* This is a way to store ref of the menu as well as the container of the ReferenceItem
* so it can be used down the tree for clickOutside handling
* @internal
*/
export const ReferenceItemRefContext = createContext<ReferenceItemRef | null>(null)
import {useContext} from 'react'
import {type ReferenceItemRef, ReferenceItemRefContext} from 'sanity/_singletons'

/**
* @internal
Expand Down

0 comments on commit a25a30b

Please sign in to comment.