Coder Social home page Coder Social logo

secretmapper / react-reader Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gerhardsletten/react-reader

0.0 2.0 0.0 191 KB

An ePub-reader for React, powered by Epub.js - http://gerhardsletten.github.io/react-reader/

CSS 10.33% JavaScript 76.68% HTML 12.99%

react-reader's Introduction

React ePub reader

An ePub-reader for react powered by EpubJS #react #epubjs #webpack #babel #standardjs

See demo

React Reader logo

In beta

Since it the underlaying library is using epub.js we need their v0.3 version to be finalized which bring commom modules to the library. Write now we use a custom fork of the work in progress branch.

About

epub.js is a great library, and this is a wrapper for this library, making it easier to use in a React-app.

import {
  EpubView, // Underlaying epub-canvas (wrapper for epub.js iframe)
  EpubViewStyle, // Styles for EpubView, you can pass it to the instance as a style prop for customize it
  ReactReader, // A simple epub-reader with left/right button and chapter navigation
  ReactReaderStyle // Styles for the epub-reader it you need to customize it
} from 'react-reader'

Usage

npm install react-reader --save

And in your react-component...

import React, {Component} from 'react'
import {ReactReader} from 'react-reader'

class App extends Component {
  render () {
    return (
      <div style={{position: 'relative', height: '100%'}}> // * Container needs a height..
        <ReactReader 
          url={'/alice.epub'} 
          title={'Alice in wonderland'}
          location={'epubcfi(/6/2[cover]!/6)'}
          locationChanged={(epubcifi) => console.log(epubcifi)}
        />
      </div>
    )
  }
}

ReactReader props

  • url [string, required] - url to the epub-file, if its on another domain, remember to add cors for the file
  • title [string] - the title of the book, displayed above the reading-canvas
  • loadingView [element] - if you want to customize the loadingView
  • showToc [bool] - wheather to show the toc / toc-nav
  • location [string, number] - set / update location of the epub
  • locationChange [func] - a function that recives the current location while user is reading
  • tocChange [func] - when the the reader has parsed the book you will recive an array of the chapters

Container needs a height.. The ReactReader will expand to 100% of width/height, so be sure to set a height on the parent element, either with position it absolute of window, set height or use paddingTop for proporsjonal scaling.

Optional use the underlaying EpubView

This is just the plain epub canvas, you will then need to implement the reader stuff like chapter (toc) navigation and next/prev buttons. Take a look at the implemention in ReactReader.js

import React, {Component} from 'react'
import {EpubView} from 'react-reader'

class App extends Component {
  render () {
    return (
      /* The ReactReader will expand to 100% of width/height, so be sure to set a height on the parent element, either with position it absolute of window, set height or use paddingTop for proporsjonal scaling */
      <div style={{position: 'relative', height: '100%'}}>
        <EpubView 
          url={'/alice.epub'} 
          location={'epubcfi(/6/2[cover]!/6)'}
          locationChanged={(epubcifi) => console.log(epubcifi)}
          tocChanged={(toc) => console.log(toc)}
        />
      </div>
    )
  }
}

EpubView props

  • url [string, required] - url to the epub-file, if its on another domain, remember to add cors for the file
  • loadingView [element] - if you want to customize the loadingView
  • location [string, number] - set / update location of the epub
  • locationChange [func] - a function that recives the current location while user is reading
  • tocChange [func] - when the the reader has parsed the book you will recive an array of the chapters

js-standard-style

react-reader's People

Contributors

gerhardsletten avatar secretmapper avatar

Watchers

 avatar  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.