From 7ef449156eb6ccf0cb1217845ca232bc4cb1b627 Mon Sep 17 00:00:00 2001 From: lukewalczak Date: Wed, 30 Apr 2025 09:41:04 +0200 Subject: [PATCH] fix: allow to override content style --- src/components/Card/CardActions.tsx | 42 +++++++++++++++++------------ 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/src/components/Card/CardActions.tsx b/src/components/Card/CardActions.tsx index 91a2e73c08..624f38411e 100644 --- a/src/components/Card/CardActions.tsx +++ b/src/components/Card/CardActions.tsx @@ -34,25 +34,33 @@ export type Props = React.ComponentPropsWithRef & { * export default MyComponent; * ``` */ -const CardActions = (props: Props) => { - const { isV3 } = useInternalTheme(props.theme); - const justifyContent = isV3 ? 'flex-end' : 'flex-start'; +const CardActions = ({ theme, style, children, ...rest }: Props) => { + const { isV3 } = useInternalTheme(theme); + + const justifyContent = ( + isV3 ? 'flex-end' : 'flex-start' + ) as ViewStyle['justifyContent']; + const containerStyle = [styles.container, { justifyContent }, style]; return ( - - {React.Children.map(props.children, (child, i) => { - return React.isValidElement(child) - ? React.cloneElement(child as React.ReactElement, { - compact: !isV3 && child.props.compact !== false, - mode: - child.props.mode || - (isV3 && (i === 0 ? 'outlined' : 'contained')), - style: [isV3 && styles.button, child.props.style], - }) - : child; + + {React.Children.map(children, (child, index) => { + if (!React.isValidElement(child)) { + return child; + } + + const compact = !isV3 && child.props.compact !== false; + const mode = + child.props.mode ?? + (isV3 ? (index === 0 ? 'outlined' : 'contained') : undefined); + const childStyle = [isV3 && styles.button, child.props.style]; + + return React.cloneElement(child, { + ...child.props, + compact, + mode, + style: childStyle, + }); })} );