@coze-arch/cli 0.0.1-beta.6 → 0.0.2

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.
Files changed (238) hide show
  1. package/README.md +1 -0
  2. package/lib/__templates__/expo/.coze +7 -2
  3. package/lib/__templates__/expo/.cozeproj/scripts/dev_build.sh +46 -0
  4. package/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +229 -0
  5. package/lib/__templates__/expo/.cozeproj/scripts/prod_build.sh +47 -0
  6. package/lib/__templates__/expo/.cozeproj/scripts/prod_run.sh +34 -0
  7. package/lib/__templates__/expo/.cozeproj/scripts/server_dev_run.sh +46 -0
  8. package/lib/__templates__/expo/README.md +68 -7
  9. package/lib/__templates__/expo/_gitignore +1 -1
  10. package/lib/__templates__/expo/_npmrc +4 -5
  11. package/lib/__templates__/expo/client/app/+not-found.tsx +15 -64
  12. package/lib/__templates__/expo/client/app/_layout.tsx +15 -12
  13. package/lib/__templates__/expo/client/app/index.tsx +1 -0
  14. package/lib/__templates__/expo/client/app.config.ts +76 -0
  15. package/lib/__templates__/expo/client/components/Screen.tsx +3 -19
  16. package/lib/__templates__/expo/client/components/ThemedText.tsx +33 -0
  17. package/lib/__templates__/expo/client/components/ThemedView.tsx +37 -0
  18. package/lib/__templates__/expo/client/constants/theme.ts +117 -58
  19. package/lib/__templates__/expo/client/contexts/AuthContext.tsx +14 -107
  20. package/lib/__templates__/expo/client/declarations.d.ts +5 -0
  21. package/lib/__templates__/expo/{eslint.config.mjs → client/eslint.config.mjs} +40 -10
  22. package/lib/__templates__/expo/client/hooks/useColorScheme.tsx +48 -0
  23. package/lib/__templates__/expo/client/hooks/useSafeRouter.ts +152 -0
  24. package/lib/__templates__/expo/client/hooks/useTheme.ts +26 -6
  25. package/lib/__templates__/expo/client/metro.config.js +124 -0
  26. package/lib/__templates__/expo/client/package.json +95 -0
  27. package/lib/__templates__/expo/client/screens/demo/index.tsx +25 -0
  28. package/lib/__templates__/expo/client/screens/demo/styles.ts +28 -0
  29. package/lib/__templates__/expo/client/scripts/install-missing-deps.js +11 -10
  30. package/lib/__templates__/expo/client/tsconfig.json +24 -0
  31. package/lib/__templates__/expo/client/utils/index.ts +23 -2
  32. package/lib/__templates__/expo/eslint-plugins/fontawesome6/index.js +9 -0
  33. package/lib/__templates__/expo/eslint-plugins/fontawesome6/names.js +1889 -0
  34. package/lib/__templates__/expo/eslint-plugins/fontawesome6/rule.js +174 -0
  35. package/lib/__templates__/expo/eslint-plugins/fontawesome6/v5-only-names.js +388 -0
  36. package/lib/__templates__/expo/eslint-plugins/forbid-emoji/index.js +9 -0
  37. package/lib/__templates__/expo/eslint-plugins/forbid-emoji/rule.js +112 -0
  38. package/lib/__templates__/expo/eslint-plugins/forbid-emoji/tech.md +94 -0
  39. package/lib/__templates__/expo/eslint-plugins/react-native/index.js +9 -0
  40. package/lib/__templates__/expo/eslint-plugins/react-native/rule.js +64 -0
  41. package/lib/__templates__/expo/eslint-plugins/reanimated/index.js +9 -0
  42. package/lib/__templates__/expo/eslint-plugins/reanimated/rule.js +88 -0
  43. package/lib/__templates__/expo/eslint-plugins/restrict-linear-gradient/index.js +9 -0
  44. package/lib/__templates__/expo/eslint-plugins/restrict-linear-gradient/rule.js +120 -0
  45. package/lib/__templates__/expo/eslint-plugins/restrict-linear-gradient/tech.md +58 -0
  46. package/lib/__templates__/expo/package.json +16 -101
  47. package/lib/__templates__/expo/patches/expo@54.0.33.patch +45 -0
  48. package/lib/__templates__/expo/pnpm-lock.yaml +1622 -3274
  49. package/lib/__templates__/expo/pnpm-workspace.yaml +3 -0
  50. package/lib/__templates__/expo/server/build.js +21 -0
  51. package/lib/__templates__/expo/server/package.json +34 -0
  52. package/lib/__templates__/expo/server/src/index.ts +20 -0
  53. package/lib/__templates__/expo/server/tsconfig.json +24 -0
  54. package/lib/__templates__/expo/template.config.js +58 -1
  55. package/lib/__templates__/expo/tsconfig.json +1 -24
  56. package/lib/__templates__/native-static/.coze +11 -0
  57. package/lib/__templates__/native-static/index.html +33 -0
  58. package/lib/__templates__/native-static/styles/main.css +136 -0
  59. package/lib/__templates__/native-static/template.config.js +22 -0
  60. package/lib/__templates__/nextjs/.coze +4 -3
  61. package/lib/__templates__/nextjs/README.md +5 -0
  62. package/lib/__templates__/nextjs/_npmrc +2 -1
  63. package/lib/__templates__/nextjs/eslint.config.mjs +5 -0
  64. package/lib/__templates__/nextjs/next.config.ts +11 -0
  65. package/lib/__templates__/nextjs/package.json +15 -1
  66. package/lib/__templates__/nextjs/pnpm-lock.yaml +7694 -4394
  67. package/lib/__templates__/nextjs/scripts/build.sh +4 -1
  68. package/lib/__templates__/nextjs/scripts/dev.sh +15 -28
  69. package/lib/__templates__/nextjs/scripts/prepare.sh +9 -0
  70. package/lib/__templates__/nextjs/scripts/start.sh +7 -1
  71. package/lib/__templates__/nextjs/src/app/globals.css +109 -89
  72. package/lib/__templates__/nextjs/src/app/layout.tsx +20 -33
  73. package/lib/__templates__/nextjs/src/app/page.tsx +18 -49
  74. package/lib/__templates__/nextjs/src/components/ui/resizable.tsx +29 -22
  75. package/lib/__templates__/nextjs/src/components/ui/sidebar.tsx +228 -230
  76. package/lib/__templates__/nextjs/src/server.ts +35 -0
  77. package/lib/__templates__/nextjs/template.config.js +68 -3
  78. package/lib/__templates__/nextjs/tsconfig.json +1 -1
  79. package/lib/__templates__/nuxt-vue/.coze +12 -0
  80. package/lib/__templates__/nuxt-vue/README.md +73 -0
  81. package/lib/__templates__/nuxt-vue/_gitignore +24 -0
  82. package/lib/__templates__/nuxt-vue/_npmrc +23 -0
  83. package/lib/__templates__/nuxt-vue/app/app.vue +6 -0
  84. package/lib/__templates__/nuxt-vue/app/pages/index.vue +23 -0
  85. package/lib/__templates__/nuxt-vue/assets/css/main.css +24 -0
  86. package/lib/__templates__/nuxt-vue/nuxt.config.ts +116 -0
  87. package/lib/__templates__/nuxt-vue/package.json +35 -0
  88. package/lib/__templates__/nuxt-vue/pnpm-lock.yaml +8759 -0
  89. package/lib/__templates__/nuxt-vue/postcss.config.mjs +8 -0
  90. package/lib/__templates__/nuxt-vue/public/favicon.ico +0 -0
  91. package/lib/__templates__/nuxt-vue/public/robots.txt +2 -0
  92. package/lib/__templates__/nuxt-vue/scripts/build.sh +14 -0
  93. package/lib/__templates__/nuxt-vue/scripts/dev.sh +39 -0
  94. package/lib/__templates__/nuxt-vue/scripts/prepare.sh +14 -0
  95. package/lib/__templates__/nuxt-vue/scripts/start.sh +21 -0
  96. package/lib/__templates__/nuxt-vue/server/api/hello.ts +10 -0
  97. package/lib/__templates__/nuxt-vue/server/middleware/logger.ts +10 -0
  98. package/lib/__templates__/nuxt-vue/server/routes/health.ts +10 -0
  99. package/lib/__templates__/nuxt-vue/tailwind.config.js +13 -0
  100. package/lib/__templates__/nuxt-vue/template.config.js +87 -0
  101. package/lib/__templates__/nuxt-vue/tsconfig.json +18 -0
  102. package/lib/__templates__/taro/.coze +14 -0
  103. package/lib/__templates__/taro/.cozeproj/scripts/deploy_build.sh +19 -0
  104. package/lib/__templates__/taro/.cozeproj/scripts/deploy_run.sh +14 -0
  105. package/lib/__templates__/taro/.cozeproj/scripts/dev_build.sh +2 -0
  106. package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +151 -0
  107. package/lib/__templates__/taro/.cozeproj/scripts/init_env.sh +5 -0
  108. package/lib/__templates__/taro/.cozeproj/scripts/pack.sh +24 -0
  109. package/lib/__templates__/taro/README.md +763 -0
  110. package/lib/__templates__/taro/_gitignore +40 -0
  111. package/lib/__templates__/taro/_npmrc +18 -0
  112. package/lib/__templates__/taro/babel.config.js +12 -0
  113. package/lib/__templates__/taro/config/dev.ts +9 -0
  114. package/lib/__templates__/taro/config/index.ts +238 -0
  115. package/lib/__templates__/taro/config/prod.ts +34 -0
  116. package/lib/__templates__/taro/eslint.config.mjs +135 -0
  117. package/lib/__templates__/taro/key/private.appid.key +0 -0
  118. package/lib/__templates__/taro/package.json +112 -0
  119. package/lib/__templates__/taro/patches/@tarojs__plugin-mini-ci@4.1.9.patch +30 -0
  120. package/lib/__templates__/taro/pnpm-lock.yaml +23412 -0
  121. package/lib/__templates__/taro/pnpm-workspace.yaml +2 -0
  122. package/lib/__templates__/taro/project.config.json +15 -0
  123. package/lib/__templates__/taro/server/nest-cli.json +10 -0
  124. package/lib/__templates__/taro/server/package.json +40 -0
  125. package/lib/__templates__/taro/server/src/app.controller.ts +23 -0
  126. package/lib/__templates__/taro/server/src/app.module.ts +10 -0
  127. package/lib/__templates__/taro/server/src/app.service.ts +8 -0
  128. package/lib/__templates__/taro/server/src/interceptors/http-status.interceptor.ts +23 -0
  129. package/lib/__templates__/taro/server/src/main.ts +49 -0
  130. package/lib/__templates__/taro/server/tsconfig.json +24 -0
  131. package/lib/__templates__/taro/src/app.config.ts +11 -0
  132. package/lib/__templates__/taro/src/app.css +156 -0
  133. package/lib/__templates__/taro/src/app.tsx +9 -0
  134. package/lib/__templates__/taro/src/components/ui/accordion.tsx +159 -0
  135. package/lib/__templates__/taro/src/components/ui/alert-dialog.tsx +260 -0
  136. package/lib/__templates__/taro/src/components/ui/alert.tsx +60 -0
  137. package/lib/__templates__/taro/src/components/ui/aspect-ratio.tsx +36 -0
  138. package/lib/__templates__/taro/src/components/ui/avatar.tsx +84 -0
  139. package/lib/__templates__/taro/src/components/ui/badge.tsx +37 -0
  140. package/lib/__templates__/taro/src/components/ui/breadcrumb.tsx +117 -0
  141. package/lib/__templates__/taro/src/components/ui/button-group.tsx +83 -0
  142. package/lib/__templates__/taro/src/components/ui/button.tsx +67 -0
  143. package/lib/__templates__/taro/src/components/ui/calendar.tsx +394 -0
  144. package/lib/__templates__/taro/src/components/ui/card.tsx +108 -0
  145. package/lib/__templates__/taro/src/components/ui/carousel.tsx +228 -0
  146. package/lib/__templates__/taro/src/components/ui/checkbox.tsx +58 -0
  147. package/lib/__templates__/taro/src/components/ui/code-block.tsx +169 -0
  148. package/lib/__templates__/taro/src/components/ui/collapsible.tsx +71 -0
  149. package/lib/__templates__/taro/src/components/ui/command.tsx +385 -0
  150. package/lib/__templates__/taro/src/components/ui/context-menu.tsx +614 -0
  151. package/lib/__templates__/taro/src/components/ui/dialog.tsx +256 -0
  152. package/lib/__templates__/taro/src/components/ui/drawer.tsx +192 -0
  153. package/lib/__templates__/taro/src/components/ui/dropdown-menu.tsx +561 -0
  154. package/lib/__templates__/taro/src/components/ui/field.tsx +228 -0
  155. package/lib/__templates__/taro/src/components/ui/hover-card.tsx +282 -0
  156. package/lib/__templates__/taro/src/components/ui/input-group.tsx +197 -0
  157. package/lib/__templates__/taro/src/components/ui/input-otp.tsx +136 -0
  158. package/lib/__templates__/taro/src/components/ui/input.tsx +56 -0
  159. package/lib/__templates__/taro/src/components/ui/label.tsx +24 -0
  160. package/lib/__templates__/taro/src/components/ui/menubar.tsx +595 -0
  161. package/lib/__templates__/taro/src/components/ui/navigation-menu.tsx +264 -0
  162. package/lib/__templates__/taro/src/components/ui/pagination.tsx +118 -0
  163. package/lib/__templates__/taro/src/components/ui/popover.tsx +291 -0
  164. package/lib/__templates__/taro/src/components/ui/portal.tsx +19 -0
  165. package/lib/__templates__/taro/src/components/ui/progress.tsx +28 -0
  166. package/lib/__templates__/taro/src/components/ui/radio-group.tsx +64 -0
  167. package/lib/__templates__/taro/src/components/ui/resizable.tsx +346 -0
  168. package/lib/__templates__/taro/src/components/ui/scroll-area.tsx +34 -0
  169. package/lib/__templates__/taro/src/components/ui/select.tsx +438 -0
  170. package/lib/__templates__/taro/src/components/ui/separator.tsx +30 -0
  171. package/lib/__templates__/taro/src/components/ui/sheet.tsx +262 -0
  172. package/lib/__templates__/taro/src/components/ui/skeleton.tsx +17 -0
  173. package/lib/__templates__/taro/src/components/ui/slider.tsx +203 -0
  174. package/lib/__templates__/taro/src/components/ui/sonner.tsx +1 -0
  175. package/lib/__templates__/taro/src/components/ui/switch.tsx +55 -0
  176. package/lib/__templates__/taro/src/components/ui/table.tsx +142 -0
  177. package/lib/__templates__/taro/src/components/ui/tabs.tsx +114 -0
  178. package/lib/__templates__/taro/src/components/ui/textarea.tsx +54 -0
  179. package/lib/__templates__/taro/src/components/ui/toast.tsx +517 -0
  180. package/lib/__templates__/taro/src/components/ui/toggle-group.tsx +120 -0
  181. package/lib/__templates__/taro/src/components/ui/toggle.tsx +77 -0
  182. package/lib/__templates__/taro/src/components/ui/tooltip.tsx +455 -0
  183. package/lib/__templates__/taro/src/index.html +39 -0
  184. package/lib/__templates__/taro/src/lib/hooks/use-keyboard-offset.ts +37 -0
  185. package/lib/__templates__/taro/src/lib/measure.ts +115 -0
  186. package/lib/__templates__/taro/src/lib/platform.ts +12 -0
  187. package/lib/__templates__/taro/src/lib/utils.ts +6 -0
  188. package/lib/__templates__/taro/src/network.ts +39 -0
  189. package/lib/__templates__/taro/src/pages/index/index.config.ts +3 -0
  190. package/lib/__templates__/taro/src/pages/index/index.css +1 -0
  191. package/lib/__templates__/taro/src/pages/index/index.tsx +33 -0
  192. package/lib/__templates__/taro/src/presets/dev-debug.ts +23 -0
  193. package/lib/__templates__/taro/src/presets/h5-container.tsx +15 -0
  194. package/lib/__templates__/taro/src/presets/h5-navbar.tsx +238 -0
  195. package/lib/__templates__/taro/src/presets/h5-styles.ts +220 -0
  196. package/lib/__templates__/taro/src/presets/index.tsx +18 -0
  197. package/lib/__templates__/taro/stylelint.config.mjs +4 -0
  198. package/lib/__templates__/taro/template.config.js +68 -0
  199. package/lib/__templates__/taro/tsconfig.json +29 -0
  200. package/lib/__templates__/taro/types/global.d.ts +32 -0
  201. package/lib/__templates__/templates.json +136 -36
  202. package/lib/__templates__/vite/.coze +4 -3
  203. package/lib/__templates__/vite/README.md +383 -26
  204. package/lib/__templates__/vite/_gitignore +1 -0
  205. package/lib/__templates__/vite/_npmrc +2 -1
  206. package/lib/__templates__/vite/eslint.config.mjs +14 -0
  207. package/lib/__templates__/vite/package.json +23 -3
  208. package/lib/__templates__/vite/pnpm-lock.yaml +2509 -293
  209. package/lib/__templates__/vite/scripts/build.sh +4 -1
  210. package/lib/__templates__/vite/scripts/dev.sh +16 -28
  211. package/lib/__templates__/vite/scripts/prepare.sh +9 -0
  212. package/lib/__templates__/vite/scripts/start.sh +9 -3
  213. package/lib/__templates__/vite/server/routes/index.ts +31 -0
  214. package/lib/__templates__/vite/server/server.ts +65 -0
  215. package/lib/__templates__/vite/server/vite.ts +67 -0
  216. package/lib/__templates__/vite/src/main.ts +17 -48
  217. package/lib/__templates__/vite/template.config.js +77 -7
  218. package/lib/__templates__/vite/tsconfig.json +4 -3
  219. package/lib/__templates__/vite/vite.config.ts +8 -3
  220. package/lib/cli.js +1545 -526
  221. package/package.json +17 -6
  222. package/lib/__templates__/expo/.cozeproj/scripts/deploy_build.sh +0 -109
  223. package/lib/__templates__/expo/.cozeproj/scripts/deploy_run.sh +0 -257
  224. package/lib/__templates__/expo/app.json +0 -63
  225. package/lib/__templates__/expo/babel.config.js +0 -9
  226. package/lib/__templates__/expo/client/app/(tabs)/_layout.tsx +0 -43
  227. package/lib/__templates__/expo/client/app/(tabs)/home.tsx +0 -1
  228. package/lib/__templates__/expo/client/app/(tabs)/index.tsx +0 -7
  229. package/lib/__templates__/expo/client/hooks/useColorScheme.ts +0 -1
  230. package/lib/__templates__/expo/client/index.js +0 -12
  231. package/lib/__templates__/expo/client/screens/home/index.tsx +0 -54
  232. package/lib/__templates__/expo/client/screens/home/styles.ts +0 -332
  233. package/lib/__templates__/expo/metro.config.js +0 -53
  234. package/lib/__templates__/expo/src/index.ts +0 -12
  235. package/lib/__templates__/nextjs/.vscode/settings.json +0 -121
  236. package/lib/__templates__/nextjs/server.mjs +0 -50
  237. package/lib/__templates__/vite/.vscode/settings.json +0 -7
  238. /package/lib/__templates__/expo/{eslint-formatter-simple.mjs → client/eslint-formatter-simple.mjs} +0 -0
