Giter Club home page Giter Club logo

react-gesture-stack's Introduction

A demo showing views being swiped left and right.

react-gesture-stack

npm package Follow on Twitter

React-gesture-stack provides an iOS stack-like interface for use on the web. It supports gestures to "go back" in the stack. View the above example on CodeSandbox.

This was originally built for use in Sancho-UI.

Install

Install react-gesture-stack and its peer dependency react-gesture-responder using yarn or npm.

yarn add react-gesture-stack react-gesture-responder

Basic usage

import { Stack, StackItem, StackTitle } from "react-gesture-stack";
// optional styles
import "react-gesture-stack/src/styles.css";

function Simple() {
  const [index, setIndex] = React.useState(0);

  return (
    <Stack
      onIndexChange={i => setIndex(i)}
      index={index}
      style={{ width: "400px", height: "600px" }}
      items={[
        {
          title: <StackTitle title="First title" />,
          content: (
            <StackItem>
              <button onClick={() => setIndex(index + 1)}>View 2</button>
            </StackItem>
          )
        },
        {
          title: <StackTitle title="Second title" />,
          content: (
            <StackItem>
              <button onClick={() => setIndex(index + 1)}>View 3</button>
            </StackItem>
          )
        },
        {
          title: <StackTitle title="Third title" />,
          content: (
            <StackItem>
              <div>No more!</div>
            </StackItem>
          )
        }
      ]}
    />
  );
}

API

Stack

Name Type Default Value Description
index * number The index of stack item to show
onIndexChange * (i: number) => void; A callback requesting the active stack item change
items * StackItemList[] A list of stack items to render (see the above example)
disableNav boolean false Hide the top navigation pane
navHeight number 50 The height of the navigation pane (in px)

StackItem

Name Type Default Value Description
style object Optional style attributes
children React.Node Content of the stack item

StackTitle

Name Type Default Value Description
title React.Node The title of the stack item
backTitle string "Back" The title of the back button
contentAfter React.Node Content that appears to the right of the title
contentBefore React.Node Content that appears to the left of the title (and replaces the back button)
backButton React.Node Render a custom back button. You're responsible for listening to click handlers and updating the current index

License

MIT

react-gesture-stack's People

Contributors

bmcmahen 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

Watchers

 avatar

react-gesture-stack's Issues

push to array based api

the more traditional way of mapping this api is probably using a push based stack (an array). So the last item on the array is the one that's shown. I haven't done this primarily because it's hard to implement using react-spring (and combine it with gestures). This might change in future releases.

One possibility is to retain a set number of stacks (like, 10) and then map pushes to the array to these existing stacks, so we don't need to worry about mount / unmount animations. This is a bit of a hack though.

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.