Skip to content

Commit

Permalink
feat: add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
immois committed Aug 4, 2024
1 parent aa7aa0d commit 5cfdf7b
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
56 changes: 56 additions & 0 deletions docs/en/use-scroll-lock.mdx
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.
56 changes: 56 additions & 0 deletions docs/es/use-scroll-lock.mdx
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.

0 comments on commit 5cfdf7b

Please sign in to comment.