Files
twenty/packages/twenty-front/src/modules/ui/utilities/scroll/hooks/useToggleScrollWrapper.ts
T
Charles Bochet 2308091b13 Remove overlay-scroll-bar (#11258)
## What

- Deprecate overlayscrollbars as we decided to follow the native
behavior
- rework on performances (avoid calling recoil states too much at field
level which is quite expensive)
- Also implements:
https://github.com/twentyhq/core-team-issues/issues/569

---------

Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
2025-04-04 16:13:48 +02:00

39 lines
1.2 KiB
TypeScript

import { ScrollWrapperComponentInstanceContext } from '@/ui/utilities/scroll/states/contexts/ScrollWrapperComponentInstanceContext';
import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow';
export const useToggleScrollWrapper = (targetComponentInstanceId?: string) => {
const instanceId = useAvailableComponentInstanceIdOrThrow(
ScrollWrapperComponentInstanceContext,
targetComponentInstanceId,
);
const toggleScrollXWrapper = (isEnabled: boolean) => {
if (isEnabled) {
document
.getElementById(`scroll-wrapper-${instanceId}`)
?.classList.add('scroll-wrapper-x-enabled');
} else {
document
.getElementById(`scroll-wrapper-${instanceId}`)
?.classList.remove('scroll-wrapper-x-enabled');
}
};
const toggleScrollYWrapper = (isEnabled: boolean) => {
if (isEnabled) {
document
.getElementById(`scroll-wrapper-${instanceId}`)
?.classList.add('scroll-wrapper-y-enabled');
} else {
document
.getElementById(`scroll-wrapper-${instanceId}`)
?.classList.remove('scroll-wrapper-y-enabled');
}
};
return {
toggleScrollXWrapper,
toggleScrollYWrapper,
};
};