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