From 2e59359d28914769b60f8b5a1c2f3b6128d0dfc6 Mon Sep 17 00:00:00 2001 From: Karishma Chadha Date: Thu, 3 Sep 2020 16:01:16 -0400 Subject: [PATCH] More work on the subnav scroll to section behavior --- src/views/annual-report/annual-report.jsx | 120 ++++++++++++++++----- src/views/annual-report/annual-report.scss | 8 +- 2 files changed, 101 insertions(+), 27 deletions(-) diff --git a/src/views/annual-report/annual-report.jsx b/src/views/annual-report/annual-report.jsx index 3f02d8081..bcf5e7f6f 100644 --- a/src/views/annual-report/annual-report.jsx +++ b/src/views/annual-report/annual-report.jsx @@ -20,25 +20,89 @@ require('./annual-report.scss'); class AnnualReport extends React.Component { constructor () { super(); + this.messageRef = null; this.missionRef = null; + this.reachRef = null; + this.milestonesRef = null; + this.initiativesRef = null; + this.financialsRef = null; + this.supportersRef = null; + this.leadershipRef = null; + this.donateRef = null; + + this.sectionRefs = { + message: () => this.messageRef, + mission: () => this.missionRef, + reach: () => this.reachRef, + milestones: () => this.milestonesRef, + initiatives: () => this.initiativesRef, + financials: () => this.financialsRef, + supporters: () => this.supportersRef, + leadership: () => this.leadershipRef, + donate: () => this.donateRef + }; bindAll(this, [ 'scrollTo', - 'setMissionRef' + 'setMessageRef', + 'setMissionRef', + 'setReachRef', + 'setMilestonesRef', + 'setInitiativesRef', + 'setFinancialsRef', + 'setSupportersRef', + 'setLeadershipRef', + 'setDonateRef', + 'handleSubNavItemClick' ]); } - scrollTo (element) { - console.log(element); - element.scrollIntoView({ - behavior: 'smooth', - block: 'start' - }); + // A generic handler for a subnav item that takes the name of the + // section to scroll to (all lowercase) + handleSubNavItemClick (sectionName) { + // Return a button click handler that scrolls to the + // correct section + return () => { + this.scrollTo(this.sectionRefs[sectionName]()); + }; } + scrollTo (element) { + if (element) { + element.scrollIntoView({ + behavior: 'smooth', + block: 'start' + }); + } + } + + setMessageRef (ref) { + this.messageRef = ref; + } setMissionRef (ref) { this.missionRef = ref; } + setReachRef (ref) { + this.reachRef = ref; + } + setMilestonesRef (ref) { + this.milestonesRef = ref; + } + setInitiativesRef (ref) { + this.initiativesRef = ref; + } + setFinancialsRef (ref) { + this.financialsRef = ref; + } + setSupportersRef (ref) { + this.supportersRef = ref; + } + setLeadershipRef (ref) { + this.leadershipRef = ref; + } + setDonateRef (ref) { + this.donateRef = ref; + } render () { return ( @@ -47,55 +111,55 @@ class AnnualReport extends React.Component { this.scrollTo(this.missionRef.current)} + onClick={this.handleSubNavItemClick('mission')} > - + @@ -118,7 +182,7 @@ class AnnualReport extends React.Component {
@@ -126,8 +190,9 @@ class AnnualReport extends React.Component {
@@ -172,8 +237,9 @@ class AnnualReport extends React.Component {
@@ -197,8 +263,9 @@ class AnnualReport extends React.Component {
@@ -222,8 +289,9 @@ class AnnualReport extends React.Component {

@@ -359,8 +427,9 @@ class AnnualReport extends React.Component {

@@ -544,8 +613,9 @@ class AnnualReport extends React.Component {