Skip to main content

Theme System

Spectacle has a robust theme system that is built upon styled system.

A theme is a 2-level deep object of labeled theme keys and CSS property object values, which is passed directly to the Deck component.

Theme Object

The following is an example of a simple custom theme object:

const theme = {
colors: {
primary: '#f00',
secondary: '#00f'
},
fontSizes: {
header: '64px',
paragraph: '28px'
}
};

Usage

Components in Spectacle can accept either a value label such as primary or a raw CSS value like #f00. The label primary returns #f00 since the backgroundColor prop (CSS property background-color) is mapped to the colors theme key.

<Box backgroundColor="primary" />
<Box backgroundColor="#f00" />

Theme Keys

Common CSS properties are divided into theme keys, which you can override in your custom theme object:

Theme KeyCSS Properties
spacemargin, padding, grid-gap
colorscolor, background-color, border-color
sizeswidth, height, min-width, max-width, min-height, max-height
fontSizesfont-size
bordersborder, border-top, border-right, border-bottom, border-left
borderWidthsborder-width
borderStylesborder-style
radiiborder-radius
fontsfont-family
fontWeightsfont-weight
lineHeightsline-height
letterSpacingsletter-spacing
shadowsbox-shadow, text-shadow
zIndicesz-index

Additionally, there are keys for assorted overrides for the presentation:

Theme KeyTypeDescription
backdropStyleReact.CSSPropertiesSet styles for the backdrop (the edge-to-edge area behind the slides) similar to React style props, e.g., { backgroundColor: '#FFF' }. Defaults to { position: 'fixed', top: 0, left: 0, width: '100vw', height: '100vh' }
BackdropReact.ElementTypeReplace the default backdrop component (which appears behind the slides) with a completely custom component or tag name, e.g., 'main' or MyCustomComponent. Defaults to 'div'.

Deck Templates

A template in Spectacle is a fixed overlay of components that are presented on every slide. They are similar to masters in Keynote or PowerPoint. It’s a function prop that has a single optional config object containing the current slide and total slide count and returns a React Node.

<Deck template={({ slideNumber, numberOfSlides }) => (
<FlexBox
justifyContent="space-between"
position="absolute"
bottom={0}
width={1}
>
<Box padding="0 1em">
<FullScreen />
</Box>
<Box padding="1em">
<Progress />
Slide {slideNumber} of {numberOfSlides}
</Box>
</FlexBox>
)}>

Scaled Spacing

The space key is used as a scale for margins, paddings, and gaps for grids. It is an array of integer values. This allows for a more consistent scale of sizes throughout your presentation. The default theme uses three values on the scale, 16, 24, and 32.

Given the following theme:

let theme = {
space: [16, 24, 32]
};

One can use a scale value by passing the index of the value as a numeric prop to any space theme property (such as padding or margin), like so:

<Text padding={2}>Hello World</Text>

Default Margin Assignments

Spectacle components use different values on the space scale as defaults for margins. The values can be overridden in your theme by providing alternative values as part of a space array that is at least 3 values deep. If no value is provided, Spectacle will default to 0. Individual margin values can be also provided as margin props to the component.

ComponentDefault Space IndexDefault Theme Value
Slide232px
Heading124px
Text016px
OrderedList016px
UnorderedList016px
ListItem016px
Link016px
Quote016px
CodeSpan016px