Skip to content

Commit e69f9d2

Browse files
authored
fix: allow to override content style (#4707)
1 parent c98a01c commit e69f9d2

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

src/components/Card/CardActions.tsx

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,33 @@ export type Props = React.ComponentPropsWithRef<typeof View> & {
3434
* export default MyComponent;
3535
* ```
3636
*/
37-
const CardActions = (props: Props) => {
38-
const { isV3 } = useInternalTheme(props.theme);
39-
const justifyContent = isV3 ? 'flex-end' : 'flex-start';
37+
const CardActions = ({ theme, style, children, ...rest }: Props) => {
38+
const { isV3 } = useInternalTheme(theme);
39+
40+
const justifyContent = (
41+
isV3 ? 'flex-end' : 'flex-start'
42+
) as ViewStyle['justifyContent'];
43+
const containerStyle = [styles.container, { justifyContent }, style];
4044

4145
return (
42-
<View
43-
{...props}
44-
style={[styles.container, props.style, { justifyContent }]}
45-
>
46-
{React.Children.map(props.children, (child, i) => {
47-
return React.isValidElement(child)
48-
? React.cloneElement(child as React.ReactElement<any>, {
49-
compact: !isV3 && child.props.compact !== false,
50-
mode:
51-
child.props.mode ||
52-
(isV3 && (i === 0 ? 'outlined' : 'contained')),
53-
style: [isV3 && styles.button, child.props.style],
54-
})
55-
: child;
46+
<View {...rest} style={containerStyle}>
47+
{React.Children.map(children, (child, index) => {
48+
if (!React.isValidElement(child)) {
49+
return child;
50+
}
51+
52+
const compact = !isV3 && child.props.compact !== false;
53+
const mode =
54+
child.props.mode ??
55+
(isV3 ? (index === 0 ? 'outlined' : 'contained') : undefined);
56+
const childStyle = [isV3 && styles.button, child.props.style];
57+
58+
return React.cloneElement(child, {
59+
...child.props,
60+
compact,
61+
mode,
62+
style: childStyle,
63+
});
5664
})}
5765
</View>
5866
);

0 commit comments

Comments
 (0)