• Stars
    star
    6,347
  • Rank 6,283 (Top 0.2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Rad code slides <๐Ÿ„/>

Code Surfer

Help to keep this project alive with your support โค๏ธ

Code Surfer adds code highlighting, code zooming, code scrolling, code focusing, code morphing, and fun to MDX Deck slides.

To create a new project run:

npm init code-surfer-deck my-deck
cd my-deck
npm start

Examples

How to use Code Surfer

It may help to know how MDX Deck works first

To use Code Surfer you need to import it and wrap the code you want to show inside <CodeSurfer> tags (the empty lines before and after the codeblock are required):

import { CodeSurfer } from "code-surfer"

# Deck Title

---

<CodeSurfer>

```js
console.log(1);
console.log(2);
console.log(3);
```

</CodeSurfer>

Features:

Here is a live deck using all the features (and its mdx source) just in case you prefer to read code instead of docs.

Focus

Add a focus string after the language in the first line of a codeblock to tell Code Surfer what lines and columns you want to focus.

Code Surfer will fade out all the code that isn't focused and, if necessary, zoom it out to fit it in the slide.

<CodeSurfer>

```js 1:2,3[8:10]
console.log(1);
console.log(2);
console.log(3);
```

</CodeSurfer>

In the example above 1:2,3[8:10] means: "focus from the line 1 to line 2 and the columns 8 to 10 from line 3". More examples:

  • 5:10 focus lines 5,6,7,8,9 and 10
  • 1,3:5,7 focus lines 1,3,4,5 and 7
  • 2[5] focus column 5 in line 2
  • 2[5:8] focus columns 5, 6, 7 and 8 in line 2
  • 1,2[1,3:5,7],3 focus line 1, columns 1, 3, 4, 5 and 7 in line 2 and line 3

Note: In previous versions of CodeSurfer we used tokens instead of columns.

Steps

Add more codeblocks to add steps to a Code Surfer slide.

<CodeSurfer>

```js
console.log(1);
console.log(2);
console.log(3);
```

```js 1
console.log(1);
console.log(2);
console.log(3);
```

```js
console.log(1);
console.log(2);
console.log(3);
console.log(4);
console.log(5);
```

</CodeSurfer>

You can change the focus and/or the code for different steps and Code Surfer will make the transition between the steps: zooming, scrolling, fading in, fading out, adding and removing lines.

Title and Subtitle

<CodeSurfer>

```js 1 title="Title" subtitle="Look at the first line"
console.log(1);
console.log(2);
console.log(3);
```

```js 2 title="Title" subtitle="and now the second"
console.log(1);
console.log(2);
console.log(3);
```

</CodeSurfer>

Themes

Code Surfer Themes

There are many Code Surfer themes available on the @code-surfer/themes package.

You can pass the theme as a prop <CodeSurfer theme={someTheme}>:

import { CodeSurfer } from "code-surfer"
import { nightOwl } from "@code-surfer/themes"

<CodeSurfer theme={nightOwl}>

```js
console.log(1);
console.log(2);
console.log(3);
```

</CodeSurfer>

Or set the theme for the whole deck as any other MDX Deck theme:

import { CodeSurfer } from "code-surfer"
import { nightOwl } from "@code-surfer/themes"

export const theme = nightOwl

<CodeSurfer>

```js
console.log(1);
console.log(2);
console.log(3);
```

</CodeSurfer>

Exporting the theme like this will also change the text and background colors for slides that aren't using Code Surfer. If you want to keep the colors from a different mdx deck theme you can compose both themes together: export const themes = [codeSurferTheme, mdxDeckTheme]

Custom Styles

You can write your own Code Surfer theme and change the style of the code, title and subtitle:

Themes use Theme UI internally

// custom-theme.js
export default {
  colors: {
    background: "#222",
    text: "#ddd",
    primary: "#a66"
  },
  styles: {
    CodeSurfer: {
      pre: {
        color: "text",
        backgroundColor: "background"
      },
      code: {
        color: "text",
        backgroundColor: "background"
      },
      tokens: {
        "comment cdata doctype": {
          fontStyle: "italic"
        },
        "builtin changed keyword punctuation operator tag deleted string attr-value char number inserted": {
          color: "primary"
        },
        "line-number": {
          opacity: 0.8
        }
      },
      title: {
        backgroundColor: "background",
        color: "text"
      },
      subtitle: {
        color: "#d6deeb",
        backgroundColor: "rgba(10,10,10,0.9)"
      },
      unfocused: {
        // only the opacity of unfocused code can be changed
        opacity: 0.1
      }
    }
  }
};

And use it in your deck like any other theme:

import { CodeSurfer } from "code-surfer"
import customTheme from "./custom-theme"

<CodeSurfer theme={customTheme}>

```js
console.log(1);
console.log(2);
console.log(3);
```

</CodeSurfer>

Languages

Code Surfer uses Prism for parsing different languages, so it supports all the languages supported by Prism.

Most popular languages are supported out of the box, for the rest you need to import them:

import { CodeSurfer } from "code-surfer"
import "prismjs/components/prism-smalltalk"

<CodeSurfer>

```smalltalk
result := a > b
    ifTrue:[ 'greater' ]
    ifFalse:[ 'less or equal' ]
```

</CodeSurfer>

Columns

If you want to show more than one piece of code at the same time, use <CodeSurferColumns>:

import { CodeSurferColumns, Step } from "code-surfer"

<CodeSurferColumns>

<Step subtitle="First Step">

```js
console.log(1);
console.log(2);
```

```js
console.log("a");
console.log("b");
```

</Step>

<Step subtitle="Second Step">

```js 2
console.log(1);
console.log(2);
```

```js 2
console.log("a");
console.log("b");
```

</Step>

</CodeSurferColumns>

Each <Step> can have its own title and subtitle.

You can use different themes for each column: <CodeSurferColumns themes={[nightOwl, ultramin]}>. And change the relative size of the columns with <CodeSurferColumns sizes={[1,3]}>.

Columns aren't only for code, you can use them for any kind of content:

import { CodeSurferColumns, Step } from "code-surfer"
import MyComponent from "./my-component.jsx"

<CodeSurferColumns>

<Step>

```js
console.log(1);
console.log(2);
```

# Some Markdown

</Step>

<Step>

```js 2
console.log(1);
console.log(2);
```

<MyComponent/>

</Step>

</CodeSurferColumns>

Import Code

Instead of writing the code inside codeblocks you can import it from a file:

import { CodeSurfer } from "code-surfer"

<CodeSurfer>

```js 5:10 file=./my-code.js
```

```js file=./my-other-code.js
```

</CodeSurfer>

Line Numbers

To show line numbers add the showNumbers flag to the first step:

import { CodeSurfer } from "code-surfer"

<CodeSurfer>

```js showNumbers
console.log(1);
console.log(2);
console.log(3);
```

```js
console.log(1);
console.log(2);
console.log(4);
```

</CodeSurfer>

Diffs

Codeblocks can also be diffs. This is particularly useful when using empty diffs for code that doesn't change:

import { CodeSurfer } from "code-surfer"

<CodeSurfer>

```js
console.log(1);
console.log(2);
console.log(3);
```

```diff 1 subtitle="log 1"

```

```diff 2 subtitle="log 2"

```

```diff 3 subtitle="log 3"

```

</CodeSurfer>

Related

Support Code Surfer

You can help keep this project alive.

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

Backers

Thank you to all our backers! ๐Ÿ™ [Become a backer]

Contributors

This project exists thanks to all the people who contribute.

More Repositories

1

git-history

Quickly browse the history of a file from any git repository
JavaScript
13,557
star
2

didact

A DIY guide to build your own React
JavaScript
6,294
star
3

stargazer

Your repo reached a stars milestone? Celebrate with a video of your stargazers!
TypeScript
1,304
star
4

covid19

JSON time-series of coronavirus cases (confirmed, deaths and recovered) per country - updated daily
JavaScript
1,227
star
5

placeholdifier

Turn any website into a live wireframe
HTML
353
star
6

scrollycoding-preview

JavaScript
267
star
7

hitchcock

The Master of Suspense ๐Ÿฟ
JavaScript
168
star
8

intersection-observer-debugger

A script you include during development that shows the root, target, and intersection every time an IntersectionObserver is triggered.
JavaScript
129
star
9

react-lazy-preload-demo

Lazy loading (and preloading) components in Reactย 16.6
JavaScript
123
star
10

react-fit-to-viewport

TypeScript
118
star
11

site

JavaScript
99
star
12

gpt-docs

An alternative take on OpenAI's Chat Completion official guide and API reference
JavaScript
67
star
13

react-conf-2018-hooks-demo

A copy of Dan's intro to hooks using Code Surfer v3
JavaScript
56
star
14

use-spring

Hooke's law hook
TypeScript
55
star
15

react-svg-curve

React components to draw different types of curves with svg
TypeScript
54
star
16

record-talk-with-remotion

TypeScript
51
star
17

codem-ipsum

Lorem ipsum for code
HTML
42
star
18

springs

Stiffness? Damping? Mass? Spring Editor
HTML
41
star
19

the-x-in-mdx

JavaScript
40
star
20

code-hike-sample

JavaScript
37
star
21

deck-studio

JavaScript
35
star
22

write-code-online

A minimalist code editor
HTML
32
star
23

code-hike-site

JavaScript
31
star
24

create-code-surfer-deck

Initialize a project with mdx deck and code surfer
JavaScript
29
star
25

docusaurus-mdx-2

A Docusaurus theme to add support for MDX v2
TypeScript
28
star
26

gatsby-remark-import-code

Gatsby remark plugin to import code from a file into code blocks
JavaScript
23
star
27

awesome-word-pairs

Opposite word pairs with the same number of letters, ideal for naming your variables.
21
star
28

full-width-text

Web component for making the inner text fit the width of the element
HTML
20
star
29

use-safe-window

React hook to bypass SSR errors when using the window object
JavaScript
19
star
30

escher-bot

https://twitter.com/mauritscorneIis
JavaScript
18
star
31

gatsby-theme-deck-n-blog

Create a deck (with mdx-deck) and a blog post from the same MDX
JavaScript
18
star
32

diagrama

JavaScript
17
star
33

paper-fab-speed-dial

A floating action button flinging out related actions
HTML
16
star
34

mdx-debugger

JavaScript
15
star
35

code-explainers

JavaScript
12
star
36

areyou10x

Quiz: Are you a real 10x programmer?
JavaScript
11
star
37

server-side-media-queries-for-react

JavaScript
9
star
38

codetv

JavaScript
9
star
39

depto_scraper

Scrape apartments from websites searches and upload them in a google spreadsheet
Python
8
star
40

remix-codehike

JavaScript
8
star
41

code-surfer-editor

JavaScript
6
star
42

intersection-observer

Intersection observer code explainer
Svelte
6
star
43

500metros

Hasta dรณnde podรฉs llegar sin pasarte de los 500 metros de distancia
HTML
6
star
44

forkbox

JavaScript
5
star
45

sim-text-edit

JavaScript
5
star
46

incremental-rendering-demo

JavaScript
5
star
47

docs-page-demo

4
star
48

aoe-widget

JavaScript
4
star
49

louis-xiv

React state as a component
JavaScript
4
star
50

css-filters-screencast

HTML
4
star
51

fail-to-pr

Post the relevant part of your broken CI build to the PR that triggered it
JavaScript
4
star
52

blog

Posts by @pomber. JavaScript, React, dev tools, animations and more.
JavaScript
3
star
53

spectacle-another-code-slide

JavaScript
3
star
54

playhead

Component-based animations (coming soon...)
JavaScript
3
star
55

hotkey-trainer

TypeScript
3
star
56

react-vista

JavaScript
3
star
57

dont-panic-js

Answer to the Ultimate Question of JavaScript, the Browser, and Everything
3
star
58

ai-rsc

TypeScript
3
star
59

webcontainer-out-of-memory

JavaScript
2
star
60

nextjs-static-props

JavaScript
2
star
61

next-require-context-issue

JavaScript
2
star
62

react-dx-boilerplate

A react starter kit, based on create-react-app, focused on developer experience
JavaScript
2
star
63

.github

https://help.github.com/en/articles/creating-a-default-community-health-file-for-your-organization
2
star
64

proto-code-hike-chat

TypeScript
2
star
65

conway

JavaScript
2
star
66

nextjs-mdx-use-client-bug

TypeScript
2
star
67

js-action

JavaScript
1
star
68

client-server-bundler

Bundle client and server folders into one build folder including a proxy server to handle static files
JavaScript
1
star
69

magic-browser-support-ball

JavaScript
1
star
70

polymer-1-samples

Polymer 1 samples
HTML
1
star
71

empty

1
star
72

yarn-workspaces-code-sharing

JavaScript
1
star
73

copy-with-ansi-codes

JavaScript
1
star
74

hylia

HTML
1
star
75

crochet

React without renderers, if you want an effect you use a hook (WIP - Paused)
JavaScript
1
star
76

bondify

JavaScript
1
star
77

ch-v1-inngest

TypeScript
1
star