Skip to content

feat(sdk-app): code panel flyout with usage snippet#1733

Merged
jeffredodd merged 2 commits intomainfrom
feat/sdk-app-code-panel
May 8, 2026
Merged

feat(sdk-app): code panel flyout with usage snippet#1733
jeffredodd merged 2 commits intomainfrom
feat/sdk-app-code-panel

Conversation

@jeffredodd
Copy link
Copy Markdown
Contributor

@jeffredodd jeffredodd commented May 7, 2026

Summary

  • Press `?` to open a right-side flyout that shows the JSX a partner would write to use the currently rendered component, complete with import + entity IDs filled in. Copy-to-clipboard button included.
  • Snippet generation is registry-driven: `requiredEntityIds` ∪ `additionalRequiredProps` ∪ component-defaults from `component-defaults.ts` ∪ `onEvent={handleEvent}`.
  • Adds an "Anonymize IDs" toggle that swaps real IDs for `{/* TODO */}` placeholders — useful for paste-and-replace handoffs.
  • Syntax highlighting via `prism-react-renderer` (~30kB gzipped, ships its own grammar bundle, no network calls).
  • Code Panel and Settings panel are mutually exclusive — opening one closes the other.

Screenshots

Screenshot 2026-05-07 at 6 03 05 PM Screenshot 2026-05-07 at 6 02 48 PM

Why

Demos consistently need to answer "what code do I actually write to use this component?" Today that's a Storybook archaeology session. This makes the answer live + copy-pasteable while the partner is looking at the rendered component.

Test plan

  • On `/employee/Profile`, press `?` — flyout opens with import + JSX showing companyId, isAdmin, and onEvent.
  • Click "Copy" — clipboard contains the snippet.
  • Toggle "Anonymize IDs" — companyId etc. swap to `{/* TODO */}`.
  • Open Settings while Code Panel is open — Code Panel closes.
  • Press `?` while Settings is open — Settings closes, Code Panel opens.
  • Focus the sidebar search field, type `?` — the panel does NOT open and the field receives the character.
  • Press Escape with Code Panel open — closes.
  • Open Code Panel, refresh — stays open after reload.

Branch base

