Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/marco-streng/styled-off-canvas

A simple off canvas menu built with styled-components 💅
https://github.com/marco-streng/styled-off-canvas

mobile navigation off-canvas react styled-components

Last synced: 3 days ago
JSON representation

A simple off canvas menu built with styled-components 💅

Awesome Lists containing this project

README

        


styled-off-canvas


💅 styled-off-canvas


A simple off canvas menu built with styled-components



Node CI build status


Built with Styled Components

## Description

styled-off-canvas is a customizable off-canvas menu built with [React](https://reactjs.org/) and [styled-components](https://www.styled-components.com/)

## Demo

A demo can be found here: Demo

## Installation

```
# via npm
npm install styled-off-canvas

# via yarn
yarn install styled-off-canvas
```

## Implementation

### Hook

The `useOffCanvas()` hook provies the current state and all methods to contorl the menu.

```javascript
const { isOpen, toggle, close, open } = useOffCanvas();
``````

### Components

`styled-off-canvas` comes with three components: ``, `` and ``.

`` is a wrapping component which provides the menus context.

`` is the off-canvas menu itself. You can pass anything you want as children (e.g. styled list of router links)

`` is an optional component which renders a semi-transparent layer above your app content.

### Example

```javascript
import React, { useState } from 'react'
import { StyledOffCanvas, Menu, Overlay } from 'styled-off-canvas'

const Navigation = () => {
const { close } = useOffCanvas();

return (

close()} />


);
};

const Burger = () => {
const { isOpen, toggle } = useOffCanvas();

return (
toggle()} />
);
};

const App = () => {
return (


this is some nice content!



);
};

export default App
```

### Properties

`` component

* `background = '#fff'`: background color of the menu
* `duration = '500ms'`: duration of the css transition of the menu
* `closeOnEsc = true`: if the menu should close on esc keydown
* `position = 'right'`: position of the menu (`left` or `right`)
* `width = '300px'`: maximum width of the menu
* `onClose`: callback function if menu closes (e.g. by click on the overlay)

`` component

* `background = '#000'`: background color of the overlay
* `duration = '500ms'`: duration of the open/close animation of the overlay
* `opacity = 0.3`: css opacity of the overlay

Also `` and `` can additionally be customized with styled-components

```jsx
// example

...
```

## License

Copyright (c) 2024-present Marco Streng. See [LICENSE](./LICENSE.md) for details.