-
Couldn't load subscription status.
- Fork 699
Code Pane! #712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code Pane! #712
Changes from all commits
cb44c3f
bd29ced
f5bead5
ae7f3cc
41c69f5
f85c1e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import * as React from 'react'; | ||
| import Highlight, { defaultProps } from 'prism-react-renderer'; | ||
| import propTypes from 'prop-types'; | ||
| import theme from 'prism-react-renderer/themes/vsDark'; | ||
| import { GoogleFont } from 'react-typography'; | ||
|
|
||
| export default function CodePane(props) { | ||
| const typography = React.useMemo( | ||
| () => ({ | ||
| options: { | ||
| googleFonts: [ | ||
| { | ||
| name: props.googleFont, | ||
| styles: ['400'] | ||
| } | ||
| ] | ||
| } | ||
| }), | ||
| [props.googleFont] | ||
| ); | ||
| const preStyles = React.useMemo( | ||
| () => ({ | ||
| fontFamily: `"${props.googleFont}", monospace`, | ||
| fontSize: props.fontSize, | ||
| margin: 0, | ||
| padding: '0 1em' | ||
| }), | ||
| [props.googleFont, props.fontSize] | ||
| ); | ||
| return ( | ||
| <> | ||
| <GoogleFont typography={typography} /> | ||
| <Highlight | ||
| {...defaultProps} | ||
| code={props.children} | ||
| language={props.language} | ||
| theme={theme} | ||
| > | ||
| {({ className, style, tokens, getLineProps, getTokenProps }) => ( | ||
| <pre className={className} style={{ ...style, ...preStyles }}> | ||
| {tokens.map((line, i) => ( | ||
| <div key={i} {...getLineProps({ line, key: i })}> | ||
| {line.map((token, key) => ( | ||
| <span key={key} {...getTokenProps({ token, key })} /> | ||
| ))} | ||
| </div> | ||
| ))} | ||
| </pre> | ||
| )} | ||
| </Highlight> | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| CodePane.propTypes = { | ||
| children: propTypes.string.isRequired, | ||
| fontSize: propTypes.number, | ||
| googleFont: propTypes.string, | ||
| language: propTypes.string.isRequired, | ||
| theme: propTypes.object | ||
| }; | ||
|
|
||
| CodePane.defaultProps = { | ||
| language: 'javascript', | ||
| theme: theme, | ||
| fontSize: 15, | ||
| googleFont: 'Fira Code' | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,6 +109,10 @@ const Deck = ({ children, loop, keyboardControls, ...rest }) => { | |
| navigateToCurrentUrl(); | ||
| }, [navigateToCurrentUrl]); | ||
|
|
||
| React.useLayoutEffect(() => { | ||
| document.body.style.margin = '0'; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some browsers add extra margins to body which throws off the full size slides. Ordinarily in an app we'd use a CSS reset, but we don't want our users to have to fuss with loading a CSS file and JS. |
||
| }, []); | ||
|
|
||
| React.useEffect(() => { | ||
| if (!transitionRef.current) { | ||
| return; | ||
|
|
@@ -135,14 +139,7 @@ const Deck = ({ children, loop, keyboardControls, ...rest }) => { | |
| )); | ||
|
|
||
| return ( | ||
| <div | ||
| style={{ | ||
| position: 'relative', | ||
| height: '50vh', | ||
| width: '100%', | ||
| overflowX: 'hidden' | ||
| }} | ||
| > | ||
| <div> | ||
| <DeckContext.Provider | ||
| value={{ | ||
| state, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,15 +20,21 @@ const Slide = ({ children, slideNum }) => { | |
| keyboardControls | ||
| ); | ||
|
|
||
| const baseSlideStyle = React.useMemo( | ||
| () => ({ | ||
| height: '100vh', | ||
| width: '100vw', | ||
| top: 0, | ||
| bottom: 0, | ||
| left: 0, | ||
| right: 0, | ||
| position: 'absolute' | ||
| }), | ||
| [] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just a memoized base style. Likely when we land upon a theming solution this would get refactored into that. |
||
| ); | ||
|
|
||
| return ( | ||
| <div | ||
| style={{ | ||
| backgroundColor: 'lavender', | ||
| border: '2px solid plum', | ||
| overflow: 'hidden' | ||
| }} | ||
| > | ||
| <p>{slideNum}</p> | ||
| <div style={baseSlideStyle}> | ||
| <SlideContext.Provider value={value}>{children}</SlideContext.Provider> | ||
| </div> | ||
| ); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes a filename case issue.