forked from premieroctet/openchakra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSkeletonPreview.tsx
68 lines (57 loc) · 1.81 KB
/
SkeletonPreview.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import React from 'react'
import { Box, Skeleton, SkeletonCircle, SkeletonText } from '@chakra-ui/react'
import ComponentPreview from '~components/editor/ComponentPreview'
import { useDropComponent } from '~hooks/useDropComponent'
import { useInteractive } from '~hooks/useInteractive'
const SkeletonPreview: React.FC<{ component: IComponent }> = ({
component,
}) => {
const { drop, isOver } = useDropComponent(component.id)
const { props, ref } = useInteractive(component, true, true)
if (isOver) {
props.bg = 'teal.50'
}
return (
<Box ref={drop(ref)} {...props} m={0}>
<Skeleton {...component.props}>
{component.children.map((key: string) => (
<ComponentPreview key={key} componentName={key} />
))}
</Skeleton>
</Box>
)
}
export const SkeletonTextPreview = ({ component }: IPreviewProps) => {
const { props, ref } = useInteractive(component, true)
const { drop, isOver } = useDropComponent(component.id)
let boxProps: any = {}
if (isOver) {
props.bg = 'teal.50'
}
return (
<Box ref={drop(ref)} {...boxProps}>
<SkeletonText {...props}>
{component.children.map((key: string) => (
<ComponentPreview key={key} componentName={key} />
))}
</SkeletonText>
</Box>
)
}
export const SkeletonCirclePreview = ({ component }: IPreviewProps) => {
const { props, ref } = useInteractive(component, true, true)
const { drop, isOver } = useDropComponent(component.id)
if (isOver) {
props.bg = 'teal.50'
}
return (
<Box display="inline-block" ref={drop(ref)} {...props}>
<SkeletonCircle {...component.props}>
{component.children.map((key: string) => (
<ComponentPreview key={key} componentName={key} />
))}
</SkeletonCircle>
</Box>
)
}
export default SkeletonPreview