βοΈβReact API
Which component or hook do I import, and what does it take?
The structural components live in @getnarro/core. Full prop tables for every
component are in the component reference, which is generated
from the types; this page covers the shape of the API and how the pieces fit.
Presentation
The root container. Owns navigation, routing, keyboard and pointer handling, and viewport scaling.
import { Presentation } from "@getnarro/core";
<Presentation
aspectRatio="16:9"
keyboard
mouse
touch
routing
onSlideChange={(index) => console.log(index)}
>
{/* slides */}
</Presentation>;
| Prop | Type | Default |
|---|---|---|
children | ReactNode | β |
aspectRatio | AspectRatio | "16:9" |
autoPlay | number | boolean | number[] | false |
autoPlayLoop | boolean | false |
baseHeight | number | 1080 |
baseWidth | number | 1920 |
className | string | β |
embedded | boolean | false |
enableViewportScaling | boolean | true |
favicon | string | null | β |
initialSlide | number | 0 |
keepAwake | boolean | false |
keyboard | boolean | true |
maxDuration | number | β |
mouse | boolean | true |
onAutoPlayComplete | (() => void) | β |
onSlideChange | ((index: number) => void) | β |
onSlidesData | ((slides: SlideData[]) => void) | β |
preserveAspectRatio | boolean | true |
routing | boolean | true |
showAutoPlayIndicator | boolean | false |
sync | PresentationSync | false |
theme | PresentationTheme | β |
touch | boolean | true |
transform | TransformConfig | β |
Slide
One slide. Give it an id if you want it linkable and stable across edits.
<Slide id="intro" layout="title" className="bg-slate-900" transition="fade">
{/* content */}
</Slide>
layout is βdefaultβ | βcenterβ | βtwo-columnβ | βimageβ | βtitleβ.
transition is βnoneβ | βfadeβ | βslideβ | βzoomβ.
SlideContent
Handles padding and vertical alignment inside a slide.
<SlideContent layout="centered">{/* content */}</SlideContent>
layout here is βdefaultβ | βcenteredβ | βtopβ | βbottomβ | βfillβ | βbetweenβ β a different
set from Slideβs layout. The two are easy to confuse; Slide positions the
slide, SlideContent positions the content within it.
Notes
Speaker notes. Renders nothing on the slide.
<Slide id="intro">
<SlideContent>β¦</SlideContent>
<Notes>Open with the customer story, then the numbers.</Notes>
</Slide>
Hooks
All hooks must be called inside a <Presentation>.
import { useNavigation } from "@getnarro/core";
function ProgressBar() {
const { currentSlide, totalSlides, next, previous, goToSlideById } = useNavigation();
return <div style={{ width: `${((currentSlide + 1) / totalSlides) * 100}%` }} />;
}
useNavigation() returns the navigation state and its actions together:
State β currentSlide, totalSlides, currentFragment, totalFragments,
currentSubSlide, totalSubSlides, isFirst, isLast, isOverviewMode,
isFullscreen.
Actions β next(), previous(), goToSlide(index),
goToSlideById(id), toggleFullscreen(), toggleOverviewMode(),
toggleAspectRatio().
Other exported hooks:
| Hook | For |
|---|---|
usePresentationContext() | The raw { state, actions } pair |
useSlideContext() | The current slideβs index and metadata |
useSlideActive() | Whether the calling slide is on screen β use this to gate animation. Also exported by @getnarro/shared-ui; both read the context Slide provides |
useSlideIndex() | The calling slideβs index |
useFullscreen() | Fullscreen state and toggle, outside a presentation |
useViewportScale() | The current scale factor |
useWakeLock() | Keep the screen awake while presenting |
Fragment is also exported as Reveal, and new decks should use that name:
import { Fragment } from "@getnarro/shared-ui" sits beside React.Fragment
and <> in a file that is mostly JSX, nothing warns about the collision, and an
author who writes <Fragment> meaning Reactβs gets a progressive reveal. Both
names are the same component, so nothing has to change.
There is no usePresentation, useSlide, or useFragment hook β those names
appeared in older documentation and were never exported.