|
| 1 | +import { useRef } from 'react'; |
| 2 | +import { type View } from 'react-native'; |
| 3 | +import { assets, ethBackground } from '@coinbase/cds-common/internal/data/assets'; |
| 4 | +import { NoopFn } from '@coinbase/cds-common/utils/mockUtils'; |
| 5 | + |
| 6 | +import { Carousel } from '../../carousel/Carousel'; |
| 7 | +import { CarouselItem } from '../../carousel/CarouselItem'; |
| 8 | +import { Example, ExampleScreen } from '../../examples/ExampleScreen'; |
| 9 | +import { RemoteImage } from '../../media/RemoteImage'; |
| 10 | +import { TextHeadline, TextLabel2, TextTitle3 } from '../../typography'; |
| 11 | +import { Text } from '../../typography/Text'; |
| 12 | +import type { MediaCardProps } from '../MediaCard'; |
| 13 | +import { MediaCard } from '../MediaCard'; |
| 14 | + |
| 15 | +const exampleProps: Omit<MediaCardProps, 'thumbnail'> = { |
| 16 | + title: 'Title', |
| 17 | + subtitle: 'Subtitle', |
| 18 | + description: 'Description', |
| 19 | + width: 320, |
| 20 | +}; |
| 21 | + |
| 22 | +const exampleThumbnail = ( |
| 23 | + <RemoteImage |
| 24 | + accessibilityLabel="Ethereum" |
| 25 | + shape="circle" |
| 26 | + size="l" |
| 27 | + source={ethBackground} |
| 28 | + testID="thumbnail" |
| 29 | + /> |
| 30 | +); |
| 31 | + |
| 32 | +const exampleMedia = ( |
| 33 | + <RemoteImage |
| 34 | + accessibilityLabel="Media" |
| 35 | + height="100%" |
| 36 | + resizeMode="cover" |
| 37 | + shape="rectangle" |
| 38 | + source={ethBackground} |
| 39 | + width="100%" |
| 40 | + /> |
| 41 | +); |
| 42 | + |
| 43 | +const MediaCardScreen = () => { |
| 44 | + const ref = useRef<View>(null); |
| 45 | + return ( |
| 46 | + <ExampleScreen> |
| 47 | + {/* Basic Examples */} |
| 48 | + <Example title="Default"> |
| 49 | + <MediaCard ref={ref} {...exampleProps} thumbnail={exampleThumbnail} /> |
| 50 | + </Example> |
| 51 | + |
| 52 | + <Example title="With Media"> |
| 53 | + <MediaCard {...exampleProps} media={exampleMedia} thumbnail={exampleThumbnail} /> |
| 54 | + </Example> |
| 55 | + |
| 56 | + {/* Media Placement */} |
| 57 | + <Example title="Media Placement Start"> |
| 58 | + <MediaCard |
| 59 | + {...exampleProps} |
| 60 | + media={exampleMedia} |
| 61 | + mediaPlacement="start" |
| 62 | + thumbnail={exampleThumbnail} |
| 63 | + /> |
| 64 | + </Example> |
| 65 | + |
| 66 | + <Example title="Media Placement End"> |
| 67 | + <MediaCard |
| 68 | + {...exampleProps} |
| 69 | + media={exampleMedia} |
| 70 | + mediaPlacement="end" |
| 71 | + thumbnail={exampleThumbnail} |
| 72 | + /> |
| 73 | + </Example> |
| 74 | + |
| 75 | + {/* Text Content */} |
| 76 | + <Example title="Long Text"> |
| 77 | + <MediaCard |
| 78 | + description="This is a very long description text that demonstrates how the card handles longer content" |
| 79 | + media={exampleMedia} |
| 80 | + onPress={NoopFn} |
| 81 | + subtitle="This is a very long subtitle text that will get truncated" |
| 82 | + thumbnail={exampleThumbnail} |
| 83 | + title="This is a very long title text that will get truncated" |
| 84 | + width={320} |
| 85 | + /> |
| 86 | + </Example> |
| 87 | + |
| 88 | + <Example title="Custom Content"> |
| 89 | + <MediaCard |
| 90 | + description={ |
| 91 | + <TextLabel2> |
| 92 | + Custom description with <Text font="headline">bold text</Text> and{' '} |
| 93 | + <Text font="label1">italic text</Text> |
| 94 | + </TextLabel2> |
| 95 | + } |
| 96 | + media={exampleMedia} |
| 97 | + subtitle={<TextHeadline color="fgPositive">Custom Subtitle</TextHeadline>} |
| 98 | + thumbnail={exampleThumbnail} |
| 99 | + title={<TextTitle3>Custom Title</TextTitle3>} |
| 100 | + width={320} |
| 101 | + /> |
| 102 | + </Example> |
| 103 | + |
| 104 | + {/* Styling */} |
| 105 | + <Example title="With Layout Overrides"> |
| 106 | + <MediaCard |
| 107 | + {...exampleProps} |
| 108 | + media={exampleMedia} |
| 109 | + styles={{ |
| 110 | + layoutContainer: { gap: 3 }, |
| 111 | + contentContainer: { padding: 3, gap: 2 }, |
| 112 | + textContainer: { gap: 1 }, |
| 113 | + headerContainer: { gap: 1 }, |
| 114 | + mediaContainer: { borderRadius: 300 }, |
| 115 | + }} |
| 116 | + thumbnail={exampleThumbnail} |
| 117 | + /> |
| 118 | + </Example> |
| 119 | + |
| 120 | + <Example title="With Root Style Override"> |
| 121 | + <MediaCard |
| 122 | + {...exampleProps} |
| 123 | + media={exampleMedia} |
| 124 | + styles={{ |
| 125 | + root: { borderWidth: 2, borderColor: 'blue' }, |
| 126 | + }} |
| 127 | + thumbnail={exampleThumbnail} |
| 128 | + /> |
| 129 | + </Example> |
| 130 | + |
| 131 | + {/* Interactive */} |
| 132 | + <Example title="Interactive with onPress"> |
| 133 | + <MediaCard |
| 134 | + description="Clickable card with onPress handler" |
| 135 | + media={exampleMedia} |
| 136 | + onPress={() => console.log('Card clicked!')} |
| 137 | + subtitle="Button" |
| 138 | + thumbnail={exampleThumbnail} |
| 139 | + title="Interactive Card" |
| 140 | + width={320} |
| 141 | + /> |
| 142 | + </Example> |
| 143 | + |
| 144 | + {/* Multiple Cards */} |
| 145 | + <Example title="Multiple Cards"> |
| 146 | + <Carousel styles={{ carousel: { gap: 16 } }}> |
| 147 | + <CarouselItem id="card1"> |
| 148 | + <MediaCard {...exampleProps} media={exampleMedia} thumbnail={exampleThumbnail} /> |
| 149 | + </CarouselItem> |
| 150 | + <CarouselItem id="card2"> |
| 151 | + <MediaCard |
| 152 | + description="Another card with different content" |
| 153 | + media={exampleMedia} |
| 154 | + onPress={NoopFn} |
| 155 | + subtitle="BTC" |
| 156 | + thumbnail={ |
| 157 | + <RemoteImage |
| 158 | + accessibilityLabel="Bitcoin" |
| 159 | + shape="square" |
| 160 | + size="l" |
| 161 | + source={assets.btc.imageUrl} |
| 162 | + /> |
| 163 | + } |
| 164 | + title="Bitcoin" |
| 165 | + width={320} |
| 166 | + /> |
| 167 | + </CarouselItem> |
| 168 | + <CarouselItem id="card3"> |
| 169 | + <MediaCard |
| 170 | + description="Card with onPress handler" |
| 171 | + onPress={NoopFn} |
| 172 | + subtitle="ETH" |
| 173 | + thumbnail={exampleThumbnail} |
| 174 | + title="Ethereum" |
| 175 | + width={320} |
| 176 | + /> |
| 177 | + </CarouselItem> |
| 178 | + </Carousel> |
| 179 | + </Example> |
| 180 | + </ExampleScreen> |
| 181 | + ); |
| 182 | +}; |
| 183 | + |
| 184 | +export default MediaCardScreen; |
0 commit comments