Updated
Disabled Reason
NewCustomize
Show for2.4s
Top
Medium
Radius12px
Installation
npx shadcn@latest add https://uibrik.com/r/disabled-reason.jsonInstall the packages
npm install motionAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Copy the source into your project
components/uibrik/disabled-reason/disabled-reason.tsx"use client"; import { AnimatePresence, motion, useAnimationControls, useReducedMotion } from "motion/react"; import { useEffect, useId, useRef, useState, type ReactNode } from "react"; import { cn } from "@/lib/utils"; const EASE_OUT: [number, number, number, number] = [0.23, 1, 0.32, 1]; const SIZES = { sm: { height: 32, padX: 12, font: 13 }, md: { height: 40, padX: 16, font: 14 }, lg: { height: 48, padX: 20, font: 15 }, } as const; export type DisabledReasonProps = { children?: ReactNode; /** Blocks the action; pressing explains why instead of doing nothing. */ disabled?: boolean; /** Why the button is blocked, shown above it on press. */ reason?: string; /** Id of the field to fix: it takes focus and flashes a ring when the blocked button is pressed. */ targetId?: string; /** Seconds the reason stays up. */ showFor?: number;
Adds the files to
components/uibrik/disabled-reason and installs motion. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/disabled-reason.Usage
import { DisabledReason } from "@/components/uibrik/disabled-reason/disabled-reason";<DisabledReason children="Continue" reason="Add your email first" showFor={2.4} side="top" size="md" radius={12} disabled type="button" onClick={() => {}} onBlocked={() => {}} // targetId="…"/>Where to use Disabled Reason
Forms with required fields
Pressing the greyed-out button points straight at the missing field instead of doing nothing.
Pairs with Multi-step Form and Auth Forms
Plan and permission limits
The reason can say a feature needs another plan or an admin, right where people tried to use it.
Pairs with Permissions Matrix
Checkout steps
A blocked Pay button explains what's left, like choosing a shipping option, so buyers don't stall.
Pairs with Checkout Flow
Props
DisabledReason- children
- Type string
- "Continue"
- Button text.
- reason
- Type string
- "Add your email first"
- Why the button is blocked, shown on press.
- showFor
- Type number
- 2.4
- How long the reason stays up.
- side
- Type "top" | "bottom"
- "top"
- Where the reason appears.
- size
- Type "sm" | "md" | "lg"
- "md"
- Height, padding and text size.
- radius
- Type number
- 12
- Corner radius.
- disabled
- Type boolean
- true
- Blocks the action; a press explains why instead.
- targetId
- Type string
- –
- Id of the field to fix; it takes focus and flashes a ring.
- onClick
- Type () => void
- –
- Called on press while allowed.
- onBlocked
- Type () => void
- –
- Called on press while blocked.
- type
- Type "button" | "submit"
- "button"
- Button type while allowed.
- className
- Type string
- –
- Classes for the wrapper.