Giter Site home page Giter Site logo

marco-streng / styled-off-canvas Goto Github PK

View Code? Open in Web Editor NEW
74.0 2.0 4.0 6.49 MB

A simple off canvas menu built with styled-components ๐Ÿ’…

Home Page: styled-off-canvas.vercel.app

License: MIT License

JavaScript 7.96% TypeScript 90.11% Shell 0.39% HTML 1.55%
styled-components react off-canvas navigation mobile

styled-off-canvas's Introduction

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 and styled-components

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.

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

Components

styled-off-canvas comes with three components: <OffCanvasProvider />, <Menu /> and <Overlay />.

<OffCanvasProvider /> is a wrapping component which provides the menus context.

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

<Overlay /> is an optional component which renders a semi-transparent layer above your app content.

Example

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

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

  return (
    <Menu closeOnEsc>
      <CrossIcon onClick={() => close()} />
      <List />
    </Menu>
  );
};

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

  return (
    <BurgerIcon onClick={() => toggle()} />
  );
};

const App = () => {
  return (
    <Container>
      <Burger />
      <Navigation />

      <div>this is some nice content!</div>

      <Overlay />
    </Container>
  );
};

export default App

Properties

<Menu /> 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)

<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 <Menu /> and <Overlay /> can additionally be customized with styled-components

// example

<Menu css={{ border: `1px solid ${theme.menu.borderColor}` }}>...</Menu>

License

Copyright (c) 2024-present Marco Streng. See LICENSE for details.

styled-off-canvas's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar marco-streng avatar mstreng-bhs avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

styled-off-canvas's Issues

Broken in ssr

I'm trying the component with Gatsby and I have an error in the SSR bundle:

WebpackError: ReferenceError: document is not defined

The problem is in Menu.js at line 27, maybe you can test document if not undefined.

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.