Skip to content

Commit 0d89b79

Browse files
authored
Merge pull request #7371 from ethereum/fade-icons-find-wallet
Find a wallet table: fade icons in and out when dropdown select is changed
2 parents 8934301 + b7a7b53 commit 0d89b79

File tree

2 files changed

+80
-25
lines changed

2 files changed

+80
-25
lines changed

src/components/FindWallet/WalletTable.tsx

Lines changed: 79 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Libraries
2-
import React, { useState } from "react"
3-
import { GatsbyImage } from "gatsby-plugin-image"
2+
import React, { useState, SVGProps } from "react"
3+
import { getImage, GatsbyImage } from "gatsby-plugin-image"
4+
import { keyframes } from "@emotion/react"
45
import styled from "@emotion/styled"
56

67
// Components
@@ -251,11 +252,34 @@ const FlexInfo = styled.div`
251252
}
252253
`
253254

255+
const fadeIn = keyframes`
256+
0% {
257+
opacity: 0;
258+
}
259+
100% {
260+
opacity: 1;
261+
}
262+
`
263+
264+
const fadeOut = keyframes`
265+
0% {
266+
opacity: 1;
267+
}
268+
100% {
269+
opacity: 0;
270+
}
271+
`
272+
254273
const FlexInfoCenter = styled(FlexInfo)`
255274
justify-content: center;
256275
cursor: pointer;
257276
height: 100%;
258277
display: flex;
278+
animation: ${fadeIn} 0.375s;
279+
280+
&.fade {
281+
animation: ${fadeOut} 0.375s;
282+
}
259283
`
260284

261285
const Image = styled(GatsbyImage)`
@@ -431,9 +455,19 @@ const StyledIcon = styled(Icon)<{ hasFeature: boolean }>`
431455
fill: ${({ theme }) => theme.colors.primary};
432456
}
433457
`
458+
// Types
459+
export interface DropdownOption {
460+
label: string
461+
value: string
462+
filterKey: string
463+
category: string
464+
icon: SVGProps<SVGElement>
465+
}
466+
467+
type ColumnClassName = "firstCol" | "secondCol" | "thirdCol"
434468

435469
// Constants
436-
const featureDropdownItems = [
470+
const featureDropdownItems: Array<DropdownOption> = [
437471
{
438472
label: "Open source",
439473
value: "Open source",
@@ -562,6 +596,10 @@ const featureDropdownItems = [
562596
},
563597
]
564598

599+
const firstCol = "firstCol"
600+
const secondCol = "secondCol"
601+
const thirdCol = "thirdCol"
602+
565603
const WalletTable = ({ data, filters, walletData }) => {
566604
const [walletCardData, setWalletData] = useState(
567605
walletData.map((wallet) => {
@@ -679,6 +717,38 @@ const WalletTable = ({ data, filters, walletData }) => {
679717
}
680718
)
681719

720+
/**
721+
*
722+
* @param selectedOption selected dropdown option
723+
* @param stateUpdateMethod method for updating state for dropdown
724+
* @param className className of column
725+
*
726+
* 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.
727+
*/
728+
const updateDropdown = (
729+
selectedOption: DropdownOption,
730+
stateUpdateMethod: Function,
731+
className: ColumnClassName
732+
) => {
733+
const domItems: HTMLCollectionOf<Element> =
734+
document.getElementsByClassName(className)
735+
for (let item of domItems) {
736+
item.classList.add("fade")
737+
}
738+
setTimeout(() => {
739+
stateUpdateMethod(selectedOption)
740+
for (let item of domItems) {
741+
item.classList.remove("fade")
742+
}
743+
}, 375)
744+
745+
trackCustomEvent({
746+
eventCategory: "WalletFeatureCompare",
747+
eventAction: `Select WalletFeatureCompare`,
748+
eventName: `${selectedOption.filterKey} selected`,
749+
})
750+
}
751+
682752
return (
683753
<Container>
684754
<WalletContentHeader>
@@ -708,12 +778,7 @@ const WalletTable = ({ data, filters, walletData }) => {
708778
},
709779
]}
710780
onChange={(selectedOption) => {
711-
setFirstFeatureSelect(selectedOption)
712-
trackCustomEvent({
713-
eventCategory: "WalletFeatureCompare",
714-
eventAction: `Select WalletFeatureCompare`,
715-
eventName: `${selectedOption.filterKey} selected`,
716-
})
781+
updateDropdown(selectedOption, setFirstFeatureSelect, firstCol)
717782
}}
718783
defaultValue={firstFeatureSelect}
719784
isSearchable={false}
@@ -730,12 +795,7 @@ const WalletTable = ({ data, filters, walletData }) => {
730795
},
731796
]}
732797
onChange={(selectedOption) => {
733-
setSecondFeatureSelect(selectedOption)
734-
trackCustomEvent({
735-
eventCategory: "WalletFeatureCompare",
736-
eventAction: `Select WalletFeatureCompare`,
737-
eventName: `${selectedOption.filterKey} selected`,
738-
})
798+
updateDropdown(selectedOption, setSecondFeatureSelect, secondCol)
739799
}}
740800
defaultValue={secondFeatureSelect}
741801
isSearchable={false}
@@ -752,12 +812,7 @@ const WalletTable = ({ data, filters, walletData }) => {
752812
},
753813
]}
754814
onChange={(selectedOption) => {
755-
setThirdFeatureSelect(selectedOption)
756-
trackCustomEvent({
757-
eventCategory: "WalletFeatureCompare",
758-
eventAction: `Select WalletFeatureCompare`,
759-
eventName: `${selectedOption.filterKey} selected`,
760-
})
815+
updateDropdown(selectedOption, setThirdFeatureSelect, thirdCol)
761816
}}
762817
defaultValue={thirdFeatureSelect}
763818
isSearchable={false}
@@ -851,7 +906,7 @@ const WalletTable = ({ data, filters, walletData }) => {
851906
</FlexInfo>
852907
</td>
853908
<td>
854-
<FlexInfoCenter>
909+
<FlexInfoCenter className={firstCol}>
855910
{wallet[firstFeatureSelect.filterKey!] ? (
856911
<GreenCheck />
857912
) : (
@@ -860,7 +915,7 @@ const WalletTable = ({ data, filters, walletData }) => {
860915
</FlexInfoCenter>
861916
</td>
862917
<td>
863-
<FlexInfoCenter>
918+
<FlexInfoCenter className={secondCol}>
864919
{wallet[secondFeatureSelect.filterKey!] ? (
865920
<GreenCheck />
866921
) : (
@@ -869,7 +924,7 @@ const WalletTable = ({ data, filters, walletData }) => {
869924
</FlexInfoCenter>
870925
</td>
871926
<td>
872-
<FlexInfoCenter>
927+
<FlexInfoCenter className={thirdCol}>
873928
{wallet[thirdFeatureSelect.filterKey!] ? (
874929
<GreenCheck />
875930
) : (

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)