2024-04-05 04:05:44 -04:00
|
|
|
import { Col } from 'react-bootstrap-5'
|
|
|
|
import { Col as BS3Col } from 'react-bootstrap'
|
|
|
|
import BootstrapVersionSwitcher from '@/features/ui/components/bootstrap-5/bootstrap-version-switcher'
|
|
|
|
|
2024-05-15 10:31:00 -04:00
|
|
|
type OLColProps = React.ComponentProps<typeof Col> & {
|
2024-04-05 04:05:44 -04:00
|
|
|
bs3Props?: Record<string, unknown>
|
|
|
|
}
|
|
|
|
|
2024-05-15 10:31:00 -04:00
|
|
|
function OLCol(props: OLColProps) {
|
2024-04-05 04:05:44 -04:00
|
|
|
const { bs3Props, ...rest } = props
|
|
|
|
|
|
|
|
const getBs3Sizes = (obj: typeof rest) => {
|
2024-05-28 04:48:42 -04:00
|
|
|
const bs5ToBs3SizeMap = {
|
2024-10-09 08:13:50 -04:00
|
|
|
xs: 'xs',
|
|
|
|
sm: 'xs',
|
2024-05-28 04:48:42 -04:00
|
|
|
md: 'sm',
|
|
|
|
lg: 'md',
|
|
|
|
xl: 'lg',
|
|
|
|
xxl: undefined,
|
|
|
|
} as const
|
|
|
|
|
|
|
|
const isBs5ToBs3SizeMapKey = (
|
|
|
|
key: string
|
|
|
|
): key is keyof typeof bs5ToBs3SizeMap => {
|
|
|
|
return key in bs5ToBs3SizeMap
|
|
|
|
}
|
|
|
|
|
|
|
|
const sizes = Object.entries(obj).reduce(
|
2024-04-05 04:05:44 -04:00
|
|
|
(prev, [key, value]) => {
|
2024-05-28 04:48:42 -04:00
|
|
|
if (isBs5ToBs3SizeMapKey(key)) {
|
|
|
|
const bs3Size = bs5ToBs3SizeMap[key]
|
|
|
|
|
|
|
|
if (bs3Size) {
|
|
|
|
if (typeof value === 'object') {
|
|
|
|
prev[bs3Size] = value.span
|
|
|
|
prev[`${bs3Size}Offset`] = value.offset
|
|
|
|
} else {
|
|
|
|
prev[bs3Size] = value
|
|
|
|
}
|
2024-04-05 04:05:44 -04:00
|
|
|
}
|
|
|
|
}
|
2024-05-28 04:48:42 -04:00
|
|
|
|
2024-04-05 04:05:44 -04:00
|
|
|
return prev
|
|
|
|
},
|
|
|
|
{} as Record<string, (typeof rest)['xs']>
|
|
|
|
)
|
2024-05-28 04:48:42 -04:00
|
|
|
|
|
|
|
// Add a default sizing for `col-xs-12` if no sizing is available
|
|
|
|
if (
|
|
|
|
!Object.keys(sizes).some(key => ['xs', 'sm', 'md', 'lg'].includes(key))
|
|
|
|
) {
|
|
|
|
sizes.xs = 12
|
|
|
|
}
|
|
|
|
|
|
|
|
return sizes
|
2024-04-05 04:05:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const bs3ColProps: React.ComponentProps<typeof BS3Col> = {
|
|
|
|
children: rest.children,
|
|
|
|
className: rest.className,
|
|
|
|
...getBs3Sizes(rest),
|
|
|
|
...bs3Props,
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<BootstrapVersionSwitcher
|
|
|
|
bs3={<BS3Col {...bs3ColProps} />}
|
|
|
|
bs5={<Col {...rest} />}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-05-15 10:31:00 -04:00
|
|
|
export default OLCol
|