-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
--- | ||
title: useScrollLock | ||
description: Disables scrolling in the document body. | ||
--- | ||
|
||
## Features | ||
|
||
- Removes the scroll bar from the document, while preserving the width of the page. | ||
- Works on any desktop or mobile browser. | ||
|
||
## Installation | ||
|
||
Install the custom hook from your command line. | ||
|
||
<Snippet pkg text='@raddix/use-scroll-lock' /> | ||
|
||
## Usage | ||
|
||
Once the component using the `useScrollLock` hook is mounted, scrolling is disabled | ||
in the document body. When the component is unmounted, the hook returns a cleanup function | ||
that restores the original overflow style. | ||
|
||
```jsx | ||
import { useState } from 'react'; | ||
import { useScrollLock } from '@raddix/use-scroll-lock'; | ||
|
||
function Modal({ handleClose }) { | ||
useScrollLock(); | ||
|
||
return ( | ||
<dialog> | ||
<button onClick={handleClose}>Close</button> | ||
<h2>Modal</h2> | ||
</dialog> | ||
) | ||
} | ||
|
||
export default function App() { | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
return ( | ||
<> | ||
{isOpen && <Modal handleClose={() => setIsOpen(false)} />} | ||
<button className="primary" onClick={() => setIsOpen(true)}> | ||
Open Modal | ||
</button> | ||
</> | ||
); | ||
} | ||
``` | ||
|
||
## API | ||
|
||
### Parameters | ||
|
||
The `useScrollLock` hook does not accept any parameters. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
--- | ||
title: useScrollLock | ||
description: Deshabilita el desplazamiento en el cuerpo del documento. | ||
--- | ||
|
||
## Características | ||
|
||
- Elimina la barra de desplazamiento del documento, conservando el ancho de la página. | ||
- Funciona en cualquier navegador de escritorio o móvil. | ||
|
||
## Instalación | ||
|
||
Instala el custom hook desde su linea de comando. | ||
|
||
<Snippet pkg text='@raddix/use-scroll-lock' /> | ||
|
||
## Uso | ||
|
||
Una vez que el componente que utiliza el hook `useScrollLock` se monta, se deshabilita el desplazamiento | ||
en el cuerpo del documento. Cuando se desmonta el componente el hook devuelve una función de limpieza | ||
que restaura el estilo de desbordamiento original. | ||
|
||
```jsx | ||
import { useState } from 'react'; | ||
import { useScrollLock } from '@raddix/use-scroll-lock'; | ||
|
||
function Modal({ handleClose }) { | ||
useScrollLock(); | ||
|
||
return ( | ||
<dialog> | ||
<button onClick={handleClose}>Close</button> | ||
<h2>Modal</h2> | ||
</dialog> | ||
) | ||
} | ||
|
||
export default function App() { | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
return ( | ||
<> | ||
{isOpen && <Modal handleClose={() => setIsOpen(false)} />} | ||
<button className="primary" onClick={() => setIsOpen(true)}> | ||
Open Modal | ||
</button> | ||
</> | ||
); | ||
} | ||
``` | ||
|
||
## API | ||
|
||
### Parámetros | ||
|
||
El hook `useScrollLock` no acepta ningun parámetro. |