bootstrap-5.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  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. export const bsVersionIcon = ({
  13. bs5,
  14. bs3,
  15. }: {
  16. bs5?: { type: string }
  17. bs3?: { type: string; fw?: boolean }
  18. }) => {
  19. return isBootstrap5() ? bs5 : bs3
  20. }
  21. // get all `aria-*` and `data-*` attributes
  22. export const getAriaAndDataProps = (obj: Record<string, unknown>) => {
  23. return Object.entries(obj).reduce(
  24. (acc, [key, value]) => {
  25. if (key.startsWith('aria-') || key.startsWith('data-')) {
  26. acc[key] = value
  27. }
  28. return acc
  29. },
  30. {} as Record<string, unknown>
  31. )
  32. }