Skip to content

Commit 4fddb69

Browse files
committed
fade icons in and out when dropdown is changed
1 parent fb28f62 commit 4fddb69

File tree

2 files changed

+79
-25
lines changed

2 files changed

+79
-25
lines changed

src/components/FindWallet/WalletTable.tsx

Lines changed: 78 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Libraries
2-
import React, { useState } from "react"
2+
import React, { useState, SVGProps } from "react"
33
import { getImage, GatsbyImage } from "gatsby-plugin-image"
4-
import styled from "styled-components"
4+
import styled, { keyframes } from "styled-components"
55

66
// Components
77
import ButtonLink from "../ButtonLink"
@@ -250,11 +250,34 @@ const FlexInfo = styled.div`
250250
}
251251
`
252252

253+
const fadeIn = keyframes`
254+
0% {
255+
opacity: 0;
256+
}
257+
100% {
258+
opacity: 1;
259+
}
260+
`
261+
262+
const fadeOut = keyframes`
263+
0% {
264+
opacity: 1;
265+
}
266+
100% {
267+
opacity: 0;
268+
}
269+
`
270+
253271
const FlexInfoCenter = styled(FlexInfo)`
254272
justify-content: center;
255273
cursor: pointer;
256274
height: 100%;
257275
display: flex;
276+
animation: ${fadeIn} 0.5s;
277+
278+
&.fade {
279+
animation: ${fadeOut} 0.5s;
280+
}
258281
`
259282

260283
const Image = styled(GatsbyImage)`
@@ -430,9 +453,19 @@ const StyledIcon = styled(Icon)<{ hasFeature: boolean }>`
430453
fill: ${({ theme }) => theme.colors.primary};
431454
}
432455
`
456+
// Types
457+
export interface DropdownOption {
458+
label: string
459+
value: string
460+
filterKey: string
461+
category: string
462+
icon: SVGProps<SVGElement>
463+
}
464+
465+
type ColumnClassName = "firstCol" | "secondCol" | "thirdCol"
433466

434467
// Constants
435-
const featureDropdownItems = [
468+
const featureDropdownItems: Array<DropdownOption> = [
436469
{
437470
label: "Open source",
438471
value: "Open source",
@@ -561,6 +594,10 @@ const featureDropdownItems = [
561594
},
562595
]
563596

597+
const firstCol = "firstCol"
598+
const secondCol = "secondCol"
599+
const thirdCol = "thirdCol"
600+
564601
const WalletTable = ({ data, filters, walletData }) => {
565602
const [walletCardData, setWalletData] = useState(
566603
walletData.map((wallet) => {
@@ -678,6 +715,38 @@ const WalletTable = ({ data, filters, walletData }) => {
678715
}
679716
)
680717

718+
/**
719+
*
720+
* @param selectedOption selected dropdown option
721+
* @param stateUpdateMethod method for updating state for dropdown
722+
* @param className className of column
723+
*
724+
* This method gets the elements with the className, adds a fade class to fade icons out, after 0.5s it will then update state for the dropdown with the selectedOption, and then remove the fade class to fade the icons back in. Then it will send a matomo event for updating the dropdown.
725+
*/
726+
const updateDropdown = (
727+
selectedOption: DropdownOption,
728+
stateUpdateMethod: Function,
729+
className: ColumnClassName
730+
) => {
731+
const domItems: HTMLCollectionOf<Element> =
732+
document.getElementsByClassName(className)
733+
for (let item of domItems) {
734+
item.classList.add("fade")
735+
}
736+
setTimeout(() => {
737+
stateUpdateMethod(selectedOption)
738+
for (let item of domItems) {
739+
item.classList.remove("fade")
740+
}
741+
}, 500)
742+
743+
trackCustomEvent({
744+
eventCategory: "WalletFeatureCompare",
745+
eventAction: `Select WalletFeatureCompare`,
746+
eventName: `${selectedOption.filterKey} selected`,
747+
})
748+
}
749+
681750
return (
682751
<Container>
683752
<WalletContentHeader>
@@ -707,12 +776,7 @@ const WalletTable = ({ data, filters, walletData }) => {
707776
},
708777
]}
709778
onChange={(selectedOption) => {
710-
setFirstFeatureSelect(selectedOption)
711-
trackCustomEvent({
712-
eventCategory: "WalletFeatureCompare",
713-
eventAction: `Select WalletFeatureCompare`,
714-
eventName: `${selectedOption.filterKey} selected`,
715-
})
779+
updateDropdown(selectedOption, setFirstFeatureSelect, firstCol)
716780
}}
717781
defaultValue={firstFeatureSelect}
718782
isSearchable={false}
@@ -729,12 +793,7 @@ const WalletTable = ({ data, filters, walletData }) => {
729793
},
730794
]}
731795
onChange={(selectedOption) => {
732-
setSecondFeatureSelect(selectedOption)
733-
trackCustomEvent({
734-
eventCategory: "WalletFeatureCompare",
735-
eventAction: `Select WalletFeatureCompare`,
736-
eventName: `${selectedOption.filterKey} selected`,
737-
})
796+
updateDropdown(selectedOption, setSecondFeatureSelect, secondCol)
738797
}}
739798
defaultValue={secondFeatureSelect}
740799
isSearchable={false}
@@ -751,12 +810,7 @@ const WalletTable = ({ data, filters, walletData }) => {
751810
},
752811
]}
753812
onChange={(selectedOption) => {
754-
setThirdFeatureSelect(selectedOption)
755-
trackCustomEvent({
756-
eventCategory: "WalletFeatureCompare",
757-
eventAction: `Select WalletFeatureCompare`,
758-
eventName: `${selectedOption.filterKey} selected`,
759-
})
813+
updateDropdown(selectedOption, setThirdFeatureSelect, thirdCol)
760814
}}
761815
defaultValue={thirdFeatureSelect}
762816
isSearchable={false}
@@ -849,7 +903,7 @@ const WalletTable = ({ data, filters, walletData }) => {
849903
</FlexInfo>
850904
</td>
851905
<td>
852-
<FlexInfoCenter>
906+
<FlexInfoCenter className={firstCol}>
853907
{wallet[firstFeatureSelect.filterKey!] ? (
854908
<GreenCheck />
855909
) : (
@@ -858,7 +912,7 @@ const WalletTable = ({ data, filters, walletData }) => {
858912
</FlexInfoCenter>
859913
</td>
860914
<td>
861-
<FlexInfoCenter>
915+
<FlexInfoCenter className={secondCol}>
862916
{wallet[secondFeatureSelect.filterKey!] ? (
863917
<GreenCheck />
864918
) : (
@@ -867,7 +921,7 @@ const WalletTable = ({ data, filters, walletData }) => {
867921
</FlexInfoCenter>
868922
</td>
869923
<td>
870-
<FlexInfoCenter>
924+
<FlexInfoCenter className={thirdCol}>
871925
{wallet[thirdFeatureSelect.filterKey!] ? (
872926
<GreenCheck />
873927
) : (

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
33
"target": "esnext",
4-
"lib": ["dom", "esnext"],
4+
"lib": ["dom", "esnext", "dom.iterable"],
55
"jsx": "react",
66
"module": "esnext",
77
"moduleResolution": "node",

0 commit comments

Comments
 (0)