Skip to content

Commit 4c49779

Browse files
feat: Atomic Components for Card refactor
1 parent 4d20882 commit 4c49779

File tree

21 files changed

+317
-38
lines changed

21 files changed

+317
-38
lines changed

apps/mobile-app/scripts/utils/routes.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ export const routes = [
4343
getComponent: () =>
4444
require('@coinbase/cds-mobile/alpha/select/__stories__/AlphaSelect.stories').default,
4545
},
46+
{
47+
key: 'AlphaSelectChip',
48+
getComponent: () =>
49+
require('@coinbase/cds-mobile/alpha/select-chip/__stories__/AlphaSelectChip.stories').default,
50+
},
4651
{
4752
key: 'AlphaTabbedChips',
4853
getComponent: () =>

apps/mobile-app/src/routes.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ export const routes = [
4343
getComponent: () =>
4444
require('@coinbase/cds-mobile/alpha/select/__stories__/AlphaSelect.stories').default,
4545
},
46+
{
47+
key: 'AlphaSelectChip',
48+
getComponent: () =>
49+
require('@coinbase/cds-mobile/alpha/select-chip/__stories__/AlphaSelectChip.stories').default,
50+
},
4651
{
4752
key: 'AlphaTabbedChips',
4853
getComponent: () =>
@@ -539,7 +544,7 @@ export const routes = [
539544
{
540545
key: 'SelectChip',
541546
getComponent: () =>
542-
require('@coinbase/cds-mobile/alpha/select-chip/__stories__/SelectChip.stories').default,
547+
require('@coinbase/cds-mobile/chips/__stories__/SelectChip.stories').default,
543548
},
544549
{
545550
key: 'SelectOption',

packages/mobile/src/alpha/select-chip/__stories__/SelectChip.stories.tsx renamed to packages/mobile/src/alpha/select-chip/__stories__/AlphaSelectChip.stories.tsx

File renamed without changes.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React, { forwardRef, memo } from 'react';
2+
import type { Text as NativeText } from 'react-native';
3+
4+
import { Text as CDSText, type TextProps } from '../typography/Text';
5+
6+
export type CardDescriptionProps = TextProps;
7+
8+
export const CardDescription = memo(
9+
forwardRef<NativeText, CardDescriptionProps>(
10+
({ font = 'label2', color = 'fgMuted', ...props }, ref) => {
11+
return <CDSText ref={ref} color={color} font={font} {...props} />;
12+
},
13+
),
14+
);
15+
16+
CardDescription.displayName = 'CardDescription';

packages/mobile/src/cards/CardMedia.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { memo } from 'react';
1+
import { memo } from 'react';
22
import {
33
defaultMediaDimension,
44
defaultMediaSize,
@@ -11,8 +11,7 @@ import type {
1111
} from '@coinbase/cds-common/types';
1212

1313
import { Pictogram, SpotSquare } from '../illustrations';
14-
15-
import { CardRemoteImage } from './CardRemoteImage';
14+
import { getSource, RemoteImage } from '../media/RemoteImage';
1615

1716
export type CardMediaProps = CommonCardMediaProps;
1817

@@ -50,8 +49,10 @@ export const CardMedia = memo(function CardMedia({ placement = 'end', ...props }
5049
);
5150
case 'image':
5251
return (
53-
<CardRemoteImage
52+
<RemoteImage
5453
alt={props.alt ?? ''}
54+
resizeMode="cover"
55+
source={getSource(props.src)}
5556
src={props.src}
5657
testID={props.testID}
5758
{...imageProps[placement]}

packages/mobile/src/cards/CardRemoteImage.tsx

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React, { forwardRef, memo } from 'react';
2+
import type { View } from 'react-native';
3+
import type { SharedAccessibilityProps, SharedProps } from '@coinbase/cds-common/types';
4+
5+
import { HStack, type HStackProps } from '../layout/HStack';
6+
import { Pressable, type PressableProps } from '../system/Pressable';
7+
8+
export type CardRootBaseProps = SharedAccessibilityProps &
9+
SharedProps & {
10+
children: React.ReactNode;
11+
actionable?: boolean;
12+
};
13+
14+
export type CardRootProps = CardRootBaseProps & PressableProps;
15+
16+
export const CardRoot = memo(
17+
forwardRef<View, CardRootBaseProps>(({ children, actionable, ...props }, ref) => {
18+
const Component = actionable ? Pressable : HStack;
19+
return (
20+
<Component ref={ref} {...props}>
21+
{children}
22+
</Component>
23+
);
24+
}),
25+
);
26+
27+
CardRoot.displayName = 'CardRoot';
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React, { forwardRef, memo } from 'react';
2+
import type { Text as NativeText } from 'react-native';
3+
4+
import { Text, type TextProps } from '../typography/Text';
5+
6+
export type CardSubtitleProps = TextProps;
7+
8+
/**
9+
* Text component with default font and color for Card subtitles.
10+
*/
11+
export const CardSubtitle = memo(
12+
forwardRef<NativeText, CardSubtitleProps>(
13+
({ font = 'label2', color = 'fgMuted', ...props }, ref) => {
14+
return <Text ref={ref} color={color} font={font} {...props} />;
15+
},
16+
),
17+
);
18+
19+
CardSubtitle.displayName = 'CardSubtitle';
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { memo } from 'react';
2+
3+
import { RemoteImage, type RemoteImageProps } from '../media/RemoteImage';
4+
5+
export type CardThumbnailProps = RemoteImageProps;
6+
7+
/**
8+
* RemoteImage component with default size and shape for Card thumbnails.
9+
*/
10+
export const CardThumbnail = memo(function CardThumbnail({
11+
size = 'l',
12+
shape = 'circle',
13+
...props
14+
}: CardThumbnailProps) {
15+
return <RemoteImage shape={shape} size={size} {...props} />;
16+
});
17+
18+
CardThumbnail.displayName = 'CardThumbnail';
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React, { forwardRef, memo } from 'react';
2+
import type { Text as NativeText } from 'react-native';
3+
4+
import { Text as CDSText, type TextProps } from '../typography/Text';
5+
6+
export type CardTitleProps = TextProps;
7+
8+
/**
9+
* Text component with default font for Card titles.
10+
*/
11+
export const CardTitle = memo(
12+
forwardRef<NativeText, CardTitleProps>(({ font = 'headline', ...props }, ref) => {
13+
return <CDSText ref={ref} font={font} {...props} />;
14+
}),
15+
);
16+
17+
CardTitle.displayName = 'CardTitle';

0 commit comments

Comments
 (0)