all files / packages/body-scroll-pane/ BodyScrollPane.js

0% Statements 0/15
0% Branches 0/2
0% Functions 0/11
0% Lines 0/15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106                                                                                                                                                                                                                   
import { DefaultDOMElement } from '../../dom'
import { AbstractScrollPane } from '../../ui'
 
/**
  Wraps content in a scroll pane.
 
  @class ScrollPane
  @component
 
  @prop {String} scrollbarType 'native' or 'substance' for a more advanced visual scrollbar. Defaults to 'native'
  @prop {String} [scrollbarPosition] 'left' or 'right' only relevant when scrollBarType: 'substance'. Defaults to 'right'
  @prop {ui/Highlights} [highlights] object that maintains highlights and can be manipulated from different sources
  @prop {ui/TOCProvider} [tocProvider] object that maintains table of content entries
 
  @example
 
  ```js
  $$(BodyScrollPane).append(
    content,
    $$(ContextMenu)
    $$(Overlay)
  )
  ```
*/
class BodyScrollPane extends AbstractScrollPane {
 
  /*
    Expose scrollPane as a child context
  */
  getChildContext() {
    return {
      scrollPane: this
    }
  }
 
  getName() {
    return 'body'
  }
 
  render($$) {
    let el = $$('div')
    if (this.props.contextMenu === 'custom') {
      el.on('contextmenu', this._onContextMenu)
    }
    el.append(this.props.children)
    return el
  }
 
  /**
    Returns the height of scrollPane (inner content overflows)
  */
  getHeight() {
    return window.innerHeight
  }
 
  /**
    Returns the cumulated height of a panel's content
  */
  getContentHeight() {
    return document.body.scrollHeight
  }
 
  getContentElement() {
    return DefaultDOMElement.wrapNativeElement(window.document.body)
  }
 
  // /**
  //   Get the `.se-scrollable` element
  // */
  getScrollableElement() {
    return document.body
  }
 
  /**
    Get current scroll position (scrollTop) of `.se-scrollable` element
  */
  getScrollPosition() {
    return document.body.scrollTop
  }
 
  setScrollPosition(scrollPos) {
    document.body.scrollTop = scrollPos
  }
 
  /**
    Get offset relative to `.se-content`.
 
    @param {DOMNode} el DOM node that lives inside the
  */
  getPanelOffsetForElement(el) { // eslint-disable-line
    console.warn('TODO: implement')
  }
 
  /**
    Scroll to a given sub component.
 
    @param {String} componentId component id, must be present in data-id attribute
  */
  scrollTo(componentId, onlyIfNotVisible) { // eslint-disable-line
    console.warn('TODO: implement')
  }
 
}
 
export default BodyScrollPane