Files
workforce-pay-bill-p/src/components/ui/stack.tsx

64 lines
1.5 KiB
TypeScript

import * as React from 'react'
import { cn } from '@/lib/utils'
export interface StackProps extends React.HTMLAttributes<HTMLDivElement> {
direction?: 'horizontal' | 'vertical'
spacing?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 8 | 10 | 12
align?: 'start' | 'center' | 'end' | 'stretch' | 'baseline'
justify?: 'start' | 'center' | 'end' | 'between' | 'around' | 'evenly'
wrap?: boolean
}
const Stack = React.forwardRef<HTMLDivElement, StackProps>(
({
className,
direction = 'vertical',
spacing = 4,
align = 'stretch',
justify = 'start',
wrap = false,
children,
...props
}, ref) => {
const isHorizontal = direction === 'horizontal'
const alignmentClass = {
start: 'items-start',
center: 'items-center',
end: 'items-end',
stretch: 'items-stretch',
baseline: 'items-baseline'
}[align]
const justifyClass = {
start: 'justify-start',
center: 'justify-center',
end: 'justify-end',
between: 'justify-between',
around: 'justify-around',
evenly: 'justify-evenly'
}[justify]
return (
<div
ref={ref}
className={cn(
'flex',
isHorizontal ? 'flex-row' : 'flex-col',
`gap-${spacing}`,
alignmentClass,
justifyClass,
wrap && 'flex-wrap',
className
)}
{...props}
>
{children}
</div>
)
}
)
Stack.displayName = 'Stack'
export { Stack }