Skip to content

Commit 5c6b9c9

Browse files
committed
feat(mdjs-preview): Move platform and sizes settings above preview
1 parent 6221e5f commit 5c6b9c9

File tree

5 files changed

+97
-18
lines changed

5 files changed

+97
-18
lines changed

.changeset/funny-news-rhyme.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
'@mdjs/mdjs-preview': patch
3+
---
4+
5+
The Platform and Size controls are now moved above the preview.
6+
For the web platform we added a special "inline" size.
7+
Only when platform=web & size=webInline it will render to dom.
8+
On all other selections it will render the preview via an iframe.
9+
10+
```js
11+
sizes: [
12+
{
13+
key: 'webInline',
14+
name: 'Inline',
15+
platform: 'web',
16+
width: 360,
17+
height: 640,
18+
dpr: 1,
19+
},
20+
{
21+
// ...
22+
},
23+
];
24+
```

docs/docs/markdown-javascript/overview.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ export const header = () => {
123123
};
124124
```
125125

126+
```js story-code
127+
// not defined for android
128+
```
129+
130+
```js story-code
131+
// not defined for ios
132+
```
133+
126134
#### Story Code
127135

128136
If your preview is followed by a code blocks marked as `story-code` then those will be shown when switching between multiple platforms

docs/docs/markdown-javascript/preview.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ will result in
4040
export const foo = () => html` <demo-element></demo-element> `;
4141
```
4242

43+
```js story-code
44+
// not defined for android
45+
```
46+
47+
```js story-code
48+
// not defined for ios
49+
```
50+
4351
#### Story Code
4452

4553
If your preview is followed by a code blocks marked as `story-code` then those will be shown when switching between multiple platforms

packages/mdjs-preview/src/MdJsPreview.js

Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,16 @@ export class MdJsPreview extends ScopedElementsMixin(LitElement) {
107107
// { key: 'ios', name: 'iOS' },
108108
];
109109

