import {
forwardRef,
type PropsWithChildren,
type HTMLAttributes,
type ForwardedRef,
} from 'react'
import {
getGridProps,
getGridItemProps,
splitClassNameProp,
} from '@pluralsight/headless-styles'
import type {
GridOptions,
GridItemOptions,
} from '@pluralsight/headless-styles/types'
//
interface GridProps extends GridOptions, HTMLAttributes {}
function GridEl(
props: PropsWithChildren,
ref: ForwardedRef
) {
const { areas, cols, gap, rows, ...nativeProps } = props
const pandoGridProps = getGridProps({
areas,
classNames: splitClassNameProp(nativeProps.className),
cols,
gap,
rows,
style: nativeProps.style,
})
return (
{nativeProps.children}
)
}
//
interface GridItemProps
extends GridItemOptions,
HTMLAttributes {}
function GridItemEl(
props: PropsWithChildren,
ref: ForwardedRef
) {
const { area, col, row, ...nativeProps } = props
const pandoGridItemProps = getGridItemProps({
area,
classNames: splitClassNameProp(nativeProps.className),
col,
row,
style: nativeProps.style,
})
return (
{nativeProps.children}
)
}
// exports
export const Grid = forwardRef(GridEl)
export const GridItem = forwardRef(GridItemEl)