1.2.14 • Published 9 months ago

@boosters/book-reader v1.2.14

Weekly downloads
-
License
-
Repository
-
Last release
9 months ago

@boosters/book-reader

It is library which export only 1 component - Reader. It is used for reading books.

Usage

To use this library you should install it:

npm i @boosters/book-reader

Then you can import it:

import { BookReader, Book } from '@boosters/book-reader';

And use it:

<BookReader
  book={book as Book}
  onSwitchPage={({ direction, page }) => {
    console.log(direction, page);
  }}
  onClose={() => {
    console.log('close');
  }}
  initialItemId={22}
/>

Props

NameTypeDefault valueDescription
bookBook-Book object
onBookReady(params: BookReadyParams => void-Callback which call when book content is ready
onSwitchPage(params: SwitchPageParams => void-Callback which call when user switch page
onClose(params: CloseParams => void-Callback which call when user click close button
initialItemIdnumber-paragraph id, which must be opened on opening reader
onSettingsChange(settings: SettingsChangeParams) => void-Callback which call when change reader settings
initialSettingsPartial<Settings>-Initial reader settings
fullScreenbooleantrueIf true the height of reader would be 100% of viewport
onEvent<T = Record<string, any>>(params: EventParams< T>) => void-Callback which call on events which do not affect the logic of the component. Events table
readerSizeReaderSize-Width and height params for reader
dyslexicModebooleanfalseIf true the main font switch to Dysfont exclude book content

Types and interfaces

Events for onEvent callback

NameDataDescription
look_up_shownDefinitionEvent which is dispatched when the look-up popover is opened
look_up_play_audio_clickedDefinitionEvent which is dispatched when the user clicked the listen button on the look-up popover
settings_button_clicked-Event which is dispatched when the user clicked the settings button

Book

type Book = {
  id: string
  title: string
  author: string
  chapters: Chapter[]
}

Chapter

type Chapter = {
  id: number
  uniq_id: number
  title: string
  subtitle: string
  paragraphs: Paragraph[]
}

Paragraph

type Paragraph = {
  id: number
  uniq_id: number
  type: 'text' | 'quote' | 'dialog'
  sentences: Sentence[]
}

Sentence

type Sentence = {
  id: number
  uniq_id: number
  elements: SentenceElement[]
}

SentenceElement

type SentenceElement = {
  id: number
  uniq_id: number
  text: string
  definition?: Definition
}

Definition

type Definition = {
  title: string
  description: string
  mp3?: string
}

BookReadyParams

type BookReadyParams = {
  pagesCount: number // total pages count (1 page - 1 column)
  actualPagesCount: number // pages count (1 page - 1 screen)
  switchToNextPage: () => void
  switchToPrevPage: () => void
}

SwitchPageParams

type SwitchPageParams = {
  page: number
  direction: 'next' | 'prev'
  activeItemId: number
  progress: number
}

CloseParams

type CloseParams = {
  activeItemId: number
  progress: number
}

SettingsChangeParams

type SettingsChangeParams = {
  settings: Settings
  prevSettings: Settings
  changedParam: keyof Settings // 'theme' | 'fontFamily' | 'fontParams'
}

Link to Settings

Settings

type Settings = {
  theme: 'light' | 'dark'
  fontFamily: 'Andada' | 'Dysfont' | 'Manrope' | 'Lora' | 'Raleway'
  fontSize: number
}

EventParams

type EventParams<T = Record<string, any>> = { event: EventNames; data?: T }

Link to EventNames

ReaderSize

type ReaderSize = {
  width: number
  height: number
}
1.2.8

9 months ago

1.2.7

9 months ago

1.2.12

9 months ago

1.2.13

9 months ago

1.2.10

9 months ago

1.2.11

9 months ago

1.2.14

9 months ago

1.2.9

9 months ago

1.2.0

1 year ago

1.2.6

1 year ago

1.2.5

1 year ago

1.2.4

1 year ago

1.2.3

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.0.2

2 years ago

0.0.40

2 years ago

1.0.1

2 years ago

0.0.41

2 years ago

1.0.0

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

0.0.37

2 years ago

0.0.38

2 years ago

0.0.39

2 years ago

0.0.30

2 years ago

0.0.31

2 years ago

0.0.32

2 years ago

0.0.33

2 years ago

0.0.34

2 years ago

0.0.35

2 years ago

0.0.36

2 years ago

0.0.26

2 years ago

0.0.27

2 years ago

0.0.28

2 years ago

0.0.29

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

0.0.20

2 years ago

0.0.21

2 years ago

0.0.22

2 years ago

0.0.23

2 years ago

0.0.24

2 years ago

0.0.25

2 years ago

1.1.2

2 years ago

0.0.15

2 years ago

0.0.16

2 years ago

0.0.17

2 years ago

0.0.18

2 years ago

0.0.19

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago