Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

feat(control-ui): add a collapsible variant to FormSection

Andy Pavia191c75040839
diff --git a/control-ui/app/globals.css b/control-ui/app/globals.css
index 911dc9cb0..b031b9302 100644
--- a/control-ui/app/globals.css
+++ b/control-ui/app/globals.css
@@ -623,6 +623,63 @@ body.cu-body {
line-height: 1.5;
}
+/* Disclosure variant: the title becomes the toggle, so a collapsed section
+ costs a single line. The chevron points right when closed and rotates down
+ when open, matching the other disclosures in the app. */
+.cu-form-section__toggle {
+ display: inline-flex;
+ align-items: center;
+ gap: var(--cu-space-1);
+ width: 100%;
+ padding: 0;
+ border: 0;
+ background: transparent;
+ color: inherit;
+ font: inherit;
+ text-align: left;
+ cursor: pointer;
+}
+
+.cu-form-section__toggle:focus-visible {
+ outline: 2px solid rgba(var(--cu-focus-rgb), 0.8);
+ outline-offset: 3px;
+ border-radius: calc(var(--cu-radius-sm) / 2);
+}
+
+.cu-form-section__toggle svg {
+ flex: none;
+ color: var(--cu-text-muted);
+ transition: transform var(--cu-control-transition) ease;
+}
+
+.cu-form-section__toggle svg.is-expanded {
+ transform: rotate(90deg);
+}
+
+.cu-form-section__content {
+ display: grid;
+ gap: var(--cu-space-3);
+}
+
+/* A labelled group of related controls inside one section — a fieldset so the
+ legend names the group for assistive tech, with the browser's default
+ fieldset chrome removed. */
+.cu-form-section__group {
+ display: grid;
+ gap: var(--cu-space-2);
+ min-width: 0;
+ margin: 0;
+ padding: 0;
+ border: 0;
+}
+
+.cu-form-section__subheading {
+ padding: 0;
+ color: var(--cu-text);
+ font-size: 0.875rem;
+ font-weight: 600;
+}
+
.cu-checkbox-field {
display: flex;
gap: var(--cu-space-2);
diff --git a/control-ui/components/__tests__/FormSection.test.tsx b/control-ui/components/__tests__/FormSection.test.tsx
new file mode 100644
index 000000000..93362a59c
--- /dev/null
+++ b/control-ui/components/__tests__/FormSection.test.tsx
@@ -0,0 +1,57 @@
+import { afterEach, describe, expect, it } from 'vitest'
+import { cleanup, fireEvent, render, screen } from '@testing-library/react'
+import { FormSection } from '../ui'
+
+afterEach(cleanup)
+
+describe('FormSection', () => {
+ it('renders its content directly when it is not collapsible', () => {
+ render(
+ <FormSection title="Execution" description="How this hook is ordered and fails.">
+ <p>order field</p>
+ </FormSection>
+ )
+ expect(screen.getByText('order field')).toBeInTheDocument()
+ expect(screen.getByText('How this hook is ordered and fails.')).toBeInTheDocument()
+ // No disclosure is introduced for the default form section.
+ expect(screen.queryByRole('button')).toBeNull()
+ })
+
+ it('collapses to the title alone, and the toggle reveals the content', () => {
+ render(
+ <FormSection title="Advanced details" description="Rarely changed." collapsible>
+ <p>order field</p>
+ </FormSection>
+ )
+
+ const toggle = screen.getByRole('button', { name: 'Advanced details' })
+ expect(toggle).toHaveAttribute('aria-expanded', 'false')
+ // Collapsed costs one line: neither the body nor the description renders.
+ expect(screen.queryByText('order field')).toBeNull()
+ expect(screen.queryByText('Rarely changed.')).toBeNull()
+
+ fireEvent.click(toggle)
+ expect(toggle).toHaveAttribute('aria-expanded', 'true')
+ expect(screen.getByText('order field')).toBeInTheDocument()
+ expect(screen.getByText('Rarely changed.')).toBeInTheDocument()
+
+ fireEvent.click(toggle)
+ expect(toggle).toHaveAttribute('aria-expanded', 'false')
+ expect(screen.queryByText('order field')).toBeNull()
+ })
+
+ it('starts open when defaultOpen is set, and points the toggle at its content', () => {
+ render(
+ <FormSection title="Advanced details" collapsible defaultOpen>
+ <p>order field</p>
+ </FormSection>
+ )
+ const toggle = screen.getByRole('button', { name: 'Advanced details' })
+ expect(toggle).toHaveAttribute('aria-expanded', 'true')
+ expect(screen.getByText('order field')).toBeInTheDocument()
+ // aria-controls has to resolve to the element actually holding the content.
+ const controlled = document.getElementById(toggle.getAttribute('aria-controls') ?? '')
+ expect(controlled).not.toBeNull()
+ expect(controlled).toHaveTextContent('order field')
+ })
+})
diff --git a/control-ui/components/ui/index.tsx b/control-ui/components/ui/index.tsx
index d7a85e209..1a3737bbb 100644
--- a/control-ui/components/ui/index.tsx
+++ b/control-ui/components/ui/index.tsx
@@ -1,6 +1,7 @@
'use client'
import React from 'react'
+import { IconChevronRight } from '@components/icons'
import { cn } from '@lib/cn'
import type {
ButtonProps,
@@ -53,14 +54,50 @@ export function Field({ children, description, error, htmlFor, label, required }
)
}
-export function FormSection({ children, description, title }: FormSectionProps) {
+export function FormSection({
+ children,
+ description,
+ title,
+ collapsible = false,
+ defaultOpen = false,
+}: FormSectionProps) {
+ const [open, setOpen] = React.useState(defaultOpen)
+ const contentId = React.useId()
+
+ if (!collapsible) {
+ return (
+ <section className="cu-form-section">
+ <div className="cu-form-section__header">
+ <h3 className="cu-form-section__title">{title}</h3>
+ {description ? <p className="cu-form-section__description">{description}</p> : null}
+ </div>
+ {children}
+ </section>
+ )
+ }
+
+ // Collapsed stays a single line: the description rides with the content it
+ // explains rather than adding a second line to the closed state.
return (
<section className="cu-form-section">
- <div className="cu-form-section__header">
- <h3 className="cu-form-section__title">{title}</h3>
- {description ? <p className="cu-form-section__description">{description}</p> : null}
- </div>
- {children}
+ <h3 className="cu-form-section__title">
+ <button
+ type="button"
+ className="cu-form-section__toggle"
+ aria-expanded={open}
+ aria-controls={contentId}
+ onClick={() => setOpen(value => !value)}
+ >
+ <IconChevronRight className={open ? 'is-expanded' : undefined} width={18} height={18} />
+ {title}
+ </button>
+ </h3>
+ {open ? (
+ <div className="cu-form-section__content" id={contentId}>
+ {description ? <p className="cu-form-section__description">{description}</p> : null}
+ {children}
+ </div>
+ ) : null}
</section>
)
}
diff --git a/control-ui/components/ui/types.ts b/control-ui/components/ui/types.ts
index 7b43c7930..7a444421e 100644
--- a/control-ui/components/ui/types.ts
+++ b/control-ui/components/ui/types.ts
@@ -28,6 +28,11 @@ export type FormSectionProps = {
children: ReactNode
description?: ReactNode
title: ReactNode
+ // Renders the section behind a disclosure toggle, for settings that most
+ // installs leave alone. Collapsed shows the title only, so the section costs
+ // one line until someone opens it.
+ collapsible?: boolean
+ defaultOpen?: boolean
}
export type TextInputProps = InputHTMLAttributes<HTMLInputElement> & {
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index 5037093b5..4ac83d4a1 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.449",
+ "version": "0.1.450",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.449",
+ "version": "0.1.450",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/llm-providers": "file:../packages/llm-providers",
diff --git a/control-ui/package.json b/control-ui/package.json
index 40c5592f7..5fef329e3 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.449",
+ "version": "0.1.450",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",