diff --git a/packages/components/src/Grid.js b/packages/components/src/Grid.js new file mode 100644 index 0000000..3f81fe7 --- /dev/null +++ b/packages/components/src/Grid.js @@ -0,0 +1,78 @@ +import React, { useEffect } from 'react' +import { Location, navigate } from '@reach/router' +import Zoom from './Zoom' +import Slide from './Slide' + +const getIndex = ({ pathname }) => { + return Number(pathname.split('/')[1] || 0) +} + +const withLocation = Component => props => ( + ( + + )} + /> +) + +export const Grid = withLocation(props => { + const { index, slides, modes, update } = props + const activeThumb = React.createRef() + + useEffect(() => { + const el = activeThumb.current + if (!el) return + if (typeof el.scrollIntoViewIfNeeded === 'function') { + el.scrollIntoViewIfNeeded() + } + }) + + return ( +
+
+ {slides.map((Component, i) => ( +
{ + navigate('/' + i) + update({ mode: modes.NORMAL }) + }} + style={{ + display: 'block', + width: '25vw', + height: '25vh', + padding: '2px', + overflow: 'hidden', + color: 'inherit', + textDecoration: 'none', + cursor: 'pointer', + }} + > + + + + + +
+ ))} +
+
+ ) +}) + +export default Grid diff --git a/packages/components/src/MDXDeck.js b/packages/components/src/MDXDeck.js index d73e038..2a1993f 100644 --- a/packages/components/src/MDXDeck.js +++ b/packages/components/src/MDXDeck.js @@ -7,6 +7,7 @@ import Provider from './Provider' import Slide from './Slide' import Presenter from './Presenter' import Overview from './Overview' +import Grid from './Grid' import Print from './Print' import GoogleFonts from './GoogleFonts' import Catch from './Catch' @@ -14,7 +15,15 @@ import Catch from './Catch' const NORMAL = 'normal' const PRESENTER = 'presenter' const OVERVIEW = 'overview' +const GRID = 'grid' const PRINT = 'print' +const modes = { + NORMAL, + PRESENTER, + OVERVIEW, + GRID, + PRINT, +} const STORAGE_INDEX = 'mdx-slide' const STORAGE_STEP = 'mdx-step' @@ -25,6 +34,7 @@ const keys = { space: 32, p: 80, o: 79, + g: 71, } const toggleMode = key => state => ({ @@ -43,6 +53,7 @@ export class MDXDeck extends React.Component { slides: props.slides, step: 0, mode: NORMAL, + update: fn => this.setState(fn), } } @@ -71,6 +82,9 @@ export class MDXDeck extends React.Component { case keys.o: this.setState(toggleMode(OVERVIEW)) break + case keys.g: + this.setState(toggleMode(GRID)) + break } } else { switch (keyCode) { @@ -217,13 +231,16 @@ export class MDXDeck extends React.Component { case OVERVIEW: Wrapper = Overview break + case GRID: + Wrapper = Grid + break } return ( - + diff --git a/packages/components/src/Overview.js b/packages/components/src/Overview.js index f5d2ab8..bda6625 100644 --- a/packages/components/src/Overview.js +++ b/packages/components/src/Overview.js @@ -52,6 +52,7 @@ export const Overview = withLocation(props => {
{ navigate('/' + i) }} diff --git a/packages/components/src/Zoom.js b/packages/components/src/Zoom.js index 12bf754..da00f79 100644 --- a/packages/components/src/Zoom.js +++ b/packages/components/src/Zoom.js @@ -3,8 +3,8 @@ import styled from '@emotion/styled' const ZoomRoot = styled.div(props => ({ backgroundColor: props.theme.colors.background, - width: 100 * props.zoom + 'vw', - height: 100 * props.zoom + 'vh', + width: `calc(${100 * props.zoom}vw)`, + height: `calc(${100 * props.zoom}vh)`, })) const ZoomInner = styled.div([], props => ({