npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-revealjs-with-code-surfer

v1.2.4

Published

A collection of React components that make it easy to create presentation slides using code-surfer with reveal.js

Downloads

22

Readme

React Reveal.js with Code Surfer

npm version

This is an assortment of unstyled utility React components that allow you to easily use Code Surfer in reveal.js presentations, without the need to use mdx-deck

Installation

npm install react-revealjs-with-code-surfer

or

yarn add react-revealjs-with-code-surfer

Why?

I created this after I struggled using the amazing code-surfer package along with the equally amazing reveal.js for a presentation I was making. code-surfer is tightly coupled with mdx-deck by default, which makes it difficult to use with any other presentation library.

But if there is a will there is a way.

showcase

No mdx-deck!

API

Components

SurferCode

Provides you with a Code Surfer code panel, with keyboard controls and animations enabled. Must be used inside a RevealJSInstanceProvider. Should be used inside a SurferSlideIDProvider if you have many SurferCode code panels, but can be used without one if you only have one.

Props

  • steps: InputStep[] : An array of input step elements. See below for info
  • theme?: string : One of the available themes bundled with code-surfer. Autocomplete gives you all the options.
  • nav?: {next: KeyboardEvent['code'], previous: KeyboardEvent['code']} : Define which keys you want to use to control the Code Surfer code panel. Default keys are [ and ] since reveal.js uses the arrows.
interface InputStep {
  code: string;
  /*
   * number -> line
   * numberA:numberB -> from line A to line B
   * numberA,numberB,numberC -> line A and line B and line C
   * [] -> columns
   * numberA[numberB] -> column B from line A
   * numberA[numberB:numberC] -> column B through column C from line A
   * numberA[numberB,numberC] -> column B and column C from line A
   * See https://github.com/pomber/code-surfer#focus
   */
  focus?: string;
  title?: ReactNode;
  subtitle?: ReactNode;
  lang?: string;
  showNumbers?: boolean;
}

SurferSlide

A utility component that provides a section slide with a slide ID. Must be used inside a SurferSlideIDProvider

Props

  • children: ReactNode
  • ...rest: HTMLProps<HTMLElement> : whatever HTML attribute you want to pass to the underlying section element. data-code-surfer values will be ignored
// example

<SurferSlideIDProvider>
  <SurferSlide className="will-be-passed-to-the-section-element">
    <div className="r-stretch text-left">
      <SurferCode steps={props.steps} />
    </div>
    <aside className={'notes'}>Some notes</aside>
  </SurferSlide>
</SurferSlideIDProvider>

SurferSlideIDProvider

A simple provider that creates a unique ID and passes it down to children. Necessary to use if you have many Code Surfer code panels, otherwise navigating in one will navigate every single one (if you are using the same navigation keys in every single one)

Props

  • children: ReactNode
  • id?: string : You may pass a predefined id if you know that it will be unique

RevealJSProvider

A provider that initializes a reveal.js instance and passes it down. Accepts a reveal.js options object, however viewdistance will be ignored since it must always be Infinity otherwise Code Surfer code panels in distant slides have sizing issues

Props

  • children: ReactNode
  • config?: Omit<RevealJS.Options, 'viewDistance'> : Default config is { plugins: [RevealNotes], hash: true, }
  • exposeToWindow?: boolean : Chose to expose the reveal.js instance to the window object. Default is false.
  • onInitialize?: (revealInstance: Reveal.Api) => void : Callback function you can pass that will be executed after reveal.js has initialized and after the reveal.js instance has been set as the current reveal.js instance internally in the provider state.

Hooks

useCodeSurferSlideID

A hook that if it's used inside the descendants of a SurferSlideIDProvider it returns the unique id that is needed to exist as a data-code-surfer attribute on the slide section in order to isolate code navigation to the currently visible Code Surfer code panel. Returns '' if it's used outside of a context provider.

useRevealJSInstance

A hook that if it's used inside the descendants of a RevealJSInstanceProvider it returns the unique currently initialized reveal.js instance. Returns null if it's used outside of a context provider or if the reveal.js instance has not completed initializing yet.

Notes

You will need to have reveal.js, react, react-dom and their types installed in your own project. This package only requires them as peer dependencies.