File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed
packages/core/src/components Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ import React from "react" ;
2+ import { withTheme } from "../theming" ;
3+ import Touchable from "./Touchable" ;
4+ import { StyleProp , ViewStyle } from "react-native" ;
5+ import theme from "../styles/DefaultTheme" ;
6+
7+ type Props = {
8+ numColumns ?: number ;
9+ children ?: React . ReactNode ;
10+ onPress ?: ( ) => void ;
11+ style ?: StyleProp < ViewStyle > ;
12+ theme : typeof theme ;
13+ } ;
14+
15+ const getWidth = ( numColumns : number ) => {
16+ switch ( numColumns ) {
17+ case 1 :
18+ return "33%" ;
19+ case 2 :
20+ return "50%" ;
21+ default :
22+ return "100%" ;
23+ }
24+ } ;
25+
26+ const Card : React . FC < React . PropsWithChildren < Props > > = ( {
27+ numColumns = 3 ,
28+ children,
29+ onPress,
30+ style,
31+ ...rest
32+ } ) => {
33+ const width = getWidth ( numColumns ) ;
34+ return (
35+ < Touchable
36+ disabled = { ! onPress }
37+ onPress = { onPress }
38+ style = { [ style , { width } ] }
39+ { ...rest }
40+ >
41+ { children }
42+ </ Touchable >
43+ ) ;
44+ } ;
45+
46+ export default withTheme ( Card ) ;
You can’t perform that action at this time.
0 commit comments