# CP UI Patterns — Visual Patterns, Conditions, Assets Battle-tested CP patterns from Craft core and first-party plugins, plus condition builders and asset bundles. For CP templates, form macros, settings pages, and navigation, see `cp.md`. For dashboard widgets, utilities, slideouts, and ajax, see `cp-components.md`. ## Contents - CP UI Patterns — tri-state inheritance, status indicators (`on`/`off` + distinct red statuses), field warnings, semantic CSS tokens (color/status/spacing/radius/control/focus/fonts), `[hidden]` gotcha, platform PHP mismatch - Condition Builders — BaseCondition, custom condition rules, rule input HTML, rendering in templates, registration - Asset Bundles — CP asset bundle, JS configuration injection, registration - CP Markup Patterns — sidebar badges, notice/warning blocks, tip/warning on form fields - Element Edit Screen — sidebar panels (`.meta` vs `.meta read-only`), `metaFieldsHtml()` override, top-toolbar split button (`EVENT_DEFINE_SIDEBAR_HTML` / `EVENT_DEFINE_ADDITIONAL_BUTTONS`) - CP Screen Composition — native UX defaults: never improvise CP UI (copy the core/vendor idiom), tabs + the namespace/id tab trap, lightswitches vs checkboxes, two-layer field guidance (`instructions` + ``), cross-setting callout markup, env-var numerics, VueAdminTable for unbounded lists, index-screen column scheme + disclosure-menu row actions, native stats, honest empty values, `.status-badge` is a draft indicator (not an empty-value badge) ## CP UI Patterns Check this section before building custom CP UI — most non-trivial patterns already exist. ### Tri-State Inheritance Controls The `craftcms/webhooks` plugin (3.x branch, `_manage/edit.html`) is the reference implementation for "off / inherit / on" controls in table rows. Key details: - Buttons use `
` not `
``` Register it (use a unique menu `id` per element so multiple instances don't collide): ```php use craft\web\View; Event::on( Entry::class, Element::EVENT_DEFINE_ADDITIONAL_BUTTONS, function(DefineHtmlEvent $event) { $entry = $event->sender; $event->html .= Craft::$app->getView()->renderTemplate( 'my-plugin/_components/toolbar-button', [ 'elementId' => $entry->id, 'exportUrl' => "my-plugin/export?elementId=$entry->id", ], View::TEMPLATE_MODE_CP, ); }, ); ``` Markup details that matter: - **Menu items must be `
  • ` inside `