Skip to content

Commit 11b9983

Browse files
committed
Expand slide background support
1 parent 99f939b commit 11b9983

File tree

6 files changed

+124
-13
lines changed

6 files changed

+124
-13
lines changed

docs/content/api-reference.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,21 @@ Wraps the entire presentation and carries most of the overarching slide logic, l
3131

3232
### Slide
3333

34-
Wraps a single slide within your presentation; identifies what is contained to a single view. The only prop available for Slide is a transition effect specific to this slide. It will override the Deck-specified transition.
35-
36-
| Props | Type |
37-
| ---------------- | -------------------------------------------------------------------------- |
38-
| transitionEffect | "fade", "slide", "none", or [custom transition object](#transition-object) |
34+
Wraps a single slide within your presentation; identifies what is contained to a single view. If a transition effect is applied to this slide, it will override the Deck-specified transition.
35+
36+
| Props | Type |
37+
| -------------------| -------------------------------------------------------------------------- |
38+
| backgroundColor | PropTypes.string |
39+
| backgroundImage | PropTypes.string |
40+
| backgroundOpacity | PropTypes.number |
41+
| backgroundPosition | PropTypes.string |
42+
| backgroundRepeat | PropTypes.string |
43+
| backgroundSize | PropTypes.string |
44+
| scaleRatio | PropTypes.number |
45+
| slideNum | PropTypes.number |
46+
| template | PropTypes.func |
47+
| textColor | PropTypes.string |
48+
| transitionEffect | "fade", "slide", "none", or [custom transition object](#transition-object) |
3949

4050
<a name="typography-tags"></a>
4151

docs/content/props.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ const transition = {
3434
};
3535
```
3636

37+
<a name="background"></a>
38+
39+
## Background
40+
41+
**Background** props used by [`Slide`](/docs/api-reference#slide).
42+
43+
| Name | PropType | Description | Example |
44+
| ------------------------- | ---------------- | ------------------------------------------------------- | -------------------------------- |
45+
| `backgroundImage` | PropTypes.string | Set CSS `backgroundImage` | `url('...')` or `require(...)` |
46+
| `backgroundSize` | PropTypes.string | Set CSS `backgroundSize` | `cover`
47+
| `backgroundPosition` | PropTypes.string | Set CSS `backgroundPosition` | `center`
48+
| `backgroundRepeat` | PropTypes.string | Set CSS `backgroundRepeat` | `no-repeat`
49+
3750
<a name="color"></a>
3851

3952
## Color

examples/js/index.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
SpectacleLogo,
2222
Stepper,
2323
Text,
24+
UnorderedList,
2425
indentNormalizer
2526
} from 'spectacle';
2627

@@ -128,6 +129,34 @@ const Presentation = () => (
128129
</p>
129130
</Notes>
130131
</Slide>
132+
<Slide
133+
backgroundColor="tertiary"
134+
backgroundImage="url(https://github.com/FormidableLabs/dogs/blob/master/beau.jpg?raw=true)"
135+
backgroundOpacity={0.5}
136+
>
137+
<Heading>Custom Backgrounds</Heading>
138+
139+
<UnorderedList>
140+
<ListItem>
141+
<CodeSpan>backgroundColor</CodeSpan>
142+
</ListItem>
143+
<ListItem>
144+
<CodeSpan>backgroundImage</CodeSpan>
145+
</ListItem>
146+
<ListItem>
147+
<CodeSpan>backgroundOpacity</CodeSpan>
148+
</ListItem>
149+
<ListItem>
150+
<CodeSpan>backgroundSize</CodeSpan>
151+
</ListItem>
152+
<ListItem>
153+
<CodeSpan>backgroundPosition</CodeSpan>
154+
</ListItem>
155+
<ListItem>
156+
<CodeSpan>backgroundRepeat</CodeSpan>
157+
</ListItem>
158+
</UnorderedList>
159+
</Slide>
131160
<Slide transitionEffect="slide">
132161
<Heading>Code Blocks</Heading>
133162
<Stepper

examples/one-page.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
SpectacleLogo,
3838
Stepper,
3939
Text,
40+
UnorderedList,
4041
indentNormalizer
4142
} = Spectacle;
4243

@@ -131,6 +132,29 @@
131132
<p>Notes are shown in presenter mode. Open up localhost:3000/?presenterMode=true to see them.</p>
132133
</${Notes}>
133134
</${Slide}>
135+
<${Slide} backgroundColor="tertiary" backgroundImage="url(https://github.com/FormidableLabs/dogs/blob/master/beau.jpg?raw=true)" backgroundOpacity=${0.5}>
136+
<${Heading}>Custom Backgrounds</${Heading}>
137+
<${UnorderedList}>
138+
<${ListItem}>
139+
<${CodeSpan}>backgroundColor</${CodeSpan}>
140+
</${ListItem}>
141+
<${ListItem}>
142+
<${CodeSpan}>backgroundImage</${CodeSpan}>
143+
</${ListItem}>
144+
<${ListItem}>
145+
<${CodeSpan}>backgroundOpacity</${CodeSpan}>
146+
</${ListItem}>
147+
<${ListItem}>
148+
<${CodeSpan}>backgroundSize</${CodeSpan}>
149+
</${ListItem}>
150+
<${ListItem}>
151+
<${CodeSpan}>backgroundPosition</${CodeSpan}>
152+
</${ListItem}>
153+
<${ListItem}>
154+
<${CodeSpan}>backgroundRepeat</${CodeSpan}>
155+
</${ListItem}>
156+
</${UnorderedList}>
157+
</${Slide}>
134158
<${Slide} transitionEffect="slide">
135159
<${Heading}>Code Blocks</${Heading}>
136160
<${Stepper} defaultValue=${[]} values=${[[1, 1], [23, 25], [40, 42]]}>

index.d.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ declare module 'spectacle' {
1313

1414
export type TransitionEffect =
1515
| {
16-
enter: Record<string, number | string>;
17-
from: Record<string, number | string>;
18-
leave: Record<string, number | string>;
19-
config: Record<string, number | string>;
20-
}
16+
enter: Record<string, number | string>;
17+
from: Record<string, number | string>;
18+
leave: Record<string, number | string>;
19+
config: Record<string, number | string>;
20+
}
2121
| 'fade'
2222
| 'slide'
2323
| 'none';
@@ -35,7 +35,12 @@ declare module 'spectacle' {
3535
}>;
3636

3737
export const Slide: React.FC<{
38-
backgroundColor?: string;
38+
backgroundColor?: PropTypes.string,
39+
backgroundImage?: PropTypes.string,
40+
backgroundOpacity?: PropTypes.number,
41+
backgroundPosition?: PropTypes.string,
42+
backgroundRepeat?: PropTypes.string,
43+
backgroundSize?: PropTypes.string,
3944
children: React.ReactNode;
4045
scaleRatio?: number;
4146
textColor?: string;

src/components/slide.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import useSlide, { SlideContext } from '../hooks/use-slide';
44
import styled, { ThemeContext, css } from 'styled-components';
5-
import { color, space } from 'styled-system';
5+
import { background, color, space } from 'styled-system';
66
import useAutofillHeight from '../hooks/use-autofill-height';
77
import { DeckContext } from '../hooks/use-deck';
88

@@ -17,6 +17,17 @@ const SlideContainer = styled('div')`
1717
height: 100vh;
1818
width: 100vw;
1919
}
20+
&:before {
21+
${background};
22+
content: ' ';
23+
position: absolute;
24+
top: 0;
25+
right: 0;
26+
bottom: 0;
27+
left: 0;
28+
z-index: -1;
29+
opacity: ${({ backgroundOpacity }) => backgroundOpacity};
30+
}
2031
`;
2132

2233
const SlideWrapper = styled('div')(
@@ -67,6 +78,11 @@ const Slide = props => {
6778
children,
6879
slideNum,
6980
backgroundColor,
81+
backgroundImage,
82+
backgroundOpacity,
83+
backgroundPosition,
84+
backgroundRepeat,
85+
backgroundSize,
7086
textColor,
7187
template,
7288
scaleRatio
@@ -161,6 +177,11 @@ const Slide = props => {
161177
<SlideContainer
162178
ref={slideRef}
163179
backgroundColor={state.printMode ? '#ffffff' : backgroundColor}
180+
backgroundImage={state.printMode ? undefined : backgroundImage}
181+
backgroundOpacity={backgroundOpacity}
182+
backgroundPosition={backgroundPosition}
183+
backgroundRepeat={backgroundRepeat}
184+
backgroundSize={backgroundSize}
164185
style={transforms}
165186
>
166187
<TemplateWrapper ref={templateRef}>
@@ -181,6 +202,11 @@ const Slide = props => {
181202

182203
Slide.propTypes = {
183204
backgroundColor: PropTypes.string,
205+
backgroundImage: PropTypes.string,
206+
backgroundOpacity: PropTypes.number,
207+
backgroundPosition: PropTypes.string,
208+
backgroundRepeat: PropTypes.string,
209+
backgroundSize: PropTypes.string,
184210
children: PropTypes.node.isRequired,
185211
scaleRatio: PropTypes.number,
186212
slideNum: PropTypes.number,
@@ -198,7 +224,11 @@ Slide.propTypes = {
198224

199225
Slide.defaultProps = {
200226
textColor: 'primary',
201-
backgroundColor: 'tertiary'
227+
backgroundColor: 'tertiary',
228+
backgroundOpacity: 1,
229+
backgroundPosition: 'center',
230+
backgroundRepeat: 'no-repeat',
231+
backgroundSize: 'cover'
202232
};
203233

204234
export default Slide;

0 commit comments

Comments
 (0)