This branch stacks on top of `feat/sdk-app-hide-chrome-shortcut` (#1732), which stacks on `feat/sdk-app-manual-token-mode` (#1727). Re-target to `al/create-secondary-ui-components` after the upstream PRs merge.

🤖 Generated with Claude Code

@jeffredodd jeffredodd marked this pull request as ready for review May 8, 2026 01:48
Copy link
Copy Markdown
Member

@serikjensen serikjensen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! i assume this can't do real time code editing? This is a great addition on its own!

@jeffredodd jeffredodd force-pushed the feat/sdk-app-hide-chrome-shortcut branch from 26692fd to 9d86618 Compare May 8, 2026 15:44
Base automatically changed from feat/sdk-app-hide-chrome-shortcut to main May 8, 2026 15:50
Copilot AI review requested due to automatic review settings May 8, 2026 15:51
@jeffredodd jeffredodd force-pushed the feat/sdk-app-code-panel branch from 6ea619f to 0839911 Compare May 8, 2026 15:51
jeffredodd and others added 2 commits May 8, 2026 08:53
Pressing ? opens a right-side flyout that shows the JSX a partner
would write to use the currently rendered component, complete with
import statement and current entity IDs filled in. Includes a
copy-to-clipboard button and an "Anonymize IDs" toggle that swaps
real IDs for {/* TODO */} placeholders.

Snippet generation is registry-driven (requiredEntityIds +
additionalRequiredProps + component-defaults + onEvent). Syntax
highlighting uses prism-react-renderer (~30kB gzipped, ships its
own grammar bundle so no network calls).

The Code Panel and the existing Settings panel are mutually
exclusive — opening one closes the other.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replace the modal flyout with a docked, resizable side panel so the
example and snippet stay visible together. Add a Code button right of
Settings (with an active state) that toggles the panel; the existing
? shortcut still works.

Drag the left edge to resize (persisted to localStorage, min 320px,
max 85vw). Double-click the handle to reset. Remove the now-redundant
Anonymize IDs toggle since this is a demo-only environment.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jeffredodd jeffredodd force-pushed the feat/sdk-app-code-panel branch from 0839911 to 0fa9eba Compare May 8, 2026 15:54
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds new secondary UI features to the sdk-app dev shell to improve demo ergonomics: a right-side Code Panel that shows a generated JSX usage snippet for the currently-rendered SDK component, plus global keyboard shortcuts for settings/theme/mode and a chrome-hide toggle.

Changes:

  • Introduces a Code Panel (with syntax highlighting + copy-to-clipboard) and wiring to track the currently rendered component for snippet generation.
  • Adds a useGlobalShortcut hook and uses it to implement chrome hide/show, settings open, theme cycle, and mode toggle shortcuts.
  • Adds a Shortcut Helper modal UI and a sidebar “Press ? for shortcuts” hint.

Reviewed changes

Copilot reviewed 11 out of 13 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
sdk-app/src/useGlobalShortcut.ts New hook for global keyboard shortcuts with typing-target filtering and optional “mod” modifier support.
sdk-app/src/useCurrentComponent.ts Adds context + hooks for reading/registering the “currently rendered” component.
sdk-app/src/useCodePanel.ts Manages Code Panel open/close state (persisted) and binds a global toggle shortcut.
sdk-app/src/useChromeVisibility.ts Manages chrome hidden state (persisted) and binds \ + Esc shortcuts.
sdk-app/src/TopBar.tsx Adds a “Code” button to toggle the Code Panel.
sdk-app/src/TopBar.module.scss Styles the active state of the Code button.
sdk-app/src/Sidebar.tsx Adds a “Press ? for shortcuts” hint button above search.
sdk-app/src/Sidebar.module.scss Styles the shortcuts hint UI.
sdk-app/src/ShortcutHelper/useShortcutHelper.ts Adds open/close state + global shortcut bindings for the shortcuts modal.
sdk-app/src/ShortcutHelper/ShortcutHelper.tsx Adds the shortcuts modal UI and list of supported shortcuts.
sdk-app/src/ShortcutHelper/ShortcutHelper.module.scss Styles the shortcuts modal and overlay.
sdk-app/src/ShortcutHelper/index.ts Barrel exports for Shortcut Helper components/hooks.
sdk-app/src/RoutedComponentRenderer.tsx Passes chromeHidden into ComponentRenderer via outlet context.
sdk-app/src/generateSnippet.ts Registry-driven usage snippet generation (required IDs + defaults + onEvent).
sdk-app/src/CurrentComponentContext.tsx Provider implementation for the current-component context.
sdk-app/src/ComponentRenderer.tsx Registers the current component into context; hides some UI when chrome is hidden.
sdk-app/src/CodePanel.tsx Implements the right-side Code Panel with resizing, copy, and syntax highlighting.
sdk-app/src/CodePanel.module.scss Styles the Code Panel layout, header, code block, and resize handle.
sdk-app/src/assets/icons/icon-code.svg New icon for the TopBar Code button.
sdk-app/src/App.tsx Wires together chrome hiding, Code Panel, Shortcut Helper, and additional global shortcuts.
sdk-app/src/app.scss Adds styling for the “Show chrome” restore pill.
package.json Adds prism-react-renderer dependency for syntax highlighting.
package-lock.json Locks prism-react-renderer (and transitive typings) into the dependency tree.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +49 to +55
useGlobalShortcut({
key: TOGGLE_KEY,
onTrigger: event => {
event.preventDefault()
toggle()
},
})
Comment thread sdk-app/src/CodePanel.tsx
Comment on lines +133 to +142
<div className={styles.subheader}>
<span className={styles.componentLabel}>
{current.entry.category}.{current.entry.name}
</span>
<div className={styles.actions}>
<button className={styles.copyBtn} onClick={handleCopy} type="button">
{copyState === 'copied' ? 'Copied' : 'Copy'}
</button>
</div>
</div>
Comment thread sdk-app/src/CodePanel.tsx
Comment on lines +50 to +61
const handleCopy = async () => {
if (!snippet) return
try {
await navigator.clipboard.writeText(snippet)
setCopyState('copied')
setTimeout(() => {
setCopyState('idle')
}, 1500)
} catch {
// Clipboard unavailable
}
}
Comment thread sdk-app/src/CodePanel.tsx
Comment on lines +65 to +71
const handleResizePointerDown = useCallback((e: ReactPointerEvent<HTMLDivElement>) => {
e.preventDefault()
isResizingRef.current = true
;(e.target as HTMLElement).setPointerCapture(e.pointerId)
document.body.style.cursor = 'col-resize'
document.body.style.userSelect = 'none'
}, [])
Comment thread sdk-app/src/App.tsx
<TopBar
companyId={activeEntities.companyId}
<CurrentComponentProvider>
<div className={`app-layout${chromeHidden ? ' app-layout-chrome-hidden' : ''}`}>
Comment thread sdk-app/src/App.tsx
Comment on lines +91 to +99
useEffect(() => {
if (codePanel.isOpen && settingsOpen) setSettingsOpen(false)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [codePanel.isOpen])

useEffect(() => {
if (settingsOpen && codePanel.isOpen) codePanel.close()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [settingsOpen])
@jeffredodd jeffredodd merged commit e298d76 into main May 8, 2026
19 checks passed
@jeffredodd jeffredodd deleted the feat/sdk-app-code-panel branch May 8, 2026 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants