Ease
The easing curve and layout springs the agent and chat components were tuned with. Adapted from beUI (MIT).
Three values for motion/react, shared by the conversation components. EASE_OUT is the strong ease-out for anything that enters or answers a press; it is the same curve as --ease-out-strong in foundation, as an array. SPRING_LAYOUT moves things that change place while they stay on screen: rows, pills, indicators. SPRING_POP_UP raises a row that was just sent. They are curves and springs only: take durations from @khaeli/motion-tokens. Animate with m from motion/react-m under @khaeli/motion-provider, and give every movement a reduced-motion branch that keeps the fade.
Ease out
Release 4.2 is published
Twelve tasks shipped and three moved to the next release.
"use client"
import { useReducedMotion } from "motion/react"
import * as m from "motion/react-m"
import { useState } from "react"
import { Button } from "@/components/ui/button"
import { EASE_OUT } from "@/lib/ease"
import { motionTokens } from "@/lib/motion-tokens"
export default function EaseEaseOut() {
const [run, setRun] = useState(0)
const reduce = useReducedMotion()
return (
<div className="flex w-full max-w-xs flex-col items-start gap-4">
{/* An entrance: fast at first, then settling. With reduced motion it only fades. */}
<m.div
key={run}
initial={run === 0 ? false : reduce ? { opacity: 0 } : { opacity: 0, y: 12 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: motionTokens.duration.standard, ease: EASE_OUT }}
className="w-full rounded-xl border border-border bg-card p-3"
>
<p className="font-medium">Release 4.2 is published</p>
<p className="text-muted-foreground">Twelve tasks shipped and three moved to the next release.</p>
</m.div>
<Button variant="outline" onClick={() => setRun(run + 1)}>
Play
</Button>
</div>
)
}
Layout spring
- Confirm the launch date28 Nov
- Migrate the staging database21 Nov
- Review the pricing page copy24 Nov
"use client"
import { useReducedMotion } from "motion/react"
import * as m from "motion/react-m"
import { useState } from "react"
import { Button } from "@/components/ui/button"
import { SPRING_LAYOUT } from "@/lib/ease"
const tasks = [
{ title: "Confirm the launch date", due: "28 Nov", day: 28 },
{ title: "Migrate the staging database", due: "21 Nov", day: 21 },
{ title: "Review the pricing page copy", due: "24 Nov", day: 24 },
]
export default function EaseLayoutSpring() {
const [byDate, setByDate] = useState(false)
const reduce = useReducedMotion()
const rows = byDate ? [...tasks].sort((a, b) => a.day - b.day) : tasks
return (
<div className="flex w-full max-w-sm flex-col items-start gap-4">
<ul className="flex w-full flex-col gap-1.5">
{rows.map((task) => (
// Each row glides to its new place. With reduced motion it is simply there.
<m.li
key={task.title}
layout={!reduce}
transition={SPRING_LAYOUT}
className="flex items-center justify-between gap-4 rounded-md bg-secondary px-3 py-2"
>
<span className="min-w-0 truncate">{task.title}</span>
<span className="shrink-0 text-muted-foreground tabular-nums">{task.due}</span>
</m.li>
))}
</ul>
<Button variant="outline" onClick={() => setByDate(!byDate)}>
{byDate ? "Sort by name" : "Sort by due date"}
</Button>
</div>
)
}
Pop up spring
- What should change before the release goes out?
"use client"
import { useReducedMotion } from "motion/react"
import * as m from "motion/react-m"
import { useState } from "react"
import { Button } from "@/components/ui/button"
import { SPRING_POP_UP } from "@/lib/ease"
const notes = ["Add the changelog.", "Move the review to Thursday.", "Close the tasks that shipped."]
export default function EasePopUpSpring() {
const [sent, setSent] = useState<string[]>([])
const reduce = useReducedMotion()
const next = notes[sent.length]
return (
<div className="flex w-full max-w-sm flex-col gap-4">
<ul aria-label="Notes" aria-live="polite" className="flex min-h-36 flex-col items-end justify-end gap-2">
<li className="self-start text-muted-foreground">What should change before the release goes out?</li>
{sent.map((note) => (
// A sent row rises from the edge it was written at. With reduced motion it only fades in.
<m.li
key={note}
initial={reduce ? { opacity: 0 } : { opacity: 0, y: 16 }}
animate={{ opacity: 1, y: 0 }}
transition={SPRING_POP_UP}
className="rounded-xl bg-secondary px-3 py-2"
>
{note}
</m.li>
))}
</ul>
<Button variant="outline" className="self-end" onClick={() => setSent(next ? [...sent, next] : [])}>
{next ? "Send a note" : "Clear"}
</Button>
</div>
)
}
Installation
npx shadcn@latest add @khaeli/easebunx --bun shadcn@latest add @khaeli/easeInstalls with
Nothing else. This item needs no other Registry item and no npm package.
Registry JSON
The item as the shadcn CLI reads it, with every file it ships: https://ui.khaeli.com/r/ease.json