-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* create fundraiser card * image size * add fundraiser example
- Loading branch information
1 parent
65d941e
commit 8dba500
Showing
6 changed files
with
233 additions
and
10 deletions.
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
packages/donate-button-v4/src/components/widget/components/NonprofitInfo/FundraiserCard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import cxs from 'cxs'; | ||
import {Fragment} from 'preact/jsx-runtime'; | ||
import {GridCard} from 'src/components/widget/components/GridCard'; | ||
import { | ||
nonprofitNameCss, | ||
descriptionCss, | ||
truncatedTextCss, | ||
fundraiserCardLogoCss, | ||
fundraiserAvatarAndNameWrapperCss, | ||
largeFundraiserCardCss, | ||
smallFundraiserCardCss | ||
} from 'src/components/widget/components/NonprofitInfo/styles'; | ||
import {useNonprofitOrError} from 'src/components/widget/hooks/useNonprofit'; | ||
import {Fundraiser} from 'src/components/widget/types/Fundraiser'; | ||
import {LOGO_IMAGE_PLACEHOLDER_ID} from 'src/constants/placeholders'; | ||
import {getCloudinaryUrl} from 'src/helpers/getCloudinaryUrl'; | ||
import joinClassNames from 'src/helpers/joinClassNames'; | ||
|
||
const coverImageCss = (url: string) => | ||
cxs({ | ||
backgroundImage: `url(${url})`, | ||
backgroundSize: 'cover', | ||
width: 'calc(100% + 25px + 25px)', | ||
height: '160px', | ||
position: 'relative', | ||
left: '-25px' | ||
}); | ||
|
||
interface FundraiserCardProps { | ||
fundraiser: Fundraiser; | ||
} | ||
|
||
export const FundraiserCard = ({fundraiser}: FundraiserCardProps) => { | ||
return ( | ||
<Fragment> | ||
<LargeFundraiserCard fundraiser={fundraiser} /> | ||
<SmallFundraiserCard fundraiser={fundraiser} /> | ||
</Fragment> | ||
); | ||
}; | ||
|
||
const LargeFundraiserCard = ({fundraiser}: FundraiserCardProps) => { | ||
const { | ||
name: nonprofitName, | ||
logoCloudinaryId, | ||
coverImageCloudinaryId, | ||
hasAdmin | ||
} = useNonprofitOrError(); | ||
const logoUrl = getCloudinaryUrl( | ||
logoCloudinaryId ?? LOGO_IMAGE_PLACEHOLDER_ID | ||
); | ||
const coverImageUrl = | ||
coverImageCloudinaryId && | ||
getCloudinaryUrl(coverImageCloudinaryId, {width: 320}); | ||
|
||
return ( | ||
<GridCard className={largeFundraiserCardCss}> | ||
<div className={fundraiserAvatarAndNameWrapperCss}> | ||
<div alt="nonprofit logo" className={fundraiserCardLogoCss(logoUrl)} /> | ||
<div className="every-embedded-fundraiser-card__nonprofit-name"> | ||
<h2 className={truncatedTextCss(1)}>{nonprofitName}</h2> | ||
{fundraiser.creatorNonprofitId === fundraiser.nonprofitId && ( | ||
<p className={descriptionCss}>Official fundraiser</p> | ||
)} | ||
</div> | ||
</div> | ||
{coverImageUrl && <div className={coverImageCss(coverImageUrl)} />} | ||
<h1 className={nonprofitNameCss}> | ||
<span>{fundraiser.title}</span> | ||
</h1> | ||
{fundraiser.description && ( | ||
<p className={joinClassNames([descriptionCss, truncatedTextCss(3)])}> | ||
{fundraiser.description} | ||
</p> | ||
)} | ||
</GridCard> | ||
); | ||
}; | ||
|
||
const SmallFundraiserCard = ({fundraiser}: FundraiserCardProps) => { | ||
const { | ||
name: nonprofitName, | ||
logoCloudinaryId, | ||
coverImageCloudinaryId, | ||
hasAdmin | ||
} = useNonprofitOrError(); | ||
const logoUrl = getCloudinaryUrl( | ||
logoCloudinaryId ?? LOGO_IMAGE_PLACEHOLDER_ID | ||
); | ||
const coverImageUrl = | ||
coverImageCloudinaryId && getCloudinaryUrl(coverImageCloudinaryId); | ||
|
||
return ( | ||
<GridCard className={smallFundraiserCardCss}> | ||
<div className={fundraiserAvatarAndNameWrapperCss}> | ||
<div alt="nonprofit logo" className={fundraiserCardLogoCss(logoUrl)} /> | ||
<h1 className={nonprofitNameCss}> | ||
<span>{fundraiser.title}</span> | ||
</h1> | ||
</div> | ||
</GridCard> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
packages/donate-button-v4/src/components/widget/components/NonprofitInfo/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
import {FundraiserCard} from 'src/components/widget/components/NonprofitInfo/FundraiserCard'; | ||
import {NonprofitCard} from 'src/components/widget/components/NonprofitInfo/NonprofitCard'; | ||
import {useFundraiserOrUndefined} from 'src/components/widget/hooks/useFundraiser'; | ||
|
||
export const NonprofitInfo = () => { | ||
const fundraiser = useFundraiserOrUndefined(); | ||
|
||
if (fundraiser) { | ||
return <FundraiserCard fundraiser={fundraiser} />; | ||
} | ||
|
||
return <NonprofitCard />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,32 @@ | ||
import {BASE_CLOUDINARY_URL} from 'src/constants/url'; | ||
|
||
const FLAGS = 'f_auto,q_auto/'; | ||
interface CloudinaryOptions { | ||
width?: number; | ||
height?: number; | ||
fillMode?: 'fill' | 'lfill'; | ||
} | ||
|
||
export const getCloudinaryUrl = (cloudinaryId: string) => { | ||
return `${BASE_CLOUDINARY_URL}${FLAGS}${cloudinaryId}`; | ||
const FLAGS = 'f_auto,q_auto'; | ||
|
||
export function fillDimensionsTransform(options: CloudinaryOptions) { | ||
if (options.width === 0 || options.height === 0) { | ||
throw new Error('dimensions cannot be 0'); | ||
} | ||
|
||
return [ | ||
`c_${options.fillMode ?? 'lfill'}`, | ||
options.width ? `w_${Math.floor(options.width)}` : undefined, | ||
options.height ? `h_${Math.floor(options.height)}` : undefined | ||
] | ||
.filter((value?: string) => value !== undefined) | ||
.join(','); | ||
} | ||
|
||
export const getCloudinaryUrl = ( | ||
cloudinaryId: string, | ||
options?: CloudinaryOptions | ||
) => { | ||
return `${BASE_CLOUDINARY_URL}${FLAGS}${ | ||
options ? `,${fillDimensionsTransform(options)}` : '' | ||
}/${cloudinaryId}`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8dba500
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
donate-button – ./
donate-button-everydotorg.vercel.app
embeds.every.org
donate-button-git-main-everydotorg.vercel.app
donate-button.vercel.app