Skip to content

Commit

Permalink
feat(playground): make it possible to render own properties panel
Browse files Browse the repository at this point in the history
Closes #286
  • Loading branch information
Niklas Kiefer committed Aug 4, 2022
1 parent 92e0308 commit 6e66134
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 122 deletions.
123 changes: 14 additions & 109 deletions packages/form-js-playground/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/form-js-playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@codemirror/basic-setup": "^0.18.2",
"@codemirror/lang-json": "^0.18.0",
"@codemirror/state": "^0.18.7",
"classnames": "^2.3.1",
"downloadjs": "^1.4.7",
"file-drops": "^0.4.0",
"mitt": "^3.0.0",
Expand All @@ -51,6 +52,7 @@
],
"devDependencies": {
"css-loader": "^6.3.0",
"min-dom": "^3.2.1",
"rollup-plugin-css-only": "^3.1.0",
"style-loader": "^3.3.0"
}
Expand Down
3 changes: 2 additions & 1 deletion packages/form-js-playground/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export default [
'preact/jsx-runtime',
'@codemirror/basic-setup',
'@codemirror/state',
'@codemirror/lang-json'
'@codemirror/lang-json',
'classnames'
]
},
{
Expand Down
17 changes: 15 additions & 2 deletions packages/form-js-playground/src/Playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,25 @@ import mitt from 'mitt';

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


/**
* @typedef { {
* container: Element,
* schema: any,
* data: any,
* editor?: { inlinePropertiesPanel: Boolean }
* } } FormPlaygroundOptions
*/

/**
* @param {FormPlaygroundOptions} options
*/
export default function Playground(options) {

const {
container: parent,
schema,
data
data,
...rest
} = options;

const emitter = mitt();
Expand Down Expand Up @@ -47,6 +59,7 @@ export default function Playground(options) {
data={ data }
onStateChanged={ (_state) => state = _state }
onInit={ _ref => ref = _ref }
{ ...rest }
/>,
container
);
Expand Down
24 changes: 23 additions & 1 deletion packages/form-js-playground/src/components/PlaygroundRoot.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
--color-palette-container-background: var(--color-grey-225-10-97);
--color-palette-container-border: var(--color-grey-225-10-80);

--color-properties-container-background: var(--color-white);

--color-text: var(--color-grey-225-10-15);

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

display: grid;
grid-template-columns: 65% 35%;
grid-template-columns: 50% 50%;
grid-template-rows: 70% 30%;
}

.fjs-pgl-inline-editor-panel .fjs-pgl-main {
grid-template-columns: 65% 35%;
}

/**
* Palette
*/
Expand Down Expand Up @@ -59,6 +65,22 @@
margin: 0;
}

/**
* Properties Panel
*/
.fjs-pgl-properties-container {
position: relative;
display: flex;
height: 100%;
overflow-y: auto;
background-color: var(--color-properties-container-background);
--properties-panel-width: 200px;
}

.fjs-pgl-properties-container .bio-properties-panel {
--font-family: var(--font-family);
}

/**
* Section
*/
Expand Down
20 changes: 19 additions & 1 deletion packages/form-js-playground/src/components/PlaygroundRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { useRef, useEffect, useState, useCallback } from 'preact/hooks';

import download from 'downloadjs';

import classNames from 'classnames';

import {
Form,
FormEditor
Expand All @@ -18,11 +20,20 @@ import './PlaygroundRoot.css';

export function PlaygroundRoot(props) {

const {
editor: editorConfig = {}
} = props;

const {
inlinePropertiesPanel = true
} = editorConfig;

const paletteContainerRef = useRef();
const editorContainerRef = useRef();
const formContainerRef = useRef();
const dataContainerRef = useRef();
const resultContainerRef = useRef();
const propertiesPanelContainerRef = useRef();

const formEditorRef = useRef();
const formRef = useRef();
Expand Down Expand Up @@ -66,6 +77,9 @@ export function PlaygroundRoot(props) {
},
palette: {
parent: paletteContainerRef.current
},
propertiesPanel: {
parent: !inlinePropertiesPanel && propertiesPanelContainerRef.current
}
});

Expand Down Expand Up @@ -141,7 +155,10 @@ export function PlaygroundRoot(props) {
}, []);

return (
<div class="fjs-container fjs-pgl-root">
<div class={ classNames(
'fjs-container',
'fjs-pgl-root',
{ 'fjs-pgl-inline-editor-panel': inlinePropertiesPanel }) }>
<div class="fjs-pgl-modals">
{ showEmbed ? <EmbedModal schema={ schema } data={ data } onClose={ hideEmbedModal } /> : null }
</div>
Expand Down Expand Up @@ -174,6 +191,7 @@ export function PlaygroundRoot(props) {
<div ref={ resultContainerRef } class="fjs-pgl-text-container"></div>
</Section>
</div>
<div class="fjs-pgl-properties-container" ref={ propertiesPanelContainerRef } />
</div>
);
}
Expand Down
Loading

0 comments on commit 6e66134

Please sign in to comment.