Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples HLD #827

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 157 additions & 0 deletions specs/examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# Nimble Examples
rajsite marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member Author

@rajsite rajsite Jul 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm gonna close this PR for now. Some things I think would be useful if re-opening:

  • Split out the new cdn / bundle packages as separate work
  • Consider completely narrowing the scope of the examples to just getting started examples. At which point maybe they should just create template packages:
  • Alternative: consider separate, 1 or more?, repos that have the getting started examples. Pros: might be easier to setup (create a repo with renovate). Cons: might not be as useful for quick one off examples locally (but probably fine for stackblitz).


## Problem Statement

Nimble should have high-level well-maintained examples for our supported frameworks.

This HLD sketches out the organization and requirements of new examples and of the current examples.

## Links To Relevant Work Items and Reference Material

- [#726 Create a "Getting Started" walkthrough for Nimble Angular](https://github.com/ni/nimble/issues/726)
- [#325 Set up stackblitz or codepen template with Nimble](https://github.com/ni/nimble/issues/325)

## Implementation / Design

### Frameworks to support
- Vanilla: TypeScript + SCSS
- No explicit examples supporting vanilla JavaScript + CSS with local npm builds. Strongly encourage TS + SCSS.
- Examples will use [vite](https://vitejs.dev/)
- Supports TS + SCSS out of the box
- Web Chapter does not have an alternate recommendation yet for Vanilla apps
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Web Chapter does not have an alternate recommendation yet for Vanilla apps
- Web UI Chapter does not have an alternate recommendation yet for Vanilla apps

- Vite works on Stackblitz and local npm builds
- Parcel [does not work on Stackblitz](https://github.com/parcel-bundler/parcel/issues/7748)
- Rollup requires extra config for TS and SCSS
- Webpack aligns with the underlying technology of Angular apps but adds lots of complexity to self manage (Angular generally manages for you)
- CDN: Vanilla JS and CSS
rajsite marked this conversation as resolved.
Show resolved Hide resolved
- Uses the CDN builds of packages via unpkg.com
- Move the prebuilt libraries to a separate package (see below).
- Known issue: fonts are not included in the [existing example](https://github.com/ni/nimble/tree/0fe8cc54f7bd444830e3974969519593b532b083/packages/nimble-components#prototyping-in-a-static-webpage)
- Angular
- Blazor
- Examples will just publish as Blazor WASM as that is most compatible with static hosting and there is not significant value in making each example show Blazor WASM, Blazor Server, and Blazor Hybrid.
- Blazor WASM examples will not have the routing restrictions we have for the all-components examples. This will make the URLs to the sub routes less useful if copy and pasted but allow better examples demonstrating routing.
- While additional routes in examples are not prevented, they should be discouraged except for the use-case of demonstrating routing. It's likely extra routes make for a less coherent and targeted example anyway.

### Migrate CDN Builds to a separate package

Part of this proposal is to migrate the prebuilt all-components bundles from nimble-components to a separate npm package.

This has a couple benefits:
- Avoids confusion within the Nimble Components package. Currently nothing prevents a user from accidentally mixing usage of the normal nimble component es modules, the all-components.js es module, or the all-components-bundle.js built output.

Mixing them is very likely to break the application in hard to predict ways by creating multiple singletons in global scope, duplicating element registrations, etc. Moving them all to a separate package can eliminate possible confusion.
- Can inline all the related content, i.e. the needed nimble fonts can be copied from nimble-tokens into the cdn package making the package standalone. Doing that with the nimble-components package would not be appropriate.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some questions that might help me understand the vision for this package, which could help with naming and with deciding what is/isn't part of it.

  1. would apps ever have an npm dependency on it or just a runtime dependency on the build hosted on unpkg?
  2. would we publish a Nuget equivalent or just an npm pakcage?
  3. a client could use either nimble-bundle or a subset of the other packages, but never mix them, correct? So any assets an app might need will need to be a part of it: fonts, icons, CSS, tokens, components?

- Proposed package name `@ni/nimble-bundle`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion, but I'd lean towards the alternative of @ni/nimble-components-bundle to make the package name better convey what is included. This isn't a bundle that includes all of nimble (Angular support + web component support + any/all other components we add first-class support for in the future).

- Alternative names:
- `@ni/nimble-bundled`
- `@ni/nimble-components-cdn`
- `@ni/nimbl-components-bundle`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `@ni/nimbl-components-bundle`
- `@ni/nimble-components-bundle`

- `@ni/nimble-cdn-bundle`
- `@ni/nimble-cdn`
- Part of this proposal would also be a breaking change to the Blazor package structure. We can leverage the `@ni/nimble-bundle` package directly in build instead of building a custom `wwwroot`.
- That would change from:
```
- wwwroot/
- nimble-components/all-components-bundle.min.js
- nimble-tokens/css/fonts.css
- nimble-tokens/assets/fonts.css
```
to the following where dist is a direct copy of the nimble-bundle `dist` output:
```
- wwwroot/
- dist/all-components-bundle.min.js
- dist/css/fonts.css
- dist/assets/fonts.css
```
- Alternatives:
- Don't introduce a breaking change, keep the existing `wwwroot` file structure in Nimble Blazor
- Pros: Not a breaking change
- Cons: Nimble Blazor continues to maintain an alternate structure of bundled output

### File structure

Examples will be organized as follows:

```
- examples/
- README.md describing folder layout and documenting example expectations (linting, etc).
- <framework>/
- README.md: Table of contents for the examples
- getting-started/
- README.md: Should include a Stackblitz link to open the example immediately in addition to other content
- package.json
- source/
- <other examples>: TBD
```

rajsite marked this conversation as resolved.
Show resolved Hide resolved
Notes:
- A subfolder per `<framework>`, i.e.: `vanilla`, `cdn`, `angular`, `blazor`
- Examples should be specific and targeted
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will each example be totally standalone or would we have an Angular workspace containing an application per example?

- Large examples or examples with multiple routes should be discouraged (but are not prohibited as to allow for examples demonstrating routing).
- Each example participates in the monorepo build
- Each example follows Web Chapter conventions:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Each example follows Web Chapter conventions:
- Each example follows Web UI Chapter conventions:

- Linting configured
- Detailed README assuming pre-existing familiarity with Nimble and framework development, i.e. detailed only about example topic.
- Each `<framework>` will have a `getting-started` example.
- Getting started example will be linked from each library package README
- Getting started examples assumes brand new developers who may not have web development experience:
- guidance on IDEs
- step-by-step instructions
- links to learn more about general web topics they need to be aware of (CSS custom properties, shadow slots, etc.)
- In addition to other example requirements, the getting started examples will include unit testing infrastructure.
- Not end-to-end as that tends to be more project specific in configuration with external services, etc.
- Issue templates should be updated to include the Stackblitz urls to make it easier to report issues
- Types of examples (just ideas / not mandatory by this spec)
- Specific-component usage - Detailed examples for some more detailed configuration of specific components
- Stress tests - Lots of components, large data sets, fast updates. Would align well with Playwright-based perf tests we have experimented with.
- Examples for unsupported frameworks, i.e. example React app, vue.js app, etc. leveraging the web-component APIs directly. While we don't provide first class well-integrated support, having smoke test examples and quickly stackblitzable examples is handy.
- High-level component patterns - We could have demo pages showing making menu bar, application shell, etc stitching together nimble-components.

This might require more discussion as to the benefit of what is being illustrated. Alternatively we should be offering those higher-level patterns as supported libraries.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This statement seems to be a comment about the "High-level component patterns". Should it be a bullet point under that item?


### Existing examples
- The current [angular client example](https://github.com/ni/nimble/tree/main/angular-workspace/projects/example-client-app) and [blazor client example](https://github.com/ni/nimble/tree/main/packages/nimble-blazor/Examples)
- Will stay in current locations (angular-workspace and blazor workspace) as they are primarily developer oriented tools and not user facing examples
- Their READMEs should direct end users to the `<framework>` examples folders
- They will be renamed to `all-components-<framework>`
- Continue to not have a Vanilla all components example
- Note: This is a breaking URL change. For example, `https://nimble.ni.dev/storybook/example-client-app/` will change to `https://nimble.ni.dev/storybook/all-components-angular/`

Alternatives:
- Move the all-components examples to the examples/ folder
- Would hurt local development experience, i.e. need to run multiple angular builds / watch as a separate package not managed by angular-workspace
- Does not seem like a high value user facing example. The examples are very large and not illustrative of specific concepts.
- Users should rely on storybook for per control usage instead
- Don't rename the current client examples
- Pros: Doesn't break existing URLs
- Cons: The current names are ambiguous about framework, i.e. `example-client-app` vs `blazor-client-app`. They also don't reflect the modern use-case of being a simple dev focused example showing all the components being used.

## Alternative Implementations / Designs

N/A

## Open Issues

### Publish examples to GitHub Pages

Should we publish the examples to GitHub pages as well as make them accessible from stackblitz.

Pros:
- Easier to open on mobile devices
- More reliable manual stress test environment (don't have to consider additional injected page content)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(don't have to consider additional injected page content)

Could you clarify what this means? Are you referring to stuff that Stackblitz adds to the page?

I have sometimes been annoyed when opening Stackblitz examples when they take more than a couple seconds to spin up their container. Having examples that avoid that would be nice. Obviously we have to consider the cost to implement it, but I like keeping it as part of the proposal.


Cons:
- Our current GitHub pages build is very large. Should research shrinking the size before adding significantly more content.

Open Questions:
- Easy way to shrink / de-dupe Blazor WASM library content?
- Maybe Blazor examples would be a single Workspace?
- Should all the examples be included in the Chromatic build like we do the angular client and blazor client apps?
- Site should include a nice high-level index page for examples. Maybe inspired by https://examples.deno.land/
- Can we strip out some content from the GitHub build like the storybook module meta data

### Avoid regressing build performance

- Don't have a clear idea yet how build performance is impacted
- Can potentially mitigate by using a build orchestrator as discussed in [#376](https://github.com/ni/nimble/issues/376).