-
Notifications
You must be signed in to change notification settings - Fork 4k
/
component.tsx
46 lines (40 loc) · 1.09 KB
/
component.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* External dependencies
*/
// eslint-disable-next-line no-restricted-imports
import type { Ref } from 'react';
/**
* Internal dependencies
*/
import { useToolsPanelItem } from './hook';
import { View } from '../../view';
import { contextConnect, WordPressComponentProps } from '../../ui/context';
import type { ToolsPanelItemProps } from '../types';
// This wraps controls to be conditionally displayed within a tools panel. It
// prevents props being applied to HTML elements that would make them invalid.
const ToolsPanelItem = (
props: WordPressComponentProps< ToolsPanelItemProps, 'div' >,
forwardedRef: Ref< any >
) => {
const {
children,
isShown,
shouldRenderPlaceholder,
...toolsPanelItemProps
} = useToolsPanelItem( props );
if ( ! isShown ) {
return shouldRenderPlaceholder ? (
<View { ...toolsPanelItemProps } ref={ forwardedRef } />
) : null;
}
return (
<View { ...toolsPanelItemProps } ref={ forwardedRef }>
{ children }
</View>
);
};
const ConnectedToolsPanelItem = contextConnect(
ToolsPanelItem,
'ToolsPanelItem'
);
export default ConnectedToolsPanelItem;