BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/ridiculous/if-function

if() Conditional Value

ridiculous/if-function
FreeComponent

Ridiculously typed editor for the CSS if() conditional value function. Validates the wrapper, splits branches, checks each condition kind (media/supports/style/else), and enforces else-last. Ships a popover branch-builder UI with a live preview.

Install it

npx shadcn@latest add http://ridiculous.turtlesocks.dev/r/if-function.json

Source

src/components/ui/if-function/if-function.tsxridiculous.turtlesocks.dev/r/if-function.json · first 6 KB
1"use client"
2
3import { useEffect, useRef, useState } from "react"
4import { Button } from "@/components/ui/button"
5import { Input } from "@/components/ui/input"
6import {
7 Popover,
8 PopoverContent,
9 PopoverTrigger,
10} from "@/components/ui/popover"
11import { cn } from "@/lib/utils"
12import {
13 branchCount,
14 defaultBranch,
15 formatIf,
16 parseIf,
17} from "./if-function.helpers"
18import type {
19 ConditionKind,
20 IfBranch,
21 IfFunctionString,
22} from "./if-function.types"
23
24// ---------------------------------------------------------------------------
25// Shared constants
26// ---------------------------------------------------------------------------
27
28const ALL_KINDS: readonly ConditionKind[] = [
29 "media",
30 "supports",
31 "style",
32 "else",
33]
34
35const CONDITION_PLACEHOLDER: Record<ConditionKind, string> = {
36 media: "width >= 600px",
37 supports: "display: grid",
38 style: "--x: 1",
39 else: "",
40}
41
42// ---------------------------------------------------------------------------
43// Props
44// ---------------------------------------------------------------------------
45
46export interface IfFunctionPanelProps {
47 value: IfFunctionString | (string & {})
48 onChange: (value: IfFunctionString) => void
49 className?: string
50 "aria-label"?: string
51}
52
53export type IfFunctionProps = IfFunctionPanelProps
54
55// ---------------------------------------------------------------------------
56// IfFunction — popover-wrapped
57// ---------------------------------------------------------------------------
58
59export function IfFunction(props: IfFunctionProps) {
60 const {
61 value,
62 className,
63 "aria-label": ariaLabel = "Edit a CSS if() conditional value",
64 } = props
65 const count = branchCount(String(value))
66
67 return (
68 <Popover>
69 <PopoverTrigger asChild>
70 <Button
71 variant="outline"
72 className={cn("h-9 gap-2 px-3 font-mono", className)}
73 aria-label={ariaLabel}
74 >
75 <span className="text-[10px] text-muted-foreground uppercase">
76 if
77 </span>
78 <span className="text-[10px] text-muted-foreground">
79 {count} {count === 1 ? "branch" : "branches"}
80 </span>
81 <span className="max-w-[200px] truncate text-xs">{value}</span>
82 </Button>
83 </PopoverTrigger>
84 <PopoverContent className="w-auto p-0" align="start">
85 <IfFunctionPanel {...props} />
86 </PopoverContent>
87 </Popover>
88 )
89}
90
91// ---------------------------------------------------------------------------
92// … truncated

What it pulls in

Other registry items

  • ridiculous-type-kit
  • button
  • popover
  • input

Files it writes

  • src/components/ui/if-function/index.ts
  • src/components/ui/if-function/if-function.tsx
  • src/components/ui/if-function/if-function.types.ts
  • src/components/ui/if-function/if-function.helpers.ts

Facts

Registry
ridiculous
Type
registry:ui
Access
Free
Files written
4
Licence
MIT
First indexed
2026-08-02
Last confirmed
yesterday

Go to the source

ridiculous.turtlesocks.dev TurtIeSocks/ridiculous on GitHub Raw registry item This item as JSON

More from ridiculous

All 22 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
All ridiculous componentsallridiculousComponentsFreeno deps
Anchor Position Editoranchor-position-editorridiculousComponentsFreeno deps · 9 files
Background Editorbackground-editorridiculousComponentsFreeno deps · 9 files
Box Shadow Editorbox-shadow-editorridiculousComponentsFreeno deps · 7 files
Calc Editorcalc-editorridiculousComponentsFreeno deps · 4 files
Clip Path Editorclip-path-editorridiculousComponentsFreeno deps · 20 files
Color Functioncolor-functionridiculousComponentsFreeno deps · 10 files
Color Pickercolor-pickerridiculousComponentsFreeno deps · 11 files
BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex