Skip to content

Commit

Permalink
feat #369 - move scrollOnClick to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
mishevong committed Jul 9, 2021
1 parent 7f4594b commit 53a2b13
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
23 changes: 2 additions & 21 deletions src/components/ScrollableSection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import { Bounce } from './Bounce'
import { Breakpoints } from '@dassana-io/web-utils'
import cn from 'classnames'
import { createUseStyles } from 'react-jss'
import { Element } from 'react-scroll'
import { IconButton } from 'components/IconButton'
import indexOf from 'lodash/indexOf'
import { mediaSelectorsWithBreakpoints } from '../Pages/utils'
import { ScrollDirections } from './utils'
import { styleguide } from 'components/assets/styles'
import { Element, scroller } from 'react-scroll'
import { faArrowDown, faArrowUp } from '@fortawesome/free-solid-svg-icons'
import React, { FC, ReactNode } from 'react'
import { ScrollDirections, scrollOnClick } from './utils'

const { tablet } = Breakpoints
const { min } = mediaSelectorsWithBreakpoints
Expand Down Expand Up @@ -78,24 +77,6 @@ export const ScrollableSection: FC<ScrollableSectionProps> = ({
}: ScrollableSectionProps) => {
const componentClasses = useStyles()

const scrollOnClick = (
sections: string[],
dir: ScrollDirections,
currentSection: string
) => {
let idx = indexOf(sections, currentSection)

if (dir === up && idx !== 0) {
idx -= 1
} else if (dir === down && idx < sections.length) {
idx += 1
}

scroller.scrollTo(sections[idx], {
smooth: true
})
}

return (
<Element
className={cn(componentClasses.container, classes)}
Expand Down
23 changes: 23 additions & 0 deletions src/components/ScrollableSection/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
import indexOf from 'lodash/indexOf'
import { scroller } from 'react-scroll'

export enum ScrollDirections {
down = 'down',
up = 'up'
}

const { down, up } = ScrollDirections

export const scrollOnClick = (
sections: string[],
dir: ScrollDirections,
currentSection: string
) => {
let idx = indexOf(sections, currentSection)

if (dir === up && idx !== 0) {
idx -= 1
} else if (dir === down && idx < sections.length) {
idx += 1
}

scroller.scrollTo(sections[idx], {
smooth: true
})
}

0 comments on commit 53a2b13

Please sign in to comment.