revealjs-react
FORKED FROM @gregcello/revealjs-react
A Typescript/React wrapper for the RevealJS Presentation Library with types for Reveal.js as well as plugins.
Installation
npm install -S @gregcello/revealjs-react react reveal.js react-dom
or
yarn add @gregcello/revealjs-react react reveal.js react-dom
Usage
import React from 'react'
import { render } from 'react-dom'
import { RevealJS, Slide, H1 } from 'revealjs-react'
import RevealHighlight from 'revealjs-react/plugins/highlight'
render(
<RevealJS plugins={[RevealHighlight]}>
<Slide>
<H1>Hello, World!</H1>
</Slide>
</RevealJS>,
document.querySelector('#root')
)
Components
All components support the following properties:
autoAnimateId?: string;
className?: string;
fragment?: boolean;
fragmentStyle?: string;
fragmentIndex?: number;
fitText?: boolean;
RevealJS
The properties are the same as the configuration object passed to Reveal.initialize(). This package adds an additional property onDeckReady which is called when initialization has succeeded and the API is ready to interact. Alternatively, to define custom interactions with child components, use the useReveal hook.
plugins = [],
controls = true,
controlsTutorial = true,
controlsLayout = 'bottom-right',
controlsBackArrows = 'faded',
progress = true,
slideNumber = false,
showSlideNumber = 'all',
hashOneBasedIndex = false,
hash = false,
respondToHashChanges = true,
history = false,
keyboard = true,
keyboardCondition = null,
disableLayout = false,
overview = true,
center = true,
touch = true,
loop = false,
rtl = false,
navigationMode = 'default',
shuffle = false,
fragments = true,
fragmentInURL = true,
embedded = false,
help = true,
pause = true,
showNotes = false,
autoPlayMedia = null,
preloadIframes = null,
autoAnimate = true,
autoAnimateMatcher = null,
autoAnimateEasing = 'ease',
autoAnimateDuration = 1.0,
autoAnimateUnmatched = true,
autoAnimateStyles = [
'opacity',
'color',
'background-color',
'padding',
'font-size',
'line-height',
'letter-spacing',
'border-width',
'border-color',
'border-radius',
'outline',
'outline-offset',
],
autoSlide = 0,
autoSlideStoppable = true,
autoSlideMethod = null,
defaultTiming = null,
mouseWheel = false,
previewLinks = false,
postMessage = true,
postMessageEvents = false,
focusBodyOnPageVisibilityChange = true,
transition = 'slide',
transitionSpeed = 'default',
backgroundTransition = 'fade',
pdfMaxPagesPerSlide = Number.POSITIVE_INFINITY,
pdfSeparateFragments = true,
pdfPageHeightOffset = -1,
viewDistance = 3,
mobileViewDistance = 2,
display = 'block',
hideInactiveCursor = true,
hideCursorTime = 5000,
parallaxBackgroundImage = '',
parallaxBackgroundSize = '',
parallaxBackgroundRepeat = '',
parallaxBackgroundPosition = '',
parallaxBackgroundHorizontal = 200,
parallaxBackgroundVertical = 50,
width = 960,
height = 700,
margin = 0.04,
minScale = 0.2,
maxScale = 2.0,
onDeckReady,
Slide
The Slide component adds a <section> to create a slide. It supports these properties
autoslide?: true;
autoAnimate?: true;
autoAnimateUnmatched?: boolean;
backgroundColor?: string;
backgroundImage?: string;
backgroundSize?: string;
backgroundPosition?: string;
backgroundRepeat?: string;
backgroundOpacity?: string;
backgroundVideo?: string;
backgroundVideoLoop?: true;
backgroundVideoMuted?: true;
backgroundIframe?: string;
backgroundInteractive?: true;
id?: string;
transition?: Transitions;
transitionSpeed?: TransitionSpeed;
visibility?: 'uncounted' | 'hidden';
Elements
Code
The Code component sets helpers for animation across slides. Use the HighlightPlugin to add code highlighting.
children: { code: string };
language?: string;
escape?: boolean;
lineNumbers?: string | true;
noTrim?: boolean;
autoAnimateId?: string;
Audio
The Audio component accepts all the parameters of the audio html tag, plus these properties:
autoplay?: boolean;
controls?: boolean;
lazy?: string;
loop?: boolean;
muted?: boolean;
preload?: boolean;
src: string;
BlockQuote
supports all the standard blockquote parameters plus the reveal.js addons above
Div
supports all the standard div parameters plus the reveal.js addons above
Div
Like Code but source is a prop. Children are rendered with a toggle to switch between viewing source and viewing the example.
For added power, use the babel macro imported from @gregcello/revealjs-react/example.macro and source code will be auto-extracted from the source file. The macro is still experimental.
import { Example } from '@gregcello/revealjs-react/example.macro'
function test() {
return (
<Example>
<span className="hi">thing</span>
</Example>
)
}
The above will toggle displaying thing and highlighted <span className="hi">thing</span>
The macro only supports tsx elements. Soon, support will be added for interpolated elements like this:
import { Example } from '@gregcello/revealjs-react/example.macro'
function test() {
return (
<Example>
{() => {
const [something, setSomething] = useState('hi')
return (
<div>
<span className="hi">{something}</span>
<button onClick={() => setSomething('other')}>change hi to something</button>
</div>
)
}}
</Example>
)
}
FigCaption
supports all the standard figcaption parameters plus the reveal.js addons above
Figure
supports all the standard figure parameters plus the reveal.js addons above
supports all the standard footer parameters plus the reveal.js addons above
Fragment
this creates a fragment. set fragment index with the index prop, and control animations with the animation prop. Use a Note inside the fragment to set fragment-specific notes.
H1
supports all the standard h1 parameters plus the reveal.js addons above
H2
supports all the standard h2 parameters plus the reveal.js addons above
H3
supports all the standard h3 parameters plus the reveal.js addons above
H4
supports all the standard h4 parameters plus the reveal.js addons above
H5
supports all the standard h5 parameters plus the reveal.js addons above
H6
supports all the standard h6 parameters plus the reveal.js addons above
supports all the standard header parameters plus the reveal.js addons above
IFrame
supports all the standard iframe parameters plus the reveal.js addons above, and these additional properties:
src must be set to the iframe source. pass in lazy={true} to lazy-load the iframe. pass preload={true} if it is safe to pre-load the iframe
Image
Li
supports all the standard li parameters plus the reveal.js addons above
Link
supports all the standard a parameters plus the reveal.js addons above. In addition, the Link component makes it possible to link to slides easily. Pass in the slide number (1-indexed), the slide id (a string), or the slide itself, retrieved using a ref, and this will link to the slide properly. Preferred is using the slide ID or the slide itself, as this will survive API changes in reveal.js
Main
supports all the standard main parameters plus the reveal.js addons above
Note
Ol
supports all the standard ol parameters plus the reveal.js addons above
P
supports all the standard p parameters plus the reveal.js addons above
Span
supports all the standard span parameters plus the reveal.js addons above
Ul
supports all the standard ul parameters plus the reveal.js addons above
Video
The Video component accepts all the parameters of the video html tag, plus these properties:
autoAnimateId?: string;
autoplay?: boolean;
controls?: boolean;
lazy?: string;
loop?: boolean;
muted?: boolean;
preload?: boolean;
height?: number;
preload?: '' | 'metadata' | 'auto' | 'none';
width?: number;
src: string[] | string;
Notes
Add speaker notes with an aside by using this component.
hooks
In order to access the internal Reveal object, a hook is provided.
useReveal
This can be used to retrieve the current Reveal instance. Note that until the deck is initialized, it will be null. The type of the deck is strictly typed using custom internal types, as @types/reveal is a full major version out of date.
import { useReveal } from '@gregcello/revealjs-react'
export function MyComponent() {
const { reveal } = useReveal()
useEffect(() => {
if (!reveal) {
return
}
reveal.on('slidechanged', () => {
})
}, [reveal])
}
Note that this hook must be used in a child component tp the RevealJs component. This will not work:
import { useReveal, RevealJS } from "@gregcello/revealjs-react";
export function MyPresentation() {
const { reveal, readyPromise } = useReveal();
return (
<RevealJs>
{ /* ... slides go here */ }
</RevealJs>
)
Instead, use the onDeckReady prop as documented in the RevealJS component
Using plugins
Built-in plugins from reveal.js are available as direct imports
import { HighlightPlugin, MarkdownPlugin, MathPlugin, NotesPlugin, SearchPlugin, ZoomPlugin } from '@gregcello/revealjs-react'
const plugins = [HighlightPlugin, MarkdownPlugin, MathPlugin, NotesPlugin, SearchPlugin, ZoomPlugin]
function MyPresentation() {
return <RevealJS plugins={plugins}>// your slides here</RevealJS>
}
Use only the plugins you need. These plugins are strictly typed using custom typescript definitions. To define or type your own custom plugin, use the RevealPlugin type exported from @gregcello/revealjs-react