@codeleap/web 3.13.1 → 3.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeleap/web",
3
- "version": "3.13.1",
3
+ "version": "3.13.2",
4
4
  "main": "src/index.ts",
5
5
  "repository": {
6
6
  "url": "https://github.com/codeleap-uk/internal-libs-monorepo.git",
@@ -25,6 +25,7 @@ import { ActionIcon, ActionIconProps } from '../ActionIcon'
25
25
  import { Scroll } from '../Scroll'
26
26
  import { ComponentCommonProps } from '../../types'
27
27
  import { Touchable, TouchableProps } from '../Touchable'
28
+ import { useLockScroll } from '../../lib'
28
29
 
29
30
  export * from './styles'
30
31
 
@@ -332,23 +333,17 @@ export const Modal = (props) => {
332
333
  appRoot.setAttribute('tabindex', `${-1}`)
333
334
  }
334
335
 
335
- const htmlElement = document.documentElement
336
-
337
336
  if (visible) {
338
337
  document.body.style.overflowY = 'hidden'
339
338
  document.body.style.overflowX = 'hidden'
340
-
341
- htmlElement.style.overflowX = 'hidden'
342
- htmlElement.style.overflowY = 'hidden'
343
339
  } else {
344
340
  document.body.style.overflowY = 'visible'
345
341
  document.body.style.overflowX = 'hidden'
346
-
347
- htmlElement.style.overflowX = 'hidden'
348
- htmlElement.style.overflowY = 'auto'
349
342
  }
350
343
  }, [visible])
351
344
 
345
+ useLockScroll(visible)
346
+
352
347
  const content = <ModalContent {...props} id={modalId.current} />
353
348
 
354
349
  // if (renderStatus === 'unmounted') return null
@@ -8,7 +8,7 @@ import { Touchable, TouchableProps } from '../Touchable'
8
8
  import { View, ViewProps } from '../View'
9
9
  import { OverlayComposition, OverlayPresets } from './styles'
10
10
  import { NativeHTMLElement } from '../../types'
11
- import { usePopState } from '../../lib'
11
+ import { useLockScroll, usePopState } from '../../lib'
12
12
 
13
13
  export type OverlayProps<T extends NativeHTMLElement = 'div'> = {
14
14
  visible?: boolean
@@ -37,6 +37,8 @@ export const Overlay = <T extends NativeHTMLElement>(overlayProps:OverlayProps<T
37
37
 
38
38
  usePopState(visible, props.onPress, scrollLocked)
39
39
 
40
+ useLockScroll(visible)
41
+
40
42
  const Component = props.onClick || props.onPress ? Touchable : View
41
43
 
42
44
  return (
package/src/lib/hooks.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AnyFunction, onMount, onUpdate, range, useUncontrolled } from '@codeleap/common'
1
+ import { AnyFunction, onMount, onUpdate, range, useIsomorphicEffect, useUncontrolled } from '@codeleap/common'
2
2
  import { useCallback, useMemo, useRef, useState } from 'react'
3
3
  import { v4 } from 'uuid'
4
4
  import { easeInOut, EasingFunction, AnimationProps, useAnimate, useAnimation, animate } from 'framer-motion'
@@ -352,3 +352,19 @@ export function useAnimatedVariantStyles<T extends Record<string|number|symbol,
352
352
 
353
353
  return animated
354
354
  }
355
+
356
+ export function useLockScroll(isLock: boolean) {
357
+ useIsomorphicEffect(() => {
358
+ const htmlElement = document.documentElement
359
+
360
+ if (htmlElement.style.overflowX !== 'hidden') {
361
+ htmlElement.style.overflowX = 'hidden'
362
+ }
363
+
364
+ if (isLock) {
365
+ htmlElement.style.overflowY = 'hidden'
366
+ } else {
367
+ htmlElement.style.overflowY = 'auto'
368
+ }
369
+ }, [isLock])
370
+ }