Skip to content

Commit

Permalink
Merge pull request #140 from duidae/jason/enable_interfaces
Browse files Browse the repository at this point in the history
Jason/enable interfaces
  • Loading branch information
duidae authored Jun 2, 2023
2 parents c2d75fb + cd520f2 commit 7422c87
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import styled, { css } from 'styled-components'
import mq from '../../utils/media-query'
import { connect } from 'react-redux'
import { Waypoint } from 'react-waypoint'
import { offsetTop } from '../../constants/customized-props'

const _ = {
get,
Expand Down Expand Up @@ -80,9 +81,9 @@ const ItemViewport = styled.div`
} else if (props.sectionsPosition === Waypoint.above) {
return `position: absolute; bottom: 50vh;`
} else if (props.sectionsPosition === Waypoint.below) {
return `position: absolute; top:0px;`
return `position: absolute; top: 0px;`
}
return `position: fixed; top: 0px;`
return `position: fixed; top: ${offsetTop}px;`
}}
`}
${mq.desktopOnly`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from 'react'
import styled from 'styled-components'
import { Waypoint } from 'react-waypoint'
import { connect } from 'react-redux'
import { scrollableAncestor } from '../constants/customized-props'

const EntryPoint = styled.div`
width: 1px;
Expand Down Expand Up @@ -51,6 +52,7 @@ class _HeadEntryPoint extends React.PureComponent {
render() {
return (
<Waypoint
scrollableAncestor={scrollableAncestor}
topOffset={this.props.topOffset}
bottomOffset={this.props.bottomOffset}
onPositionChange={this._handlePositionChange}
Expand Down
8 changes: 5 additions & 3 deletions packages/dual-channel/src/app/components/text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import React from 'react'
import styled from 'styled-components'
import { Waypoint } from 'react-waypoint'
import { connect } from 'react-redux'
import { scrollableAncestor } from '../../constants/customized-props'

const _ = {
get,
Expand Down Expand Up @@ -67,7 +68,7 @@ class ArticleText extends React.Component {
chapters: PropTypes.arrayOf(predefinedPropTypes.chapter).isRequired,
// provided by redux
// currentAnchor: PropTypes.number.isRequired,
updatAnchorIndex: PropTypes.func.isRequired,
updateAnchorIndex: PropTypes.func.isRequired,
}

_handlePositionChange = (
Expand All @@ -87,7 +88,7 @@ class ArticleText extends React.Component {
positionState.previousSection = sectionIndex
}

this.props.updatAnchorIndex({
this.props.updateAnchorIndex({
...positionState,
})
}
Expand All @@ -110,6 +111,7 @@ class ArticleText extends React.Component {
const _renderSection = (section, sectionIndex) => {
const sectionJsx = (
<Waypoint
scrollableAncestor={scrollableAncestor}
key={section.id}
id={section.id}
topOffset="49%"
Expand Down Expand Up @@ -142,7 +144,7 @@ class ArticleText extends React.Component {
}

const mapDispatchToProps = dispatch => ({
updatAnchorIndex: dispatch.position.update,
updateAnchorIndex: dispatch.position.update,
})

export default connect(
Expand Down
16 changes: 16 additions & 0 deletions packages/dual-channel/src/app/constants/customized-props.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const isClientSide =
typeof window !== 'undefined' && typeof window.document !== 'undefined'

const scrollableAncestorValue =
isClientSide &&
document.currentScript.getAttribute('data-scrollable-ancestor')
export const scrollableAncestor = scrollableAncestorValue || undefined

const offsetTopValue =
isClientSide && document.currentScript.getAttribute('data-offset-top')
export const offsetTop =
offsetTopValue &&
Number.isInteger(Number(offsetTopValue)) &&
Number(offsetTopValue) > 0
? offsetTopValue
: 0

0 comments on commit 7422c87

Please sign in to comment.