GithubHelp home page GithubHelp logo

luciapuccini / react-swipeable-drawer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from damusnet/react-swipeable-drawer

0.0 1.0 0.0 1.61 MB

A swipeable drawer for the mobile web

Home Page: https://damusnet.github.io/react-swipeable-drawer/

License: MIT License

JavaScript 100.00%

react-swipeable-drawer's Introduction

react-swipeable-drawer

A swipeable drawer for the mobile web


Build Status Code Coverage Greenkeeper badge downloads version MIT License

All Contributors PRs Welcome Code of Conduct

size gzip size module formats: umd, cjs, and es

Watch on GitHub Star on GitHub Tweet

The problem

Every time I see a hamburger menu and a drawer, I try to swipe it open.

This solution

A tiny react library, with no dependencies, that relies mostly on css transforms.

demo

Installation

This module is distributed via npm which is bundled with node and should be installed as one of your project's dependencies:

npm install --save react-swipeable-drawer

This package also depends on react and prop-types. Please make sure you have those installed as well.

Usage

See the complete example.

react-swipeable-drawer allows to either use the built-in components out of the box, or to roll your own. Here is a basic example with everything included but no room for customization:

import React from "react";

import Drawer, {
  DrawerContainer,
  MainContentContainer,
} from "react-swipeable-drawer";

import DrawerContent from "./DrawerContent";
import MainContent from "./MainContent";

const App = () => (
  <Drawer position="left" size={80}>
    {({
      position,
      size,
      swiping,
      translation,
      mainContentScroll,
      toggleDrawer,
      handleTouchStart,
      handleTouchMove,
      handleTouchEnd,
    }) => (
      <div>
        <DrawerContainer
          position={position}
          size={size}
          swiping={swiping}
          translation={translation}
          toggleDrawer={toggleDrawer}
          handleTouchStart={handleTouchStart}
          handleTouchMove={handleTouchMove}
          handleTouchEnd={handleTouchEnd}
          drawerContent={<DrawerContent />}
        />
        <MainContentContainer
          translation={translation}
          mainContentScroll={mainContentScroll}
        >
          <MainContent />
        </MainContentContainer>
      </div>
    )}
  </Drawer>
);

export default App;

Alternatively, you can look at the code for <DrawerOverlay /> and <DrawerContentContainer /> and copy/paste it in place of <DrawerContainer /> to make your own customizations. Same thing for <MainContentContainer />.

Props

Drawer

  • size (integer): size (width or height) in percent (%) of the drawer
  • position (string): one of left, right, top or bottom

DrawerContainer

<DrawerContainer /> requires all the props passed down by the <Drawer /> render function. It also accepts two optionnal props:

  • overlayStyle (object): overrides the <DrawerOverlay /> style
  • contentStyle (object): overrides the <DrawerContentContainer /> style

Known limitations

Due to the fact that Safari on iOS interprets a swipe from the left as a navigation to the previous page, you will not be able to swipe the drawer open. The toggleDrawer function should still work though.

Other Solutions

Contributors

Thanks goes to these people (emoji key):


Damien Varron

๐Ÿ’ป ๐Ÿ“– ๐Ÿš‡ โš ๏ธ ๐Ÿค” ๐Ÿ”ง

Oscar Martinez

๐Ÿ’ป

This project follows the all-contributors specification. Contributions of any kind welcome!

Many thanks also to Kent C. Dodds from whom I stole the template for this repo and the build process.

LICENSE

MIT

react-swipeable-drawer's People

Contributors

damusnet avatar greenkeeper[bot] avatar lupuccini avatar

Watchers

 avatar

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.