11import { useArray , useString , core , collections } from '@tomic/react' ;
2- import { useState } from 'react' ;
2+ import { FC , PropsWithChildren , useState } from 'react' ;
33
44import Markdown from '../../components/datatypes/Markdown' ;
55import { CardInsideFull , CardRow } from '../../components/Card' ;
66import { ResourceInline } from '../ResourceInline' ;
77import { CardViewProps } from './CardViewProps' ;
88import { Button } from '../../components/Button' ;
99import { ResourceCardTitle } from './ResourceCardTitle' ;
10+ import { Column } from '../../components/Row' ;
11+ import { styled } from 'styled-components' ;
1012
1113const MAX_COUNT = 5 ;
1214
@@ -27,31 +29,43 @@ function CollectionCard({ resource, small }: CardViewProps): JSX.Element {
2729 }
2830
2931 return (
30- < >
32+ < Column gap = '0.5rem' >
3133 < ResourceCardTitle resource = { resource } />
3234 { description && < Markdown text = { description } /> }
33- { ! small && (
34- < CardInsideFull >
35- { subjects . map ( member => {
36- return (
37- < CardRow key = { member } >
38- < ResourceInline subject = { member } />
35+ < Show show = { ! small } >
36+ { subjects . length === 0 ? (
37+ < Empty > No resources</ Empty >
38+ ) : (
39+ < CardInsideFull >
40+ { subjects . map ( member => {
41+ return (
42+ < CardRow key = { member } >
43+ < ResourceInline subject = { member } />
44+ </ CardRow >
45+ ) ;
46+ } ) }
47+ { tooMany && (
48+ < CardRow >
49+ < Button clean onClick = { ( ) => setShowMore ( ! showAll ) } >
50+ { showAll
51+ ? 'show less'
52+ : `show ${ members . length - MAX_COUNT } more` }
53+ </ Button >
3954 </ CardRow >
40- ) ;
41- } ) }
42- { tooMany && (
43- < CardRow >
44- < Button clean onClick = { ( ) => setShowMore ( ! showAll ) } >
45- { showAll
46- ? 'show less'
47- : `show ${ members . length - MAX_COUNT } more` }
48- </ Button >
49- </ CardRow >
50- ) }
51- </ CardInsideFull >
52- ) }
53- </ >
55+ ) }
56+ </ CardInsideFull >
57+ ) }
58+ </ Show >
59+ </ Column >
5460 ) ;
5561}
5662
63+ const Show : FC < PropsWithChildren < { show : boolean } > > = ( { show, children } ) => {
64+ return show ? children : null ;
65+ } ;
66+
67+ const Empty = styled . span `
68+ color: ${ ( { theme } ) => theme . colors . textLight } ;
69+ ` ;
70+
5771export default CollectionCard ;
0 commit comments