Breakpoint Display
abui/breakpoint-displayFreeComponent
A breakpoint display component.
Live preview
live · rendered by the registry
Rendered by abui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://abui.io/r/breakpoint-display.jsonSource
1"use client"23import * as React from "react"4import { cva, type VariantProps } from "class-variance-authority"56import { cn } from "@/lib/utils"78const breakpointDisplayVariants = cva(9 "pointer-events-none select-none bg-foreground text-background px-2 py-1 z-50 rounded-b",10 {11 variants: {12 position: {13 fixed: "fixed top-0 right-[50%] translate-x-1/2",14 relative: "relative",15 absolute: "absolute top-0 right-[50%] translate-x-1/2",16 },17 },18 defaultVariants: {19 position: "fixed",20 },21 },22)2324// Canonical ordering of breakpoints from smallest to largest25// This defines the semantic order - actual pixel values are defined in Tailwind config26const BREAKPOINT_ORDER = ["xxs", "xs", "sm", "md", "lg", "xl", "2xl", "3xl"] as const2728type BreakpointKey = (typeof BREAKPOINT_ORDER)[number]2930// Map breakpoint keys to their display labels31const BREAKPOINT_LABELS: Record<BreakpointKey, string> = {32 xxs: "XXS",33 xs: "XS",34 sm: "SM",35 md: "MD",36 lg: "LG",37 xl: "XL",38 "2xl": "2XL",39 "3xl": "3XL",40}4142// Default Tailwind breakpoints (standard v3/v4)43const DEFAULT_BREAKPOINTS: BreakpointKey[] = ["sm", "md", "lg", "xl", "2xl"]4445interface BreakpointDisplayProps46 extends React.HTMLAttributes<HTMLDivElement>,47 VariantProps<typeof breakpointDisplayVariants> {48 /**49 * Additional breakpoints to include beyond the default Tailwind breakpoints.50 * These will be automatically sorted by semantic order (xxs < xs < sm < md < lg < xl < 2xl < 3xl).51 * Actual pixel values are defined in your Tailwind configuration.52 * @example extraBreakpoints={["xxs", "xs", "3xl"]}53 */54 extraBreakpoints?: BreakpointKey[]55}5657function BreakpointDisplay({ className, position, extraBreakpoints = [], ...props }: BreakpointDisplayProps) {58 // Combine default and extra breakpoints, remove duplicates, and sort by semantic order59 const activeBreakpoints = React.useMemo(() => {60 const combined = [...DEFAULT_BREAKPOINTS, ...extraBreakpoints]61 const unique = Array.from(new Set(combined))6263 // Sort by their position in the canonical BREAKPOINT_ORDER array64 return unique.sort((a, b) => {65 return BREAKPOINT_ORDER.indexOf(a) - BREAKPOINT_ORDER.indexOf(b)66 })67 }, [extraBreakpoints])6869 // Create a Set for O(1) lookup70 const activeSet = React.useMemo(() => new Set(activeBreakpoints), [activeBreakpoints])7172 // Determine the first and last active breakpoints73 const firstBreakpoint = activeBreakpoints[0]74// … truncated
Files it writes
More from abui
All 20 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordion Multiselectaccordion-multiselect | abui | Components | Free | 3 deps | |
| Color Swatch Selectorcolor-swatch-selector | abui | Components | Free | no deps | |
| Label Selectorlabel-selector | abui | Components | Free | 2 deps | |
| Radio Rowsradio-rows | abui | Components | Free | no deps | |
| Radio Tabsradio-tabs | abui | Components | Free | no deps | |
| Scroll Progressscroll-progress | abui | Components | Free | 1 dep | |
| Spinnerspinner | abui | Components | Free | 1 dep | |
| Text Gradienttext-gradient | abui | Components | Free | no deps |
