@tamagui/stacks 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/stacks",
3
- "version": "1.0.1-beta.56",
3
+ "version": "1.0.1-beta.60",
4
4
  "sideEffects": false,
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
  ],
@@ -16,14 +17,14 @@
16
17
  "watch": "tamagui-build --watch"
17
18
  },
18
19
  "dependencies": {
19
- "@tamagui/core": "^1.0.1-beta.56"
20
+ "@tamagui/core": "^1.0.1-beta.60"
20
21
  },
21
22
  "peerDependencies": {
22
23
  "react": "*",
23
24
  "react-dom": "*"
24
25
  },
25
26
  "devDependencies": {
26
- "@tamagui/build": "^1.0.1-beta.56",
27
+ "@tamagui/build": "^1.0.1-beta.60",
27
28
  "react": "*",
28
29
  "react-dom": "*"
29
30
  },
@@ -0,0 +1,29 @@
1
+ import { GetProps, getButtonSize, styled } from '@tamagui/core'
2
+
3
+ import { YStack } from './Stacks'
4
+ import { bordered, circular, elevate, focusable, hoverable, pressable } from './variants'
5
+
6
+ export const SizableStack = styled(YStack, {
7
+ name: 'SizableStack',
8
+ backgroundColor: '$background',
9
+ flexDirection: 'row',
10
+ flexShrink: 1,
11
+
12
+ variants: {
13
+ // allows the type to come in for use in size
14
+ fontFamily: () => ({}),
15
+
16
+ hoverable,
17
+ pressable,
18
+ focusable,
19
+ circular,
20
+ elevate,
21
+ bordered,
22
+
23
+ size: {
24
+ '...size': getButtonSize,
25
+ },
26
+ },
27
+ })
28
+
29
+ export type SizableStackProps = GetProps<typeof SizableStack>
package/src/Stacks.tsx ADDED
@@ -0,0 +1,90 @@
1
+ import {
2
+ GetProps,
3
+ SizeTokens,
4
+ SizeVariantSpreadFunction,
5
+ Stack,
6
+ StackProps,
7
+ VariantSpreadExtras,
8
+ getVariableValue,
9
+ isVariable,
10
+ styled,
11
+ } from '@tamagui/core'
12
+
13
+ export type YStackProps = GetProps<typeof YStack>
14
+ export type XStackProps = YStackProps
15
+ export type ZStackProps = YStackProps
16
+
17
+ export const getElevation: SizeVariantSpreadFunction<StackProps> = (size, extras) => {
18
+ const { tokens } = extras
19
+ const token = tokens.size[size]
20
+ const sizeNum = (isVariable(token) ? +token.val : size) as number
21
+ // TODO this could be configurable with require('tamagui').configure({ elevation: () => {} })
22
+ return getSizedElevation(sizeNum, extras)
23
+ }
24
+
25
+ const fullscreenStyle = {
26
+ position: 'absolute',
27
+ top: 0,
28
+ left: 0,
29
+ right: 0,
30
+ bottom: 0,
31
+ } as const
32
+
33
+ const variants = {
34
+ fullscreen: {
35
+ true: fullscreenStyle,
36
+ },
37
+ elevation: {
38
+ '...size': getElevation,
39
+ },
40
+ } as const
41
+
42
+ export const YStack = styled(Stack, {
43
+ flexDirection: 'column',
44
+ name: 'YStack',
45
+ variants,
46
+ })
47
+
48
+ export const XStack = styled(Stack, {
49
+ flexDirection: 'row',
50
+ name: 'XStack',
51
+ variants,
52
+ })
53
+
54
+ export const ZStack = styled(
55
+ YStack,
56
+ {
57
+ name: 'ZStack',
58
+ position: 'relative',
59
+ },
60
+ {
61
+ neverFlatten: true,
62
+ isZStack: true,
63
+ }
64
+ )
65
+
66
+ export const getSizedElevation = (
67
+ val: SizeTokens | number | boolean,
68
+ { theme, tokens }: VariantSpreadExtras<any>
69
+ ) => {
70
+ const num =
71
+ val === false
72
+ ? 0
73
+ : val === true
74
+ ? // handles true
75
+ (() => {
76
+ const val = getVariableValue(tokens.size['true'])
77
+ if (typeof val === 'number') {
78
+ return val
79
+ }
80
+ return 10
81
+ })()
82
+ : +val
83
+ const [height, shadowRadius] = [Math.round(num / 4 + 1), Math.round(num / 2 + 2)]
84
+ const shadow = {
85
+ shadowColor: theme.shadowColor,
86
+ shadowRadius,
87
+ shadowOffset: { height, width: 0 },
88
+ }
89
+ return shadow
90
+ }
@@ -0,0 +1,53 @@
1
+ import { GetProps, styled } from '@tamagui/core'
2
+
3
+ import { YStack } from './Stacks'
4
+ import {
5
+ bordered,
6
+ circular,
7
+ elevate,
8
+ focusable,
9
+ hoverable,
10
+ padded,
11
+ pressable,
12
+ radiused,
13
+ } from './variants'
14
+
15
+ export const ThemeableStack = styled(YStack, {
16
+ name: 'SizableStack',
17
+
18
+ variants: {
19
+ // allows the type to come in for use in size
20
+ fontFamily: () => ({}),
21
+
22
+ backgrounded: {
23
+ true: {
24
+ backgroundColor: '$background',
25
+ },
26
+ },
27
+
28
+ radiused,
29
+ hoverable,
30
+ pressable,
31
+ focusable,
32
+ circular,
33
+ padded,
34
+ elevate,
35
+ bordered,
36
+
37
+ transparent: {
38
+ true: {
39
+ backgroundColor: 'transparent',
40
+ },
41
+ },
42
+
43
+ chromeless: {
44
+ true: {
45
+ backgroundColor: 'transparent',
46
+ borderColor: 'transparent',
47
+ shadowColor: 'transparent',
48
+ },
49
+ },
50
+ },
51
+ })
52
+
53
+ export type ThemeableStackProps = GetProps<typeof ThemeableStack>
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './Stacks'
2
+ export * from './SizableStack'
3
+ export * from './ThemeableStack'
@@ -0,0 +1,113 @@
1
+ import { getElevation } from './Stacks'
2
+
3
+ export const elevate = {
4
+ true: (_, extras) => {
5
+ return getElevation(extras.props['size'], extras)
6
+ },
7
+ }
8
+
9
+ export const bordered = (val: boolean | number, { props }) => {
10
+ return {
11
+ // TODO size it with size in '...size'
12
+ borderWidth: typeof val === 'number' ? val : 1,
13
+ borderColor: '$borderColor',
14
+
15
+ ...(props.hoverable && {
16
+ hoverStyle: {
17
+ borderColor: '$borderColorHover',
18
+ },
19
+ }),
20
+
21
+ ...(props.pressable && {
22
+ pressStyle: {
23
+ borderColor: '$borderColorPress',
24
+ },
25
+ }),
26
+
27
+ ...(props.focusable && {
28
+ focusStyle: {
29
+ borderColor: '$borderColorFocus',
30
+ },
31
+ }),
32
+ }
33
+ }
34
+
35
+ export const padded = {
36
+ true: (_, extras) => {
37
+ const { tokens, props } = extras
38
+ return {
39
+ padding: tokens.size[props.size] || tokens.size['$4'],
40
+ }
41
+ },
42
+ }
43
+
44
+ export const radiused = {
45
+ true: (_, extras) => {
46
+ const { tokens, props } = extras
47
+ return {
48
+ borderRadius: tokens.radius[props.size] || tokens.radius['$4'],
49
+ }
50
+ },
51
+ }
52
+
53
+ export const circular = {
54
+ true: (_, { props, tokens }) => {
55
+ const size = tokens.size[props.size]
56
+ return {
57
+ width: size,
58
+ height: size,
59
+ maxWidth: size,
60
+ maxHeight: size,
61
+ minWidth: size,
62
+ minHeight: size,
63
+ borderRadius: 100_000,
64
+ paddingVertical: 0,
65
+ paddingHorizontal: 0,
66
+ }
67
+ },
68
+ }
69
+
70
+ export const hoverable = {
71
+ true: {
72
+ hoverStyle: {
73
+ backgroundColor: '$backgroundHover',
74
+ borderColor: '$borderColorHover',
75
+ },
76
+ },
77
+ false: {
78
+ hoverStyle: {
79
+ backgroundColor: '$background',
80
+ borderColor: '$borderColor',
81
+ },
82
+ },
83
+ }
84
+
85
+ export const pressable = {
86
+ true: {
87
+ pressStyle: {
88
+ backgroundColor: '$backgroundPress',
89
+ borderColor: '$borderColorPress',
90
+ },
91
+ },
92
+ false: {
93
+ pressStyle: {
94
+ backgroundColor: '$background',
95
+ borderColor: '$borderColor',
96
+ },
97
+ },
98
+ }
99
+
100
+ export const focusable = {
101
+ true: {
102
+ focusStyle: {
103
+ backgroundColor: '$backgroundFocus',
104
+ borderColor: '$borderColorFocus',
105
+ },
106
+ },
107
+ false: {
108
+ focusStyle: {
109
+ backgroundColor: '$background',
110
+ borderColor: '$borderColor',
111
+ },
112
+ },
113
+ }