@@ -2,22 +2,18 @@ import React from 'react';
22import  PropTypes  from  'prop-types' ; 
33import  useSlide ,  {  SlideContext  }  from  '../hooks/use-slide' ; 
44import  {  DeckContext  }  from  '../hooks/use-deck' ; 
5- import  styled  from  'styled-components' ; 
5+ import  styled ,   {   ThemeContext   }  from  'styled-components' ; 
66import  {  color  }  from  'styled-system' ; 
77
88const  SlideContainer  =  styled ( 'div' ) ` 
99  ${ color }  
1010  position: relative; 
11-   width: 100%; 
12-   padding-top: 56.25%; 
11+   transform-origin: left center; 
12+   width: ${ ( {  theme } )  =>  theme . size . width  ||  1366 }  
13+   height: ${ ( {  theme } )  =>  theme . size . height  ||  768 }  
1314` ; 
1415const  SlideWrapper  =  styled ( 'div' ) ` 
1516  ${ color }  
16-   top: 0; 
17-   left: 0; 
18-   right: 0; 
19-   bottom: 0; 
20-   position: absolute; 
2117  overflow-y: scroll; 
2218` ; 
2319const  TemplateWrapper  =  styled ( 'div' ) ` 
@@ -40,19 +36,47 @@ const Slide = props => {
4036    backgroundColor, 
4137    textColor, 
4238    template, 
43-     numberOfSlides
39+     numberOfSlides, 
40+     scaleRatio
4441  }  =  props ; 
42+   const  theme  =  React . useContext ( ThemeContext ) ; 
4543  const  {  slideElementMap,  keyboardControls }  =  React . useContext ( DeckContext ) ; 
4644  const  initialState  =  {  currentSlideElement : 0 ,  immediate : false  } ; 
4745  const  numberOfSlideElements  =  slideElementMap [ slideNum ] ; 
46+   const  [ ratio ,  setRatio ]  =  React . useState ( scaleRatio  ||  1 ) ; 
47+ 
48+   const  transformForWindowSize  =  React . useCallback ( ( )  =>  { 
49+     const  slideWidth  =  theme . size . width  ||  1366 ; 
50+     const  clientWidth  =  Math . max ( 
51+       document . documentElement . clientWidth , 
52+       window . innerWidth  ||  0 
53+     ) ; 
54+     const  ratio  =  clientWidth  /  slideWidth ; 
55+     setRatio ( ratio ) ; 
56+   } ,  [ theme ] ) ; 
57+ 
58+   React . useEffect ( ( )  =>  { 
59+     if  ( ! isNaN ( scaleRatio ) )  { 
60+       return ; 
61+     } 
62+     transformForWindowSize ( ) ; 
63+     window . addEventListener ( 'resize' ,  transformForWindowSize ) ; 
64+     return  ( )  =>  { 
65+       window . removeEventListener ( 'resize' ,  transformForWindowSize ) ; 
66+     } ; 
67+   } ,  [ transformForWindowSize ,  scaleRatio ] ) ; 
68+ 
4869  const  value  =  useSlide ( 
4970    initialState , 
5071    slideNum , 
5172    numberOfSlideElements , 
5273    keyboardControls 
5374  ) ; 
5475  return  ( 
55-     < SlideContainer  backgroundColor = { backgroundColor } > 
76+     < SlideContainer 
77+       backgroundColor = { backgroundColor } 
78+       style = { {  transform : `scale(${ ratio }   } } 
79+     > 
5680      < TemplateWrapper > 
5781        { typeof  template  ===  'function'  && 
5882          template ( {  slideNumber : slideNum ,  numberOfSlides } ) } 
@@ -67,8 +91,9 @@ const Slide = props => {
6791Slide . propTypes  =  { 
6892  backgroundColor : PropTypes . string , 
6993  children : PropTypes . node . isRequired , 
70-   slideNum : PropTypes . number , 
7194  numberOfSlides : PropTypes . number , 
95+   scaleRatio : PropTypes . number , 
96+   slideNum : PropTypes . number , 
7297  template : PropTypes . func , 
7398  textColor : PropTypes . string 
7499} ; 
0 commit comments