sanity-plugin-studio-scene
Put Create the Box STUDIO scroll scenes on Sanity pages.
- A scene library. Drop the
scroll-scene.zip that STUDIO exports onto a studioScene document. The files
it needs become Sanity assets, and the zip is checked (size limits, only the files a page loads).
- Placements. Add a
studioScenePlacement to any page or page builder: pick a scene, pick a shot on the
strip, and write the content for it. Text on a shot makes the camera pause there while the text scrolls past.
- A live preview of the scene with your content, using the same player the page uses.
Install
npm install sanity-plugin-studio-scene
// sanity.config.ts
import { defineConfig } from 'sanity'
import { studioScene } from 'sanity-plugin-studio-scene'
export default defineConfig({
// …
plugins: [
studioScene({
// What editors can put on a shot: your own block types. Default: rich text.
stopContent: [{ type: 'block' }],
placementTitle: 'Scroll scene',
styles: {
colors: [{ title: 'Brand', value: 'var(--brand)', preview: '#4370f7' }],
},
}),
],
})
Then add the placement wherever pages are built:
defineField({
name: 'sections',
type: 'array',
of: [defineArrayMember({ type: 'studioScenePlacement' }) /* , your other blocks */],
})
Options
| Option |
What it does |
stopContent |
Block types editors can put on a shot. Default: rich text. |
styles.colors |
Swatches for the colour controls (any CSS colour, including var(--token) with a preview). |
styles.paletteOnly |
Only allow the swatches. Default false. |
styles.controls |
Which style controls "Customise" shows. Default: all (STYLE_CONTROLS). |
styles.presets |
One-click looks. Default: Dark card, Light card, Outline, Text only. |
placementTitle |
What editors see the placement called. Default "Scroll scene". |
runtimeUrl |
URL of scroll-scene.js for the preview. Default: the @createthebox/scroll-scene package, which installs with the plugin. |
On your site
Query a placement with the projection the plugin exports, then render it with the
@createthebox/scroll-scene element:
import { studioScenePlacementProjection } from 'sanity-plugin-studio-scene/groq'
import { styleVars, motionVars, MOTION_CSS } from 'sanity-plugin-studio-scene/style'
sanity-plugin-studio-scene/groq and /style don't import Sanity or React, so a frontend can use them. Sanity,
React and @sanity/ui are optional peer dependencies: a Studio has them already, and a site that only uses
/groq and /style doesn't need them.
styleVars and motionVars turn a slot's style and motion into the CSS variables the content reads, and
MOTION_CSS is the stylesheet that animates shot content in step with the camera.
Licence
MIT © Create the Box, LLC