@tamagui/menu 1.0.1-beta.59 → 1.0.1-beta.62

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/menu",
3
- "version": "1.0.1-beta.59",
3
+ "version": "1.0.1-beta.62",
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
  ],
@@ -19,9 +20,9 @@
19
20
  },
20
21
  "dependencies": {
21
22
  "@gorhom/bottom-sheet": "^4.3.1",
22
- "@tamagui/core": "^1.0.1-beta.59",
23
- "@tamagui/polyfill-dev": "^1.0.1-beta.59",
24
- "@tamagui/use-controllable-state": "^1.0.1-beta.59",
23
+ "@tamagui/core": "^1.0.1-beta.62",
24
+ "@tamagui/polyfill-dev": "^1.0.1-beta.62",
25
+ "@tamagui/use-controllable-state": "^1.0.1-beta.62",
25
26
  "react-native-gesture-handler": "*",
26
27
  "react-native-reanimated": "~2.8.0"
27
28
  },
@@ -30,7 +31,7 @@
30
31
  "react-dom": "*"
31
32
  },
32
33
  "devDependencies": {
33
- "@tamagui/build": "^1.0.1-beta.59",
34
+ "@tamagui/build": "^1.0.1-beta.62",
34
35
  "react": "*",
35
36
  "react-dom": "*"
36
37
  },
package/src/Menu.tsx ADDED
@@ -0,0 +1,69 @@
1
+ import { useMedia, withStaticProperties } from '@tamagui/core'
2
+ import { Drawer, DrawerProvider } from '@tamagui/drawer'
3
+ import { useControllableState } from '@tamagui/use-controllable-state'
4
+ import React, { cloneElement, useEffect, useMemo, useState } from 'react'
5
+ import { Popover, YStack } from 'tamagui'
6
+
7
+ const MenuItem = (props) => {
8
+ return props.children
9
+ }
10
+
11
+ type MenuProps = {
12
+ children?: React.ReactNode
13
+ open?: boolean
14
+ defaultOpen?: boolean
15
+ trigger?: any
16
+ onChangeOpen?: (next: boolean) => void
17
+ }
18
+
19
+ export const Menu = withStaticProperties(
20
+ ({ children, open: openProp, defaultOpen, trigger, onChangeOpen }: MenuProps) => {
21
+ const media = useMedia()
22
+ const [open, setOpen] = useControllableState({
23
+ prop: openProp,
24
+ defaultProp: defaultOpen || false,
25
+ onChange(next) {
26
+ onChangeOpen?.(next)
27
+ },
28
+ })
29
+
30
+ const triggerProps = useMemo(() => {
31
+ return {
32
+ onPress: () => {
33
+ setOpen((x) => !x)
34
+ },
35
+ }
36
+ }, [])
37
+
38
+ if (media.sm) {
39
+ return (
40
+ <>
41
+ {cloneElement(trigger, triggerProps)}
42
+ <Drawer open={open} onDismiss={() => setOpen(false)}>
43
+ {children}
44
+ </Drawer>
45
+ </>
46
+ )
47
+ }
48
+
49
+ return null
50
+ // return (
51
+ // <Popover
52
+ // trigger={(props) => cloneElement(trigger, { ...props, ...triggerProps })}
53
+ // open={open}
54
+ // onChangeOpen={setOpen}
55
+ // >
56
+ // <Popover.Content>
57
+ // <Popover.Arrow />
58
+ // <YStack backgroundColor="$background" borderRadius="$2">
59
+ // {children}
60
+ // </YStack>
61
+ // </Popover.Content>
62
+ // </Popover>
63
+ // )
64
+ },
65
+ {
66
+ Item: MenuItem,
67
+ Provider: DrawerProvider,
68
+ }
69
+ )
package/src/index.tsx ADDED
@@ -0,0 +1,2 @@
1
+ import '@tamagui/polyfill-dev'
2
+ export * from './Menu'