This repository was archived by the owner on Dec 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathindex.tsx
More file actions
44 lines (41 loc) · 1.31 KB
/
index.tsx
File metadata and controls
44 lines (41 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import React, {useEffect, useState} from 'react';
import { Style } from "react-style-tag";
import JsxParser from "react-jsx-parser";
import Timer from "react-compound-timer";
import styled from 'styled-components';
const Prompt = styled.div`
font-size: 1.5em
`;
const LiveTemplate = styled.div`
margin: 20px;
padding: 20px;
border: ${props => !props.jsxString ? 'dashed black' : 'none'};
};
`;
/**
* Display a react com
* @param jsxString
* @param cssString
* @constructor
*/
const TemplateDisplay = ({jsxString, cssString}) => {
if (!jsxString) {
return (
<LiveTemplate jsxString={jsxString}>
<Prompt>Press the <span className='fa fa-bell'></span> bell icon in the editor's toolbar to copy the template HTML/JSX here to have a live version of it!</Prompt>
</LiveTemplate>
);
}
return (
<LiveTemplate jsxString={jsxString}>
<Style>{cssString}</Style>
<JsxParser components={{Timer}} jsx={jsxString} bindings={
{
// This is called from the formatValue attribute of the Timer coming in htmlString
formatValue: (value) => `${(value < 10 ? `0${value}` : value)}`
}
}/>
</LiveTemplate>
);
}
export default TemplateDisplay;