UNPKG

@atlaskit/app-provider

Version:

A top level provider for the Design System.

31 lines (30 loc) 1.51 kB
import { useEffect } from 'react'; import { getDocument } from '@atlaskit/browser-apis'; import { fg } from '@atlaskit/platform-feature-flags/fg'; import { installScrollbarHarmonisation } from './install-scrollbar-harmonisation'; import { installScrollbarHarmonisationTransparentTrack } from './install-scrollbar-harmonisation-transparent-track'; /** * Activates the harmonised scrollbar appearance. An explicit value overrides the shared rollout * gate; when omitted, the shared gate controls the appearance. */ export function useScrollbarHarmonisation(isEnabled) { const isGateEnabled = fg('platform_dst_scrollbar_harmonisation'); const shouldEnable = isEnabled !== null && isEnabled !== void 0 ? isEnabled : isGateEnabled; const isTransparentTrackGateEnabled = fg('platform_dst_scrollbar_harmonisation_transparent'); const shouldUseTransparentTrack = isGateEnabled && isTransparentTrackGateEnabled; useEffect(() => { if (!shouldEnable) { return; } const targetDocument = getDocument(); if (!targetDocument) { return; } const cleanupHarmonisation = installScrollbarHarmonisation(targetDocument); const cleanupTransparentTrack = shouldUseTransparentTrack ? installScrollbarHarmonisationTransparentTrack(targetDocument) : undefined; return () => { cleanupTransparentTrack === null || cleanupTransparentTrack === void 0 ? void 0 : cleanupTransparentTrack(); cleanupHarmonisation(); }; }, [shouldEnable, shouldUseTransparentTrack]); }