Skip to content

Commit ba68cbb

Browse files
authored
feat: local configuration (#91)
1 parent 1fe9145 commit ba68cbb

24 files changed

+273
-290
lines changed

README.md

Lines changed: 32 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22

33
A library to show off your widget library.
44

5-
* Show running demos
6-
* Syntax highlighted example code
7-
* Auto documented widget properties
8-
* Auto documented theme class hooks
9-
* Run on codesandbox
10-
* Run unit tests
5+
- Show running demos
6+
- Syntax highlighted example code
7+
- Auto documented widget properties
8+
- Auto documented theme class hooks
9+
- Run on codesandbox
10+
- Run unit tests
1111

12-
![screenshot](/screenshot.png?raw=true "screenshot")
12+
![screenshot](/screenshot.png?raw=true 'screenshot')
1313

1414
## Compatibility
1515

1616
Each major release of Dojo Parade is compatible with a specific major version of the rest of the Dojo framework:
1717

1818
| Parade Version | Dojo Version |
19-
| :------------: | :-----------:|
20-
| `1.*.*` | `7.*.*` |
19+
| :------------: | :----------: |
20+
| `1.*.*` | `7.*.*` |
2121

2222
## Usage
2323

@@ -26,13 +26,15 @@ npm install @dojo/parade
2626
```
2727

2828
#### **`.dojorc`**
29+
2930
```json
3031
{
31-
"extends": "./node_modules/@dojo/parade/parade.json"
32+
"extends": "./node_modules/@dojo/parade/parade.json"
3233
}
3334
```
3435

3536
#### **`main.tsx`**
37+
3638
```tsx
3739
import parade from '@dojo/parade';
3840

@@ -42,14 +44,15 @@ import config from './config';
4244
parade({ config });
4345
```
4446

45-
### Example config:
47+
### Example global config:
48+
4649
#### **`config.tsx`**
50+
4751
```tsx
4852
import dojoTheme from '@dojo/themes/dojo';
4953
import '@dojo/themes/dojo/index.css';
5054

5155
import BasicAccordion from './widgets/accordion/Basic';
52-
import Exclusive from './widgets/accordion/Exclusive';
5356
import BasicButton from './widgets/button/Basic';
5457
import DisabledSubmit from './widgets/button/DisabledSubmit';
5558
import ToggleButton from './widgets/button/ToggleButton';
@@ -60,43 +63,21 @@ export default {
6063
header: 'My Widget Library',
6164
codesandbox: {},
6265
tests,
63-
themes: [ dojoTheme ],
64-
widgets: {
65-
accordion: {
66-
examples: [
67-
{
68-
filename: 'Exclusive',
69-
module: Exclusive
70-
}
71-
],
72-
filename: 'index',
73-
overview: {
74-
example: {
75-
filename: 'Basic',
76-
module: BasicAccordion
77-
}
78-
}
79-
},
80-
button: {
81-
examples: [
82-
{
83-
filename: 'DisabledSubmit',
84-
module: DisabledSubmit,
85-
title: 'Disabled Submit Button'
86-
},
87-
{
88-
filename: 'ToggleButton',
89-
module: ToggleButton,
90-
title: 'Toggle Button'
91-
}
92-
],
93-
filename: 'index',
94-
overview: {
95-
example: {
96-
filename: 'Basic',
97-
module: BasicButton
98-
}
99-
}
100-
}
101-
}
66+
themes: [ dojoTheme ]
67+
```
68+
69+
### Example local config:
70+
71+
#### **`AccordionBasic.example.tsx`**
72+
73+
```tsx
74+
import dojoTheme from '@dojo/themes/dojo';
75+
import '@dojo/themes/dojo/index.css';
76+
77+
import AccordionBasic from './widgets/accordion/Basic';
78+
79+
export default {
80+
module: AccordionBasic,
81+
overview: true
82+
};
10283
```

package.json

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
11
{
2-
"name": "@dojo/parade",
3-
"version": "1.0.2-pre",
4-
"scripts": {
5-
"dev": "dojo build app -m dev -w -s",
6-
"start": "npm run dev",
7-
"dist": "dojo build widget -t lib",
8-
"dist:legacy": "dojo build widget -t lib --legacy",
9-
"copy": "shx mkdir -p ./dist/release && shx cp -r ./output/dist/* ./dist/release/",
10-
"clean": "shx rm -rf ./output/dist && shx rm -rf output",
11-
"package": "npm run clean && npm run dist && npm run copy && npm run dist:legacy && npm run copy",
12-
"prettier": "prettier --write \"src/**/*.{ts,tsx,css}\"",
13-
"release": "npm run package && dojo-release"
14-
},
15-
"peerDependencies": {
16-
"@dojo/framework": "~7.0.0"
17-
},
18-
"dependencies": {
19-
"@fortawesome/fontawesome-free": "5.15.3",
20-
"canonical-path": "1.0.0",
21-
"cldr-data": "36.0.0",
22-
"postcss": "7.0.21",
23-
"prismjs": "1.17.1",
24-
"rehype-add-classes": "^1.0.0",
25-
"rehype-stringify": "6.0.0",
26-
"remark-parse": "7.0.1",
27-
"remark-rehype": "5.0.0",
28-
"remark-sectionize": "^1.1.0",
29-
"ts-morph": "4.2.0",
30-
"tslib": "~1.9.1",
31-
"unified": "8.4.1"
32-
},
33-
"devDependencies": {
34-
"@dojo/cli": "~7.0.0",
35-
"@dojo/cli-build-app": "~7.0.0",
36-
"@dojo/cli-build-widget": "~7.0.0",
37-
"@dojo/framework": "~7.0.0",
38-
"@dojo/scripts": "^4.0.2",
39-
"@types/node": "~9.6.5",
40-
"intern": "^4.6.0",
41-
"prettier": "^1.19.1",
42-
"shx": "^0.3.2",
43-
"tailwindcss": "^1.1.4",
44-
"typescript": "~3.4.5"
45-
},
46-
"prettier": {
47-
"singleQuote": true,
48-
"tabWidth": 4,
49-
"useTabs": true,
50-
"printWidth": 100,
51-
"arrowParens": "always"
52-
}
2+
"name": "@dojo/parade",
3+
"version": "1.0.2-pre",
4+
"scripts": {
5+
"dev": "dojo build app -m dev -w -s",
6+
"start": "npm run dev",
7+
"dist": "dojo build widget -t lib",
8+
"dist:legacy": "dojo build widget -t lib --legacy",
9+
"copy": "shx mkdir -p ./dist/release && shx cp -r ./output/dist/* ./dist/release/",
10+
"clean": "shx rm -rf ./output/dist && shx rm -rf output",
11+
"package": "npm run clean && npm run dist && npm run copy && npm run dist:legacy && npm run copy",
12+
"prettier": "prettier --write \"src/**/*.{ts,tsx,css}\"",
13+
"release": "npm run package && dojo-release"
14+
},
15+
"peerDependencies": {
16+
"@dojo/framework": "~7.0.0"
17+
},
18+
"dependencies": {
19+
"@fortawesome/fontawesome-free": "5.15.3",
20+
"canonical-path": "1.0.0",
21+
"cldr-data": "36.0.0",
22+
"postcss": "7.0.21",
23+
"prismjs": "1.17.1",
24+
"rehype-add-classes": "^1.0.0",
25+
"rehype-stringify": "6.0.0",
26+
"remark-parse": "7.0.1",
27+
"remark-rehype": "5.0.0",
28+
"remark-sectionize": "^1.1.0",
29+
"ts-morph": "4.2.0",
30+
"tslib": "~1.9.1",
31+
"unified": "8.4.1"
32+
},
33+
"devDependencies": {
34+
"@dojo/cli": "~7.0.0",
35+
"@dojo/cli-build-app": "~7.0.0",
36+
"@dojo/cli-build-widget": "~7.0.0",
37+
"@dojo/framework": "~7.0.0",
38+
"@dojo/scripts": "^4.0.2",
39+
"@types/node": "~9.6.5",
40+
"intern": "^4.6.0",
41+
"prettier": "^1.19.1",
42+
"shx": "^0.3.2",
43+
"tailwindcss": "^1.1.4",
44+
"typescript": "~3.4.5"
45+
},
46+
"prettier": {
47+
"singleQuote": true,
48+
"tabWidth": 4,
49+
"useTabs": true,
50+
"printWidth": 100,
51+
"arrowParens": "always"
52+
}
5353
}

src/App.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,21 @@ import getTheme from './theme.block';
1919
import code from './code.block';
2020

2121
import '@fortawesome/fontawesome-free/css/all.css';
22+
import { Config } from '.';
2223

23-
function getWidgetFileNames(config: any): { [index: string]: string } {
24+
function getWidgetFileNames(config: Config): { [index: string]: string } {
25+
if (!config.widgets) return {};
2426
return Object.keys(config.widgets).reduce((newConfig, widget) => {
2527
return {
2628
...newConfig,
27-
[widget]: config.widgetPath(widget, config.widgets[widget].filename)
29+
[widget]: config.widgetPath(widget)
2830
};
2931
}, {});
3032
}
3133

32-
function getReadmeFileNames(config: any): string[] {
34+
function getReadmeFileNames(config: Config): string[] {
3335
const filenames: string[] = [];
36+
if (!config.widgets) return filenames;
3437
Object.keys(config.widgets).forEach((key) => {
3538
filenames.push(config.readmePath(key));
3639
});
@@ -40,18 +43,16 @@ function getReadmeFileNames(config: any): string[] {
4043
return filenames;
4144
}
4245

43-
function getExampleFileNames(config: any): string[] {
46+
function getExampleFileNames(config: Config): string[] {
4447
const filenames: string[] = [];
48+
if (!config.widgets) {
49+
return filenames;
50+
}
4551
Object.keys(config.widgets).forEach((key) => {
46-
const widget = config.widgets[key];
47-
if (widget.overview && widget.overview.example) {
48-
filenames.push(config.examplePath(key, widget.overview.example.filename));
49-
}
50-
if (widget.examples) {
51-
widget.examples.forEach((example: any) => {
52-
filenames.push(config.examplePath(key, example.filename));
53-
});
54-
}
52+
const examples = config.widgets![key];
53+
examples.forEach((example) => {
54+
filenames.push(config.examplePath(key, example.filename));
55+
});
5556
});
5657
return filenames;
5758
}
@@ -69,7 +70,6 @@ export default factory(function App({ properties, middleware: { block, icache, t
6970
window.location.search = `theme=${label}`;
7071
theme.set(newTheme);
7172
};
72-
7373
const widgetReadmeContent = isCodeSandbox ? {} : block(readme)(readmeFilenames) || {};
7474
const widgetExampleContent = isCodeSandbox ? {} : block(code)(exampleFilenames) || {};
7575
const widgetProperties = isCodeSandbox ? {} : block(getWidgetProperties)(widgetFilenames) || {};

src/Example.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { isThemeInjectorPayloadWithVariant } from '@dojo/framework/core/ThemeInj
77
import HorizontalRule from './HorizontalRule';
88
import ThemeTable from './ThemeTable';
99
import InterfaceTable from './InterfaceTable';
10+
import { Config } from '.';
1011

1112
const middleware = create({ destroy, icache });
1213

@@ -29,7 +30,7 @@ const factory = create({ theme, icache, postMessage }).properties<{
2930
widgetExamples: any;
3031
widgetProperties: any;
3132
widgetThemes: any;
32-
config: any;
33+
config: Config;
3334
}>();
3435

3536
export default factory(function Example({
@@ -58,11 +59,14 @@ export default factory(function Example({
5859
}
5960
});
6061
const isOverview = !exampleName;
61-
const example = isOverview
62-
? config.widgets[widgetName].overview.example
63-
: config.widgets[widgetName].examples.find(
64-
(e: any) => e.filename.toLowerCase() === exampleName
65-
);
62+
const example =
63+
config.widgets &&
64+
config.widgets[widgetName].find((e: any) =>
65+
isOverview ? e.overview : e.filename.toLowerCase() === exampleName
66+
);
67+
if (!example) {
68+
return;
69+
}
6670
const codesandboxPath =
6771
config.codesandboxPath && config.codesandboxPath(widgetName, example.filename, themeName);
6872
const examplePath = config.examplePath(widgetName, example.filename);

src/ExampleSandbox.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,12 @@ export default factory(function Example({ properties, middleware: { theme, resiz
2626
if (height) {
2727
parent.postMessage(JSON.stringify({ height: `${height}px` }), '*');
2828
}
29-
const isOverview =
30-
config.widgets[widgetName].overview.example.filename.toLowerCase() === exampleName;
31-
const example = isOverview
32-
? config.widgets[widgetName].overview.example
33-
: config.widgets[widgetName].examples.find(
34-
(e: any) => e.filename.toLowerCase() === exampleName
35-
);
36-
return (
29+
const example =
30+
config.widgets &&
31+
config.widgets[widgetName].find((e: any) => e.filename.toLowerCase() === exampleName);
32+
return example ? (
3733
<div key="example-container" classes={css.container}>
3834
<example.module />
3935
</div>
40-
);
36+
) : null;
4137
});

0 commit comments

Comments
 (0)