- Docs
- Components
- Interface
- Product Mockups
- Code Morph
A code window that morphs between snippets, token by token
| Name | Type | Default | Description |
|---|---|---|---|
steps | CodeMorphStep[] | counter example | The snippets to morph between. Each step is { code, label?, file?, language?, highlight? }. label names the tab, file is shown in the window title, and highlight focuses lines, as an array of line numbers or a string like "2-4, 7". |
language | "tsx" | "python" | "json" | "css" | "bash" | "tsx" | Language used to highlight steps that do not set their own. tsx covers JavaScript, TypeScript and JSX. |
chrome | "tabs" | "window" | "none" | "tabs" | Tabs shows a clickable tab per step, window shows the dots and the file name, none removes the title bar. |
frame | "solid" | "inset" | "inset" | Solid draws one surface. Inset puts the title bar on a tinted frame and sets the code in its own rounded panel, with corners concentric to the frame. |
dots | "mono" | "color" | "mono" | Window dots in quiet grey, or the classic red, yellow and green. |
theme | "auto" | "light" | "dark" | "auto" | Auto picks a light or dark window from the colour behind it, so it follows your site theme. |
accentColor | string | theme violet | Colour of keywords, the active tab and the focus band. |
windowColor | string | from theme | Background of the window. |
textColor | string | from theme | Colour of plain code. |
fontFamily | string | system monospace | Font of the code. Uses your --font-mono variable when it exists. |
fontSize | number | 13 | Font size in pixels. |
lineHeight | number | 1.7 | Line height as a multiple of the font size. |
radius | number | 16 | Corner radius of the window in pixels. |
height | number | "auto" | "auto" | Auto sizes the window to the longest step, so it never jumps between steps. |
lineNumbers | boolean | true | Shows line numbers in a gutter. |
focus | boolean | true | Dims the lines outside a step's highlight and marks the highlighted lines with a band. |
fit | boolean | true | Scales the code down to fit narrow containers. When off, long lines fade out at the right edge. |
duration | number | 800 | Length of the morph in milliseconds. |
interval | number | 4200 | Milliseconds each step stays on screen while autoplaying. |
autoplay | boolean | true | Advances through the steps on its own while the window is in view. |
loop | boolean | true | Returns to the first step after the last. |
pauseOnHover | boolean | true | Holds the current step while the pointer is over the window. |
copyable | boolean | true | Shows a button that copies the current step's code. |
defaultStep | number | 0 | Step shown first. |
onStepChange | (index: number) => void | — | Called whenever the window morphs to another step. |
ref | { next, prev, goTo, play, pause } | — | Controls the steps, for example to sync them with your own copy. |
className | string | — | Classes for the window. |
style | CSSProperties | — | Inline styles for the window. |
stepsCodeMorphStep[]The snippets to morph between. Each step is { code, label?, file?, language?, highlight? }. label names the tab, file is shown in the window title, and highlight focuses lines, as an array of line numbers or a string like "2-4, 7".
counter examplelanguage"tsx" | "python" | "json" | "css" | "bash"Language used to highlight steps that do not set their own. tsx covers JavaScript, TypeScript and JSX.
"tsx"chrome"tabs" | "window" | "none"Tabs shows a clickable tab per step, window shows the dots and the file name, none removes the title bar.
"tabs"frame"solid" | "inset"Solid draws one surface. Inset puts the title bar on a tinted frame and sets the code in its own rounded panel, with corners concentric to the frame.
"inset"dots"mono" | "color"Window dots in quiet grey, or the classic red, yellow and green.
"mono"theme"auto" | "light" | "dark"Auto picks a light or dark window from the colour behind it, so it follows your site theme.
"auto"accentColorstringColour of keywords, the active tab and the focus band.
theme violetwindowColorstringBackground of the window.
from themetextColorstringColour of plain code.
from themefontFamilystringFont of the code. Uses your --font-mono variable when it exists.
system monospacefontSizenumberFont size in pixels.
13lineHeightnumberLine height as a multiple of the font size.
1.7radiusnumberCorner radius of the window in pixels.
16heightnumber | "auto"Auto sizes the window to the longest step, so it never jumps between steps.
"auto"lineNumbersbooleanShows line numbers in a gutter.
truefocusbooleanDims the lines outside a step's highlight and marks the highlighted lines with a band.
truefitbooleanScales the code down to fit narrow containers. When off, long lines fade out at the right edge.
truedurationnumberLength of the morph in milliseconds.
800intervalnumberMilliseconds each step stays on screen while autoplaying.
4200autoplaybooleanAdvances through the steps on its own while the window is in view.
trueloopbooleanReturns to the first step after the last.
truepauseOnHoverbooleanHolds the current step while the pointer is over the window.
truecopyablebooleanShows a button that copies the current step's code.
truedefaultStepnumberStep shown first.
0onStepChange(index: number) => voidCalled whenever the window morphs to another step.
—ref{ next, prev, goTo, play, pause }Controls the steps, for example to sync them with your own copy.
—classNamestringClasses for the window.
—styleCSSPropertiesInline styles for the window.
—