@@ -4,11 +4,7 @@ import PhotoSwipeLightbox from 'photoswipe/lightbox';
4
4
import Mousetrap from 'mousetrap' ;
5
5
import 'photoswipe/photoswipe.css' ;
6
6
import '../../styles/shared/lighbox.scss' ;
7
- import { renderToString } from 'react-dom/server' ;
8
- import { createElement } from 'react' ;
9
- import { faCompress , faExpand } from '@fortawesome/free-solid-svg-icons' ;
10
7
import { getFullscreenAPI } from '../utils/fullscreen' ;
11
- import { Icon } from '../components/fontawesome-icons' ;
12
8
13
9
const prevHotKeys = [ 'a' , 'ф' , 'h' , 'р' , '4' ] ;
14
10
const nextHotKeys = [ 'd' , 'в' , 'k' , 'л' , '6' ] ;
@@ -20,8 +16,16 @@ export function openLightbox(index, dataSource) {
20
16
21
17
const fsApi = getFullscreenAPI ( ) ;
22
18
23
- const expandIconHTML = renderToString ( createElement ( Icon , { icon : faExpand } ) ) ;
24
- const compressIconHTML = renderToString ( createElement ( Icon , { icon : faCompress } ) ) ;
19
+ // @see https://github.com/dimsemenov/PhotoSwipe/issues/1759#issue-914638063
20
+ const fullscreenIconsHtml = `<svg aria-hidden="true" class="pswp__icn" viewBox="0 0 32 32" width="32" height="32">
21
+ <!-- duplicate the paths for adding strokes -->
22
+ <use class="pswp__icn-shadow" xlink:href="#pswp__icn-fullscreen-close"/>
23
+ <use class="pswp__icn-shadow" xlink:href="#pswp__icn-fullscreen-open"/>
24
+ <!-- toggle full-screen mode icon path (id="pswp__icn-fullscreen-open") -->
25
+ <path d="M8 8v6.047h2.834v-3.213h3.213V8h-3.213zm9.953 0v2.834h3.213v3.213H24V8h-2.834zM8 17.953V24h6.047v-2.834h-3.213v-3.213zm13.166 0v3.213h-3.213V24H24v-6.047z" id="pswp__icn-fullscreen-open"/>
26
+ <!-- exit full-screen mode icon path (id="pswp__icn-fullscreen-close") -->
27
+ <path d="M11.213 8v3.213H8v2.834h6.047V8zm6.74 0v6.047H24v-2.834h-3.213V8zM8 17.953v2.834h3.213V24h2.834v-6.047h-2.834zm9.953 0V24h2.834v-3.213H24v-2.834h-3.213z" id="pswp__icn-fullscreen-close"/>
28
+ </svg>` ;
25
29
26
30
function initLightbox ( ) {
27
31
const lightbox = new PhotoSwipeLightbox ( {
@@ -39,7 +43,7 @@ function initLightbox() {
39
43
ariaLabel : 'Full screen' ,
40
44
order : 9 ,
41
45
isButton : true ,
42
- html : expandIconHTML ,
46
+ html : fullscreenIconsHtml ,
43
47
onClick : ( ) => {
44
48
if ( fsApi . isFullscreen ( ) ) {
45
49
fsApi . exit ( ) ;
@@ -49,10 +53,8 @@ function initLightbox() {
49
53
} ,
50
54
} ) ;
51
55
52
- const h = ( ) => {
53
- const btn = document . querySelector ( '.pswp__button--fs' ) ;
54
- btn . innerHTML = fsApi . isFullscreen ( ) ? compressIconHTML : expandIconHTML ;
55
- } ;
56
+ const h = ( ) =>
57
+ document . documentElement . classList . toggle ( 'pswp__fullscreen-mode' , ! ! fsApi . isFullscreen ( ) ) ;
56
58
57
59
document . addEventListener ( fsApi . changeEvent , h ) ;
58
60
lightbox . on ( 'destroy' , ( ) => document . removeEventListener ( fsApi . changeEvent , h ) ) ;
0 commit comments