@remix-run/ui 0.1.2 → 0.3.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 (318) hide show
  1. package/README.md +9 -7
  2. package/dist/animation/demos/animation.demo.d.ts +5 -0
  3. package/dist/animation/demos/animation.demo.js +92 -0
  4. package/dist/animation/demos/animation.demo.js.map +1 -0
  5. package/dist/animation/demos/aspect-ratio.d.ts +2 -0
  6. package/dist/animation/demos/aspect-ratio.js +69 -0
  7. package/dist/animation/demos/aspect-ratio.js.map +1 -0
  8. package/dist/animation/demos/bouncy-switch.d.ts +2 -0
  9. package/dist/animation/demos/bouncy-switch.js +36 -0
  10. package/dist/animation/demos/bouncy-switch.js.map +1 -0
  11. package/dist/animation/demos/color-interpolation.d.ts +1 -0
  12. package/dist/animation/demos/color-interpolation.js +53 -0
  13. package/dist/animation/demos/color-interpolation.js.map +1 -0
  14. package/dist/animation/demos/cube.d.ts +2 -0
  15. package/dist/animation/demos/cube.js +86 -0
  16. package/dist/animation/demos/cube.js.map +1 -0
  17. package/dist/animation/demos/default-animate.d.ts +2 -0
  18. package/dist/animation/demos/default-animate.js +89 -0
  19. package/dist/animation/demos/default-animate.js.map +1 -0
  20. package/dist/animation/demos/drag-release.d.ts +24 -0
  21. package/dist/animation/demos/drag-release.js +96 -0
  22. package/dist/animation/demos/drag-release.js.map +1 -0
  23. package/dist/animation/demos/enter.d.ts +1 -0
  24. package/dist/animation/demos/enter.js +19 -0
  25. package/dist/animation/demos/enter.js.map +1 -0
  26. package/dist/animation/demos/exit.d.ts +2 -0
  27. package/dist/animation/demos/exit.js +58 -0
  28. package/dist/animation/demos/exit.js.map +1 -0
  29. package/dist/animation/demos/flip-toggle.d.ts +2 -0
  30. package/dist/animation/demos/flip-toggle.js +37 -0
  31. package/dist/animation/demos/flip-toggle.js.map +1 -0
  32. package/dist/animation/demos/hold-to-confirm.d.ts +13 -0
  33. package/dist/animation/demos/hold-to-confirm.js +211 -0
  34. package/dist/animation/demos/hold-to-confirm.js.map +1 -0
  35. package/dist/animation/demos/html-content.d.ts +2 -0
  36. package/dist/animation/demos/html-content.js +30 -0
  37. package/dist/animation/demos/html-content.js.map +1 -0
  38. package/dist/animation/demos/interruptible-keyframes.d.ts +1 -0
  39. package/dist/animation/demos/interruptible-keyframes.js +48 -0
  40. package/dist/animation/demos/interruptible-keyframes.js.map +1 -0
  41. package/dist/animation/demos/keyframes.d.ts +1 -0
  42. package/dist/animation/demos/keyframes.js +24 -0
  43. package/dist/animation/demos/keyframes.js.map +1 -0
  44. package/dist/animation/demos/material-ripple.d.ts +2 -0
  45. package/dist/animation/demos/material-ripple.js +127 -0
  46. package/dist/animation/demos/material-ripple.js.map +1 -0
  47. package/dist/animation/demos/mixin-presence-list.d.ts +2 -0
  48. package/dist/animation/demos/mixin-presence-list.js +88 -0
  49. package/dist/animation/demos/mixin-presence-list.js.map +1 -0
  50. package/dist/animation/demos/mixin-reclaim.d.ts +2 -0
  51. package/dist/animation/demos/mixin-reclaim.js +90 -0
  52. package/dist/animation/demos/mixin-reclaim.js.map +1 -0
  53. package/dist/animation/demos/multi-state-badge.d.ts +2 -0
  54. package/dist/animation/demos/multi-state-badge.js +231 -0
  55. package/dist/animation/demos/multi-state-badge.js.map +1 -0
  56. package/dist/animation/demos/press.d.ts +2 -0
  57. package/dist/animation/demos/press.js +63 -0
  58. package/dist/animation/demos/press.js.map +1 -0
  59. package/dist/animation/demos/reordering.d.ts +2 -0
  60. package/dist/animation/demos/reordering.js +50 -0
  61. package/dist/animation/demos/reordering.js.map +1 -0
  62. package/dist/animation/demos/rolling-square.d.ts +2 -0
  63. package/dist/animation/demos/rolling-square.js +42 -0
  64. package/dist/animation/demos/rolling-square.js.map +1 -0
  65. package/dist/animation/demos/rotate.d.ts +1 -0
  66. package/dist/animation/demos/rotate.js +18 -0
  67. package/dist/animation/demos/rotate.js.map +1 -0
  68. package/dist/animation/demos/shared-layout.d.ts +2 -0
  69. package/dist/animation/demos/shared-layout.js +114 -0
  70. package/dist/animation/demos/shared-layout.js.map +1 -0
  71. package/dist/animation/demos/spring.demo.d.ts +6 -0
  72. package/dist/animation/demos/spring.demo.js +304 -0
  73. package/dist/animation/demos/spring.demo.js.map +1 -0
  74. package/dist/animation/demos/transition-options.d.ts +1 -0
  75. package/dist/animation/demos/transition-options.js +21 -0
  76. package/dist/animation/demos/transition-options.js.map +1 -0
  77. package/dist/animation/spring.d.ts +24 -31
  78. package/dist/animation/spring.js +31 -8
  79. package/dist/animation/spring.js.map +1 -1
  80. package/dist/components/accordion/accordion.d.ts +6 -6
  81. package/dist/components/accordion/accordion.js.map +1 -1
  82. package/dist/components/accordion/demos/card.demo.d.ts +1 -0
  83. package/dist/components/accordion/demos/card.demo.js +1 -0
  84. package/dist/components/accordion/demos/card.demo.js.map +1 -1
  85. package/dist/components/accordion/demos/multiple.demo.d.ts +1 -0
  86. package/dist/components/accordion/demos/multiple.demo.js +1 -0
  87. package/dist/components/accordion/demos/multiple.demo.js.map +1 -1
  88. package/dist/components/accordion/demos/overview.demo.d.ts +1 -0
  89. package/dist/components/accordion/demos/overview.demo.js +1 -0
  90. package/dist/components/accordion/demos/overview.demo.js.map +1 -1
  91. package/dist/components/anchor/anchor.d.ts +8 -1
  92. package/dist/components/anchor/anchor.js +30 -11
  93. package/dist/components/anchor/anchor.js.map +1 -1
  94. package/dist/components/breadcrumbs/{demos/basic.demo.d.ts → basic.demo.d.ts} +1 -0
  95. package/dist/components/breadcrumbs/{demos/basic.demo.js → basic.demo.js} +1 -0
  96. package/dist/components/breadcrumbs/basic.demo.js.map +1 -0
  97. package/dist/components/breadcrumbs/breadcrumbs.d.ts +1 -1
  98. package/dist/components/breadcrumbs/{demos/separator.demo.d.ts → separator.demo.d.ts} +1 -0
  99. package/dist/components/breadcrumbs/{demos/separator.demo.js → separator.demo.js} +1 -0
  100. package/dist/components/breadcrumbs/separator.demo.js.map +1 -0
  101. package/dist/components/button/button.d.ts +4 -4
  102. package/dist/components/button/button.js +3 -1
  103. package/dist/components/button/button.js.map +1 -1
  104. package/dist/components/button/demos/aliases.demo.d.ts +1 -0
  105. package/dist/components/button/demos/aliases.demo.js +1 -0
  106. package/dist/components/button/demos/aliases.demo.js.map +1 -1
  107. package/dist/components/button/demos/basic.demo.d.ts +1 -0
  108. package/dist/components/button/demos/basic.demo.js +1 -0
  109. package/dist/components/button/demos/basic.demo.js.map +1 -1
  110. package/dist/components/button/demos/states.demo.d.ts +1 -0
  111. package/dist/components/button/demos/states.demo.js +1 -0
  112. package/dist/components/button/demos/states.demo.js.map +1 -1
  113. package/dist/components/combobox/combobox.d.ts +10 -10
  114. package/dist/components/combobox/combobox.js.map +1 -1
  115. package/dist/components/combobox/{demos/overview.demo.d.ts → overview.demo.d.ts} +1 -0
  116. package/dist/components/combobox/{demos/overview.demo.js → overview.demo.js} +1 -0
  117. package/dist/components/combobox/overview.demo.js.map +1 -0
  118. package/dist/components/listbox/listbox.d.ts +3 -3
  119. package/dist/components/listbox/listbox.js.map +1 -1
  120. package/dist/components/listbox/{demos/overview.demo.d.ts → overview.demo.d.ts} +1 -0
  121. package/dist/components/listbox/{demos/overview.demo.js → overview.demo.js} +1 -0
  122. package/dist/components/listbox/overview.demo.js.map +1 -0
  123. package/dist/components/menu/demos/bubbling.demo.d.ts +1 -0
  124. package/dist/components/menu/demos/bubbling.demo.js +1 -0
  125. package/dist/components/menu/demos/bubbling.demo.js.map +1 -1
  126. package/dist/components/menu/demos/context-trigger.demo.d.ts +7 -0
  127. package/dist/components/menu/demos/context-trigger.demo.js +87 -0
  128. package/dist/components/menu/demos/context-trigger.demo.js.map +1 -0
  129. package/dist/components/menu/demos/overview.demo.d.ts +1 -0
  130. package/dist/components/menu/demos/overview.demo.js +1 -0
  131. package/dist/components/menu/demos/overview.demo.js.map +1 -1
  132. package/dist/components/menu/menu.d.ts +15 -12
  133. package/dist/components/menu/menu.js +55 -0
  134. package/dist/components/menu/menu.js.map +1 -1
  135. package/dist/components/popover/{demos/overview.demo.d.ts → overview.demo.d.ts} +1 -0
  136. package/dist/components/popover/{demos/overview.demo.js → overview.demo.js} +1 -0
  137. package/dist/components/popover/overview.demo.js.map +1 -0
  138. package/dist/components/popover/popover.d.ts +7 -7
  139. package/dist/components/popover/popover.js +11 -4
  140. package/dist/components/popover/popover.js.map +1 -1
  141. package/dist/components/select/{demos/deconstructed.demo.d.ts → deconstructed.demo.d.ts} +1 -0
  142. package/dist/components/select/{demos/deconstructed.demo.js → deconstructed.demo.js} +1 -0
  143. package/dist/components/select/deconstructed.demo.js.map +1 -0
  144. package/dist/components/select/{demos/overview.demo.d.ts → overview.demo.d.ts} +1 -0
  145. package/dist/components/select/{demos/overview.demo.js → overview.demo.js} +1 -0
  146. package/dist/components/select/overview.demo.js.map +1 -0
  147. package/dist/components/select/select.d.ts +10 -10
  148. package/dist/components/select/select.js +1 -1
  149. package/dist/components/select/select.js.map +1 -1
  150. package/dist/components/tabs/tabs.d.ts +3 -3
  151. package/dist/index.d.ts +1 -1
  152. package/dist/index.js.map +1 -1
  153. package/dist/interactions/keydown/keydown.d.ts +1 -1
  154. package/dist/interactions/outside-click/outside-click-mixin.d.ts +2 -1
  155. package/dist/interactions/typeahead/typeahead-mixin.d.ts +3 -1
  156. package/dist/runtime/client-entries.d.ts +1 -2
  157. package/dist/runtime/client-entries.js.map +1 -1
  158. package/dist/runtime/component.d.ts +20 -17
  159. package/dist/runtime/component.js +15 -6
  160. package/dist/runtime/component.js.map +1 -1
  161. package/dist/runtime/core/attributes.d.ts +3 -1
  162. package/dist/runtime/core/attributes.js +19 -1
  163. package/dist/runtime/core/attributes.js.map +1 -1
  164. package/dist/runtime/core/props.js +6 -5
  165. package/dist/runtime/core/props.js.map +1 -1
  166. package/dist/runtime/demos/basic.demo.d.ts +6 -0
  167. package/dist/runtime/demos/basic.demo.js +16 -0
  168. package/dist/runtime/demos/basic.demo.js.map +1 -0
  169. package/dist/runtime/demos/controlled-uncontrolled-values.demo.d.ts +6 -0
  170. package/dist/runtime/demos/controlled-uncontrolled-values.demo.js +77 -0
  171. package/dist/runtime/demos/controlled-uncontrolled-values.demo.js.map +1 -0
  172. package/dist/runtime/demos/keyed-list.demo.d.ts +6 -0
  173. package/dist/runtime/demos/keyed-list.demo.js +62 -0
  174. package/dist/runtime/demos/keyed-list.demo.js.map +1 -0
  175. package/dist/runtime/demos/readme.demo.d.ts +5 -0
  176. package/dist/runtime/demos/readme.demo.js +396 -0
  177. package/dist/runtime/demos/readme.demo.js.map +1 -0
  178. package/dist/runtime/diff-dom.js +194 -21
  179. package/dist/runtime/diff-dom.js.map +1 -1
  180. package/dist/runtime/dom.d.ts +16 -9
  181. package/dist/runtime/frame.d.ts +7 -0
  182. package/dist/runtime/frame.js +176 -41
  183. package/dist/runtime/frame.js.map +1 -1
  184. package/dist/runtime/jsx.d.ts +3 -4
  185. package/dist/runtime/jsx.js.map +1 -1
  186. package/dist/runtime/mixins/link-mixin.d.ts +5 -1
  187. package/dist/runtime/mixins/link-mixin.js.map +1 -1
  188. package/dist/runtime/mixins/mixin.d.ts +2 -1
  189. package/dist/runtime/mixins/mixin.js.map +1 -1
  190. package/dist/runtime/mixins/ref-mixin.d.ts +2 -1
  191. package/dist/runtime/mixins/ref-mixin.js.map +1 -1
  192. package/dist/runtime/reconcile.d.ts +1 -1
  193. package/dist/runtime/reconcile.js +19 -5
  194. package/dist/runtime/reconcile.js.map +1 -1
  195. package/dist/runtime/scheduler.d.ts +10 -10
  196. package/dist/runtime/scheduler.js +1 -1
  197. package/dist/runtime/scheduler.js.map +1 -1
  198. package/dist/runtime/svg-attributes.js +1 -0
  199. package/dist/runtime/svg-attributes.js.map +1 -1
  200. package/dist/runtime/to-vnode.js +2 -2
  201. package/dist/runtime/to-vnode.js.map +1 -1
  202. package/dist/runtime/vnode.d.ts +6 -1
  203. package/dist/runtime/vnode.js +4 -0
  204. package/dist/runtime/vnode.js.map +1 -1
  205. package/dist/server/stream.d.ts +2 -0
  206. package/dist/server/stream.js +82 -11
  207. package/dist/server/stream.js.map +1 -1
  208. package/dist/style/css-mixin.d.ts +2 -1
  209. package/dist/style/css-mixin.js.map +1 -1
  210. package/dist/style/index.d.ts +1 -1
  211. package/dist/style/style.js +27 -10
  212. package/dist/style/style.js.map +1 -1
  213. package/dist/style/stylesheet.d.ts +13 -13
  214. package/dist/style/stylesheet.js.map +1 -1
  215. package/dist/theme/contract.d.ts +24 -222
  216. package/dist/theme/contract.js +2 -2
  217. package/dist/theme/contract.js.map +1 -1
  218. package/dist/theme/glyph-contract.d.ts +1 -3
  219. package/dist/theme/glyph-contract.js.map +1 -1
  220. package/dist/theme/presets/rmx-01/index.d.ts +4 -2
  221. package/dist/theme/presets/rmx-01/index.js.map +1 -1
  222. package/dist/utils/scroll-lock.d.ts +3 -3
  223. package/dist/utils/scroll-lock.js.map +1 -1
  224. package/package.json +4 -4
  225. package/src/animation/README.md +7 -5
  226. package/src/animation/demos/animation.demo.tsx +194 -0
  227. package/src/animation/demos/aspect-ratio.tsx +120 -0
  228. package/src/animation/demos/bouncy-switch.tsx +47 -0
  229. package/src/animation/demos/color-interpolation.tsx +73 -0
  230. package/src/animation/demos/cube.tsx +116 -0
  231. package/src/animation/demos/default-animate.tsx +129 -0
  232. package/src/animation/demos/drag-release.ts +118 -0
  233. package/src/animation/demos/enter.tsx +22 -0
  234. package/src/animation/demos/exit.tsx +79 -0
  235. package/src/animation/demos/flip-toggle.tsx +46 -0
  236. package/src/animation/demos/hold-to-confirm.tsx +317 -0
  237. package/src/animation/demos/html-content.tsx +41 -0
  238. package/src/animation/demos/interruptible-keyframes.tsx +62 -0
  239. package/src/animation/demos/keyframes.tsx +29 -0
  240. package/src/animation/demos/material-ripple.tsx +158 -0
  241. package/src/animation/demos/mixin-presence-list.tsx +121 -0
  242. package/src/animation/demos/mixin-reclaim.tsx +125 -0
  243. package/src/animation/demos/multi-state-badge.tsx +426 -0
  244. package/src/animation/demos/press.tsx +67 -0
  245. package/src/animation/demos/reordering.tsx +65 -0
  246. package/src/animation/demos/rolling-square.tsx +57 -0
  247. package/src/animation/demos/rotate.tsx +21 -0
  248. package/src/animation/demos/shared-layout.tsx +211 -0
  249. package/src/animation/demos/spring.demo.tsx +385 -0
  250. package/src/animation/demos/transition-options.tsx +24 -0
  251. package/src/animation/spring.ts +43 -9
  252. package/src/components/accordion/accordion.tsx +7 -5
  253. package/src/components/accordion/demos/card.demo.tsx +1 -0
  254. package/src/components/accordion/demos/multiple.demo.tsx +1 -0
  255. package/src/components/accordion/demos/overview.demo.tsx +1 -0
  256. package/src/components/anchor/README.md +11 -3
  257. package/src/components/anchor/anchor.ts +54 -13
  258. package/src/components/breadcrumbs/{demos/basic.demo.tsx → basic.demo.tsx} +1 -0
  259. package/src/components/breadcrumbs/breadcrumbs.tsx +1 -1
  260. package/src/components/breadcrumbs/{demos/separator.demo.tsx → separator.demo.tsx} +1 -0
  261. package/src/components/button/button.tsx +30 -18
  262. package/src/components/button/demos/aliases.demo.tsx +1 -0
  263. package/src/components/button/demos/basic.demo.tsx +1 -0
  264. package/src/components/button/demos/states.demo.tsx +1 -0
  265. package/src/components/combobox/README.md +1 -1
  266. package/src/components/combobox/combobox.tsx +30 -12
  267. package/src/components/combobox/{demos/overview.demo.tsx → overview.demo.tsx} +1 -0
  268. package/src/components/glyph/glyph.tsx +2 -2
  269. package/src/components/listbox/listbox.ts +88 -83
  270. package/src/components/listbox/{demos/overview.demo.tsx → overview.demo.tsx} +1 -0
  271. package/src/components/menu/README.md +26 -2
  272. package/src/components/menu/demos/bubbling.demo.tsx +1 -0
  273. package/src/components/menu/demos/context-trigger.demo.tsx +133 -0
  274. package/src/components/menu/demos/overview.demo.tsx +1 -0
  275. package/src/components/menu/menu.tsx +100 -16
  276. package/src/components/popover/{demos/overview.demo.tsx → overview.demo.tsx} +1 -0
  277. package/src/components/popover/popover.ts +101 -81
  278. package/src/components/select/{demos/deconstructed.demo.tsx → deconstructed.demo.tsx} +1 -0
  279. package/src/components/select/{demos/overview.demo.tsx → overview.demo.tsx} +1 -0
  280. package/src/components/select/select.tsx +27 -10
  281. package/src/index.ts +1 -0
  282. package/src/runtime/client-entries.ts +1 -5
  283. package/src/runtime/component.ts +37 -15
  284. package/src/runtime/core/attributes.ts +21 -0
  285. package/src/runtime/core/props.ts +6 -4
  286. package/src/runtime/demos/basic.demo.tsx +21 -0
  287. package/src/runtime/demos/controlled-uncontrolled-values.demo.tsx +177 -0
  288. package/src/runtime/demos/keyed-list.demo.tsx +94 -0
  289. package/src/runtime/demos/readme.demo.tsx +702 -0
  290. package/src/runtime/diff-dom.ts +270 -20
  291. package/src/runtime/dom.ts +16 -9
  292. package/src/runtime/frame.ts +218 -41
  293. package/src/runtime/jsx.ts +7 -11
  294. package/src/runtime/mixins/link-mixin.ts +88 -86
  295. package/src/runtime/mixins/mixin.ts +9 -1
  296. package/src/runtime/mixins/ref-mixin.ts +4 -5
  297. package/src/runtime/reconcile.ts +23 -14
  298. package/src/runtime/scheduler.ts +20 -20
  299. package/src/runtime/svg-attributes.ts +1 -0
  300. package/src/runtime/to-vnode.ts +2 -2
  301. package/src/runtime/vnode.ts +10 -0
  302. package/src/server/README.md +4 -2
  303. package/src/server/stream.ts +84 -10
  304. package/src/style/css-mixin.ts +6 -1
  305. package/src/style/index.ts +1 -2
  306. package/src/style/style.ts +29 -10
  307. package/src/style/stylesheet.ts +14 -2
  308. package/src/theme/contract.ts +37 -5
  309. package/src/theme/glyph-contract.ts +3 -1
  310. package/src/theme/presets/rmx-01/index.ts +4 -2
  311. package/src/utils/scroll-lock.ts +7 -3
  312. package/dist/components/breadcrumbs/demos/basic.demo.js.map +0 -1
  313. package/dist/components/breadcrumbs/demos/separator.demo.js.map +0 -1
  314. package/dist/components/combobox/demos/overview.demo.js.map +0 -1
  315. package/dist/components/listbox/demos/overview.demo.js.map +0 -1
  316. package/dist/components/popover/demos/overview.demo.js.map +0 -1
  317. package/dist/components/select/demos/deconstructed.demo.js.map +0 -1
  318. package/dist/components/select/demos/overview.demo.js.map +0 -1
