@property Syntax Editor
ridiculous/property-syntax-editorFreeComponent
Ridiculously typed editor for the CSS @property syntax: descriptor. The namesake types one CSS string with another — InitialValueLiteral<Syntax, V> checks an initial-value against the validated syntax, so cssProperty("<length>", "red") is a compile error. A chip builder sits beside a live green/red demo.
Install it
npx shadcn@latest add http://ridiculous.turtlesocks.dev/r/property-syntax-editor.jsonSource
1"use client"23import { useEffect, useRef, useState } from "react"4import { Button } from "@/components/ui/button"5import {6 Popover,7 PopoverContent,8 PopoverTrigger,9} from "@/components/ui/popover"10import { cn } from "@/lib/utils"11import { InitialValueField } from "./initial-value-field"12import {13 defaultInitialValue,14 formatSyntax,15 parseSyntax,16} from "./property-syntax-editor.helpers"17import type {18 PropertySyntaxState,19 SyntaxString,20} from "./property-syntax-editor.types"21import { SyntaxChipBuilder } from "./syntax-chip-builder"2223// Re-export the public sub-components + their prop types so consumers (and the24// barrel) can import them from `./property-syntax-editor`.25export type { InitialValueFieldProps } from "./initial-value-field"26export { InitialValueField } from "./initial-value-field"27export type { MiniSelectProps } from "./mini-select"28export { MiniSelect } from "./mini-select"29export type { SyntaxChipBuilderProps } from "./syntax-chip-builder"30export { SyntaxChipBuilder } from "./syntax-chip-builder"3132// ---------------------------------------------------------------------------33// value string ⇄ editor state34// ---------------------------------------------------------------------------3536function deriveState(37 value: string,38 prev?: PropertySyntaxState,39): PropertySyntaxState {40 const { universal, components } = parseSyntax(value)41 return {42 universal,43 components,44 initialValue: prev?.initialValue ?? defaultInitialValue(value),45 inherits: prev?.inherits ?? false,46 }47}4849// ---------------------------------------------------------------------------50// Props51// ---------------------------------------------------------------------------5253export interface PropertySyntaxEditorPanelProps {54 value: SyntaxString | (string & {})55 onChange: (value: SyntaxString) => void56 className?: string57 "aria-label"?: string58}5960export interface PropertySyntaxEditorProps61 extends PropertySyntaxEditorPanelProps {}6263// ---------------------------------------------------------------------------64// PropertySyntaxEditor — popover-wrapped65// ---------------------------------------------------------------------------6667export function PropertySyntaxEditor(props: PropertySyntaxEditorProps) {68 const {69 value,70 className,71 "aria-label": ariaLabel = "Edit a CSS @property syntax descriptor",72 } = props7374 return (75 <Popover>76 <PopoverTrigger asChild>77 <Button78 variant="outline"79// … truncated
What it pulls in
Other registry items
Files it writes
More from ridiculous
All 22 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| All ridiculous componentsall | ridiculous | Components | Free | no deps | |
| Anchor Position Editoranchor-position-editor | ridiculous | Components | Free | no deps · 9 files | |
| Background Editorbackground-editor | ridiculous | Components | Free | no deps · 9 files | |
| Box Shadow Editorbox-shadow-editor | ridiculous | Components | Free | no deps · 7 files | |
| Calc Editorcalc-editor | ridiculous | Components | Free | no deps · 4 files | |
| Clip Path Editorclip-path-editor | ridiculous | Components | Free | no deps · 20 files | |
| Color Functioncolor-function | ridiculous | Components | Free | no deps · 10 files | |
| Color Pickercolor-picker | ridiculous | Components | Free | no deps · 11 files |
