1
1
// Libraries
2
- import React , { useState } from "react"
2
+ import React , { useState , SVGProps } from "react"
3
3
import { getImage , GatsbyImage } from "gatsby-plugin-image"
4
- import styled from "styled-components"
4
+ import styled , { keyframes } from "styled-components"
5
5
6
6
// Components
7
7
import ButtonLink from "../ButtonLink"
@@ -250,11 +250,34 @@ const FlexInfo = styled.div`
250
250
}
251
251
`
252
252
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
+
253
271
const FlexInfoCenter = styled ( FlexInfo ) `
254
272
justify-content: center;
255
273
cursor: pointer;
256
274
height: 100%;
257
275
display: flex;
276
+ animation: ${ fadeIn } 0.5s;
277
+
278
+ &.fade {
279
+ animation: ${ fadeOut } 0.5s;
280
+ }
258
281
`
259
282
260
283
const Image = styled ( GatsbyImage ) `
@@ -430,9 +453,19 @@ const StyledIcon = styled(Icon)<{ hasFeature: boolean }>`
430
453
fill: ${ ( { theme } ) => theme . colors . primary } ;
431
454
}
432
455
`
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"
433
466
434
467
// Constants
435
- const featureDropdownItems = [
468
+ const featureDropdownItems : Array < DropdownOption > = [
436
469
{
437
470
label : "Open source" ,
438
471
value : "Open source" ,
@@ -561,6 +594,10 @@ const featureDropdownItems = [
561
594
} ,
562
595
]
563
596
597
+ const firstCol = "firstCol"
598
+ const secondCol = "secondCol"
599
+ const thirdCol = "thirdCol"
600
+
564
601
const WalletTable = ( { data, filters, walletData } ) => {
565
602
const [ walletCardData , setWalletData ] = useState (
566
603
walletData . map ( ( wallet ) => {
@@ -678,6 +715,38 @@ const WalletTable = ({ data, filters, walletData }) => {
678
715
}
679
716
)
680
717
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
+
681
750
return (
682
751
< Container >
683
752
< WalletContentHeader >
@@ -707,12 +776,7 @@ const WalletTable = ({ data, filters, walletData }) => {
707
776
} ,
708
777
] }
709
778
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 )
716
780
} }
717
781
defaultValue = { firstFeatureSelect }
718
782
isSearchable = { false }
@@ -729,12 +793,7 @@ const WalletTable = ({ data, filters, walletData }) => {
729
793
} ,
730
794
] }
731
795
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 )
738
797
} }
739
798
defaultValue = { secondFeatureSelect }
740
799
isSearchable = { false }
@@ -751,12 +810,7 @@ const WalletTable = ({ data, filters, walletData }) => {
751
810
} ,
752
811
] }
753
812
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 )
760
814
} }
761
815
defaultValue = { thirdFeatureSelect }
762
816
isSearchable = { false }
@@ -849,7 +903,7 @@ const WalletTable = ({ data, filters, walletData }) => {
849
903
</ FlexInfo >
850
904
</ td >
851
905
< td >
852
- < FlexInfoCenter >
906
+ < FlexInfoCenter className = { firstCol } >
853
907
{ wallet [ firstFeatureSelect . filterKey ! ] ? (
854
908
< GreenCheck />
855
909
) : (
@@ -858,7 +912,7 @@ const WalletTable = ({ data, filters, walletData }) => {
858
912
</ FlexInfoCenter >
859
913
</ td >
860
914
< td >
861
- < FlexInfoCenter >
915
+ < FlexInfoCenter className = { secondCol } >
862
916
{ wallet [ secondFeatureSelect . filterKey ! ] ? (
863
917
< GreenCheck />
864
918
) : (
@@ -867,7 +921,7 @@ const WalletTable = ({ data, filters, walletData }) => {
867
921
</ FlexInfoCenter >
868
922
</ td >
869
923
< td >
870
- < FlexInfoCenter >
924
+ < FlexInfoCenter className = { thirdCol } >
871
925
{ wallet [ thirdFeatureSelect . filterKey ! ] ? (
872
926
< GreenCheck />
873
927
) : (
0 commit comments