@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.
- package/README.md +9 -7
- package/dist/animation/demos/animation.demo.d.ts +5 -0
- package/dist/animation/demos/animation.demo.js +92 -0
- package/dist/animation/demos/animation.demo.js.map +1 -0
- package/dist/animation/demos/aspect-ratio.d.ts +2 -0
- package/dist/animation/demos/aspect-ratio.js +69 -0
- package/dist/animation/demos/aspect-ratio.js.map +1 -0
- package/dist/animation/demos/bouncy-switch.d.ts +2 -0
- package/dist/animation/demos/bouncy-switch.js +36 -0
- package/dist/animation/demos/bouncy-switch.js.map +1 -0
- package/dist/animation/demos/color-interpolation.d.ts +1 -0
- package/dist/animation/demos/color-interpolation.js +53 -0
- package/dist/animation/demos/color-interpolation.js.map +1 -0
- package/dist/animation/demos/cube.d.ts +2 -0
- package/dist/animation/demos/cube.js +86 -0
- package/dist/animation/demos/cube.js.map +1 -0
- package/dist/animation/demos/default-animate.d.ts +2 -0
- package/dist/animation/demos/default-animate.js +89 -0
- package/dist/animation/demos/default-animate.js.map +1 -0
- package/dist/animation/demos/drag-release.d.ts +24 -0
- package/dist/animation/demos/drag-release.js +96 -0
- package/dist/animation/demos/drag-release.js.map +1 -0
- package/dist/animation/demos/enter.d.ts +1 -0
- package/dist/animation/demos/enter.js +19 -0
- package/dist/animation/demos/enter.js.map +1 -0
- package/dist/animation/demos/exit.d.ts +2 -0
- package/dist/animation/demos/exit.js +58 -0
- package/dist/animation/demos/exit.js.map +1 -0
- package/dist/animation/demos/flip-toggle.d.ts +2 -0
- package/dist/animation/demos/flip-toggle.js +37 -0
- package/dist/animation/demos/flip-toggle.js.map +1 -0
- package/dist/animation/demos/hold-to-confirm.d.ts +13 -0
- package/dist/animation/demos/hold-to-confirm.js +211 -0
- package/dist/animation/demos/hold-to-confirm.js.map +1 -0
- package/dist/animation/demos/html-content.d.ts +2 -0
- package/dist/animation/demos/html-content.js +30 -0
- package/dist/animation/demos/html-content.js.map +1 -0
- package/dist/animation/demos/interruptible-keyframes.d.ts +1 -0
- package/dist/animation/demos/interruptible-keyframes.js +48 -0
- package/dist/animation/demos/interruptible-keyframes.js.map +1 -0
- package/dist/animation/demos/keyframes.d.ts +1 -0
- package/dist/animation/demos/keyframes.js +24 -0
- package/dist/animation/demos/keyframes.js.map +1 -0
- package/dist/animation/demos/material-ripple.d.ts +2 -0
- package/dist/animation/demos/material-ripple.js +127 -0
- package/dist/animation/demos/material-ripple.js.map +1 -0
- package/dist/animation/demos/mixin-presence-list.d.ts +2 -0
- package/dist/animation/demos/mixin-presence-list.js +88 -0
- package/dist/animation/demos/mixin-presence-list.js.map +1 -0
- package/dist/animation/demos/mixin-reclaim.d.ts +2 -0
- package/dist/animation/demos/mixin-reclaim.js +90 -0
- package/dist/animation/demos/mixin-reclaim.js.map +1 -0
- package/dist/animation/demos/multi-state-badge.d.ts +2 -0
- package/dist/animation/demos/multi-state-badge.js +231 -0
- package/dist/animation/demos/multi-state-badge.js.map +1 -0
- package/dist/animation/demos/press.d.ts +2 -0
- package/dist/animation/demos/press.js +63 -0
- package/dist/animation/demos/press.js.map +1 -0
- package/dist/animation/demos/reordering.d.ts +2 -0
- package/dist/animation/demos/reordering.js +50 -0
- package/dist/animation/demos/reordering.js.map +1 -0
- package/dist/animation/demos/rolling-square.d.ts +2 -0
- package/dist/animation/demos/rolling-square.js +42 -0
- package/dist/animation/demos/rolling-square.js.map +1 -0
- package/dist/animation/demos/rotate.d.ts +1 -0
- package/dist/animation/demos/rotate.js +18 -0
- package/dist/animation/demos/rotate.js.map +1 -0
- package/dist/animation/demos/shared-layout.d.ts +2 -0
- package/dist/animation/demos/shared-layout.js +114 -0
- package/dist/animation/demos/shared-layout.js.map +1 -0
- package/dist/animation/demos/spring.demo.d.ts +6 -0
- package/dist/animation/demos/spring.demo.js +304 -0
- package/dist/animation/demos/spring.demo.js.map +1 -0
- package/dist/animation/demos/transition-options.d.ts +1 -0
- package/dist/animation/demos/transition-options.js +21 -0
- package/dist/animation/demos/transition-options.js.map +1 -0
- package/dist/animation/spring.d.ts +24 -31
- package/dist/animation/spring.js +31 -8
- package/dist/animation/spring.js.map +1 -1
- package/dist/components/accordion/accordion.d.ts +6 -6
- package/dist/components/accordion/accordion.js.map +1 -1
- package/dist/components/accordion/demos/card.demo.d.ts +1 -0
- package/dist/components/accordion/demos/card.demo.js +1 -0
- package/dist/components/accordion/demos/card.demo.js.map +1 -1
- package/dist/components/accordion/demos/multiple.demo.d.ts +1 -0
- package/dist/components/accordion/demos/multiple.demo.js +1 -0
- package/dist/components/accordion/demos/multiple.demo.js.map +1 -1
- package/dist/components/accordion/demos/overview.demo.d.ts +1 -0
- package/dist/components/accordion/demos/overview.demo.js +1 -0
- package/dist/components/accordion/demos/overview.demo.js.map +1 -1
- package/dist/components/anchor/anchor.d.ts +8 -1
- package/dist/components/anchor/anchor.js +30 -11
- package/dist/components/anchor/anchor.js.map +1 -1
- package/dist/components/breadcrumbs/{demos/basic.demo.d.ts → basic.demo.d.ts} +1 -0
- package/dist/components/breadcrumbs/{demos/basic.demo.js → basic.demo.js} +1 -0
- package/dist/components/breadcrumbs/basic.demo.js.map +1 -0
- package/dist/components/breadcrumbs/breadcrumbs.d.ts +1 -1
- package/dist/components/breadcrumbs/{demos/separator.demo.d.ts → separator.demo.d.ts} +1 -0
- package/dist/components/breadcrumbs/{demos/separator.demo.js → separator.demo.js} +1 -0
- package/dist/components/breadcrumbs/separator.demo.js.map +1 -0
- package/dist/components/button/button.d.ts +4 -4
- package/dist/components/button/button.js +3 -1
- package/dist/components/button/button.js.map +1 -1
- package/dist/components/button/demos/aliases.demo.d.ts +1 -0
- package/dist/components/button/demos/aliases.demo.js +1 -0
- package/dist/components/button/demos/aliases.demo.js.map +1 -1
- package/dist/components/button/demos/basic.demo.d.ts +1 -0
- package/dist/components/button/demos/basic.demo.js +1 -0
- package/dist/components/button/demos/basic.demo.js.map +1 -1
- package/dist/components/button/demos/states.demo.d.ts +1 -0
- package/dist/components/button/demos/states.demo.js +1 -0
- package/dist/components/button/demos/states.demo.js.map +1 -1
- package/dist/components/combobox/combobox.d.ts +10 -10
- package/dist/components/combobox/combobox.js.map +1 -1
- package/dist/components/combobox/{demos/overview.demo.d.ts → overview.demo.d.ts} +1 -0
- package/dist/components/combobox/{demos/overview.demo.js → overview.demo.js} +1 -0
- package/dist/components/combobox/overview.demo.js.map +1 -0
- package/dist/components/listbox/listbox.d.ts +3 -3
- package/dist/components/listbox/listbox.js.map +1 -1
- package/dist/components/listbox/{demos/overview.demo.d.ts → overview.demo.d.ts} +1 -0
- package/dist/components/listbox/{demos/overview.demo.js → overview.demo.js} +1 -0
- package/dist/components/listbox/overview.demo.js.map +1 -0
- package/dist/components/menu/demos/bubbling.demo.d.ts +1 -0
- package/dist/components/menu/demos/bubbling.demo.js +1 -0
- package/dist/components/menu/demos/bubbling.demo.js.map +1 -1
- package/dist/components/menu/demos/context-trigger.demo.d.ts +7 -0
- package/dist/components/menu/demos/context-trigger.demo.js +87 -0
- package/dist/components/menu/demos/context-trigger.demo.js.map +1 -0
- package/dist/components/menu/demos/overview.demo.d.ts +1 -0
- package/dist/components/menu/demos/overview.demo.js +1 -0
- package/dist/components/menu/demos/overview.demo.js.map +1 -1
- package/dist/components/menu/menu.d.ts +15 -12
- package/dist/components/menu/menu.js +55 -0
- package/dist/components/menu/menu.js.map +1 -1
- package/dist/components/popover/{demos/overview.demo.d.ts → overview.demo.d.ts} +1 -0
- package/dist/components/popover/{demos/overview.demo.js → overview.demo.js} +1 -0
- package/dist/components/popover/overview.demo.js.map +1 -0
- package/dist/components/popover/popover.d.ts +7 -7
- package/dist/components/popover/popover.js +11 -4
- package/dist/components/popover/popover.js.map +1 -1
- package/dist/components/select/{demos/deconstructed.demo.d.ts → deconstructed.demo.d.ts} +1 -0
- package/dist/components/select/{demos/deconstructed.demo.js → deconstructed.demo.js} +1 -0
- package/dist/components/select/deconstructed.demo.js.map +1 -0
- package/dist/components/select/{demos/overview.demo.d.ts → overview.demo.d.ts} +1 -0
- package/dist/components/select/{demos/overview.demo.js → overview.demo.js} +1 -0
- package/dist/components/select/overview.demo.js.map +1 -0
- package/dist/components/select/select.d.ts +10 -10
- package/dist/components/select/select.js +1 -1
- package/dist/components/select/select.js.map +1 -1
- package/dist/components/tabs/tabs.d.ts +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/interactions/keydown/keydown.d.ts +1 -1
- package/dist/interactions/outside-click/outside-click-mixin.d.ts +2 -1
- package/dist/interactions/typeahead/typeahead-mixin.d.ts +3 -1
- package/dist/runtime/client-entries.d.ts +1 -2
- package/dist/runtime/client-entries.js.map +1 -1
- package/dist/runtime/component.d.ts +20 -17
- package/dist/runtime/component.js +15 -6
- package/dist/runtime/component.js.map +1 -1
- package/dist/runtime/core/attributes.d.ts +3 -1
- package/dist/runtime/core/attributes.js +19 -1
- package/dist/runtime/core/attributes.js.map +1 -1
- package/dist/runtime/core/props.js +6 -5
- package/dist/runtime/core/props.js.map +1 -1
- package/dist/runtime/demos/basic.demo.d.ts +6 -0
- package/dist/runtime/demos/basic.demo.js +16 -0
- package/dist/runtime/demos/basic.demo.js.map +1 -0
- package/dist/runtime/demos/controlled-uncontrolled-values.demo.d.ts +6 -0
- package/dist/runtime/demos/controlled-uncontrolled-values.demo.js +77 -0
- package/dist/runtime/demos/controlled-uncontrolled-values.demo.js.map +1 -0
- package/dist/runtime/demos/keyed-list.demo.d.ts +6 -0
- package/dist/runtime/demos/keyed-list.demo.js +62 -0
- package/dist/runtime/demos/keyed-list.demo.js.map +1 -0
- package/dist/runtime/demos/readme.demo.d.ts +5 -0
- package/dist/runtime/demos/readme.demo.js +396 -0
- package/dist/runtime/demos/readme.demo.js.map +1 -0
- package/dist/runtime/diff-dom.js +194 -21
- package/dist/runtime/diff-dom.js.map +1 -1
- package/dist/runtime/dom.d.ts +16 -9
- package/dist/runtime/frame.d.ts +7 -0
- package/dist/runtime/frame.js +176 -41
- package/dist/runtime/frame.js.map +1 -1
- package/dist/runtime/jsx.d.ts +3 -4
- package/dist/runtime/jsx.js.map +1 -1
- package/dist/runtime/mixins/link-mixin.d.ts +5 -1
- package/dist/runtime/mixins/link-mixin.js.map +1 -1
- package/dist/runtime/mixins/mixin.d.ts +2 -1
- package/dist/runtime/mixins/mixin.js.map +1 -1
- package/dist/runtime/mixins/ref-mixin.d.ts +2 -1
- package/dist/runtime/mixins/ref-mixin.js.map +1 -1
- package/dist/runtime/reconcile.d.ts +1 -1
- package/dist/runtime/reconcile.js +19 -5
- package/dist/runtime/reconcile.js.map +1 -1
- package/dist/runtime/scheduler.d.ts +10 -10
- package/dist/runtime/scheduler.js +1 -1
- package/dist/runtime/scheduler.js.map +1 -1
- package/dist/runtime/svg-attributes.js +1 -0
- package/dist/runtime/svg-attributes.js.map +1 -1
- package/dist/runtime/to-vnode.js +2 -2
- package/dist/runtime/to-vnode.js.map +1 -1
- package/dist/runtime/vnode.d.ts +6 -1
- package/dist/runtime/vnode.js +4 -0
- package/dist/runtime/vnode.js.map +1 -1
- package/dist/server/stream.d.ts +2 -0
- package/dist/server/stream.js +82 -11
- package/dist/server/stream.js.map +1 -1
- package/dist/style/css-mixin.d.ts +2 -1
- package/dist/style/css-mixin.js.map +1 -1
- package/dist/style/index.d.ts +1 -1
- package/dist/style/style.js +27 -10
- package/dist/style/style.js.map +1 -1
- package/dist/style/stylesheet.d.ts +13 -13
- package/dist/style/stylesheet.js.map +1 -1
- package/dist/theme/contract.d.ts +24 -222
- package/dist/theme/contract.js +2 -2
- package/dist/theme/contract.js.map +1 -1
- package/dist/theme/glyph-contract.d.ts +1 -3
- package/dist/theme/glyph-contract.js.map +1 -1
- package/dist/theme/presets/rmx-01/index.d.ts +4 -2
- package/dist/theme/presets/rmx-01/index.js.map +1 -1
- package/dist/utils/scroll-lock.d.ts +3 -3
- package/dist/utils/scroll-lock.js.map +1 -1
- package/package.json +4 -4
- package/src/animation/README.md +7 -5
- package/src/animation/demos/animation.demo.tsx +194 -0
- package/src/animation/demos/aspect-ratio.tsx +120 -0
- package/src/animation/demos/bouncy-switch.tsx +47 -0
- package/src/animation/demos/color-interpolation.tsx +73 -0
- package/src/animation/demos/cube.tsx +116 -0
- package/src/animation/demos/default-animate.tsx +129 -0
- package/src/animation/demos/drag-release.ts +118 -0
- package/src/animation/demos/enter.tsx +22 -0
- package/src/animation/demos/exit.tsx +79 -0
- package/src/animation/demos/flip-toggle.tsx +46 -0
- package/src/animation/demos/hold-to-confirm.tsx +317 -0
- package/src/animation/demos/html-content.tsx +41 -0
- package/src/animation/demos/interruptible-keyframes.tsx +62 -0
- package/src/animation/demos/keyframes.tsx +29 -0
- package/src/animation/demos/material-ripple.tsx +158 -0
- package/src/animation/demos/mixin-presence-list.tsx +121 -0
- package/src/animation/demos/mixin-reclaim.tsx +125 -0
- package/src/animation/demos/multi-state-badge.tsx +426 -0
- package/src/animation/demos/press.tsx +67 -0
- package/src/animation/demos/reordering.tsx +65 -0
- package/src/animation/demos/rolling-square.tsx +57 -0
- package/src/animation/demos/rotate.tsx +21 -0
- package/src/animation/demos/shared-layout.tsx +211 -0
- package/src/animation/demos/spring.demo.tsx +385 -0
- package/src/animation/demos/transition-options.tsx +24 -0
- package/src/animation/spring.ts +43 -9
- package/src/components/accordion/accordion.tsx +7 -5
- package/src/components/accordion/demos/card.demo.tsx +1 -0
- package/src/components/accordion/demos/multiple.demo.tsx +1 -0
- package/src/components/accordion/demos/overview.demo.tsx +1 -0
- package/src/components/anchor/README.md +11 -3
- package/src/components/anchor/anchor.ts +54 -13
- package/src/components/breadcrumbs/{demos/basic.demo.tsx → basic.demo.tsx} +1 -0
- package/src/components/breadcrumbs/breadcrumbs.tsx +1 -1
- package/src/components/breadcrumbs/{demos/separator.demo.tsx → separator.demo.tsx} +1 -0
- package/src/components/button/button.tsx +30 -18
- package/src/components/button/demos/aliases.demo.tsx +1 -0
- package/src/components/button/demos/basic.demo.tsx +1 -0
- package/src/components/button/demos/states.demo.tsx +1 -0
- package/src/components/combobox/README.md +1 -1
- package/src/components/combobox/combobox.tsx +30 -12
- package/src/components/combobox/{demos/overview.demo.tsx → overview.demo.tsx} +1 -0
- package/src/components/glyph/glyph.tsx +2 -2
- package/src/components/listbox/listbox.ts +88 -83
- package/src/components/listbox/{demos/overview.demo.tsx → overview.demo.tsx} +1 -0
- package/src/components/menu/README.md +26 -2
- package/src/components/menu/demos/bubbling.demo.tsx +1 -0
- package/src/components/menu/demos/context-trigger.demo.tsx +133 -0
- package/src/components/menu/demos/overview.demo.tsx +1 -0
- package/src/components/menu/menu.tsx +100 -16
- package/src/components/popover/{demos/overview.demo.tsx → overview.demo.tsx} +1 -0
- package/src/components/popover/popover.ts +101 -81
- package/src/components/select/{demos/deconstructed.demo.tsx → deconstructed.demo.tsx} +1 -0
- package/src/components/select/{demos/overview.demo.tsx → overview.demo.tsx} +1 -0
- package/src/components/select/select.tsx +27 -10
- package/src/index.ts +1 -0
- package/src/runtime/client-entries.ts +1 -5
- package/src/runtime/component.ts +37 -15
- package/src/runtime/core/attributes.ts +21 -0
- package/src/runtime/core/props.ts +6 -4
- package/src/runtime/demos/basic.demo.tsx +21 -0
- package/src/runtime/demos/controlled-uncontrolled-values.demo.tsx +177 -0
- package/src/runtime/demos/keyed-list.demo.tsx +94 -0
- package/src/runtime/demos/readme.demo.tsx +702 -0
- package/src/runtime/diff-dom.ts +270 -20
- package/src/runtime/dom.ts +16 -9
- package/src/runtime/frame.ts +218 -41
- package/src/runtime/jsx.ts +7 -11
- package/src/runtime/mixins/link-mixin.ts +88 -86
- package/src/runtime/mixins/mixin.ts +9 -1
- package/src/runtime/mixins/ref-mixin.ts +4 -5
- package/src/runtime/reconcile.ts +23 -14
- package/src/runtime/scheduler.ts +20 -20
- package/src/runtime/svg-attributes.ts +1 -0
- package/src/runtime/to-vnode.ts +2 -2
- package/src/runtime/vnode.ts +10 -0
- package/src/server/README.md +4 -2
- package/src/server/stream.ts +84 -10
- package/src/style/css-mixin.ts +6 -1
- package/src/style/index.ts +1 -2
- package/src/style/style.ts +29 -10
- package/src/style/stylesheet.ts +14 -2
- package/src/theme/contract.ts +37 -5
- package/src/theme/glyph-contract.ts +3 -1
- package/src/theme/presets/rmx-01/index.ts +4 -2
- package/src/utils/scroll-lock.ts +7 -3
- package/dist/components/breadcrumbs/demos/basic.demo.js.map +0 -1
- package/dist/components/breadcrumbs/demos/separator.demo.js.map +0 -1
- package/dist/components/combobox/demos/overview.demo.js.map +0 -1
- package/dist/components/listbox/demos/overview.demo.js.map +0 -1
- package/dist/components/popover/demos/overview.demo.js.map +0 -1
- package/dist/components/select/demos/deconstructed.demo.js.map +0 -1
- 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
|
+
}
|