/**
* Material 3: the controls.
*
* A press is answered by a state layer and a ripple from where it landed;
* nothing lifts or scales. Every one of these is a `ui/core` hook in a
* different coat — the state, the keyboard and the `aria-` come from there.
*/
import * as SelectPrimitive from "@radix-ui/react-select"
import { Check, ChevronDown } from "lucide-react"
import { AnimatePresence, motion } from "motion/react"
import { cn } from "@/lib/utils"
import { asOriginal, text } from "../core/config"
import type {
ButtonProps,
InputProps,
SegmentedProps,
SelectProps,
SliderProps,
SwitchProps,
} from "../core/contract"
import {
type Press,
usePress,
useSegmented,
useSliderDrag,
useSwitch,
} from "../core/controls"
import { useLook } from "../core/look"
import { LOOK } from "../core/motion"
/** The state layer plus whatever presses are still fading. */
function Skin({
presses,
done,
}: {
presses: Press[]
done: (id: number) => void
}) {
return (
<>
{presses.map((press) => (
done(press.id)}
/>
))}
>
)
}
export function Button({
variant = "tonal",
pressed,
disabled,
label,
onClick,
children,
}: ButtonProps) {
const { presses, onPointerDown, done } = usePress()
return (
)
}
export function Switch(props: SwitchProps) {
const { buttonProps } = useSwitch(props)
const { presses, onPointerDown, done } = usePress()
return (
)
}
export function Slider(props: SliderProps) {
const { fraction, inputProps, marks, markAt, trackRef } = useSliderDrag(props)
const orientation = props.orientation ?? "horizontal"
return (
{/* The control itself, laid transparent over what is drawn: it keeps
the keyboard, the pointer and every `aria-`, and owes the look
nothing. */}
{/* Under the handle, so where the two meet the value being set wins;
after the input only for its `:disabled`, as it takes no pointer. */}
{markAt === null ? null : (
)}
{marks.length > 0 ? (
// Decoration: the input itself announces min, max and where it stands.