Skip to content

Commit 10e82ea

Browse files
author
Niklas Kiefer
committed
feat(playground): make it possible to render own properties panel
Closes #286
1 parent 74bdc70 commit 10e82ea

File tree

8 files changed

+165
-122
lines changed

8 files changed

+165
-122
lines changed

packages/form-js-playground/package-lock.json

Lines changed: 14 additions & 109 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/form-js-playground/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"@codemirror/basic-setup": "^0.18.2",
4242
"@codemirror/lang-json": "^0.18.0",
4343
"@codemirror/state": "^0.18.7",
44+
"classnames": "^2.3.1",
4445
"downloadjs": "^1.4.7",
4546
"file-drops": "^0.4.0",
4647
"mitt": "^3.0.0",
@@ -51,6 +52,7 @@
5152
],
5253
"devDependencies": {
5354
"css-loader": "^6.3.0",
55+
"min-dom": "^3.2.1",
5456
"rollup-plugin-css-only": "^3.1.0",
5557
"style-loader": "^3.3.0"
5658
}

packages/form-js-playground/rollup.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ export default [
5252
'preact/jsx-runtime',
5353
'@codemirror/basic-setup',
5454
'@codemirror/state',
55-
'@codemirror/lang-json'
55+
'@codemirror/lang-json',
56+
'classnames'
5657
]
5758
},
5859
{

packages/form-js-playground/src/Playground.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,25 @@ import mitt from 'mitt';
66

77
import { PlaygroundRoot } from './components/PlaygroundRoot';
88

9-
9+
/**
10+
* @typedef { {
11+
* container: Element,
12+
* schema: any,
13+
* data: any,
14+
* propertiesPanel?: { inline: Boolean }
15+
* } } FormPlaygroundOptions
16+
*/
17+
18+
/**
19+
* @param {FormPlaygroundOptions} options
20+
*/
1021
export default function Playground(options) {
1122

1223
const {
1324
container: parent,
1425
schema,
15-
data
26+
data,
27+
propertiesPanel = {}
1628
} = options;
1729

1830
const emitter = mitt();
@@ -45,6 +57,7 @@ export default function Playground(options) {
4557
<PlaygroundRoot
4658
schema={ schema }
4759
data={ data }
60+
propertiesPanel={ propertiesPanel }
4861
onStateChanged={ (_state) => state = _state }
4962
onInit={ _ref => ref = _ref }
5063
/>,

packages/form-js-playground/src/components/PlaygroundRoot.css

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
--color-palette-container-background: var(--color-grey-225-10-97);
99
--color-palette-container-border: var(--color-grey-225-10-80);
1010

11+
--color-properties-container-background: var(--color-white);
12+
1113
--color-text: var(--color-grey-225-10-15);
1214

1315
--font-family: 'IBM Plex Sans', sans-serif;
@@ -28,10 +30,14 @@
2830
height: 100%;
2931

3032
display: grid;
31-
grid-template-columns: 65% 35%;
33+
grid-template-columns: 50% 50%;
3234
grid-template-rows: 70% 30%;
3335
}
3436

37+
.fjs-pgl-inline-panel .fjs-pgl-main {
38+
grid-template-columns: 65% 35%;
39+
}
40+
3541
/**
3642
* Palette
3743
*/
@@ -59,6 +65,22 @@
5965
margin: 0;
6066
}
6167

68+
/**
69+
* Properties Panel
70+
*/
71+
.fjs-pgl-properties-container {
72+
position: relative;
73+
display: flex;
74+
height: 100%;
75+
overflow-y: auto;
76+
background-color: var(--color-properties-container-background);
77+
--properties-panel-width: 200px;
78+
}
79+
80+
.fjs-pgl-properties-container .bio-properties-panel {
81+
--font-family: var(--font-family);
82+
}
83+
6284
/**
6385
* Section
6486
*/

packages/form-js-playground/src/components/PlaygroundRoot.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { useRef, useEffect, useState, useCallback } from 'preact/hooks';
22

33
import download from 'downloadjs';
44

5+
import classNames from 'classnames';
6+
57
import {
68
Form,
79
FormEditor
@@ -18,11 +20,20 @@ import './PlaygroundRoot.css';
1820

1921
export function PlaygroundRoot(props) {
2022

23+
const {
24+
propertiesPanel = {}
25+
} = props;
26+
27+
const {
28+
inline: inlinePropertiesPanel = true
29+
} = propertiesPanel;
30+
2131
const paletteContainerRef = useRef();
2232
const editorContainerRef = useRef();
2333
const formContainerRef = useRef();
2434
const dataContainerRef = useRef();
2535
const resultContainerRef = useRef();
36+
const propertiesPanelRef = useRef();
2637

2738
const formEditorRef = useRef();
2839
const formRef = useRef();
@@ -66,6 +77,9 @@ export function PlaygroundRoot(props) {
6677
},
6778
palette: {
6879
parent: paletteContainerRef.current
80+
},
81+
propertiesPanel: {
82+
parent: !inlinePropertiesPanel && propertiesPanelRef.current
6983
}
7084
});
7185

@@ -141,7 +155,10 @@ export function PlaygroundRoot(props) {
141155
}, []);
142156

143157
return (
144-
<div class="fjs-container fjs-pgl-root">
158+
<div class={ classNames(
159+
'fjs-container',
160+
'fjs-pgl-root',
161+
{ 'fjs-pgl-inline-panel': inlinePropertiesPanel }) }>
145162
<div class="fjs-pgl-modals">
146163
{ showEmbed ? <EmbedModal schema={ schema } data={ data } onClose={ hideEmbedModal } /> : null }
147164
</div>
@@ -174,6 +191,7 @@ export function PlaygroundRoot(props) {
174191
<div ref={ resultContainerRef } class="fjs-pgl-text-container"></div>
175192
</Section>
176193
</div>
194+
<div class="fjs-pgl-properties-container" ref={ propertiesPanelRef } />
177195
</div>
178196
);
179197
}

0 commit comments

Comments
 (0)