Skip to content

Commit 257f640

Browse files
authored
feat: add content style prop to the Card (#3657)
1 parent 787ba37 commit 257f640

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

src/components/Card/Card.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ export type Props = React.ComponentProps<typeof Surface> & {
6767
* Changes Card shadow and background on iOS and Android.
6868
*/
6969
elevation?: 0 | 1 | 2 | 3 | 4 | 5 | Animated.Value;
70-
style?: Animated.WithAnimatedValue<StyleProp<ViewStyle>>;
70+
/**
71+
* Style of card's inner content.
72+
*/
73+
contentStyle?: StyleProp<ViewStyle>;
74+
style?: StyleProp<ViewStyle>;
7175
/**
7276
* @optional
7377
*/
@@ -133,6 +137,7 @@ const Card = ({
133137
mode: cardMode = 'elevated',
134138
children,
135139
style,
140+
contentStyle,
136141
theme: themeOverrides,
137142
testID = 'card',
138143
accessible,
@@ -275,7 +280,7 @@ const Card = ({
275280
testID={testID}
276281
accessible={accessible}
277282
>
278-
<View style={styles.innerContainer}>
283+
<View style={[styles.innerContainer, contentStyle]}>
279284
{React.Children.map(children, (child, index) =>
280285
React.isValidElement(child)
281286
? React.cloneElement(child as React.ReactElement<any>, {

src/components/__tests__/Card/Card.test.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { Animated, StyleSheet } from 'react-native';
2+
import { Animated, StyleSheet, Text } from 'react-native';
33

44
import { render } from '@testing-library/react-native';
55
import color from 'color';
@@ -16,6 +16,9 @@ const styles = StyleSheet.create({
1616
customBorderRadius: {
1717
borderRadius: 32,
1818
},
19+
contentStyle: {
20+
flexDirection: 'column-reverse',
21+
},
1922
});
2023

2124
describe('Card', () => {
@@ -73,6 +76,16 @@ describe('Card', () => {
7376
backgroundColor: '#0000FF',
7477
});
7578
});
79+
80+
it('renders with a content style', () => {
81+
const { getByTestId } = render(
82+
<Card contentStyle={styles.contentStyle}>
83+
<Text>Content</Text>
84+
</Card>
85+
);
86+
87+
expect(getByTestId('card')).toHaveStyle(styles.contentStyle);
88+
});
7689
});
7790

7891
describe('CardActions', () => {

src/components/__tests__/Card/__snapshots__/Card.test.tsx.snap

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,12 @@ exports[`Card renders an outlined card 1`] = `
8888
onResponderTerminationRequest={[Function]}
8989
onStartShouldSetResponder={[Function]}
9090
style={
91-
Object {
92-
"flexShrink": 1,
93-
}
91+
Array [
92+
Object {
93+
"flexShrink": 1,
94+
},
95+
undefined,
96+
]
9497
}
9598
testID="card"
9699
/>

0 commit comments

Comments
 (0)