Skip to content

Commit b4b254f

Browse files
eneufeldedgarmueller
authored andcommitted
Remove reference to vanilla styles from example module (#788)
- vanillaStyles are passed via new additionalState parameter - Clean up example tsconfig
1 parent 3662790 commit b4b254f

File tree

5 files changed

+24
-19
lines changed

5 files changed

+24
-19
lines changed

packages/examples/src/day1.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { registerExamples } from './register';
2+
13
export const schema = {
24
type: 'object',
35
properties: {
@@ -19,3 +21,12 @@ export const data = {
1921
description: 'Confirm if you have passed the subject\nHereby ...',
2022
done: true,
2123
};
24+
registerExamples([
25+
{
26+
name: 'day1',
27+
label: 'Day 1',
28+
data,
29+
schema,
30+
uiSchema: undefined
31+
}
32+
]);

packages/examples/src/day3.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { registerExamples } from './register';
2-
import { schema as day2Schema, uischema as day2UiSchema, data as day2Data } from './day2';
2+
import { data as day2Data, schema as day2Schema, uischema as day2UiSchema } from './day2';
33

44
export const schema = {
55
type: 'object',

packages/examples/src/register.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
import { JsonFormsElement } from '@jsonforms/core';
22
import { ExampleDescription } from './example';
3-
import { vanillaStyles } from '../../vanilla/src/helpers';
43

54
declare let exampleDivId;
65
declare let viewDivId;
76

87
const knownExamples: {[key: string]: ExampleDescription} = {};
98

9+
export interface AdditionalState {
10+
[x: string]: any;
11+
}
12+
1013
export const registerExamples = (examples: ExampleDescription[]): void => {
1114
examples.forEach(example => knownExamples[example.name] = example);
1215
};
1316

14-
export const changeExample = (selectedExample: string) => {
17+
export const changeExample = (selectedExample: string, additionalState: AdditionalState) => {
1518
let body = document.getElementById(viewDivId);
1619
if (body.firstChild !== null && body.firstChild.childNodes.length !== 0) {
1720
body.removeChild(body.firstChild);
@@ -29,13 +32,13 @@ export const changeExample = (selectedExample: string) => {
2932
data: example.data,
3033
schema: example.schema,
3134
uischema: example.uiSchema,
32-
styles: vanillaStyles
35+
...additionalState,
3336
};
3437

3538
body.appendChild(jsonForms);
3639
};
3740

38-
export const createExampleSelection = (): HTMLSelectElement => {
41+
export const createExampleSelection = (additionalState?: AdditionalState): HTMLSelectElement => {
3942
const examplesDiv = document.getElementById(exampleDivId);
4043
const labelExample = document.createElement('label');
4144
labelExample.textContent = 'Example:';
@@ -52,10 +55,10 @@ export const createExampleSelection = (): HTMLSelectElement => {
5255
select.appendChild(option);
5356
});
5457
select.onchange = () => {
55-
changeExample(select.value);
58+
changeExample(select.value, additionalState);
5659
};
5760
examplesDiv.appendChild(select);
58-
changeExample(select.value);
61+
changeExample(select.value, additionalState);
5962

6063
return select;
6164
};

packages/examples/tsconfig.json

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
{
2+
"extends": "../../tsconfig.base",
23
"compilerOptions": {
3-
"baseUrl": "src",
4-
"declaration": true,
5-
"emitDecoratorMetadata": true,
6-
"experimentalDecorators": true,
7-
"lib": ["es6", "dom"],
8-
"module": "commonjs",
9-
"moduleResolution": "node",
104
"outDir": "dist/ts-build",
11-
"sourceMap": true,
12-
"target": "es5",
13-
"jsx": "react",
14-
"typeRoots": ["../../node_modules/@types"]
155
},
166
"exclude":[
177
"node_modules"

packages/vanilla/example/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { createExampleSelection } from '../../examples/src/register';
22
import { createThemeSelection } from './theme.switcher';
3+
import { vanillaStyles } from '../src/helpers';
34

45
window.onload = () => {
5-
createExampleSelection();
6+
createExampleSelection({styles: vanillaStyles});
67
createThemeSelection();
78
};

0 commit comments

Comments
 (0)