@windrun-huaiin/base-ui 3.1.0

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 (123) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +190 -0
  3. package/dist/base-ui.css +3 -0
  4. package/dist/components/index.d.mts +144 -0
  5. package/dist/components/index.d.ts +144 -0
  6. package/dist/components/index.js +1699 -0
  7. package/dist/components/index.js.map +1 -0
  8. package/dist/components/index.mjs +1741 -0
  9. package/dist/components/index.mjs.map +1 -0
  10. package/dist/index.d.mts +47 -0
  11. package/dist/index.d.ts +47 -0
  12. package/dist/index.js +6055 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/index.mjs +5842 -0
  15. package/dist/index.mjs.map +1 -0
  16. package/dist/lib/index.d.mts +24 -0
  17. package/dist/lib/index.d.ts +24 -0
  18. package/dist/lib/index.js +1324 -0
  19. package/dist/lib/index.js.map +1 -0
  20. package/dist/lib/index.mjs +1372 -0
  21. package/dist/lib/index.mjs.map +1 -0
  22. package/dist/ui/index.d.mts +754 -0
  23. package/dist/ui/index.d.ts +754 -0
  24. package/dist/ui/index.js +5796 -0
  25. package/dist/ui/index.js.map +1 -0
  26. package/dist/ui/index.mjs +5593 -0
  27. package/dist/ui/index.mjs.map +1 -0
  28. package/package.json +120 -0
  29. package/src/assets/bitcoin.tsx +23 -0
  30. package/src/assets/clerk.tsx +23 -0
  31. package/src/assets/css.tsx +21 -0
  32. package/src/assets/csv.tsx +35 -0
  33. package/src/assets/d8.tsx +25 -0
  34. package/src/assets/diff.tsx +23 -0
  35. package/src/assets/dpa.tsx +22 -0
  36. package/src/assets/github.tsx +23 -0
  37. package/src/assets/html.tsx +22 -0
  38. package/src/assets/http.tsx +23 -0
  39. package/src/assets/index.ts +61 -0
  40. package/src/assets/iterm.tsx +23 -0
  41. package/src/assets/java.tsx +23 -0
  42. package/src/assets/json.tsx +23 -0
  43. package/src/assets/last-updated.tsx +23 -0
  44. package/src/assets/log.tsx +28 -0
  45. package/src/assets/mac.tsx +23 -0
  46. package/src/assets/markdown.tsx +24 -0
  47. package/src/assets/mdx.tsx +98 -0
  48. package/src/assets/mermaid.tsx +24 -0
  49. package/src/assets/scheme.tsx +22 -0
  50. package/src/assets/snippets.tsx +23 -0
  51. package/src/assets/sql.tsx +31 -0
  52. package/src/assets/subp.tsx +22 -0
  53. package/src/assets/t3p.tsx +23 -0
  54. package/src/assets/test.tsx +23 -0
  55. package/src/assets/txt.tsx +23 -0
  56. package/src/assets/xml.tsx +23 -0
  57. package/src/assets/yaml.tsx +23 -0
  58. package/src/components/404-page.tsx +106 -0
  59. package/src/components/global-icon.tsx +193 -0
  60. package/src/components/go-to-top.tsx +43 -0
  61. package/src/components/index.ts +10 -0
  62. package/src/components/language-detector.tsx +175 -0
  63. package/src/components/language-switcher.tsx +77 -0
  64. package/src/components/script/google-analytics-script.tsx +56 -0
  65. package/src/components/script/microsoft-clarity-script.tsx +24 -0
  66. package/src/index.ts +4 -0
  67. package/src/lib/icon-context.tsx +57 -0
  68. package/src/lib/index.ts +3 -0
  69. package/src/lib/site-icon.tsx +46 -0
  70. package/src/lib/theme-util.ts +7 -0
  71. package/src/styles/base-ui.css +2 -0
  72. package/src/ui/accordion.tsx +58 -0
  73. package/src/ui/alert-dialog.tsx +141 -0
  74. package/src/ui/alert.tsx +59 -0
  75. package/src/ui/aspect-ratio.tsx +7 -0
  76. package/src/ui/avatar.tsx +50 -0
  77. package/src/ui/badge.tsx +36 -0
  78. package/src/ui/breadcrumb.tsx +115 -0
  79. package/src/ui/button.tsx +76 -0
  80. package/src/ui/calendar.tsx +66 -0
  81. package/src/ui/card.tsx +79 -0
  82. package/src/ui/carousel.tsx +262 -0
  83. package/src/ui/chart.tsx +365 -0
  84. package/src/ui/checkbox.tsx +30 -0
  85. package/src/ui/collapsible.tsx +11 -0
  86. package/src/ui/command.tsx +153 -0
  87. package/src/ui/context-menu.tsx +200 -0
  88. package/src/ui/dialog.tsx +122 -0
  89. package/src/ui/drawer.tsx +118 -0
  90. package/src/ui/dropdown-menu.tsx +200 -0
  91. package/src/ui/form.tsx +178 -0
  92. package/src/ui/hover-card.tsx +29 -0
  93. package/src/ui/index.ts +52 -0
  94. package/src/ui/input-otp.tsx +71 -0
  95. package/src/ui/input.tsx +22 -0
  96. package/src/ui/label.tsx +26 -0
  97. package/src/ui/language-button.tsx +43 -0
  98. package/src/ui/menubar.tsx +236 -0
  99. package/src/ui/navigation-menu.tsx +128 -0
  100. package/src/ui/pagination.tsx +117 -0
  101. package/src/ui/popover.tsx +31 -0
  102. package/src/ui/progress.tsx +28 -0
  103. package/src/ui/radio-group.tsx +44 -0
  104. package/src/ui/resizable.tsx +45 -0
  105. package/src/ui/scroll-area.tsx +48 -0
  106. package/src/ui/select.tsx +160 -0
  107. package/src/ui/separator.tsx +31 -0
  108. package/src/ui/sheet.tsx +140 -0
  109. package/src/ui/sidebar.tsx +763 -0
  110. package/src/ui/skeleton.tsx +15 -0
  111. package/src/ui/slider.tsx +28 -0
  112. package/src/ui/sonner.tsx +31 -0
  113. package/src/ui/switch.tsx +29 -0
  114. package/src/ui/table.tsx +117 -0
  115. package/src/ui/tabs.tsx +55 -0
  116. package/src/ui/textarea.tsx +22 -0
  117. package/src/ui/toast.tsx +129 -0
  118. package/src/ui/toaster.tsx +35 -0
  119. package/src/ui/toggle-group.tsx +61 -0
  120. package/src/ui/toggle.tsx +45 -0
  121. package/src/ui/tooltip.tsx +30 -0
  122. package/src/ui/use-mobile.tsx +19 -0
  123. package/src/ui/use-toast.ts +194 -0
