Skip to content

Commit

Permalink
fix: default media to square (#1548)
Browse files Browse the repository at this point in the history
  • Loading branch information
alessey authored Oct 31, 2024
1 parent 5b822f2 commit 72dfc41
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/kind-stingrays-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@coinbase/onchainkit': patch
---

-fix: Add media square prop, default to true. By @alessey #1548
8 changes: 7 additions & 1 deletion src/nft/components/view/NFTImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import { useNFTContext } from '../NFTProvider';

type NFTImageReact = {
className?: string;
square?: boolean;
onLoading?: (mediaUrl: string) => void;
onLoaded?: () => void;
onError?: (error: NFTError) => void;
};

export function NFTImage({
className,
square = true,
onLoading,
onLoaded,
onError,
Expand Down Expand Up @@ -83,7 +85,11 @@ export function NFTImage({
src={imageUrl}
alt={description}
decoding="async"
className={`max-h-[450px] transition-[opacity] duration-500 ease-in-out ${loaded ? 'opacity-100' : 'opacity-0'}`}
className={cn(
'max-h-[450px] transition-[opacity] duration-500 ease-in-out',
`${loaded ? 'opacity-100' : 'opacity-0'}`,
{ 'h-full w-full object-cover': square },
)}
onTransitionEnd={handleTransitionEnd}
/>
</div>
Expand Down
13 changes: 11 additions & 2 deletions src/nft/components/view/NFTMedia.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { NFTAudio } from './NFTAudio';
import { NFTImage } from './NFTImage';
import { NFTVideo } from './NFTVideo';

export function NFTMedia() {
type NFTMediaReact = {
className?: string;
square?: boolean;
};

export function NFTMedia({ className, square }: NFTMediaReact) {
const { mimeType } = useNFTContext();
const { type, updateLifecycleStatus } = useNFTLifecycleContext();

Expand Down Expand Up @@ -57,6 +62,8 @@ export function NFTMedia() {
case MediaType.Video:
return (
<NFTVideo
className={className}
square={square}
onLoading={handleLoading}
onLoaded={handleLoaded}
onError={handleError}
Expand All @@ -65,7 +72,7 @@ export function NFTMedia() {
case MediaType.Audio:
return (
<div className="relative w-full">
<NFTImage />
<NFTImage className={className} square={square} />
<div className="absolute bottom-4 mx-auto w-full">
<NFTAudio />
</div>
Expand All @@ -75,6 +82,8 @@ export function NFTMedia() {
// fallback to image
return (
<NFTImage
className={className}
square={square}
onLoading={handleLoading}
onLoaded={handleLoaded}
onError={handleError}
Expand Down
10 changes: 9 additions & 1 deletion src/nft/components/view/NFTVideo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import { useNFTContext } from '../NFTProvider';

type NFTVideoReact = {
className?: string;
square?: boolean;
onLoading?: (mediaUrl: string) => void;
onLoaded?: () => void;
onError?: (error: NFTError) => void;
};

export function NFTVideo({
className,
square = true,
onLoading,
onLoaded,
onError,
Expand Down Expand Up @@ -45,10 +47,16 @@ export function NFTVideo({
}

return (
<div className={cn('max-h-350 w-350 max-w-350', className)}>
<div
className={cn(
'relative flex h-[450px] max-h-screen items-center justify-center',
className,
)}
>
<video
ref={videoRef}
data-testid="ockNFTVideo"
className={cn({ 'h-full w-full object-cover': square })}
poster={imageUrl}
controls={true}
loop={true}
Expand Down

0 comments on commit 72dfc41

Please sign in to comment.