Skip to content

Commit d4185e4

Browse files
committed
Update fullscreen icon, it now has the same stroke as other
1 parent 1b121f8 commit d4185e4

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

src/services/lightbox.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ import PhotoSwipeLightbox from 'photoswipe/lightbox';
44
import Mousetrap from 'mousetrap';
55
import 'photoswipe/photoswipe.css';
66
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';
107
import { getFullscreenAPI } from '../utils/fullscreen';
11-
import { Icon } from '../components/fontawesome-icons';
128

139
const prevHotKeys = ['a', 'ф', 'h', 'р', '4'];
1410
const nextHotKeys = ['d', 'в', 'k', 'л', '6'];
@@ -20,8 +16,16 @@ export function openLightbox(index, dataSource) {
2016

2117
const fsApi = getFullscreenAPI();
2218

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>`;
2529

2630
function initLightbox() {
2731
const lightbox = new PhotoSwipeLightbox({
@@ -39,7 +43,7 @@ function initLightbox() {
3943
ariaLabel: 'Full screen',
4044
order: 9,
4145
isButton: true,
42-
html: expandIconHTML,
46+
html: fullscreenIconsHtml,
4347
onClick: () => {
4448
if (fsApi.isFullscreen()) {
4549
fsApi.exit();
@@ -49,10 +53,8 @@ function initLightbox() {
4953
},
5054
});
5155

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());
5658

5759
document.addEventListener(fsApi.changeEvent, h);
5860
lightbox.on('destroy', () => document.removeEventListener(fsApi.changeEvent, h));

src/utils/fullscreen.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ export function getFullscreenAPI() {
1111
let changeEvent;
1212
let errorEvent;
1313

14-
if (document.documentElement.requestFullscreen) {
14+
if (document.fullscreenEnabled) {
1515
enterFS = 'requestFullscreen';
1616
exitFS = 'exitFullscreen';
1717
elementFS = 'fullscreenElement';
1818
changeEvent = 'fullscreenchange';
1919
errorEvent = 'fullscreenerror';
20-
} else if (document.documentElement.webkitRequestFullscreen) {
20+
} else if (document.webkitFullscreenEnabled) {
2121
enterFS = 'webkitRequestFullscreen';
2222
exitFS = 'webkitExitFullscreen';
2323
elementFS = 'webkitFullscreenElement';

styles/shared/lighbox.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,17 @@
5151
.pswp__button--close {
5252
order: 3;
5353
}
54+
55+
#pswp__icn-fullscreen-close {
56+
display: none;
57+
}
58+
59+
.pswp__fullscreen-mode {
60+
#pswp__icn-fullscreen-close {
61+
display: block;
62+
}
63+
64+
#pswp__icn-fullscreen-open {
65+
display: none;
66+
}
67+
}

0 commit comments

Comments
 (0)