Skip to content

Commit 9ed1c39

Browse files
committed
refactor: update Viewport to render using lit-html
1 parent 395dd2c commit 9ed1c39

File tree

1 file changed

+27
-60
lines changed
  • packages/uikit-workshop/src/scripts/components/pl-viewport

1 file changed

+27
-60
lines changed

packages/uikit-workshop/src/scripts/components/pl-viewport/pl-viewport.js

Lines changed: 27 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ import { minViewportWidth, maxViewportWidth } from '../../utils';
1111
import { BaseComponent } from '../base-component.js';
1212
import { urlHandler, patternName } from '../../utils';
1313

14+
import { html } from 'lit-html';
15+
import { BaseLitComponent } from '../base-component.js';
16+
1417
import styles from '../../../sass/pattern-lab--iframe-loader.scss';
1518

1619
let trackingPageChange = false;
1720

1821
@define
19-
class IFrame extends BaseComponent {
22+
class IFrame extends BaseLitComponent {
2023
static is = 'pl-iframe';
2124

2225
constructor(self) {
@@ -360,81 +363,45 @@ class IFrame extends BaseComponent {
360363

361364
const url = urlHandler.getFileName(patternParam);
362365

363-
const IframeInner = () => {
364-
return (
365-
<div className={`pl-c-body--theme-${this.themeMode}`}>
366-
<style>{styles[0][1]}</style>
367-
<div className={'pl-c-loader'}>
368-
<div className={'pl-c-loader__content'}>
369-
<div className={'pl-c-loader__message'}>Loading Pattern Lab</div>
370-
<div className={'pl-c-loader__spinner'}>
371-
<svg className={'pl-c-loader-svg'} viewBox={'0 0 268 255'}>
372-
<circle
373-
className={'pl-c-loader-svg__outer-circle'}
374-
cx={'134.2'}
375-
cy={'127.6'}
376-
r={'115.1'}
377-
/>
378-
<circle
379-
className={'pl-c-loader-svg__inner-circle'}
380-
cx={'134.2'}
381-
cy={'127.6'}
382-
r={'66.3'}
383-
/>
384-
<path
385-
className={'pl-c-loader-svg__electron'}
386-
d={
387-
'M253,56.3c0,15.6-12.6,28.2-28.2,28.2s-28.2-12.6-28.2-28.2s12.6-28.2,28.2-28.2C240.3,28.1,253,40.7,253,56.3z'
388-
}
389-
/>
390-
</svg>
391-
</div>
392-
</div>
393-
</div>
394-
</div>
395-
);
396-
};
397-
398366
const initialWidth =
399367
store.getState().app.viewportPx &&
400368
store.getState().app.viewportPx <= this.clientWidth
401369
? store.getState().app.viewportPx + 'px;'
402370
: '100%';
403371

404-
return (
372+
return html`
405373
<div class="pl-c-viewport pl-js-viewport">
406-
<div class="pl-c-viewport__cover pl-js-viewport-cover" />
374+
<div class="pl-c-viewport__cover pl-js-viewport-cover"></div>
407375
<div
408376
class="pl-c-viewport__iframe-wrapper pl-js-vp-iframe-container"
409-
style={`width: ${initialWidth}`}
377+
style="width: ${initialWidth}"
410378
>
411379
<iframe
412-
className={`pl-c-viewport__iframe pl-js-iframe pl-c-body--theme-${this.themeMode}`}
380+
class="pl-c-viewport__iframe pl-js-iframe pl-c-body--theme-${this
381+
.themeMode}"
413382
sandbox="allow-same-origin allow-scripts allow-popups allow-forms allow-modals"
414-
// srcdoc={render(<IframeInner />)}
415-
src={url}
416-
/>
417-
{
418-
<div class="pl-c-viewport__resizer pl-js-resize-container">
419-
<div
420-
class="pl-c-viewport__resizer-handle pl-js-resize-handle"
421-
onMouseDown={e => this.handleMouseDown(e)}
383+
src="${url}"
384+
></iframe>
385+
386+
<div class="pl-c-viewport__resizer pl-js-resize-container">
387+
<div
388+
class="pl-c-viewport__resizer-handle pl-js-resize-handle"
389+
@mousedown="${this.handleMouseDown}"
390+
>
391+
<svg
392+
viewBox="0 0 20 20"
393+
preserveAspectRatio="xMidYMid"
394+
focusable="false"
395+
style="width: 30px; fill: currentColor; position: absolute; top: 50%; transform: translate3d(0, -50%, 0); z-index: 100;"
422396
>
423-
<svg
424-
viewBox="0 0 20 20"
425-
preserveAspectRatio="xMidYMid"
426-
focusable="false"
427-
style="width: 30px; fill: currentColor; position: absolute; top: 50%; transform: translate3d(0, -50%, 0); z-index: 100;"
428-
>
429-
<title>Drag to resize Pattern Lab</title>
430-
<path d="M6 0h2v20H6zM13 0h2v20h-2z" />
431-
</svg>
432-
</div>
397+
<title>Drag to resize Pattern Lab</title>
398+
<path d="M6 0h2v20H6zM13 0h2v20h-2z" />
399+
</svg>
433400
</div>
434-
}
401+
</div>
435402
</div>
436403
</div>
437-
);
404+
`;
438405
}
439406

440407
handleMouseDown(event) {

0 commit comments

Comments
 (0)