110-
this.size = 'webSmall';
110+
this.size = 'webInline';
111111
this.sizes = [
112+
{
113+
key: 'webInline',
114+
name: 'Inline',
115+
platform: 'web',
116+
width: 360,
117+
height: 640,
118+
dpr: 1,
119+
},
112120
{
113121
key: 'webSmall',
114122
name: 'Small',
@@ -241,6 +249,10 @@ export class MdJsPreview extends ScopedElementsMixin(LitElement) {
241249
if (this.lightDomRenderTarget && changeProps.has('story')) {
242250
render(this.story({ shadowRoot: this }), this.lightDomRenderTarget);
243251
}
252+
253+
if (changeProps.has('platform') || changeProps.has('size')) {
254+
this.deviceMode = this.platform === 'web' && this.size === 'webInline' ? false : true;
255+
}
244256
}
245257

246258
disconnectedCallback() {
@@ -311,7 +323,6 @@ export class MdJsPreview extends ScopedElementsMixin(LitElement) {
311323
renderPlatforms() {
312324
if (this.platforms.length) {
313325
return html`
314-
<h4>Platform</h4>
315326
<div
316327
class="segmented-control"
317328
@change=${
@@ -344,17 +355,27 @@ export class MdJsPreview extends ScopedElementsMixin(LitElement) {
344355
if (this.platforms.length) {
345356
return html`
346357
<div>
347-
<h3>Platform</h3>
358+
<h4>Platform</h4>
348359
${this.renderPlatforms()}
349360
</div>
350361
`;
351362
}
352363
}
353364

365+
renderSize() {
366+
if (this.sizes.length) {
367+
return html`
368+
<div>
369+
<h4>Size</h4>
370+
${this.renderSizes()}
371+
</div>
372+
`;
373+
}
374+
}
375+
354376
renderSizes() {
355377
if (this.sizes.length) {
356378
return html`
357-
<h4>Size</h4>
358379
<div
359380
class="segmented-control"
360381
@change=${
@@ -387,7 +408,7 @@ export class MdJsPreview extends ScopedElementsMixin(LitElement) {
387408
return html`
388409
<div>
389410
<h3>Viewport</h3>
390-
${this.renderSizes()} ${this.renderAutoHeight()}
411+
${this.renderAutoHeight()}
391412
</div>
392413
`;
393414
}
@@ -571,6 +592,11 @@ export class MdJsPreview extends ScopedElementsMixin(LitElement) {
571592

572593
render() {
573594
return html`
595+
${this.simulatorUrl
596+
? html`
597+
<div class="platform-size-controls">${this.renderPlatform()} ${this.renderSize()}</div>
598+
`
599+
: ``}
574600
<div id="wrapper">
575601
<slot name="story"></slot>
576602
${this.deviceMode === true
@@ -588,19 +614,28 @@ export class MdJsPreview extends ScopedElementsMixin(LitElement) {
588614
: nothing}
589615
</div>
590616
<lion-accordion class="options">
591-
${this.deviceMode
617+
${this.simulatorUrl
592618
? html`
593619
<h3 slot="invoker">
594620
<button>Settings</button>
595621
</h3>
596622
<div slot="content">
623+
${this.deviceMode
624+
? ``
625+
: html`<div>
626+
Note: Additional settings become available when not in web inline mode
627+
</div>`}
597628
<div class="settings-wrapper">
598-
${this.renderPlatform()} ${this.renderViewport()} ${this.renderVisual()}
599-
${this.renderLocalization()} ${this.renderSyncSettings()}
629+
${this.deviceMode
630+
? html`
631+
${this.renderViewport()} ${this.renderVisual()} ${this.renderLocalization()}
632+
${this.renderSyncSettings()}
633+
`
634+
: html` ${this.renderSyncSettings()} `}
600635
</div>
601636
</div>
602637
`
603-
: ''}
638+
: ``}
604639
<h3 slot="invoker">
605640
<button>Code</button>
606641
</h3>
@@ -615,12 +650,6 @@ export class MdJsPreview extends ScopedElementsMixin(LitElement) {
615650
? html`
616651
<div class="controls">
617652
<a href=${this.iframeUrl} target="_blank">Open simulation in new window</a>
618-
<button
619-
@click=${() => (this.deviceMode = !this.deviceMode)}
620-
class="simulation-toggle"
621-
>
622-
${this.deviceMode ? html`Disable` : html`Enable`} device simulation
623-
</button>
624653
</div>
625654
`
626655
: ''}
@@ -638,6 +667,10 @@ export class MdJsPreview extends ScopedElementsMixin(LitElement) {
638667
display: none;
639668
}
640669
670+
:host(:not([device-mode])) #wrapper {
671+
border: 2px solid #4caf50;
672+
}
673+
641674
iframe {
642675
border: 2px solid #4caf50;
643676
background: #fff;
@@ -732,6 +765,15 @@ export class MdJsPreview extends ScopedElementsMixin(LitElement) {
732765
padding: 15px 0;
733766
}
734767
768+
.platform-size-controls {
769+
display: flex;
770+
justify-content: flex-start;
771+
}
772+
773+
.platform-size-controls > * {
774+
margin-right: 25px;
775+
}
776+
735777
.controls {
736778
display: flex;
737779
justify-content: space-between;

packages/mdjs-preview/test-web/mdjs-preview.test.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,8 @@ describe('mdjs-preview', () => {
2828
expect(preview1.edgeDistance).to.be.true;
2929
expect(preview2.edgeDistance).to.be.true;
3030

31-
preview1.platform = 'android';
3231
preview1.edgeDistance = false;
3332
await preview1.updateComplete;
34-
expect(preview1.platform).to.equal('android');
35-
expect(preview2.platform).to.equal('android');
3633
expect(preview1.edgeDistance).to.be.false;
3734
expect(preview2.edgeDistance).to.be.false;
3835
});

0 commit comments

Comments
 (0)