(props: {
name: string;
schema: JsonSchema;
root: JsonSchema;
required: boolean;
depth: number;
isLast?: boolean;
/** Hide the required/optional badge entirely (e.g. for union variants) */
hideRequiredBadge?: boolean;
})
| 210 | // --------------------------------------------------------------------------- |
| 211 | |
| 212 | function PropertyRow(props: { |
| 213 | name: string; |
| 214 | schema: JsonSchema; |
| 215 | root: JsonSchema; |
| 216 | required: boolean; |
| 217 | depth: number; |
| 218 | isLast?: boolean; |
| 219 | /** Hide the required/optional badge entirely (e.g. for union variants) */ |
| 220 | hideRequiredBadge?: boolean; |
| 221 | }) { |
| 222 | const { name, schema, root, required, depth, hideRequiredBadge } = props; |
| 223 | const [open, setOpen] = useState(false); |
| 224 | const [resolved, setResolved] = useState<JsonSchema | null>(null); |
| 225 | |
| 226 | const expandable = isExpandable(schema, root); |
| 227 | const typeLabel = getTypeLabel(schema, root); |
| 228 | const description = |
| 229 | schemaText(schema.description) ?? |
| 230 | (schema.$ref ? schemaText(resolveRef(schema.$ref, root)?.description) : undefined); |
| 231 | |
| 232 | const handleToggle = useCallback(() => { |
| 233 | if (!open && !resolved && schema.$ref) { |
| 234 | setResolved(resolveRef(schema.$ref, root)); |
| 235 | } |
| 236 | setOpen((v) => !v); |
| 237 | }, [open, resolved, schema, root]); |
| 238 | |
| 239 | const childSchema = schema.$ref ? (resolved ?? resolveRef(schema.$ref, root) ?? schema) : schema; |
| 240 | |
| 241 | return ( |
| 242 | <div> |
| 243 | <div |
| 244 | role={expandable ? "button" : undefined} |
| 245 | tabIndex={expandable ? 0 : undefined} |
| 246 | onClick={expandable ? handleToggle : undefined} |
| 247 | onKeyDown={ |
| 248 | expandable |
| 249 | ? (e) => { |
| 250 | if (e.key === "Enter" || e.key === " ") { |
| 251 | e.preventDefault(); |
| 252 | handleToggle(); |
| 253 | } |
| 254 | } |
| 255 | : undefined |
| 256 | } |
| 257 | className={[ |
| 258 | "flex items-start gap-2 py-2.5 px-4", |
| 259 | expandable ? "cursor-pointer hover:bg-accent/40 transition-colors" : "", |
| 260 | ].join(" ")} |
| 261 | style={depth > 0 ? { paddingLeft: `${depth * 16 + 16}px` } : undefined} |
| 262 | > |
| 263 | {/* Chevron or dot */} |
| 264 | <div className="mt-0.5 flex size-4 shrink-0 items-center justify-center"> |
| 265 | {expandable ? ( |
| 266 | <ChevronRight |
| 267 | className="size-3.5 shrink-0 text-muted-foreground transition-transform duration-150" |
| 268 | style={open ? { transform: "rotate(90deg)" } : undefined} |
| 269 | /> |
nothing calls this directly
no test coverage detected