1- import React , { useContext } from 'react' ;
1+ import React , { useContext , FunctionComponent } from 'react' ;
22import Link from 'next/link' ;
33import useSWR from 'swr' ;
44
@@ -10,8 +10,13 @@ import { CampaignEmptyState } from '../empty-states/campaign';
1010import fetch from '../../lib/fetch' ;
1111import { ShareContext } from '../../services/share' ;
1212import { truncateString } from '../../utils' ;
13+ import clsx from 'clsx' ;
1314
14- export const CampaignList = ( ) => {
15+ interface Props {
16+ inline ?: boolean ;
17+ }
18+
19+ export const CampaignList : FunctionComponent < Props > = ( { inline = false } ) => {
1520 const { isOpen, openShareDialog } = useContext ( ShareContext ) ;
1621 const { data, error } = useSWR < Campaign [ ] > ( '/api/campaigns' , fetch ) ;
1722
@@ -39,15 +44,15 @@ export const CampaignList = () => {
3944 < ul className = "w-full md:flex md:flex-wrap" >
4045 { data . map ( item => {
4146 return (
42- < li key = { item . id } className = " mx-0 my-4 md:mx-4" >
47+ < li key = { item . id } className = { clsx ( ' mx-0 my-4 md:mx-4' , inline && 'inline' ) } >
4348 < Link href = "/crowdfund/[slug]" as = { `/crowdfund/${ item . slug } ` } >
44- < a className = "block p-4 px-6 bg-white shadow-lg rounded-lg" style = { { maxWidth : 420 } } >
49+ < a className = "block p-4 px-6 bg-white shadow-lg rounded-lg list-item" >
4550 < h3 className = "text-xl mb-1 font-medium text-gray-800" >
4651 < span className = "hidden md:block" > { truncateString ( item . title , 30 ) } </ span >
4752 < span className = "md:hidden" > { item . title } </ span >
4853 </ h3 >
49- < p className = "text-sm mb-4 text-gray-700" >
50- < span className = "hidden md:block" > { truncateString ( item . short_description , 45 ) } </ span >
54+ < p className = "text-sm mb-4 text-gray-700 md:h-8 " >
55+ < span className = "hidden md:block" > { truncateString ( item . short_description , 91 ) } </ span >
5156 < span className = "md:hidden" > { item . short_description } </ span >
5257 </ p >
5358 < CampaignProgress campaign = { item } />
@@ -66,6 +71,26 @@ export const CampaignList = () => {
6671 </ div >
6772 </ a >
6873 </ Link >
74+ < style jsx > { `
75+ li {
76+ width: calc(50% - 32px);
77+ }
78+ @media (max-width: 1224px) {
79+ li.inline {
80+ width: 80%;
81+ }
82+ }
83+ @media (max-width: 1000px) {
84+ li.inline {
85+ width: 100%;
86+ }
87+ }
88+ @media (max-width: 900px) {
89+ li {
90+ width: 100%;
91+ }
92+ }
93+ ` } </ style >
6994 </ li >
7095 ) ;
7196 } ) }
0 commit comments