FormidableLabs / spectacle

A React-based library for creating sleek presentations using JSX syntax that gives you the ability to live demo your code.
https://commerce.nearform.com/open-source/spectacle/
MIT License
9.7k stars 690 forks source link

[Feature] Add keyboard shortcuts for next _slide_ / previous _slide_ #1310

Open mathieucaroff opened 6 months ago

mathieucaroff commented 6 months ago

The current shortcuts (left) and (right) only switch to the next or previous Step, which can be e.g. a text fading in.

Description

When there are a lot of steps in slides, navigating the deck can be quite slow.

Proposal

Add a pair of keyboard shortcuts for switching to the next or previous slide. I would suggest to pick one among:

Links / References

Further ideas

oliviertassinari commented 1 month ago

Agree, see https://github.com/slidevjs/slidev/issues/126 for why.

oliviertassinari commented 1 month ago

The workaround I used:

diff --git a/src/App.tsx b/src/App.tsx
index 6c61dcf..781508c 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -1,3 +1,4 @@
+import * as React from 'react';
 import { styled, css } from '@pigment-css/react';
 import { Template } from './Template';
 import { Backdrop } from './Backdrop';
@@ -14,7 +15,10 @@ import {
   Notes,
   UnorderedList,
   ListItem,
+  DeckContext,
+  useMousetrap,
 } from 'spectacle';
 import { rawTheme } from '../rawTheme';

 // Slides
@@ -77,9 +81,24 @@ const transition = {
   },
 };

+function KeyboardShortcut() {
+  const deckContext = React.useContext(DeckContext);
+
+  useMousetrap(
+    {
+      pageup: deckContext.stepBackward,
+      pagedown: deckContext.stepForward,
+    },
+    [],
+  );
+
+  return null;
+}
+
 export default function Presentation() {
   return (
     <Deck theme={spectacleTheme} transition={transition} template={<Template />}>
+      <KeyboardShortcut />
       <Slide>
         <Slide1 />
         <Notes>
@@ -604,7 +623,7 @@ https://github.com/styled-components/styled-components/issues/4025
           8m45s
         </Notes>
       </Slide>