Jack Franklin | 1557a1c | 2020-06-08 14:22:13 | [diff] [blame] | 1 | # Components dev server |
| 2 | |
| 3 | This server serves up examples of the web components built within DevTools and provides a useful way to document various states of components. |
| 4 | |
| 5 | For more background, see the [initial proposal and design doc](https://docs.google.com/document/d/1P6qtACf4aryfT9OSHxNFI3okMKt9oUrtzOKCws5bOec/edit?pli=1). |
| 6 | |
| 7 | To add an example for your component: |
| 8 | |
Tim van der Lippe | e622f55 | 2021-04-14 14:15:18 | [diff] [blame] | 9 | 1. Create `front_end/ui/components/docs/DIR` where `DIR` is the name of your component. |
Jack Franklin | 7a75e46 | 2021-01-08 16:17:13 | [diff] [blame] | 10 | 2. Within the new `DIR`, add HTML and TypeScript files. Each one of these is a standalone example. You should name the HTML file based on what it's documenting, e.g. `basic.html` or `data-missing.html`, and add a TypeScript file with the same name. The TypeScript file should contain all the code to import and run your component, and within the HTML file you can place any HTML or CSS you need (inline style tags are fine for examples) to render the component in the right context. |
Jack Franklin | 12ba06c | 2020-07-20 11:21:38 | [diff] [blame] | 11 | 3. Create a `BUILD.gn` in your new `DIR`. This should contain the following code: |
| 12 | |
| 13 | ``` |
| 14 | import("../../../scripts/build/ninja/copy.gni") |
Simon Zünd | e20bdac | 2024-08-27 07:35:53 | [diff] [blame] | 15 | import("../../../scripts/build/typescript/typescript.gni") |
Jack Franklin | 7a75e46 | 2021-01-08 16:17:13 | [diff] [blame] | 16 | |
| 17 | ts_library("ts") { |
| 18 | sources = [ |
| 19 | "basic.ts" |
| 20 | ] |
| 21 | |
| 22 | deps = [ |
| 23 | # As an example: anything your TS code imports needs to be listed here as a dep. |
Tim van der Lippe | 67d60bf | 2021-04-14 11:40:47 | [diff] [blame] | 24 | "../../ui/components/data_grid:bundle", |
Jack Franklin | 7a75e46 | 2021-01-08 16:17:13 | [diff] [blame] | 25 | ] |
| 26 | } |
Jack Franklin | 12ba06c | 2020-07-20 11:21:38 | [diff] [blame] | 27 | |
| 28 | copy_to_gen("elements_breadcrumbs") { |
| 29 | sources = [ |
Jack Franklin | 7a75e46 | 2021-01-08 16:17:13 | [diff] [blame] | 30 | "basic.html", |
Jack Franklin | 12ba06c | 2020-07-20 11:21:38 | [diff] [blame] | 31 | # list all other examples here |
| 32 | ] |
| 33 | |
| 34 | deps = [ |
Jack Franklin | 7a75e46 | 2021-01-08 16:17:13 | [diff] [blame] | 35 | ":ts" |
Jack Franklin | 12ba06c | 2020-07-20 11:21:38 | [diff] [blame] | 36 | ] |
| 37 | } |
| 38 | ``` |
| 39 | |
| 40 | |
Tim van der Lippe | e622f55 | 2021-04-14 14:15:18 | [diff] [blame] | 41 | 4. Update `front_end/ui/components/docs/BUILD.gn` to add your new directory's `BUILD.GN` to the `public_deps` array. |
Jack Franklin | 12ba06c | 2020-07-20 11:21:38 | [diff] [blame] | 42 | 5. Run `npm run components-server` to fire up a server on `localhost:8090`. You should now see your component listed and you can click on the link to view the examples. |
| 43 | 6. **Note**: the server assumes your built target is `Default`. If not, run the server and pass the `--target` flag: `npm run components-server -- --target=Release`. |