Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit e6df5c0

Browse files
committed
chore: Added support to run demos for local development
1 parent d66d22b commit e6df5c0

3 files changed

Lines changed: 87 additions & 0 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ node_modules/
1212

1313
# Build output
1414
/build/
15+
/dist/
1516
/coverage/
1617
packages/*/dist
1718
packages/**/*.js

‎.sassrc.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Sass configuration file used by Parcel.js for running local demos.
3+
*/
4+
const path = require('path')
5+
const glob = require('glob');
6+
7+
const CWD = process.cwd()
8+
const includePaths = glob.sync(path.join(CWD, 'packages/mdc-*/node_modules'));
9+
10+
module.exports = {
11+
"includePaths": includePaths,
12+
}

‎docs/local-development.md‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Local Development
2+
3+
Use this document to run demos for local development of Material Components Web project.
4+
5+
## Create demo assets
6+
7+
Create `demo/` folder inside component package folder that you're working on. For example, `packages/mdc-checkbox/demo/`
8+
9+
### HTML
10+
11+
Add HTML structure to required to render component (Copy HTML structure from component README files).
12+
13+
Sample HTML structure for checkbox:
14+
15+
```html
16+
<div class="mdc-form-field">
17+
<div class="mdc-checkbox">
18+
<input type="checkbox"
19+
class="mdc-checkbox__native-control"
20+
id="checkbox-1"/>
21+
<div class="mdc-checkbox__background">
22+
<svg class="mdc-checkbox__checkmark"
23+
viewBox="0 0 24 24">
24+
<path class="mdc-checkbox__checkmark-path"
25+
fill="none"
26+
d="M1.73,12.91 8.1,19.28 22.79,4.59"/>
27+
</svg>
28+
<div class="mdc-checkbox__mixedmark"></div>
29+
</div>
30+
<div class="mdc-checkbox__ripple"></div>
31+
</div>
32+
<label for="checkbox-1">Checkbox 1</label>
33+
</div>
34+
35+
<script type="module" src="./index.ts"></script>
36+
```
37+
38+
We'll create demo `index.ts` file in following steps.
39+
40+
### Sass
41+
42+
Include Sass files required to style target components using relative path (relative to `demo/` folder).
43+
44+
```scss
45+
@use "../../mdc-form-field/mdc-form-field";
46+
@use "../mdc-checkbox";
47+
```
48+
49+
### TypeScript
50+
51+
```ts
52+
import {MDCFormField} from '../../mdc-form-field/component';
53+
import {MDCCheckbox} from '../component';
54+
55+
const checkboxEl = document.querySelector<HTMLElement>('.mdc-checkbox');
56+
const formFieldEl = document.querySelector<HTMLElement>('.mdc-form-field');
57+
58+
if (checkboxEl && formFieldEl) {
59+
const checkbox = new MDCCheckbox();
60+
const formField = new MDCFormField();
61+
formField.input = checkbox;
62+
}
63+
```
64+
65+
## Run dev server
66+
67+
We'll use [Parcel.js](https://parceljs.org) bundler to compile & run dev server. Use `index.html` created above as entry point to parcel bundler CLI.
68+
69+
```shell
70+
npm i
71+
npx parcel packages/mdc-checkbox/demo/index.html
72+
```
73+
74+
Now open http://localhost:1234/ in your browser.

0 commit comments

Comments
 (0)