diff --git a/packages/example/src/App.css b/packages/example/src/App.css index 990bbbcf1..f5a9dec8d 100644 --- a/packages/example/src/App.css +++ b/packages/example/src/App.css @@ -2,6 +2,7 @@ body { margin: 0; padding: 0; font-family: sans-serif; + background: #f3f4fa; } .header { @@ -35,7 +36,7 @@ body { margin: 0 10px 0 0; } .tools .example-selector select { - background: #f3f4fa; + background: #fff; border-radius: 9px; height: 30px; border: 0; @@ -80,20 +81,11 @@ body { text-align: center; } .demo-wrapper .demoform .demo { - background: #f3f4fa; + background: #fff; border-radius: 9px; padding: 20px; margin-top: 20px; } -.demo-wrapper .demoform .demo h4 { - text-align: center; - margin-top: -30px; -} -.demo-wrapper .demoform .demo h4 span { - padding: 10px; - background-color: #fff; - border-radius: 5px; -} .action-button { margin-right: 10px; @@ -135,7 +127,7 @@ body { max-width: 400px; margin: 40px auto 20px auto; padding: 0; - background: #f3f4fa; + background: #fff; border-radius: 9px; display: inline-block; } @@ -167,13 +159,9 @@ body { background-color: #0047a1; } .react-tabs .panel-wrapper { - max-height: 150px; overflow: scroll; padding: 0 15px; } -.react-tabs .panel-wrapper.full-height { - max-height: none !important; -} .react-tabs .panel-wrapper .react-tabs__tab-panel { display: none; } diff --git a/packages/example/src/App.tsx b/packages/example/src/App.tsx index e8887289c..5b39d966c 100644 --- a/packages/example/src/App.tsx +++ b/packages/example/src/App.tsx @@ -23,7 +23,7 @@ THE SOFTWARE. */ -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useMemo, useState } from 'react'; import { JsonForms, JsonFormsInitStateProps, JsonFormsReactProps } from '@jsonforms/react'; import { ExampleDescription } from '@jsonforms/examples'; import { @@ -91,10 +91,10 @@ const App = ({ examples, cells, renderers}: AppProps) => { const [currentExample, setExample] = useState(examples[0]); const [currentIndex, setIndex] = useState(0); const [dataAsString, setDataAsString] = useState(''); - const [schemaAsString, setSchemaAsString] = useState(''); - const [uiSchemaAsString, setUiSchemaAsString] = useState(''); const [props, setProps] = useState(getProps(currentExample, cells, renderers)); const [showPanel, setShowPanel] = useState(true); + const schemaAsString = useMemo(() => JSON.stringify(props.schema, null, 2), [props.schema]); + const uiSchemaAsString = useMemo(() => JSON.stringify(props.uischema, null, 2), [props.uischema]); const actions: Action[] = currentExample.actions; @@ -119,41 +119,10 @@ const App = ({ examples, cells, renderers}: AppProps) => { } }; - useEffect(() => { - if(props.schema != undefined) { - setSchemaAsString(JSON.stringify(props.schema, null, 2)); - } else { - setSchemaAsString('No schema set'); - } - if(props.uischema != undefined) { - setUiSchemaAsString(JSON.stringify(props.uischema, null, 2)); - } else { - setUiSchemaAsString('No ui schema set'); - } - }, [props.schema, props.uischema]); - - useEffect(() => { - var panel = document.getElementsByClassName('props-panel')[0]; - if(showPanel) { - panel.classList.remove('hide'); - } else { - panel.classList.add('hide'); - } - }, [showPanel]); - const changeData = (data: any) => { setDataAsString(JSON.stringify(data, null, 2)); }; - const togglePanelHeight = () => { - var panel = document.getElementsByClassName('panel-wrapper')[0]; - panel.classList.toggle('full-height'); - } - - const togglePanel = (checked: boolean) => { - setShowPanel(checked); - } - return (
@@ -182,39 +151,40 @@ const App = ({ examples, cells, renderers}: AppProps) => {
- togglePanel(e.target.checked)} /> + setShowPanel(!showPanel)} />
-
- - - Data - Schema - UISchema - -

togglePanelHeight()}>Click here to expand

-
- - - {dataAsString} - - - - - {schemaAsString} - - - - - {uiSchemaAsString} - - -
-
-
+ { showPanel && +
+ + + Data + Schema + UISchema + +
+ + + {dataAsString} + + + + + {schemaAsString} + + + + + {uiSchemaAsString} + + +
+
+
+ }
{actions?.map((action: Action, index: number) => ( @@ -222,7 +192,6 @@ const App = ({ examples, cells, renderers}: AppProps) => { ))}
-

Example