pending
diceui-radix/pendingFreeComponent
diceui/radix publishes no description for this item.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/sadmann7/diceui/HEAD/docs/public/r/styles/radix-nova/pending.jsonSource
1/**2 * Based on React Aria's Button implementation3 * @see https://github.com/adobe/react-spectrum/blob/main/packages/react-aria-components/src/Button.tsx4 */56import { Slot as SlotPrimitive } from "radix-ui";7import * as React from "react";89interface UsePendingOptions {10 id?: string;11 isPending?: boolean;12 disabled?: boolean;13}1415interface UsePendingReturn<T extends HTMLElement = HTMLElement> {16 pendingProps: React.HTMLAttributes<T> & {17 "aria-busy"?: "true";18 "aria-disabled"?: "true";19 "data-pending"?: true;20 "data-disabled"?: true;21 };22 isPending: boolean;23}2425function usePending<T extends HTMLElement = HTMLElement>(26 options: UsePendingOptions = {},27): UsePendingReturn<T> {28 const { id, isPending = false, disabled = false } = options;2930 const instanceId = React.useId();31 const pendingId = id || instanceId;3233 const pendingProps = React.useMemo(() => {34 const props: React.HTMLAttributes<T> & {35 "aria-busy"?: "true";36 "aria-disabled"?: "true";37 "data-pending"?: true;38 "data-disabled"?: true;39 } = {40 id: pendingId,41 };4243 if (isPending) {44 props["aria-busy"] = "true";45 props["aria-disabled"] = "true";46 props["data-pending"] = true;4748 function onEventPrevent(event: React.SyntheticEvent) {49 event.preventDefault();50 }5152 function onKeyEventPrevent(event: React.KeyboardEvent<T>) {53 if (event.key === "Enter" || event.key === " ") {54 event.preventDefault();55 }56 }5758 props.onClick = onEventPrevent;59 props.onPointerDown = onEventPrevent;60 props.onPointerUp = onEventPrevent;61 props.onMouseDown = onEventPrevent;62 props.onMouseUp = onEventPrevent;63 props.onKeyDown = onKeyEventPrevent;64 props.onKeyUp = onKeyEventPrevent;65 }6667 if (disabled) {68 props["data-disabled"] = true;69 }7071 return props;72 }, [isPending, disabled, pendingId]);7374 return React.useMemo(() => {75 return {76 pendingProps,77 isPending,78 };79 }, [pendingProps, isPending]);80}8182interface PendingProps extends React.ComponentProps<typeof SlotPrimitive.Slot> {83 isPending?: boolean;84 disabled?: boolean;85}8687function Pending({ id, isPending, disabled, ...props }: PendingProps) {88 const { pendingProps } = usePending({ id, isPending, disabled });8990 return <SlotPrimitive.Slot {...props} {...pendingProps} />;91}9293export { Pending, usePending };
What it pulls in
npm packages
Files it writes
More from diceui/radix
All 58 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| action-baraction-bar | diceui/radix | Components | Free | 1 dep · 2 files | |
| angle-sliderangle-slider | diceui/radix | Components | Free | 1 dep · 3 files | |
| avatar-groupavatar-group | diceui/radix | Components | Free | 1 dep | |
| badge-overflowbadge-overflow | diceui/radix | Components | Free | 1 dep · 2 files | |
| bannerbanner | diceui/radix | Components | Free | 1 dep | |
| checkbox-groupcheckbox-group | diceui/radix | Components | Free | 1 dep | |
| circular-progresscircular-progress | diceui/radix | Components | Free | 1 dep | |
| client-onlyclient-only | diceui/radix | Components | Free | no deps |
