2024-04-03 07:01:56 -04:00
|
|
|
import getMeta from '@/utils/meta'
|
|
|
|
|
2024-08-21 06:33:17 -04:00
|
|
|
// The reason this is a function is to ensure that the meta tag is read before
|
|
|
|
// any isBootstrap5 check is performed
|
2024-07-24 09:40:24 -04:00
|
|
|
export const isBootstrap5 = () => getMeta('ol-bootstrapVersion') === 5
|
2024-04-03 07:01:56 -04:00
|
|
|
|
2024-10-10 03:26:37 -04:00
|
|
|
/* eslint-disable no-redeclare */
|
|
|
|
export function bsVersion<A>({ bs5 }: { bs5: A }): A | undefined
|
|
|
|
export function bsVersion<B>({ bs3 }: { bs3: B }): B | undefined
|
|
|
|
export function bsVersion<A, B>({ bs5, bs3 }: { bs5: A; bs3: B }): A | B
|
|
|
|
export function bsVersion({ bs5, bs3 }: { bs5?: unknown; bs3?: unknown }) {
|
2024-07-24 09:40:24 -04:00
|
|
|
return isBootstrap5() ? bs5 : bs3
|
2024-04-03 07:01:56 -04:00
|
|
|
}
|
2024-07-10 09:34:19 -04:00
|
|
|
|
2024-10-11 05:22:38 -04:00
|
|
|
export const bsVersionIcon = ({
|
|
|
|
bs5,
|
|
|
|
bs3,
|
|
|
|
}: {
|
|
|
|
bs5?: { type: string }
|
|
|
|
bs3?: { type: string; fw?: boolean }
|
|
|
|
}) => {
|
|
|
|
return isBootstrap5() ? bs5 : bs3
|
|
|
|
}
|
|
|
|
|
2024-07-10 09:34:19 -04:00
|
|
|
// get all `aria-*` and `data-*` attributes
|
|
|
|
export const getAriaAndDataProps = (obj: Record<string, unknown>) => {
|
|
|
|
return Object.entries(obj).reduce(
|
|
|
|
(acc, [key, value]) => {
|
|
|
|
if (key.startsWith('aria-') || key.startsWith('data-')) {
|
|
|
|
acc[key] = value
|
|
|
|
}
|
|
|
|
return acc
|
|
|
|
},
|
|
|
|
{} as Record<string, unknown>
|
|
|
|
)
|
|
|
|
}
|