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