Skip to content

Commit a68ef61

Browse files
authored
feat: render placeholder image when no markup is provided (#74)
fixes #30
1 parent ef2450d commit a68ef61

File tree

4 files changed

+46
-5
lines changed

4 files changed

+46
-5
lines changed

public/code_thinking.png

28.9 KB
Loading

src/components/AddHtml.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from 'react';
2+
import icon from '../../public/code_thinking.png';
3+
4+
function AddHtml() {
5+
return (
6+
<div className="flex-auto absolute overflow-hidden h-full w-full flex flex-col justify-center items-center">
7+
<div className="h-48 overflow-hidden w-full flex item-center">
8+
<img
9+
className="flex-auto resize opacity-50 object-contain max-h-full min-h-0"
10+
src={icon}
11+
/>
12+
</div>
13+
<p className="opacity-50 ml-24">Try adding some html</p>
14+
</div>
15+
);
16+
}
17+
18+
export default AddHtml;

src/components/Preview.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useState, useEffect, useRef } from 'react';
22
import { usePlayground } from './Context';
33
import Scrollable from './Scrollable';
44
import PreviewHint from './PreviewHint';
5+
import AddHtml from './AddHtml';
56
import { getQueryAdvise } from '../lib';
67

78
function selectByCssPath(rootNode, cssPath) {
@@ -86,7 +87,7 @@ function Preview() {
8687
setHighlighted(target);
8788
};
8889

89-
return (
90+
return state.markup ? (
9091
<div
9192
className="w-full h-full flex flex-col relative overflow-hidden"
9293
onMouseEnter={() => setHighlighted(true)}
@@ -106,6 +107,10 @@ function Preview() {
106107

107108
<PreviewHint roles={roles} suggestion={suggestion} />
108109
</div>
110+
) : (
111+
<div className="w-full h-full flex flex-col relative overflow-hidden">
112+
<AddHtml />
113+
</div>
109114
);
110115
}
111116

src/components/Result.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,30 @@ function Result() {
1717
);
1818
}
1919

20-
const { data, suggestion } = state.result.elements?.[0] || {};
21-
22-
if (!data || !suggestion) {
23-
return <div />;
20+
if (!state.result.expression) {
21+
return (
22+
<div className="space-y-4 text-sm">
23+
<div className="min-h-8">
24+
<p>
25+
I don&apos;t know what to say. This is a playground for{' '}
26+
<a
27+
href="https://testing-library.com/docs/dom-testing-library/example-intro"
28+
rel="noopener noreferrer"
29+
target="_blank"
30+
className="font-bold"
31+
>
32+
React Testing Library
33+
</a>
34+
.<br /> Please insert some html and queries to be adviced on which
35+
should be used.
36+
</p>
37+
</div>
38+
</div>
39+
);
2440
}
2541

42+
const { data, suggestion } = state.result.elements?.[0] || {};
43+
2644
return (
2745
<div className="flex flex-col overflow-hidden w-full h-full">
2846
<div className="flex-none pb-4 border-b">

0 commit comments

Comments
 (0)