bootstrap-5.ts 920 B

1234567891011121314151617181920212223242526
  1. import getMeta from '@/utils/meta'
  2. // The reason this is a function is to ensure that the meta tag is read before
  3. // any isBootstrap5 check is performed
  4. export const isBootstrap5 = () => getMeta('ol-bootstrapVersion') === 5
  5. /* eslint-disable no-redeclare */
  6. export function bsVersion<A>({ bs5 }: { bs5: A }): A | undefined
  7. export function bsVersion<B>({ bs3 }: { bs3: B }): B | undefined
  8. export function bsVersion<A, B>({ bs5, bs3 }: { bs5: A; bs3: B }): A | B
  9. export function bsVersion({ bs5, bs3 }: { bs5?: unknown; bs3?: unknown }) {
  10. return isBootstrap5() ? bs5 : bs3
  11. }
  12. // get all `aria-*` and `data-*` attributes
  13. export const getAriaAndDataProps = (obj: Record<string, unknown>) => {
  14. return Object.entries(obj).reduce(
  15. (acc, [key, value]) => {
  16. if (key.startsWith('aria-') || key.startsWith('data-')) {
  17. acc[key] = value
  18. }
  19. return acc
  20. },
  21. {} as Record<string, unknown>
  22. )
  23. }