Skip to content

Commit d428f30

Browse files
committed
feat[Card]:Add SelectedStyle prop<Card 组件增加自定选中状态api>
1 parent 26a85db commit d428f30

File tree

5 files changed

+26
-6
lines changed

5 files changed

+26
-6
lines changed

example/examples/src/routes/Card/index.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,15 @@ const CardDemo = (props: any) => {
8989
borderRadius={12}
9090
onPress={() => {
9191
setSelected(!selected);
92-
}}>
92+
}}
93+
// 自定义选中状态
94+
// selectedStyle={{
95+
// icon: null,
96+
// style: {
97+
// borderColor: "#fd8a00",
98+
// }
99+
// }}
100+
>
93101
{basicRender}
94102
</Card>
95103
</ScrollView>

packages/core/src/Card/Card.Actions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export type CardActionsProps = {
2828
const CardActions = ({ actions = [], actionsContainerStyle, children }: CardActionsProps) => {
2929
return (
3030
<Fragment>
31-
<Divider style={StyleSheet.flatten({ marginTop: 15 })} />
31+
<Divider style={StyleSheet.flatten({ marginTop: 15 })} lineStyle={{ backgroundColor: '#e6e6e6' }} />
3232
{React.isValidElement(children) ? React.cloneElement(children) : null}
3333
<View style={[styles.actionsContainer, actionsContainerStyle]}>
3434
{map(actions, (item, index) => {

packages/core/src/Card/Card.Title.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const CardTitle = ({ title, titleStyle, children }: CardTitleProps) => {
1818
</Text>
1919
)}
2020
{React.isValidElement(children) ? React.cloneElement(children) : null}
21-
<Divider style={StyleSheet.flatten([styles.divider])} />
21+
<Divider style={StyleSheet.flatten([styles.divider])} lineStyle={{ backgroundColor: '#e6e6e6' }} />
2222
</View>
2323
);
2424
};

packages/core/src/Card/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ export interface CardProps {
116116
onPress?: TouchableOpacityProps['onPress'];
117117
/** 长按下卡片时的动作(可选) */
118118
onLongPress?: TouchableOpacityProps['onLongPress'];
119+
/** 自定义选中样式 */
120+
selectedStyle?: {
121+
icon?: React.ReactNode;
122+
style?: ViewStyle
123+
}
119124
}
120125
```
121126

packages/core/src/Card/index.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ export type CardProps = {
2323
children?: React.ReactNode;
2424
onPress?: TouchableOpacityProps['onPress'];
2525
onLongPress?: TouchableOpacityProps['onLongPress'];
26+
selectedStyle?: {
27+
icon?: React.ReactNode;
28+
style?: ViewStyle;
29+
};
2630
};
2731

2832
const Card = ({
@@ -33,6 +37,10 @@ const Card = ({
3337
selected,
3438
onPress,
3539
onLongPress,
40+
selectedStyle = {
41+
icon: <Icon xml={checked} size={30} />,
42+
style: {},
43+
},
3644
...attributes
3745
}: CardProps) => {
3846
const Container: any = onPress || onLongPress ? TouchableOpacity : View;
@@ -53,13 +61,12 @@ const Card = ({
5361
{
5462
opacity: 1,
5563
borderRadius: getBorderRadius(),
64+
...selectedStyle?.style,
5665
},
5766
]}
5867
pointerEvents="none"
5968
>
60-
<View style={styles.selectedIndicator}>
61-
<Icon xml={checked} size={30} />
62-
</View>
69+
<View style={styles.selectedIndicator}>{selectedStyle?.icon}</View>
6370
</Animated.View>
6471
);
6572
};

0 commit comments

Comments
 (0)