Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/onurkerimov/animate-code

A React component (and a set of hooks) for animating code blocks into one another
https://github.com/onurkerimov/animate-code

Last synced: 13 days ago
JSON representation

A React component (and a set of hooks) for animating code blocks into one another

Awesome Lists containing this project

README

        

# animate-code
The **AnimateCode** component is a React component designed to animate code blocks. It uses **Prismjs** for code highlighting and **@formkit/auto-animate** for transitions.

See it in heavy action in **xoid**'s docs: [xoid.dev](https://xoid.dev)

### Usage
```js
import CodeAnimate from 'animate-code';
import 'prismjs/components/prism-jsx' // Make sure to include Prismjs grammar you want to use.
import 'prismjs/themes/prism-tomorrow.css' // Use a Prismjs theme

```

### Props

- `value`: (required) The code string to be displayed and animated.
- `animationEnabled`: (optional) A boolean indicating whether animation is enabled. Defaults to `true`.
- `animationOptions`: (optional) An object containing animation options compatible with **@formkit/auto-animate/react**.
- `grammar`: (optional) The Prism grammar object to be used for syntax highlighting. Defaults to `Prism.languages.jsx`.
- `language`: (optional) The language string used for Prism highlighting. Defaults to `"javascript"`.
- `getKey`: (optional) A function used to generate unique keys for lines of code. Defaults to: `(line) => line.trimStart()`. Trimming the beginning makes morphing into different indentations of the same line possible.
- `checkSpecialLine`: (optional) A function used to determine if a line of code is special and should be rendered differently.
- `renderSpecialLine`: (optional) A function used to render special lines of code differently.
- `maxAnchor`: (optional) The maximum number of characters to pad each line by. Defaults to `20`. (You probably won't need this as long as you're animating an indentation level of 20 spaces)
- `innerProps`: (optional) `ComponentProps<'code'>`