1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | import {DOMAttributes, RefObject} from '@react-types/shared';
|
14 | import {mergeProps, useSyncRef} from '@react-aria/utils';
|
15 | import React, {MutableRefObject, useContext} from 'react';
|
16 |
|
17 | interface DOMPropsResponderProps extends DOMAttributes {
|
18 | ref?: RefObject<Element | null>
|
19 | }
|
20 |
|
21 | interface IDOMPropsResponderContext extends DOMAttributes {
|
22 | register(): void,
|
23 | ref?: MutableRefObject<Element | null>
|
24 | }
|
25 |
|
26 | export const DOMPropsResponderContext = React.createContext<IDOMPropsResponderContext | null>(null);
|
27 |
|
28 | export function useDOMPropsResponderContext(props: DOMPropsResponderProps): DOMPropsResponderProps {
|
29 |
|
30 | let context = useContext(DOMPropsResponderContext);
|
31 | if (context) {
|
32 | let {register, ...contextProps} = context;
|
33 | props = mergeProps(contextProps, props);
|
34 | register();
|
35 | }
|
36 | useSyncRef(context, props.ref);
|
37 |
|
38 | return props;
|
39 | }
|