forked from callstack/react-native-paper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCardActions.tsx
59 lines (54 loc) · 1.29 KB
/
CardActions.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import * as React from 'react';
import { StyleSheet, StyleProp, View, ViewStyle } from 'react-native';
type Props = React.ComponentPropsWithRef<typeof View> & {
/**
* Items inside the `CardActions`.
*/
children: React.ReactNode;
style?: StyleProp<ViewStyle>;
};
/**
* A component to show a list of actions inside a Card.
*
* ## Usage
* ```js
* import * as React from 'react';
* import { Button, Card } from 'react-native-paper';
*
* const MyComponent = () => (
* <Card>
* <Card.Actions>
* <Button>Cancel</Button>
* <Button>Ok</Button>
* </Card.Actions>
* </Card>
* );
*
* export default MyComponent;
* ```
*/
class CardActions extends React.Component<Props> {
static displayName = 'Card.Actions';
render() {
return (
<View {...this.props} style={[styles.container, this.props.style]}>
{React.Children.map(this.props.children, child =>
React.isValidElement(child)
? React.cloneElement(child, {
compact: child.props.compact !== false,
})
: child
)}
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'flex-start',
padding: 8,
},
});
export default CardActions;