-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ add ref support to Container component
- Loading branch information
1 parent
20cf2f3
commit aa02f87
Showing
1 changed file
with
9 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
import type { HTMLAttributes } from 'react'; | ||
import { HTMLAttributes, forwardRef } from 'react'; | ||
import cn from '@/utils/cn'; | ||
|
||
type ContainerProps = { | ||
as?: 'main' | 'header' | 'footer' | 'div'; | ||
} & HTMLAttributes<HTMLElement>; | ||
|
||
function Container({ as = 'div', className, ...props }: ContainerProps) { | ||
const Component = as; | ||
const Container = forwardRef<HTMLDivElement, ContainerProps>( | ||
function InternalContainer({ as = 'div', className, ...props }, ref) { | ||
const Component = as; | ||
|
||
return <Component className={cn('mx-auto', className)} {...props} />; | ||
} | ||
return ( | ||
<Component className={cn('mx-auto', className)} ref={ref} {...props} /> | ||
); | ||
} | ||
); | ||
|
||
export default Container; |