Skip to content

Commit

Permalink
(fix):Update Card & Card docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenlingasMx committed Aug 31, 2021
1 parent dbdb333 commit 96c582b
Show file tree
Hide file tree
Showing 6 changed files with 215 additions and 148 deletions.
37 changes: 20 additions & 17 deletions example/examples/src/routes/Card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,31 @@ const CardDemo = (props: any) => {
<ScrollView style={{flex: 1}}>
<Header title={title} description={description} />
<Header description={'基本使用'} />
<Card
actions={[
{
text: '点赞',
icon: <Icon name="like-o" size={16} color="#5847FF" />,
onPress: (e: any, index: number) => {
console.log('e', e, 'index', index);
<Card>
{basicRender}
<Card.Actions
actions={[
{
text: '点赞',
icon: <Icon name="like-o" size={16} color="#5847FF" />,
onPress: (e: any, index: number) => {
console.log('e', e, 'index', index);
},
},
},
{
text: '分享',
icon: <Icon name="share" size={16} color="#5847FF" />,
onPress: (e: any, index: number) => {
console.log('e', e, 'index', index);
{
text: '分享',
icon: <Icon name="share" size={16} color="#5847FF" />,
onPress: (e: any, index: number) => {
console.log('e', e, 'index', index);
},
},
},
]}>
{basicRender}
]}
/>
</Card>
<Divider />
<Header description={'带标题下划线圆角卡片'} />
<Card title={TITLE} borderRadius={12}>
<Card borderRadius={12}>
<Card.Title title="@uiw/react-native" />
{basicRender}
</Card>
<Divider />
Expand Down
17 changes: 5 additions & 12 deletions example/examples/src/routes/Progress/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,11 @@ const ProgressDemo = (props: any) => {

return (
<Container>
<Progress progress={30} />
<Header title={title} description={description} />
<Body>
<Card title="基础实例" style={{margin: 10}}>
<Header description={'基本使用'} />
<Progress progressColor="#5847FF" progress={40} />
<Spacing />
<Button color={'#5847FF'} onPress={onPress}>
(+-)10
</Button>
<Spacing />
<Header description={'点击变化'} />
<View
style={{
flexDirection: 'row',
Expand All @@ -43,11 +38,9 @@ const ProgressDemo = (props: any) => {
{val}%
</Text>
</View>
<Spacing />
<Progress progressColor="#5847FF" progress={60} />
<Spacing />
<Progress progressColor="#5847FF" progress={80} />
</Card>
<Button color={'#5847FF'} onPress={onPress}>
(+-)10
</Button>
</Body>
</Container>
);
Expand Down
82 changes: 82 additions & 0 deletions packages/core/src/Card/Card.Actions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import React, { Fragment } from 'react';
import {
View,
Text,
StyleSheet,
StyleProp,
ViewStyle,
TextStyle,
Platform,
TouchableOpacity,
GestureResponderEvent
} from 'react-native';
import Divider from '../Divider';
import map from 'lodash/map';
import { colors } from '../utils';

export type CardActionsProps = {
actions?: Array<{
text?: string;
icon?: JSX.Element;
onPress?: (e: GestureResponderEvent, index: number) => void;
actionsTextStyle?: StyleProp<TextStyle>
}>;
actionsContainerStyle?: StyleProp<ViewStyle>
children?: React.ReactNode;
};

const CardActions = ({
actions = [],
actionsContainerStyle,
children
}: CardActionsProps) => {
return (
<Fragment>
<Divider style={StyleSheet.flatten({ marginTop: 15 })} />
{React.isValidElement(children) ? React.cloneElement(children) : null}
<View style={[styles.actionsContainer, actionsContainerStyle]}>
{map(actions, (item, index) => {
return (
<TouchableOpacity
style={[styles.actionsTitleContainer, { marginLeft: index === 0 ? 0 : 10 }]}
key={index}
onPress={(event) => item.onPress && item.onPress(event, index)}
>
{item.icon && item.icon}
{item.text && <Text style={[styles.actionsTitle, item.actionsTextStyle]}>{item.text}</Text>}
</TouchableOpacity>
);
})}
</View>
</Fragment>
)
}

const styles = StyleSheet.create({
actionsContainer: {
display: 'flex',
flexDirection: 'row',
justifyContent: 'flex-end',
paddingTop: 15,
},
actionsTitleContainer: {
display: 'flex',
flexDirection: 'row',
fontSize: 16,
},
actionsTitle: {
color: colors.colorsPalette.violet30,
...Platform.select({
android: {
fontFamily: 'sans-serif',
fontWeight: 'bold',
},
default: {
fontWeight: 'bold',
},
}),
textAlign: 'center',
},
});

export default CardActions
58 changes: 58 additions & 0 deletions packages/core/src/Card/Card.Title.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React from 'react';
import {
View,
Text,
StyleSheet,
Platform,
TextStyle,
StyleProp
} from 'react-native';
import { colors } from '../utils';
import Divider from '../Divider';

export type CardTitleProps = {
title?: string;
titleStyle?: StyleProp<TextStyle>
children?: React.ReactNode;
};

const CardTitle = ({
title,
titleStyle,
children
}: CardTitleProps) => {
return (
<View>
{title && (
<Text testID="cardTitle" style={StyleSheet.flatten([styles.title, titleStyle]) as TextStyle}>
{title}
</Text>
)}
{React.isValidElement(children)?React.cloneElement(children):null}
<Divider style={StyleSheet.flatten([styles.divider])} />
</View>
)
}

const styles = StyleSheet.create({
title: {
fontSize: 14,
color: colors.colorsPalette.grey10,
...Platform.select({
android: {
fontFamily: 'sans-serif',
fontWeight: 'bold',
},
default: {
fontWeight: 'bold',
},
}),
textAlign: 'center',
marginBottom: 15,
},
divider: {
marginBottom: 15,
}
});

export default CardTitle
69 changes: 43 additions & 26 deletions packages/core/src/Card/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,10 @@ import { Card } from '@uiw/react-native';

class Demo extends Component {
render() {
return (
return (
<SafeAreaView style={{ flex: 1 }}>
<Card
title="我是标题"
showDriver={true}
borderRadius={12}
>
<Card borderRadius={12}>
<Card.Title title="@uiw/react-native" />
<Image
source={{
uri: 'https://nimg.ws.126.net/?url=http%3A%2F%2Fdingyue.ws.126.net%2F2019%2F04%2F22%2Fca22d8623fe7454ea9cdb33f3137d14e.jpeg&thumbnail=650x2147483647&quality=80&type=jpg',
Expand All @@ -56,25 +53,37 @@ class Demo extends Component {
```
<!--End-->

### 可点击选中卡片
### 可点击选中带操作卡片

<!--DemoStart-->
```jsx
import React, { useState } from 'react';
import { SafeAreaView, View, Image } from 'react-native';
import { Card } from '@uiw/react-native';
import { Card ,Icon } from '@uiw/react-native';

const Demo = () => {
const [selected, setSelected] = useState(false)
return (
<SafeAreaView style={{ flex: 1 }}>
<Card
selected={selected}
title="我是标题"
showDriver={true}
borderRadius={12}
onPress={() => { setSelected(!selected) }}
>
<Card.Actions
actions={[
{
text: '点赞',
icon: <Icon name="like-o" size={16} color="#5847FF" />,
onPress: (e: any, index: number) => { }
},
{
text: '分享',
icon: <Icon name="share" size={16} color="#5847FF" />,
onPress: (e: any, index: number) => { }
},
]}
/>
<Image
source={{
uri: 'https://wx1.sinaimg.cn/mw690/4718260ely1gt2cg5r9zij22yo1o0x6p.jpg',
Expand All @@ -88,38 +97,46 @@ const Demo = () => {
```
<!--End-->

### Props

### CardProps
```ts
export interface CardProps {
/** 外容器样式(可选) */
containerStyle?: StyleProp<ViewStyle>;
/** 内容器样式(可选) */
wrapperStyle?: StyleProp<ViewStyle>;
/** 标题(可选) */
title?: string
/** 标题样式(可选) */
titleStyle?: StyleProp<TextStyle>;
/** 设置卡片圆角度数(可选) */
borderRadius?: number;
/** 是否选中(可选) */
selected?: boolean;
/** 渲染内容 */
children?: React.ReactNode;
/** 操作 */
actions?: Array<{
text?: string;
icon?: JSX.Element;
onPress?: (e: GestureResponderEvent, index: number) => void;
}>;
/** 操作容器样式(可选) */
actionsContainerStyle?: StyleProp<ViewStyle>;
/** 操作文字样式(可选) */
actionsTextStyle?: StyleProp<ViewStyle>;
/** 按下卡片时的动作(可选) */
onPress?: TouchableOpacityProps['onPress'];
/** 长按下卡片时的动作(可选) */
onLongPress?: TouchableOpacityProps['onLongPress'];
}
```

### CardTitleProps
```ts
type CardTitleProps = {
title?: string;
titleStyle?: StyleProp<TextStyle>
children?: React.ReactNode;
};
```

### CardActionsProps
```ts
type CardActionsProps = {
actions?: Array<{
text?: string;
icon?: JSX.Element;
onPress?: (e: GestureResponderEvent, index: number) => void;
actionsTextStyle?: StyleProp<TextStyle>
}>;
actionsContainerStyle?: StyleProp<ViewStyle>
children?: React.ReactNode;
};
```

Loading

0 comments on commit 96c582b

Please sign in to comment.