@@ -11,6 +11,8 @@ import { Card, FilterOption, Group } from './types';
11
11
12
12
const cardWidthHeight = 160 ; // pixels
13
13
const expandPreviewHeight = 50 //pixels
14
+ // FIXME: remove transition on page load
15
+ const transitionStyle = "0.3s ease"
14
16
15
17
type ShowcaseProps = {
16
18
cards : Card [ ]
@@ -20,6 +22,7 @@ type ShowcaseProps = {
20
22
export const Showcase = ( { cards, setSelectedFilterOptions} : ShowcaseProps ) => {
21
23
22
24
const [ numRows , setNumRows ] = useState < number > ( 0 ) ;
25
+ const [ showcaseHeight , setShowcaseHeight ] = useState < number > ( 0 ) ;
23
26
const [ isExpanded , setIsExpanded ] = useState < boolean > ( false ) ;
24
27
25
28
const toggleExpand = ( ) => {
@@ -35,6 +38,9 @@ export const Showcase = ({cards, setSelectedFilterOptions}: ShowcaseProps) => {
35
38
if ( ! container ) return ;
36
39
37
40
const cards = container . children ;
41
+ if ( showcaseHeight != container . clientHeight ) {
42
+ setShowcaseHeight ( container . clientHeight )
43
+ }
38
44
39
45
if ( cards && cards . length > 0 ) {
40
46
const leftBorder = ( cards [ 0 ] as HTMLElement ) . offsetLeft ;
@@ -58,13 +64,13 @@ export const Showcase = ({cards, setSelectedFilterOptions}: ShowcaseProps) => {
58
64
< Byline >
59
65
Showcase resources: click to filter the resources to a pathogen
60
66
</ Byline >
61
- < ShowcaseContainer $isExpanded = { isExpanded } $isExpandable = { isExpandable } >
67
+ < ShowcaseContainer className = { ! isExpandable ? "singleRow" : isExpanded ? "expanded" : "collapsed" } $fullHeight = { showcaseHeight } >
62
68
< CardsContainer ref = { containerRef } >
63
69
{ cards . map ( ( el ) => (
64
70
< ShowcaseTile card = { el } key = { el . name } setSelectedFilterOptions = { setSelectedFilterOptions } />
65
71
) ) }
66
72
</ CardsContainer >
67
- { isExpandable && ! isExpanded && < PreviewOverlay onClick = { toggleExpand } /> }
73
+ < PreviewOverlay onClick = { toggleExpand } className = { ! isExpandable || isExpanded ? "hiding" : "visible" } />
68
74
</ ShowcaseContainer >
69
75
{ isExpandable && < >
70
76
< ArrowButton onClick = { toggleExpand } >
@@ -112,15 +118,22 @@ const ShowcaseTile = ({card, setSelectedFilterOptions}: ShowcaseTileProps) => {
112
118
element we can leverage the intelligent wrapping of the flexbox to decide how
113
119
many tiles to show in a single row. The downside is that showcase tiles are
114
120
still in the DOM, and the images are still fetched etc */
115
- const ShowcaseContainer = styled . div < { $isExpanded : boolean , $isExpandable : boolean } > `
121
+ const ShowcaseContainer = styled . div < { $fullHeight : number } > `
116
122
position: relative;
117
- height: ${ ( props ) =>
118
- props . $isExpandable ?
119
- props . $isExpanded ?
120
- "" : `${ cardWidthHeight + expandPreviewHeight } px`
121
- : `${ cardWidthHeight } px`
122
123
123
- } ;
124
+ &.singleRow {
125
+ max-height: ${ cardWidthHeight } px
126
+ }
127
+
128
+ &.collapsed {
129
+ max-height: ${ cardWidthHeight + expandPreviewHeight } px
130
+ }
131
+
132
+ &.expanded {
133
+ max-height: ${ ( props ) => `${ props . $fullHeight } px` }
134
+ }
135
+
136
+ transition: max-height ${ transitionStyle } ;
124
137
overflow-y: hidden;
125
138
`
126
139
@@ -143,6 +156,16 @@ const PreviewOverlay = styled.div`
143
156
width: 100%;
144
157
height: ${ expandPreviewHeight } px;
145
158
cursor: pointer;
159
+
160
+ &.visible {
161
+ opacity: 1;
162
+ }
163
+
164
+ &.hiding {
165
+ opacity: 0;
166
+ }
167
+
168
+ transition: opacity ${ transitionStyle } ;
146
169
` ;
147
170
148
171
const CardsContainer = styled . div `
0 commit comments