-
Notifications
You must be signed in to change notification settings - Fork 377
Expand file tree
/
Copy pathLoadingContainer.tsx
More file actions
51 lines (48 loc) · 1.09 KB
/
LoadingContainer.tsx
File metadata and controls
51 lines (48 loc) · 1.09 KB
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
import type { Side } from '@/types'
import { cn } from '@/utils'
import React from 'react'
import { LoadingIcon } from './LoadingIcon'
export interface LoadingContainerProps
extends React.HTMLAttributes<HTMLDivElement> {
isLoading?: boolean
message?: React.ReactNode
side?: Side
className?: string
}
export const LoadingContainer = React.forwardRef<
HTMLDivElement,
LoadingContainerProps
>(
(
{
isLoading = true,
side = 'left',
message,
children,
className,
}: LoadingContainerProps,
ref,
) => {
function renderLoading() {
return (
<>
<LoadingIcon />
{message && <span className="text-sm">{message}</span>}
</>
)
}
return isLoading ? (
<div
ref={ref}
data-component="LoadingContainer"
className={cn('flex items-center justify-center gap-2', className)}
>
{(side === 'left' || side === 'both') && renderLoading()}
{children}
{(side === 'right' || side === 'both') && renderLoading()}
</div>
) : (
children
)
},
)