1
1
// 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"
4
5
import styled from "@emotion/styled"
5
6
6
7
// Components
@@ -251,11 +252,34 @@ const FlexInfo = styled.div`
251
252
}
252
253
`
253
254
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
+
254
273
const FlexInfoCenter = styled ( FlexInfo ) `
255
274
justify-content: center;
256
275
cursor: pointer;
257
276
height: 100%;
258
277
display: flex;
278
+ animation: ${ fadeIn } 0.375s;
279
+
280
+ &.fade {
281
+ animation: ${ fadeOut } 0.375s;
282
+ }
259
283
`
260
284
261
285
const Image = styled ( GatsbyImage ) `
@@ -431,9 +455,19 @@ const StyledIcon = styled(Icon)<{ hasFeature: boolean }>`
431
455
fill: ${ ( { theme } ) => theme . colors . primary } ;
432
456
}
433
457
`
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"
434
468
435
469
// Constants
436
- const featureDropdownItems = [
470
+ const featureDropdownItems : Array < DropdownOption > = [
437
471
{
438
472
label : "Open source" ,
439
473
value : "Open source" ,
@@ -562,6 +596,10 @@ const featureDropdownItems = [
562
596
} ,
563
597
]
564
598
599
+ const firstCol = "firstCol"
600
+ const secondCol = "secondCol"
601
+ const thirdCol = "thirdCol"
602
+
565
603
const WalletTable = ( { data, filters, walletData } ) => {
566
604
const [ walletCardData , setWalletData ] = useState (
567
605
walletData . map ( ( wallet ) => {
@@ -679,6 +717,38 @@ const WalletTable = ({ data, filters, walletData }) => {
679
717
}
680
718
)
681
719
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
+
682
752
return (
683
753
< Container >
684
754
< WalletContentHeader >
@@ -708,12 +778,7 @@ const WalletTable = ({ data, filters, walletData }) => {
708
778
} ,
709
779
] }
710
780
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 )
717
782
} }
718
783
defaultValue = { firstFeatureSelect }
719
784
isSearchable = { false }
@@ -730,12 +795,7 @@ const WalletTable = ({ data, filters, walletData }) => {
730
795
} ,
731
796
] }
732
797
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 )
739
799
} }
740
800
defaultValue = { secondFeatureSelect }
741
801
isSearchable = { false }
@@ -752,12 +812,7 @@ const WalletTable = ({ data, filters, walletData }) => {
752
812
} ,
753
813
] }
754
814
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 )
761
816
} }
762
817
defaultValue = { thirdFeatureSelect }
763
818
isSearchable = { false }
@@ -851,7 +906,7 @@ const WalletTable = ({ data, filters, walletData }) => {
851
906
</ FlexInfo >
852
907
</ td >
853
908
< td >
854
- < FlexInfoCenter >
909
+ < FlexInfoCenter className = { firstCol } >
855
910
{ wallet [ firstFeatureSelect . filterKey ! ] ? (
856
911
< GreenCheck />
857
912
) : (
@@ -860,7 +915,7 @@ const WalletTable = ({ data, filters, walletData }) => {
860
915
</ FlexInfoCenter >
861
916
</ td >
862
917
< td >
863
- < FlexInfoCenter >
918
+ < FlexInfoCenter className = { secondCol } >
864
919
{ wallet [ secondFeatureSelect . filterKey ! ] ? (
865
920
< GreenCheck />
866
921
) : (
@@ -869,7 +924,7 @@ const WalletTable = ({ data, filters, walletData }) => {
869
924
</ FlexInfoCenter >
870
925
</ td >
871
926
< td >
872
- < FlexInfoCenter >
927
+ < FlexInfoCenter className = { thirdCol } >
873
928
{ wallet [ thirdFeatureSelect . filterKey ! ] ? (
874
929
< GreenCheck />
875
930
) : (
0 commit comments