1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | import {DOMPropsResponderContext} from './DOMPropsContext';
|
14 | import {HoverProps} from './useHover';
|
15 | import React, {ForwardedRef, ReactNode, useEffect, useRef} from 'react';
|
16 | import {useObjectRef} from '@react-aria/utils';
|
17 |
|
18 | interface DOMPropsResponderProps extends HoverProps {
|
19 | children: ReactNode
|
20 | }
|
21 |
|
22 | export const DOMPropsResponder = React.forwardRef(({children, ...props}: DOMPropsResponderProps, ref: ForwardedRef<Element>) => {
|
23 | let isRegistered = useRef(false);
|
24 | let objRef = useObjectRef(ref);
|
25 | let context = {
|
26 | ...props,
|
27 | ref: objRef,
|
28 | register() {
|
29 | isRegistered.current = true;
|
30 | }
|
31 | };
|
32 |
|
33 |
|
34 | useEffect(() => {
|
35 | if (!isRegistered.current) {
|
36 | console.warn(
|
37 | 'A DOMPropsResponder was ultilized without a hoverable DOM node.'
|
38 | );
|
39 | }
|
40 | }, []);
|
41 |
|
42 | return (
|
43 | <DOMPropsResponderContext.Provider value={context}>
|
44 | {children}
|
45 | </DOMPropsResponderContext.Provider>
|
46 | );
|
47 | });
|