shadcn.io is not affiliated with official shadcn/ui
Split Code Preview Hero Block for React
A reverse split hero for a job-queue SDK: a code window in a hairline frame with a copy button, beside the headline, three checks and two calls to action.
Installation
Overview
A reverse split hero for API products and SDKs that lets the code make the pitch. The code window sits on the start side in a hairline frame with + marks on its corners; across a solid divider, on the end side, are a bold two-line headline, a subtitle, three checks and two calls to action (a Shine Button and an outline Button). The window has a file tab and a copy button, and a short TypeScript snippet, the install comment and three lines of code, comes in token by token, coloured like an editor. It's written for Tern, a made-up job-queue SDK. It's built from Guides, Shine Button, Button, Copy Button and Syntax Text, with CSS transitions for the entrance and your theme's tokens for every colour. The page follows your theme, light or dark; only the code window is always dark, like a terminal. For API products, developer SDKs, CLI tools and any landing page where how little code it takes is the selling point.
FAQ
How do I change the code in the window?
Edit CODE at the top of the file: it's the snippet as you'd write it, its lines and indentation kept, and it's also exactly what the copy button copies. Syntax Text colours it as it renders (comments, strings, numbers, keywords and punctuation). FILE is the name in the tab, and it names the code for screen readers. Keep it short enough to match the headline's promise; for another language than JavaScript or TypeScript, pass Syntax Text that language's keywords.
What does the copy button copy, and how does it confirm?
It copies CODE, the whole snippet, to the clipboard. Its icon turns into a check for three seconds and screen readers hear "Copied"; if the browser refuses, which happens on a page not served over HTTPS, it shows a cross and says "Couldn't copy". To copy something else, such as only the install command, pass that text as its content.
Why is the code window dark when the rest of the hero follows the theme?
A code window is dark by nature, like a terminal, so only the window carries the dark class: everything inside it reads your theme's dark tokens, with no overrides. The headline, the checks, the buttons, the frame and the page's lines follow the theme, light or dark. A comment in the file says so. Remove the dark class for a window that follows the page too.
How are the lines drawn?
The section is the page's spine: solid side rails and a top rule running to the viewport edges with + marks. The code is a framed figure: Guides with extend="sm" and marks="corners" draw a hairline box with + marks around the window. The text column is the split divider: lg:border-s, with + marks where it meets the top rule.
Can screen reader and keyboard users read and copy the code?
Yes. The snippet is real text, read as written and selectable, in a region named after the file that Tab can reach, so a line wider than the window can be scrolled with the arrow keys. Only the window's dots and tab are hidden from assistive tech; the copy button is a real button named "Copy the code", and it announces the result. The headline is the page's h1, and with reduced motion nothing fades in or scales.
How does it fit on a phone?
Below the lg breakpoint the two halves stack with the copy first, so the Shine Button sits on the first screen, then the framed code window under one rule. The headline steps down from text-5xl to text-4xl, the buttons wrap when they don't fit side by side, and the code drops to 12px. A line longer than the window scrolls sideways inside it rather than wrapping.
When should I use this instead of a centred code hero?
Use this split layout when you have a value proposition to make beside the code: a headline, a few checks and two calls to action. Use a centred hero such as Dark Code Window or Code Snippet when the code, or the install command, is the whole message and deserves the middle of the page.
Related
- Pro
Code Window Hero
Code and terminalA split hero for an API client generator on solid rails: a headline and a Shine Button beside a code window whose snippet comes in token by token, in a hairline frame with + marks.
- Pro
Install Command Snippet Hero
Code and terminalA compact centred hero for a web framework: an install command with a copy button, two calls to action and a band of three stats.
- Pro
Split Layout Dark Terminal Hero
Code and terminalA split hero for an API: the headline, a Shine Button and three ticks beside a dark terminal with a request, a status and a JSON response that writes itself out, above a band of three figures.
- Pro
Install Command Hero
Code and terminalA compact centred hero for an open-source library with a star count pill, an install command to copy, a Shine Button, a GitHub star button and a ruled band of the repository's stats at the foot.
- Pro
Split API Playground Hero
Code and terminalA showcase hero for a payments API: a headline, a Shine Button, a second action and three ticks, then a wide playground under its own rule: a POST request beside the 200 response, each JSON body writing itself out.
- Pro
Terminal Copy Command Hero
Code and terminalA split hero for a project scaffolder: text with a Shine Button and three stats on a ruled row, and a terminal in a hairline frame that shows the install command with a copy button and what it set up.