@@ -0,0 +1,256 @@
1
+ import * as React from "react"
2
+ import { View } from "@tarojs/components"
3
+ import { X } from "lucide-react-taro"
4
+ import { cn } from "@/lib/utils"
5
+ import { Portal } from "@/components/ui/portal"
6
+ import { useKeyboardOffset } from "@/lib/hooks/use-keyboard-offset"
7
+
8
+ const DialogContext = React.createContext<{
9
+ open?: boolean
10
+ onOpenChange?: (open: boolean) => void
11
+ } | null>(null)
12
+
13
+ const usePresence = (open: boolean | undefined, durationMs: number) => {
14
+ const [present, setPresent] = React.useState(!!open)
15
+ const timeoutRef = React.useRef<ReturnType<typeof setTimeout> | null>(null)
16
+
17
+ React.useEffect(() => {
18
+ if (open) {
19
+ if (timeoutRef.current) clearTimeout(timeoutRef.current)
20
+ timeoutRef.current = null
21
+ setPresent(true)
22
+ return
23
+ }
24
+
25
+ timeoutRef.current = setTimeout(() => setPresent(false), durationMs)
26
+ return () => {
27
+ if (timeoutRef.current) clearTimeout(timeoutRef.current)
28
+ timeoutRef.current = null
29
+ }
30
+ }, [open, durationMs])
31
+
32
+ return present
33
+ }
34
+
35
+ interface DialogProps {
36
+ children: React.ReactNode
37
+ open?: boolean
38
+ defaultOpen?: boolean
39
+ onOpenChange?: (open: boolean) => void
40
+ modal?: boolean
41
+ }
42
+
43
+ const Dialog = ({ children, open: openProp, defaultOpen, onOpenChange }: DialogProps) => {
44
+ const [openState, setOpenState] = React.useState(defaultOpen || false)
45
+ const open = openProp !== undefined ? openProp : openState
46
+
47
+ const handleOpenChange = (newOpen: boolean) => {
48
+ if (openProp === undefined) {
49
+ setOpenState(newOpen)
50
+ }
51
+ onOpenChange?.(newOpen)
52
+ }
53
+
54
+ return (
55
+ <DialogContext.Provider value={{ open, onOpenChange: handleOpenChange }}>
56
+ {children}
57
+ </DialogContext.Provider>
58
+ )
59
+ }
60
+
61
+ const DialogTrigger = React.forwardRef<
62
+ React.ElementRef<typeof View>,
63
+ React.ComponentPropsWithoutRef<typeof View> & { asChild?: boolean }
64
+ >(({ className, children, asChild, ...props }, ref) => {
65
+ const context = React.useContext(DialogContext)
66
+ return (
67
+ <View
68
+ ref={ref}
69
+ className={cn("w-fit", className)}
70
+ onClick={(e) => {
71
+ e.stopPropagation()
72
+ context?.onOpenChange?.(true)
73
+ }}
74
+ {...props}
75
+ >
76
+ {children}
77
+ </View>
78
+ )
79
+ })
80
+ DialogTrigger.displayName = "DialogTrigger"
81
+
82
+ const DialogPortal = ({ children }: { children: React.ReactNode }) => {
83
+ const context = React.useContext(DialogContext)
84
+ const present = usePresence(context?.open, 200)
85
+ if (!present) return null
86
+
87
+ return <Portal>{children}</Portal>
88
+ }
89
+
90
+ const DialogOverlay = React.forwardRef<
91
+ React.ElementRef<typeof View>,
92
+ React.ComponentPropsWithoutRef<typeof View>
93
+ >(({ className, onClick, ...props }, ref) => {
94
+ const context = React.useContext(DialogContext)
95
+ const state = context?.open ? "open" : "closed"
96
+ return (
97
+ <View
98
+ ref={ref}
99
+ data-state={state}
100
+ className={cn(
101
+ "fixed inset-0 isolate z-50 bg-black bg-opacity-10 transition-opacity duration-100 supports-[backdrop-filter]:backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
102
+ className
103
+ )}
104
+ onClick={(e) => {
105
+ e.stopPropagation()
106
+ onClick?.(e)
107
+ context?.onOpenChange?.(false)
108
+ }}
109
+ {...props}
110
+ />
111
+ )
112
+ })
113
+ DialogOverlay.displayName = "DialogOverlay"
114
+
115
+ interface DialogContentProps extends React.ComponentPropsWithoutRef<typeof View> {
116
+ closeClassName?: string
117
+ }
118
+
119
+ const DialogContent = React.forwardRef<
120
+ React.ElementRef<typeof View>,
121
+ DialogContentProps
122
+ >(({ className, children, style, closeClassName, ...props }, ref) => {
123
+ const context = React.useContext(DialogContext)
124
+ const offset = useKeyboardOffset()
125
+ const state = context?.open ? "open" : "closed"
126
+
127
+ return (
128
+ <DialogPortal>
129
+ <View
130
+ className="fixed inset-0 z-50"
131
+ onClick={() => context?.onOpenChange?.(false)}
132
+ >
133
+ <DialogOverlay />
134
+ <View
135
+ ref={ref}
136
+ data-state={state}
137
+ className={cn(
138
+ "fixed left-[50%] top-[50%] z-50 grid w-[calc(100%-2rem)] max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] rounded-xl",
139
+ className
140
+ )}
141
+ style={{
142
+ ...(style as object),
143
+ top: offset > 0 ? `calc(50% - ${offset / 2}px)` : undefined
144
+ }}
145
+ onClick={(e) => e.stopPropagation()}
146
+ {...props}
147
+ >
148
+ {children}
149
+ <View
150
+ data-slot="dialog-close"
151
+ className={cn(
152
+ "absolute right-4 top-4 flex h-6 w-6 items-center justify-center rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",
153
+ closeClassName
154
+ )}
155
+ data-state={state}
156
+ onClick={(e) => {
157
+ e.stopPropagation()
158
+ context?.onOpenChange?.(false)
159
+ }}
160
+ >
161
+ <X size={16} />
162
+ <View className="sr-only">Close</View>
163
+ </View>
164
+ </View>
165
+ </View>
166
+ </DialogPortal>
167
+ )
168
+ })
169
+ DialogContent.displayName = "DialogContent"
170
+
171
+ const DialogHeader = ({
172
+ className,
173
+ ...props
174
+ }: React.ComponentPropsWithoutRef<typeof View>) => (
175
+ <View
176
+ className={cn(
177
+ "flex flex-col space-y-2 text-center sm:text-left",
178
+ className
179
+ )}
180
+ {...props}
181
+ />
182
+ )
183
+ DialogHeader.displayName = "DialogHeader"
184
+
185
+ const DialogFooter = ({
186
+ className,
187
+ ...props
188
+ }: React.ComponentPropsWithoutRef<typeof View>) => (
189
+ <View
190
+ className={cn(
191
+ "flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
192
+ className
193
+ )}
194
+ {...props}
195
+ />
196
+ )
197
+ DialogFooter.displayName = "DialogFooter"
198
+
199
+ const DialogTitle = React.forwardRef<
200
+ React.ElementRef<typeof View>,
201
+ React.ComponentPropsWithoutRef<typeof View>
202
+ >(({ className, ...props }, ref) => (
203
+ <View
204
+ ref={ref}
205
+ className={cn(
206
+ "text-lg font-semibold leading-none tracking-tight",
207
+ className
208
+ )}
209
+ {...props}
210
+ />
211
+ ))
212
+ DialogTitle.displayName = "DialogTitle"
213
+
214
+ const DialogDescription = React.forwardRef<
215
+ React.ElementRef<typeof View>,
216
+ React.ComponentPropsWithoutRef<typeof View>
217
+ >(({ className, ...props }, ref) => (
218
+ <View
219
+ ref={ref}
220
+ className={cn("text-sm text-muted-foreground", className)}
221
+ {...props}
222
+ />
223
+ ))
224
+ DialogDescription.displayName = "DialogDescription"
225
+
226
+ const DialogClose = React.forwardRef<
227
+ React.ElementRef<typeof View>,
228
+ React.ComponentPropsWithoutRef<typeof View>
229
+ >(({ className, ...props }, ref) => {
230
+ const context = React.useContext(DialogContext)
231
+ return (
232
+ <View
233
+ ref={ref}
234
+ className={className}
235
+ onClick={(e) => {
236
+ e.stopPropagation()
237
+ context?.onOpenChange?.(false)
238
+ }}
239
+ {...props}
240
+ />
241
+ )
242
+ })
243
+ DialogClose.displayName = "DialogClose"
244
+
245
+ export {
246
+ Dialog,
247
+ DialogPortal,
248
+ DialogOverlay,
249
+ DialogTrigger,
250
+ DialogClose,
251
+ DialogContent,
252
+ DialogHeader,
253
+ DialogFooter,
254
+ DialogTitle,
255
+ DialogDescription,
256
+ }
@@ -0,0 +1,192 @@
1
+ import * as React from "react"
2
+ import { View } from "@tarojs/components"
3
+ import { cn } from "@/lib/utils"
4
+ import { Portal } from "@/components/ui/portal"
5
+
6
+ const DrawerContext = React.createContext<{
7
+ open?: boolean
8
+ onOpenChange?: (open: boolean) => void
9
+ } | null>(null)
10
+
11
+ interface DrawerProps extends React.ComponentPropsWithoutRef<typeof View> {
12
+ shouldScaleBackground?: boolean
13
+ open?: boolean
14
+ defaultOpen?: boolean
15
+ onOpenChange?: (open: boolean) => void
16
+ }
17
+
18
+ const Drawer = ({
19
+ shouldScaleBackground = true,
20
+ children,
21
+ open: openProp,
22
+ defaultOpen,
23
+ onOpenChange,
24
+ ...props
25
+ }: DrawerProps) => {
26
+ const [openState, setOpenState] = React.useState(defaultOpen || false)
27
+ const open = openProp !== undefined ? openProp : openState
28
+
29
+ const handleOpenChange = (newOpen: boolean) => {
30
+ if (openProp === undefined) {
31
+ setOpenState(newOpen)
32
+ }
33
+ onOpenChange?.(newOpen)
34
+ }
35
+
36
+ return (
37
+ <DrawerContext.Provider value={{ open, onOpenChange: handleOpenChange }}>
38
+ <View {...props}>{children}</View>
39
+ </DrawerContext.Provider>
40
+ )
41
+ }
42
+ Drawer.displayName = "Drawer"
43
+
44
+ const DrawerTrigger = React.forwardRef<
45
+ React.ElementRef<typeof View>,
46
+ React.ComponentPropsWithoutRef<typeof View> & { asChild?: boolean }
47
+ >(({ className, children, asChild, ...props }, ref) => {
48
+ const context = React.useContext(DrawerContext)
49
+ return (
50
+ <View
51
+ ref={ref}
52
+ className={cn("w-fit", className)}
53
+ onClick={(e) => {
54
+ e.stopPropagation()
55
+ context?.onOpenChange?.(true)
56
+ }}
57
+ {...props}
58
+ >
59
+ {children}
60
+ </View>
61
+ )
62
+ })
63
+ DrawerTrigger.displayName = "DrawerTrigger"
64
+
65
+ const DrawerPortal = ({ children }: { children: React.ReactNode }) => {
66
+ const context = React.useContext(DrawerContext)
67
+ if (!context?.open) return null
68
+ return <Portal>{children}</Portal>
69
+ }
70
+
71
+ const DrawerClose = React.forwardRef<
72
+ React.ElementRef<typeof View>,
73
+ React.ComponentPropsWithoutRef<typeof View> & { asChild?: boolean }
74
+ >(({ className, children, asChild, ...props }, ref) => {
75
+ const context = React.useContext(DrawerContext)
76
+ return (
77
+ <View
78
+ ref={ref}
79
+ className={className}
80
+ onClick={(e) => {
81
+ e.stopPropagation()
82
+ context?.onOpenChange?.(false)
83
+ }}
84
+ {...props}
85
+ >
86
+ {children}
87
+ </View>
88
+ )
89
+ })
90
+ DrawerClose.displayName = "DrawerClose"
91
+
92
+ const DrawerOverlay = React.forwardRef<
93
+ React.ElementRef<typeof View>,
94
+ React.ComponentPropsWithoutRef<typeof View>
95
+ >(({ className, ...props }, ref) => {
96
+ const context = React.useContext(DrawerContext)
97
+ return (
98
+ <View
99
+ ref={ref}
100
+ className={cn(
101
+ "fixed inset-0 isolate z-50 bg-black bg-opacity-10 transition-opacity duration-100 supports-[backdrop-filter]:backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
102
+ className
103
+ )}
104
+ onClick={() => context?.onOpenChange?.(false)}
105
+ {...props}
106
+ />
107
+ )
108
+ })
109
+ DrawerOverlay.displayName = "DrawerOverlay"
110
+
111
+ const DrawerContent = React.forwardRef<
112
+ React.ElementRef<typeof View>,
113
+ React.ComponentPropsWithoutRef<typeof View>
114
+ >(({ className, children, ...props }, ref) => (
115
+ <DrawerPortal>
116
+ <DrawerOverlay />
117
+ <View
118
+ ref={ref}
119
+ className={cn(
120
+ "fixed inset-x-0 bottom-0 z-50 mt-24 flex h-auto flex-col rounded-t-[10px] border bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom duration-300",
121
+ className
122
+ )}
123
+ {...props}
124
+ >
125
+ <View className="mx-auto mt-4 h-2 w-[100px] rounded-full bg-muted" />
126
+ {children}
127
+ </View>
128
+ </DrawerPortal>
129
+ ))
130
+ DrawerContent.displayName = "DrawerContent"
131
+
132
+ const DrawerHeader = ({
133
+ className,
134
+ ...props
135
+ }: React.ComponentPropsWithoutRef<typeof View>) => (
136
+ <View
137
+ className={cn("grid gap-2 p-4 text-center sm:text-left", className)}
138
+ {...props}
139
+ />
140
+ )
141
+ DrawerHeader.displayName = "DrawerHeader"
142
+
143
+ const DrawerFooter = ({
144
+ className,
145
+ ...props
146
+ }: React.ComponentPropsWithoutRef<typeof View>) => (
147
+ <View
148
+ className={cn("mt-auto flex flex-col gap-2 p-4", className)}
149
+ {...props}
150
+ />
151
+ )
152
+ DrawerFooter.displayName = "DrawerFooter"
153
+
154
+ const DrawerTitle = React.forwardRef<
155
+ React.ElementRef<typeof View>,
156
+ React.ComponentPropsWithoutRef<typeof View>
157
+ >(({ className, ...props }, ref) => (
158
+ <View
159
+ ref={ref}
160
+ className={cn(
161
+ "text-lg font-semibold leading-none tracking-tight",
162
+ className
163
+ )}
164
+ {...props}
165
+ />
166
+ ))
167
+ DrawerTitle.displayName = "DrawerTitle"
168
+
169
+ const DrawerDescription = React.forwardRef<
170
+ React.ElementRef<typeof View>,
171
+ React.ComponentPropsWithoutRef<typeof View>
172
+ >(({ className, ...props }, ref) => (
173
+ <View
174
+ ref={ref}
175
+ className={cn("text-sm text-muted-foreground", className)}
176
+ {...props}
177
+ />
178
+ ))
179
+ DrawerDescription.displayName = "DrawerDescription"
180
+
181
+ export {
182
+ Drawer,
183
+ DrawerPortal,
184
+ DrawerOverlay,
185
+ DrawerTrigger,
186
+ DrawerClose,
187
+ DrawerContent,
188
+ DrawerHeader,
189
+ DrawerFooter,
190
+ DrawerTitle,
191
+ DrawerDescription,
192
+ }