Using SlideCode for syntax-highlighted code examples in your presentations
The SlideCode component provides syntax-highlighted code blocks powered by highlight.js. Language is automatically inferred from the file extension in the title prop.
Use SlideColumns to show code blocks side by side:
slides.tsx
import { Slide, SlideBadge, SlideTitle, SlideSubtitle, SlideColumns, SlideCode, SlideNote,} from 'nextjs-slides';<Slide key="columns" align="left"> <SlideBadge>SlideColumns</SlideBadge> <SlideTitle className="text-3xl sm:text-4xl md:text-5xl"> Title + two columns </SlideTitle> <SlideSubtitle> Inline two-column grid for use inside Slide, when you need a spanning title above the columns </SlideSubtitle> <SlideColumns left={ <SlideCode title="slide.tsx">{`<Slide> <SlideTitle>Two columns</SlideTitle> <SlideColumns left={...} right={...} /></Slide>`}</SlideCode> } right={ <SlideCode title="slide.tsx">{`<SlideColumns left={<SlideCode>...</SlideCode>} right={<SlideList>...</SlideList>}/>`}</SlideCode> } /> <SlideNote> Props: left, right, className · Unlike SlideSplitLayout, this is a child component, not a full-viewport slide </SlideNote></Slide>
<SlideCode title="component.tsx">{`interface Props {name: string;age: number;}export function User({ name, age }: Props) {return <div>{name} is {age} years old</div>;}`}</SlideCode>
<SlideCode title="helper.js">{`export function formatDate(date) {return new Intl.DateTimeFormat('en-US').format(date);}export function capitalize(str) {return str.charAt(0).toUpperCase() + str.slice(1);}`}</SlideCode>
Use SlideSplitLayout for full-viewport split between description and code:
slides.tsx
import { SlideSplitLayout, SlideBadge, SlideTitle, SlideSubtitle, SlideCode,} from 'nextjs-slides';<SlideSplitLayout key="split-code" left={ <> <SlideBadge>Pattern</SlideBadge> <SlideTitle className="text-3xl sm:text-4xl md:text-5xl"> Explanation + source </SlideTitle> <SlideSubtitle> Use SlideSplitLayout to pair explanatory content with code examples </SlideSubtitle> </> } right={ <SlideCode title="Counter.tsx">{`'use client';import { useState } from 'react';export function Counter() { const [count, setCount] = useState(0); return ( <button onClick={() => setCount(c => c + 1)}> Count: {count} </button> );}`}</SlideCode> }/>
SlideSplitLayout is a full-viewport component. Do not nest it inside <Slide>. Use <SlideColumns> inside <Slide> instead if you need a title above the columns.