@tamagui/card 1.0.1-beta.56 → 1.0.1-beta.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -5
- package/src/Card.tsx +114 -0
- package/src/index.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/card",
|
|
3
|
-
"version": "1.0.1-beta.
|
|
3
|
+
"version": "1.0.1-beta.60",
|
|
4
4
|
"sideEffects": true,
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"types": "./types/index.d.ts",
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
"module": "dist/esm",
|
|
9
9
|
"module:jsx": "dist/jsx",
|
|
10
10
|
"files": [
|
|
11
|
+
"src",
|
|
11
12
|
"types",
|
|
12
13
|
"dist"
|
|
13
14
|
],
|
|
@@ -18,9 +19,9 @@
|
|
|
18
19
|
"clean:build": "tamagui-build clean:build"
|
|
19
20
|
},
|
|
20
21
|
"dependencies": {
|
|
21
|
-
"@tamagui/core": "^1.0.1-beta.
|
|
22
|
-
"@tamagui/create-context": "^1.0.1-beta.
|
|
23
|
-
"@tamagui/stacks": "^1.0.1-beta.
|
|
22
|
+
"@tamagui/core": "^1.0.1-beta.60",
|
|
23
|
+
"@tamagui/create-context": "^1.0.1-beta.60",
|
|
24
|
+
"@tamagui/stacks": "^1.0.1-beta.60"
|
|
24
25
|
},
|
|
25
26
|
"peerDependencies": {
|
|
26
27
|
"react": "*",
|
|
@@ -28,7 +29,7 @@
|
|
|
28
29
|
"react-native": "*"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
|
-
"@tamagui/build": "^1.0.1-beta.
|
|
32
|
+
"@tamagui/build": "^1.0.1-beta.60",
|
|
32
33
|
"@types/react-native": "^0.67.3",
|
|
33
34
|
"react": "*",
|
|
34
35
|
"react-dom": "*",
|
package/src/Card.tsx
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GetProps,
|
|
3
|
+
SizeTokens,
|
|
4
|
+
isTamaguiElement,
|
|
5
|
+
styled,
|
|
6
|
+
themeable,
|
|
7
|
+
withStaticProperties,
|
|
8
|
+
} from '@tamagui/core'
|
|
9
|
+
import { ScopedProps, createContextScope } from '@tamagui/create-context'
|
|
10
|
+
import { ThemeableStack } from '@tamagui/stacks'
|
|
11
|
+
import React, { cloneElement, forwardRef } from 'react'
|
|
12
|
+
import { View } from 'react-native'
|
|
13
|
+
|
|
14
|
+
// bugfix esbuild strips react jsx: 'preserve'
|
|
15
|
+
React['createElement']
|
|
16
|
+
|
|
17
|
+
const CARD_NAME = 'CARD'
|
|
18
|
+
|
|
19
|
+
type CardContextValue = {
|
|
20
|
+
size?: SizeTokens
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const [createCardContext, createCardScope] = createContextScope(CARD_NAME)
|
|
24
|
+
const [CardProvider, useCardContext] = createCardContext<CardContextValue>(CARD_NAME)
|
|
25
|
+
|
|
26
|
+
const CardFrame = styled(ThemeableStack, {
|
|
27
|
+
name: 'Card',
|
|
28
|
+
backgroundColor: '$background',
|
|
29
|
+
position: 'relative',
|
|
30
|
+
overflow: 'hidden',
|
|
31
|
+
|
|
32
|
+
variants: {
|
|
33
|
+
size: {
|
|
34
|
+
'...size': (val, { tokens }) => {
|
|
35
|
+
return {
|
|
36
|
+
borderRadius: tokens.radius[val] ?? val,
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
defaultVariants: {
|
|
43
|
+
size: '$4',
|
|
44
|
+
},
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
const CardHeader = styled(ThemeableStack, {
|
|
48
|
+
name: 'CardHeader',
|
|
49
|
+
zIndex: 10,
|
|
50
|
+
backgroundColor: 'transparent',
|
|
51
|
+
marginBottom: 'auto',
|
|
52
|
+
|
|
53
|
+
variants: {
|
|
54
|
+
size: {
|
|
55
|
+
'...size': (val, { tokens }) => {
|
|
56
|
+
return {
|
|
57
|
+
padding: tokens.space[val] ?? val,
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
const CardFooter = styled(CardHeader, {
|
|
65
|
+
name: 'CardFooter',
|
|
66
|
+
zIndex: 5,
|
|
67
|
+
flexDirection: 'row',
|
|
68
|
+
marginTop: 'auto',
|
|
69
|
+
marginBottom: 0,
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
const CardBackground = styled(ThemeableStack, {
|
|
73
|
+
name: 'CardBackground',
|
|
74
|
+
zIndex: 0,
|
|
75
|
+
fullscreen: true,
|
|
76
|
+
overflow: 'hidden',
|
|
77
|
+
pointerEvents: 'none',
|
|
78
|
+
padding: 0,
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
export type CardHeaderProps = GetProps<typeof CardHeader>
|
|
82
|
+
export type CardFooterProps = GetProps<typeof CardFooter>
|
|
83
|
+
|
|
84
|
+
export type CardProps = GetProps<typeof CardFrame>
|
|
85
|
+
|
|
86
|
+
export const Card = withStaticProperties(
|
|
87
|
+
themeable(
|
|
88
|
+
forwardRef<HTMLElement | View, ScopedProps<CardProps, 'Card'>>(
|
|
89
|
+
({ size, __scopeCard, children, ...props }, ref) => {
|
|
90
|
+
return (
|
|
91
|
+
<CardProvider scope={__scopeCard} size={size}>
|
|
92
|
+
<CardFrame ref={ref} {...props}>
|
|
93
|
+
{React.Children.map(children, (child) => {
|
|
94
|
+
if (isTamaguiElement(child) && !child.props.size) {
|
|
95
|
+
return cloneElement(child, {
|
|
96
|
+
size,
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
return child
|
|
100
|
+
})}
|
|
101
|
+
</CardFrame>
|
|
102
|
+
</CardProvider>
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
)
|
|
106
|
+
),
|
|
107
|
+
{
|
|
108
|
+
Header: CardHeader,
|
|
109
|
+
Footer: CardFooter,
|
|
110
|
+
Background: CardBackground,
|
|
111
|
+
}
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
export { createCardScope, useCardContext, CardHeader, CardFooter, CardBackground }
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Card'
|