@@ -0,0 +1,194 @@
1
+ "use client"
2
+
3
+ // Inspired by react-hot-toast library
4
+ import * as React from "react"
5
+
6
+ import type {
7
+ ToastActionElement,
8
+ ToastProps,
9
+ } from "@base-ui/ui/toast"
10
+
11
+ const TOAST_LIMIT = 1
12
+ const TOAST_REMOVE_DELAY = 1000000
13
+
14
+ type ToasterToast = ToastProps & {
15
+ id: string
16
+ title?: React.ReactNode
17
+ description?: React.ReactNode
18
+ action?: ToastActionElement
19
+ }
20
+
21
+ const ACTIONS = {
22
+ ADD_TOAST: "ADD_TOAST",
23
+ UPDATE_TOAST: "UPDATE_TOAST",
24
+ DISMISS_TOAST: "DISMISS_TOAST",
25
+ REMOVE_TOAST: "REMOVE_TOAST",
26
+ } as const
27
+
28
+ // 删除未使用的 ActionType 类型定义
29
+ type Action =
30
+ | {
31
+ type: typeof ACTIONS.ADD_TOAST
32
+ toast: ToasterToast
33
+ }
34
+ | {
35
+ type: typeof ACTIONS.UPDATE_TOAST
36
+ toast: Partial<ToasterToast>
37
+ }
38
+ | {
39
+ type: typeof ACTIONS.DISMISS_TOAST
40
+ toastId?: ToasterToast["id"]
41
+ }
42
+ | {
43
+ type: typeof ACTIONS.REMOVE_TOAST
44
+ toastId?: ToasterToast["id"]
45
+ }
46
+
47
+ let count = 0
48
+
49
+ function genId() {
50
+ count = (count + 1) % Number.MAX_SAFE_INTEGER
51
+ return count.toString()
52
+ }
53
+
54
+
55
+ interface State {
56
+ toasts: ToasterToast[]
57
+ }
58
+
59
+ const toastTimeouts = new Map<string, ReturnType<typeof setTimeout>>()
60
+
61
+ const addToRemoveQueue = (toastId: string) => {
62
+ if (toastTimeouts.has(toastId)) {
63
+ return
64
+ }
65
+
66
+ const timeout = setTimeout(() => {
67
+ toastTimeouts.delete(toastId)
68
+ dispatch({
69
+ type: ACTIONS.REMOVE_TOAST,
70
+ toastId: toastId,
71
+ })
72
+ }, TOAST_REMOVE_DELAY)
73
+
74
+ toastTimeouts.set(toastId, timeout)
75
+ }
76
+
77
+ export const reducer = (state: State, action: Action): State => {
78
+ switch (action.type) {
79
+ case "ADD_TOAST":
80
+ return {
81
+ ...state,
82
+ toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT),
83
+ }
84
+
85
+ case "UPDATE_TOAST":
86
+ return {
87
+ ...state,
88
+ toasts: state.toasts.map((t) =>
89
+ t.id === action.toast.id ? { ...t, ...action.toast } : t
90
+ ),
91
+ }
92
+
93
+ case "DISMISS_TOAST": {
94
+ const { toastId } = action
95
+
96
+ // ! Side effects ! - This could be extracted into a dismissToast() action,
97
+ // but I'll keep it here for simplicity
98
+ if (toastId) {
99
+ addToRemoveQueue(toastId)
100
+ } else {
101
+ state.toasts.forEach((toast) => {
102
+ addToRemoveQueue(toast.id)
103
+ })
104
+ }
105
+
106
+ return {
107
+ ...state,
108
+ toasts: state.toasts.map((t) =>
109
+ t.id === toastId || toastId === undefined
110
+ ? {
111
+ ...t,
112
+ open: false,
113
+ }
114
+ : t
115
+ ),
116
+ }
117
+ }
118
+ case "REMOVE_TOAST":
119
+ if (action.toastId === undefined) {
120
+ return {
121
+ ...state,
122
+ toasts: [],
123
+ }
124
+ }
125
+ return {
126
+ ...state,
127
+ toasts: state.toasts.filter((t) => t.id !== action.toastId),
128
+ }
129
+ }
130
+ }
131
+
132
+ const listeners: Array<(state: State) => void> = []
133
+
134
+ let memoryState: State = { toasts: [] }
135
+
136
+ function dispatch(action: Action) {
137
+ memoryState = reducer(memoryState, action)
138
+ listeners.forEach((listener) => {
139
+ listener(memoryState)
140
+ })
141
+ }
142
+
143
+ type Toast = Omit<ToasterToast, "id">
144
+
145
+ function toast({ ...props }: Toast) {
146
+ const id = genId()
147
+
148
+ const update = (props: ToasterToast) =>
149
+ dispatch({
150
+ type: "UPDATE_TOAST",
151
+ toast: { ...props, id },
152
+ })
153
+ const dismiss = () => dispatch({ type: "DISMISS_TOAST", toastId: id })
154
+
155
+ dispatch({
156
+ type: "ADD_TOAST",
157
+ toast: {
158
+ ...props,
159
+ id,
160
+ open: true,
161
+ onOpenChange: (open) => {
162
+ if (!open) dismiss()
163
+ },
164
+ },
165
+ })
166
+
167
+ return {
168
+ id: id,
169
+ dismiss,
170
+ update,
171
+ }
172
+ }
173
+
174
+ function useToast() {
175
+ const [state, setState] = React.useState<State>(memoryState)
176
+
177
+ React.useEffect(() => {
178
+ listeners.push(setState)
179
+ return () => {
180
+ const index = listeners.indexOf(setState)
181
+ if (index > -1) {
182
+ listeners.splice(index, 1)
183
+ }
184
+ }
185
+ }, [state])
186
+
187
+ return {
188
+ ...state,
189
+ toast,
190
+ dismiss: (toastId?: string) => dispatch({ type: "DISMISS_TOAST", toastId }),
191
+ }
192
+ }
193
+
194
+ export { useToast, toast }