@@ -0,0 +1,118 @@
1
+ import { addEventListeners, createMixin } from '@remix-run/ui'
2
+
3
+ export const dragVelocityReleaseEventType = 'rmx:drag-velocity-release' as const
4
+
5
+ declare global {
6
+ interface HTMLElementEventMap {
7
+ [dragVelocityReleaseEventType]: DragVelocityEvent
8
+ }
9
+ }
10
+
11
+ export class DragVelocityEvent extends Event {
12
+ clientX: number
13
+ clientY: number
14
+ velocityX: number // px/s
15
+ velocityY: number // px/s
16
+
17
+ constructor(
18
+ type: typeof dragVelocityReleaseEventType,
19
+ init: { clientX: number; clientY: number; velocityX: number; velocityY: number },
20
+ ) {
21
+ super(type, { bubbles: true, cancelable: true })
22
+ this.clientX = init.clientX
23
+ this.clientY = init.clientY
24
+ this.velocityX = init.velocityX
25
+ this.velocityY = init.velocityY
26
+ }
27
+ }
28
+
29
+ const baseDragVelocityEvents = createMixin<HTMLElement>((handle) => {
30
+ let target: HTMLElement
31
+ let isTracking = false
32
+ let pointerId: number | null = null
33
+ let lastX = 0
34
+ let lastY = 0
35
+ let lastTime = 0
36
+ let velocityX = 0
37
+ let velocityY = 0
38
+
39
+ let onPointerDown = (event: PointerEvent) => {
40
+ if (!event.isPrimary) return
41
+ isTracking = true
42
+ pointerId = event.pointerId
43
+ lastX = event.clientX
44
+ lastY = event.clientY
45
+ lastTime = performance.now()
46
+ velocityX = 0
47
+ velocityY = 0
48
+ target.setPointerCapture(event.pointerId)
49
+ }
50
+
51
+ let onPointerMove = (event: PointerEvent) => {
52
+ if (!isTracking) return
53
+ if (!event.isPrimary) return
54
+ if (pointerId != null && event.pointerId !== pointerId) return
55
+
56
+ let now = performance.now()
57
+ let dt = (now - lastTime) / 1000 // seconds
58
+
59
+ if (dt > 0) {
60
+ // Smooth velocity with some decay of previous velocity
61
+ let newVelocityX = (event.clientX - lastX) / dt
62
+ let newVelocityY = (event.clientY - lastY) / dt
63
+ velocityX = velocityX * 0.5 + newVelocityX * 0.5
64
+ velocityY = velocityY * 0.5 + newVelocityY * 0.5
65
+ }
66
+
67
+ lastX = event.clientX
68
+ lastY = event.clientY
69
+ lastTime = now
70
+ }
71
+
72
+ let onPointerUp = (event: PointerEvent) => {
73
+ if (!isTracking) return
74
+ if (!event.isPrimary) return
75
+ if (pointerId != null && event.pointerId !== pointerId) return
76
+ isTracking = false
77
+ pointerId = null
78
+
79
+ // If too much time passed since last move, velocity is zero
80
+ let timeSinceLastMove = (performance.now() - lastTime) / 1000
81
+ if (timeSinceLastMove > 0.1) {
82
+ velocityX = 0
83
+ velocityY = 0
84
+ }
85
+
86
+ target.dispatchEvent(
87
+ new DragVelocityEvent(dragVelocityReleaseEventType, {
88
+ clientX: event.clientX,
89
+ clientY: event.clientY,
90
+ velocityX,
91
+ velocityY,
92
+ }),
93
+ )
94
+ }
95
+
96
+ let onPointerCancel = () => {
97
+ isTracking = false
98
+ pointerId = null
99
+ }
100
+
101
+ handle.addEventListener('insert', (event) => {
102
+ target = event.node
103
+ addEventListeners(target, handle.signal, {
104
+ pointerdown: onPointerDown,
105
+ pointermove: onPointerMove,
106
+ pointerup: onPointerUp,
107
+ pointercancel: onPointerCancel,
108
+ })
109
+ })
110
+ })
111
+
112
+ type DragVelocityEventsMixin = typeof baseDragVelocityEvents & {
113
+ readonly release: typeof dragVelocityReleaseEventType
114
+ }
115
+
116
+ export const dragVelocityEvents: DragVelocityEventsMixin = Object.assign(baseDragVelocityEvents, {
117
+ release: dragVelocityReleaseEventType,
118
+ })
@@ -0,0 +1,22 @@
1
+ import { css } from '@remix-run/ui'
2
+ import { animateEntrance, spring } from '@remix-run/ui/animation'
3
+
4
+ export function EnterAnimation() {
5
+ return () => (
6
+ <div
7
+ mix={[
8
+ css({
9
+ width: 100,
10
+ height: 100,
11
+ backgroundColor: '#dd00ee',
12
+ borderRadius: '50%',
13
+ }),
14
+ animateEntrance({
15
+ opacity: 0,
16
+ transform: 'scale(0)',
17
+ ...spring({ duration: 400, bounce: 0.5 }),
18
+ }),
19
+ ]}
20
+ />
21
+ )
22
+ }
@@ -0,0 +1,79 @@
1
+ import type { Handle } from '@remix-run/ui'
2
+ import { css, on } from '@remix-run/ui'
3
+
4
+ import { animateEntrance, animateExit, spring } from '@remix-run/ui/animation'
5
+
6
+ export function ExitAnimation(handle: Handle) {
7
+ let isVisible = true
8
+
9
+ let shouldAnimate = false
10
+ handle.queueTask(() => {
11
+ shouldAnimate = true
12
+ })
13
+
14
+ return () => (
15
+ <div
16
+ mix={[
17
+ css({
18
+ display: 'flex',
19
+ flexDirection: 'column',
20
+ width: '100px',
21
+ height: '160px',
22
+ position: 'relative',
23
+ }),
24
+ ]}
25
+ >
26
+ {isVisible && (
27
+ <div
28
+ key="exit-animation"
29
+ mix={[
30
+ css({
31
+ width: '100px',
32
+ height: '100px',
33
+ backgroundColor: '#0cdcf7',
34
+ borderRadius: '10px',
35
+ }),
36
+ animateEntrance(
37
+ shouldAnimate && {
38
+ opacity: 0,
39
+ transform: 'scale(0)',
40
+ ...spring('snappy'),
41
+ },
42
+ ),
43
+ animateExit({
44
+ opacity: 0,
45
+ transform: 'scale(0)',
46
+ ...spring(),
47
+ }),
48
+ ]}
49
+ />
50
+ )}
51
+ <button
52
+ mix={[
53
+ css({
54
+ backgroundColor: '#0cdcf7',
55
+ borderRadius: '10px',
56
+ padding: '10px 20px',
57
+ color: '#0f1115',
58
+ border: 'none',
59
+ cursor: 'pointer',
60
+ position: 'absolute',
61
+ bottom: 0,
62
+ left: 0,
63
+ right: 0,
64
+ transition: `transform 100ms ease-in-out`,
65
+ '&:active': {
66
+ transform: 'translateY(1px)',
67
+ },
68
+ }),
69
+ on('click', () => {
70
+ isVisible = !isVisible
71
+ handle.update()
72
+ }),
73
+ ]}
74
+ >
75
+ {isVisible ? 'Hide' : 'Show'}
76
+ </button>
77
+ </div>
78
+ )
79
+ }
@@ -0,0 +1,46 @@
1
+ import { css, on, type Handle } from '@remix-run/ui'
2
+ import { animateLayout } from '@remix-run/ui/animation'
3
+
4
+ export function FlipToggle(handle: Handle) {
5
+ let isOn = false
6
+
7
+ return () => (
8
+ <button
9
+ mix={[
10
+ css({
11
+ width: 90,
12
+ height: 50,
13
+ backgroundColor: 'rgba(153, 17, 255, 0.2)',
14
+ borderRadius: 50,
15
+ cursor: 'pointer',
16
+ display: 'flex',
17
+ padding: 10,
18
+ border: 'none',
19
+ }),
20
+ on('click', () => {
21
+ isOn = !isOn
22
+ handle.update()
23
+ }),
24
+ ]}
25
+ style={{
26
+ // The actual layout property that changes
27
+ justifyContent: isOn ? 'flex-start' : 'flex-end',
28
+ }}
29
+ >
30
+ <div
31
+ mix={[
32
+ css({
33
+ width: 30,
34
+ height: 30,
35
+ backgroundColor: '#9911ff',
36
+ borderRadius: '50%',
37
+ }),
38
+ animateLayout({
39
+ duration: 200,
40
+ easing: 'ease-in-out',
41
+ }),
42
+ ]}
43
+ />
44
+ </button>
45
+ )
46
+ }
@@ -0,0 +1,317 @@
1
+ import { createMixin, css, on, type Handle } from '@remix-run/ui'
2
+ import { animateEntrance, animateExit, spring } from '@remix-run/ui/animation'
3
+
4
+ // Demo
5
+ const buttonExitAnimation = {
6
+ opacity: 0,
7
+ transform: 'scale(1.15)',
8
+ duration: 100,
9
+ easing: 'ease-in',
10
+ }
11
+
12
+ const confirmationEnterAnimation = {
13
+ opacity: 0,
14
+ transform: 'scale(0.9)',
15
+ duration: 200,
16
+ easing: 'ease-out',
17
+ }
18
+
19
+ export function HoldToConfirm(handle: Handle) {
20
+ let confirmed = false
21
+
22
+ return () => (
23
+ <div
24
+ mix={[
25
+ css({
26
+ display: 'grid',
27
+ placeItems: 'center',
28
+ minHeight: 140,
29
+ // so children can animate in the same position
30
+ '& > *': { gridArea: '1 / 1' },
31
+ }),
32
+ ]}
33
+ >
34
+ {!confirmed && (
35
+ <HoldButton
36
+ key="hold-button"
37
+ onConfirm={() => {
38
+ confirmed = true
39
+ handle.update()
40
+ }}
41
+ />
42
+ )}
43
+ {confirmed && (
44
+ <Confirmation
45
+ key="confirmed"
46
+ onReset={() => {
47
+ confirmed = false
48
+ handle.update()
49
+ }}
50
+ />
51
+ )}
52
+ </div>
53
+ )
54
+ }
55
+
56
+ function HoldButton(handle: Handle<{ onConfirm: () => void }>) {
57
+ let confirming = false
58
+
59
+ return () => (
60
+ <button
61
+ mix={[
62
+ animateExit(buttonExitAnimation),
63
+ css({
64
+ position: 'relative',
65
+ overflow: 'hidden',
66
+ width: 200,
67
+ height: 56,
68
+ border: 'none',
69
+ borderRadius: 12,
70
+ backgroundColor: '#dc2626',
71
+ color: 'white',
72
+ fontSize: 16,
73
+ fontWeight: 600,
74
+ cursor: 'pointer',
75
+ userSelect: 'none',
76
+ transition: 'transform 150ms ease',
77
+ '&:focus': {
78
+ outline: '3px solid rgba(220, 38, 38, 0.4)',
79
+ outlineOffset: 2,
80
+ },
81
+ '&:active': {
82
+ transform: 'scale(0.98)',
83
+ },
84
+ }),
85
+ confirmPress(),
86
+ on(confirmPress.start, () => {
87
+ confirming = true
88
+ handle.update()
89
+ }),
90
+ on(confirmPress.cancel, () => {
91
+ if (!confirming) return
92
+ confirming = false
93
+ handle.update()
94
+ }),
95
+ on(confirmPress.end, () => {
96
+ handle.props.onConfirm()
97
+ }),
98
+ ]}
99
+ >
100
+ <div
101
+ mix={[
102
+ css({
103
+ position: 'absolute',
104
+ inset: 0,
105
+ backgroundColor: 'rgba(0, 0, 0, 0.3)',
106
+ transformOrigin: 'left',
107
+ }),
108
+ ]}
109
+ style={{
110
+ transform: confirming ? 'scaleX(1)' : 'scaleX(0)',
111
+ transition: confirming
112
+ ? `transform ${PRESS_CONFIRM_TIME}ms linear`
113
+ : `transform ${spring({ duration: 100, bounce: 0 })}`,
114
+ }}
115
+ />
116
+
117
+ <span
118
+ mix={[
119
+ css({
120
+ position: 'relative',
121
+ zIndex: 1,
122
+ display: 'flex',
123
+ alignItems: 'center',
124
+ justifyContent: 'center',
125
+ gap: 8,
126
+ }),
127
+ ]}
128
+ >
129
+ <TrashIcon />
130
+ Hold to Delete
131
+ </span>
132
+ </button>
133
+ )
134
+ }
135
+
136
+ function Confirmation(handle: Handle<{ onReset: () => void }>) {
137
+ return () => (
138
+ <div
139
+ mix={[
140
+ animateEntrance(confirmationEnterAnimation),
141
+ css({
142
+ display: 'flex',
143
+ flexDirection: 'column',
144
+ alignItems: 'center',
145
+ gap: 16,
146
+ }),
147
+ ]}
148
+ >
149
+ <div
150
+ mix={[
151
+ css({
152
+ display: 'flex',
153
+ alignItems: 'center',
154
+ gap: 8,
155
+ color: '#22c55e',
156
+ fontSize: 18,
157
+ fontWeight: 600,
158
+ }),
159
+ ]}
160
+ >
161
+ <CheckIcon />
162
+ Deleted
163
+ </div>
164
+
165
+ <button
166
+ mix={[
167
+ css({
168
+ padding: '8px 16px',
169
+ border: '1px solid #e2e8f0',
170
+ borderRadius: 8,
171
+ backgroundColor: 'white',
172
+ color: '#64748b',
173
+ fontSize: 14,
174
+ cursor: 'pointer',
175
+ transition: 'all 150ms ease',
176
+ '&:hover': {
177
+ backgroundColor: '#f8fafc',
178
+ borderColor: '#cbd5e1',
179
+ },
180
+ }),
181
+ on('click', () => handle.props.onReset()),
182
+ ]}
183
+ >
184
+ Reset Demo
185
+ </button>
186
+ </div>
187
+ )
188
+ }
189
+
190
+ function TrashIcon() {
191
+ return () => (
192
+ <svg
193
+ width={16}
194
+ height={16}
195
+ viewBox="0 0 24 24"
196
+ fill="none"
197
+ stroke="currentColor"
198
+ strokeWidth={2}
199
+ strokeLinecap="round"
200
+ strokeLinejoin="round"
201
+ >
202
+ <polyline points="3 6 5 6 21 6" />
203
+ <path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" />
204
+ </svg>
205
+ )
206
+ }
207
+
208
+ function CheckIcon() {
209
+ return () => (
210
+ <svg
211
+ width={16}
212
+ height={16}
213
+ viewBox="0 0 24 24"
214
+ fill="none"
215
+ stroke="currentColor"
216
+ strokeWidth={2.5}
217
+ strokeLinecap="round"
218
+ strokeLinejoin="round"
219
+ >
220
+ <polyline points="20 6 9 17 4 12" />
221
+ </svg>
222
+ )
223
+ }
224
+
225
+ const PRESS_CONFIRM_TIME = 2000
226
+ const pressConfirmStartEventType = 'demo:press-confirm-start' as const
227
+ const pressConfirmCancelEventType = 'demo:press-confirm-cancel' as const
228
+ const pressConfirmEndEventType = 'demo:press-confirm-end' as const
229
+
230
+ declare global {
231
+ interface HTMLElementEventMap {
232
+ [pressConfirmStartEventType]: Event
233
+ [pressConfirmCancelEventType]: Event
234
+ [pressConfirmEndEventType]: Event
235
+ }
236
+ }
237
+
238
+ const baseConfirmPress = createMixin<HTMLElement>((handle) => {
239
+ let timer = 0
240
+ let pressing = false
241
+
242
+ let clearTimer = () => {
243
+ if (timer) {
244
+ clearTimeout(timer)
245
+ timer = 0
246
+ }
247
+ }
248
+
249
+ let start = (target: Element) => {
250
+ clearTimer()
251
+ pressing = true
252
+ target.dispatchEvent(new Event(pressConfirmStartEventType, { bubbles: true }))
253
+ timer = window.setTimeout(() => {
254
+ timer = 0
255
+ pressing = false
256
+ target.dispatchEvent(new Event(pressConfirmEndEventType, { bubbles: true }))
257
+ }, PRESS_CONFIRM_TIME)
258
+ }
259
+
260
+ let cancel = (target: Element) => {
261
+ if (!pressing) return
262
+ clearTimer()
263
+ pressing = false
264
+ target.dispatchEvent(new Event(pressConfirmCancelEventType, { bubbles: true }))
265
+ }
266
+
267
+ handle.addEventListener('remove', () => {
268
+ clearTimer()
269
+ pressing = false
270
+ })
271
+
272
+ return (props) => (
273
+ <handle.element
274
+ {...props}
275
+ mix={[
276
+ on('pointerdown', (event) => {
277
+ if (event.isPrimary === false) return
278
+ start(event.currentTarget)
279
+ }),
280
+ on('pointerup', (event) => {
281
+ cancel(event.currentTarget)
282
+ }),
283
+ on('pointercancel', (event) => {
284
+ cancel(event.currentTarget)
285
+ }),
286
+ on('pointerleave', (event) => {
287
+ cancel(event.currentTarget)
288
+ }),
289
+ on('keydown', (event) => {
290
+ if (!(event.key === 'Enter' || event.key === ' ') || event.repeat) return
291
+ event.preventDefault()
292
+ start(event.currentTarget)
293
+ }),
294
+ on('keyup', (event) => {
295
+ if (!(event.key === 'Enter' || event.key === ' ')) return
296
+ event.preventDefault()
297
+ cancel(event.currentTarget)
298
+ }),
299
+ on('blur', (event) => {
300
+ cancel(event.currentTarget)
301
+ }),
302
+ ]}
303
+ />
304
+ )
305
+ })
306
+
307
+ type ConfirmPressMixin = typeof baseConfirmPress & {
308
+ readonly start: typeof pressConfirmStartEventType
309
+ readonly cancel: typeof pressConfirmCancelEventType
310
+ readonly end: typeof pressConfirmEndEventType
311
+ }
312
+
313
+ const confirmPress: ConfirmPressMixin = Object.assign(baseConfirmPress, {
314
+ start: pressConfirmStartEventType,
315
+ cancel: pressConfirmCancelEventType,
316
+ end: pressConfirmEndEventType,
317
+ })
@@ -0,0 +1,41 @@
1
+ import type { Handle } from '@remix-run/ui'
2
+ import { css } from '@remix-run/ui'
3
+
4
+ import { spring } from '@remix-run/ui/animation'
5
+
6
+ export function HTMLContent(handle: Handle) {
7
+ let count = 0
8
+ let from = 0
9
+ let to = 100
10
+
11
+ let counter = spring({ duration: 3000, bounce: 0 })
12
+
13
+ function animate() {
14
+ if (handle.signal.aborted) return
15
+
16
+ let { value: t, done } = counter.next()
17
+ if (done) return
18
+
19
+ count = Math.round(from + (to - from) * t)
20
+ handle.update()
21
+ requestAnimationFrame(animate)
22
+ }
23
+
24
+ handle.queueTask(() => {
25
+ requestAnimationFrame(animate)
26
+ })
27
+
28
+ return () => (
29
+ <pre
30
+ mix={[
31
+ css({
32
+ fontSize: '64px',
33
+ margin: 0,
34
+ color: '#8df0cc',
35
+ }),
36
+ ]}
37
+ >
38
+ {count}
39
+ </pre>
40
+ )
41
+ }
@@ -0,0 +1,62 @@
1
+ import { css, on, ref } from '@remix-run/ui'
2
+
3
+ export function InterruptibleKeyframes() {
4
+ let box: HTMLDivElement
5
+ let currentAnimation: Animation | null = null
6
+
7
+ function getCurrentScale(): number {
8
+ let matrix = new DOMMatrix(getComputedStyle(box).transform)
9
+ return matrix.a
10
+ }
11
+
12
+ function interruptAnimation() {
13
+ if (currentAnimation) {
14
+ currentAnimation.commitStyles()
15
+ currentAnimation.cancel()
16
+ currentAnimation = null
17
+ }
18
+ }
19
+
20
+ return () => (
21
+ <div
22
+ mix={[
23
+ ref((node) => (box = node)),
24
+ css({
25
+ width: 100,
26
+ height: 100,
27
+ backgroundColor: '#0cdcf7',
28
+ borderRadius: 5,
29
+ }),
30
+ on('pointerenter', () => {
31
+ interruptAnimation()
32
+ let startScale = getCurrentScale()
33
+
34
+ currentAnimation = box.animate(
35
+ [
36
+ { transform: `scale(${startScale})`, offset: 0, easing: 'ease-in-out' },
37
+ { transform: 'scale(1.1)', offset: 0.6, easing: 'ease-out' },
38
+ { transform: 'scale(1.6)', offset: 1 },
39
+ ],
40
+ {
41
+ duration: 500,
42
+ fill: 'forwards',
43
+ },
44
+ )
45
+ }),
46
+ on('pointerleave', () => {
47
+ interruptAnimation()
48
+ let startScale = getCurrentScale()
49
+
50
+ currentAnimation = box.animate(
51
+ [{ transform: `scale(${startScale})` }, { transform: 'scale(1)' }],
52
+ {
53
+ duration: 300,
54
+ easing: 'ease-out',
55
+ fill: 'forwards',
56
+ },
57
+ )
58
+ }),
59
+ ]}
60
+ />
61
+ )
62
+ }