Skip to content

Commit 92d6cdd

Browse files
docs(www): add install instructions component (#5114)
1 parent 0d1e693 commit 92d6cdd

File tree

16 files changed

+123
-161
lines changed

16 files changed

+123
-161
lines changed

projects/www/src/app/app.component.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { AlertComponent } from './components/docs/alert.component';
1414
import { CodeExampleComponent } from './components/docs/code-example.component';
1515
import { CodeTabsComponent } from './components/docs/code-tabs.component';
1616
import { StackblitzComponent } from './components/docs/stackblitz.component';
17+
import { InstallInstructionsComponent } from './components/docs/install-instructions.component';
1718
import { FooterComponent } from './components/footer.component';
1819
import {
1920
TOP_BANNER_DISMISSED_STORAGE_KEY,
@@ -30,6 +31,7 @@ import {
3031
AlertComponent,
3132
CodeExampleComponent,
3233
StackblitzComponent,
34+
InstallInstructionsComponent,
3335
FooterComponent,
3436
],
3537
template: `
@@ -132,5 +134,11 @@ export class AppComponent {
132134
injector: this.#injector,
133135
});
134136
customElements.define('ngrx-docs-stackblitz', stackblitzElement);
137+
138+
const installInstructionsElement = createCustomElement(
139+
InstallInstructionsComponent,
140+
{ injector: this.#injector }
141+
);
142+
customElements.define('ngrx-docs-install', installInstructionsElement);
135143
}
136144
}

projects/www/src/app/components/docs/code-example.component.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ import { ExamplesService } from '@ngrx-io/app/examples/examples.service';
4040
}
4141
</button>
4242
<div #codeBody>
43-
@if (path) {
44-
<div [innerHTML]="codeContent() | ngrxCodeHighlight"></div>
43+
@if (snippet || path) {
44+
<div [innerHTML]="codeContent() | ngrxCodeHighlight: language"></div>
4545
} @else {
4646
<ng-content />
4747
}
@@ -138,6 +138,7 @@ export class CodeExampleComponent implements AfterViewInit {
138138
@Input() path = '';
139139
@Input() region = '';
140140
@Input() language = 'typescript';
141+
@Input() snippet = '';
141142

142143
codeBody = viewChild.required<ElementRef>('codeBody');
143144
copied = signal(false);
@@ -160,6 +161,11 @@ export class CodeExampleComponent implements AfterViewInit {
160161

161162
async ngAfterViewInit() {
162163
if (isPlatformServer(this.platformId)) return;
164+
if (this.snippet) {
165+
this.codeContent.set(this.snippet);
166+
return;
167+
}
168+
163169
if (!this.path) return;
164170

165171
const content = await this.exampleService.extractSnippet(

projects/www/src/app/components/docs/code-highlight.pipe.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010

1111
let highlighter: HighlighterGeneric<BundledLanguage, BundledTheme>;
1212
getHighlighter({
13-
langs: ['typescript'],
13+
langs: ['typescript', 'sh', 'html'],
1414
themes: [ngrxTheme],
1515
}).then((h) => (highlighter = h));
1616

@@ -22,9 +22,9 @@ getHighlighter({
2222
export class CodeHighlightPipe implements PipeTransform {
2323
private sanitizer = inject(DomSanitizer);
2424

25-
transform(code: string): SafeHtml {
25+
transform(code: string, language = 'typescript'): SafeHtml {
2626
const html = highlighter?.codeToHtml(code, {
27-
lang: 'typescript',
27+
lang: language,
2828
theme: 'ngrx-theme',
2929
});
3030

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { Component, computed, input } from '@angular/core';
2+
import { MatTabsModule } from '@angular/material/tabs';
3+
import { CodeExampleComponent } from './code-example.component';
4+
5+
@Component({
6+
selector: 'ngrx-install-instructions',
7+
standalone: true,
8+
imports: [MatTabsModule, CodeExampleComponent],
9+
template: `
10+
<mat-tab-group [preserveContent]="true">
11+
<mat-tab label="npm">
12+
<p>
13+
For more information on using <code>npm</code> check out the docs
14+
<a
15+
href="https://docs.npmjs.com/cli/install"
16+
target="_blank"
17+
rel="noopener noreferrer"
18+
>here</a
19+
>.
20+
</p>
21+
<ngrx-code-example [snippet]="npmCommand()" language="sh" />
22+
</mat-tab>
23+
<mat-tab label="pnpm">
24+
<p>
25+
For more information on using <code>pnpm</code> check out the docs
26+
<a
27+
href="https://pnpm.io/cli/add"
28+
target="_blank"
29+
rel="noopener noreferrer"
30+
>here</a
31+
>.
32+
</p>
33+
<ngrx-code-example [snippet]="pnpmCommand()" language="sh" />
34+
</mat-tab>
35+
<mat-tab label="yarn">
36+
<p>
37+
For more information on using <code>yarn</code> check out the docs
38+
<a
39+
href="https://yarnpkg.com/getting-started/usage#installing-all-the-dependencies"
40+
target="_blank"
41+
rel="noopener noreferrer"
42+
>here</a
43+
>.
44+
</p>
45+
<ngrx-code-example [snippet]="yarnCommand()" language="sh" />
46+
</mat-tab>
47+
</mat-tab-group>
48+
`,
49+
})
50+
export class InstallInstructionsComponent {
51+
packageName = input('');
52+
devDependency = input(false);
53+
54+
npmCommand = computed(
55+
() =>
56+
`npm install ${this.packageName()}${this.devDependency() ? ' --save-dev' : ''}`
57+
);
58+
59+
pnpmCommand = computed(
60+
() =>
61+
`pnpm add ${this.packageName()}${this.devDependency() ? ' --save-dev' : ''}`
62+
);
63+
64+
yarnCommand = computed(
65+
() =>
66+
`yarn add ${this.packageName()}${this.devDependency() ? ' --dev' : ''}`
67+
);
68+
}

projects/www/src/app/pages/guide/component-store/install.md

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,8 @@ This command will automate the following steps:
2222
1. Update `package.json` > `dependencies` with `@ngrx/component-store`.
2323
2. Run the package manager to install the added dependency.
2424

25-
## Installing with `npm`
25+
## Manual Installation
2626

27-
For more information on using `npm` check out the docs <a href="https://docs.npmjs.com/cli/install" target="_blank">here</a>.
27+
You can also install `@ngrx/component-store` manually using one of the following commands:
2828

29-
```sh
30-
npm install @ngrx/component-store --save
31-
```
32-
33-
## Installing with `yarn`
34-
35-
For more information on using `yarn` check out the docs <a href="https://yarnpkg.com/getting-started/usage#installing-all-the-dependencies" target="_blank">here</a>.
36-
37-
```sh
38-
yarn add @ngrx/component-store
39-
```
29+
<ngrx-docs-install package-name="@ngrx/component-store"></ngrx-docs-install>

projects/www/src/app/pages/guide/component/install.md

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,8 @@ This command will automate the following steps:
2020
1. Update `package.json` > `dependencies` with `@ngrx/component`.
2121
2. Run the package manager to install the added dependency.
2222

23-
## Installing with `npm`
23+
## Manual Installation
2424

25-
For more information on using `npm` check out the docs <a href="https://docs.npmjs.com/cli/install" target="_blank">here</a>.
25+
You can also install `@ngrx/component` manually using one of the following commands:
2626

27-
```sh
28-
npm install @ngrx/component --save
29-
```
30-
31-
## Installing with `yarn`
32-
33-
For more information on using `yarn` check out the docs <a href="https://yarnpkg.com/getting-started/usage#installing-all-the-dependencies" target="_blank">here</a>.
34-
35-
```sh
36-
yarn add @ngrx/component
37-
```
27+
<ngrx-docs-install package-name="@ngrx/component"></ngrx-docs-install>

projects/www/src/app/pages/guide/data/install.md

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,8 @@ With the `migrateNgRxData` flag the following will also take place:
3636
1. Remove `ngrx-data` from `package.json` > `dependencies`.
3737
2. Rename `ngrx-data` types to the matching `@ngrx/data` types.
3838

39-
## Installing with `npm`
39+
## Manual Installation
4040

41-
For more information on using `npm` check out the docs <a href="https://docs.npmjs.com/cli/install" target="_blank">here</a>.
41+
You can also install `@ngrx/data` manually using one of the following commands:
4242

43-
```sh
44-
npm install @ngrx/data --save
45-
```
46-
47-
## Installing with `yarn`
48-
49-
For more information on using `yarn` check out the docs <a href="https://yarnpkg.com/getting-started/usage#installing-all-the-dependencies" target="_blank">here</a>.
50-
51-
```sh
52-
yarn add @ngrx/data
53-
```
43+
<ngrx-docs-install package-name="@ngrx/data"></ngrx-docs-install>

projects/www/src/app/pages/guide/effects/install.md

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,8 @@ This command will automate the following steps:
2727
3. Update your `src/app/app.module.ts` > `imports` array with `EffectsModule.forRoot([AppEffects])`. If you provided flags then the command will attempt to locate and update module found by the flags.
2828
4. If the project is using a `standalone bootstrap`, it adds `provideEffects()` into the application config.
2929

30-
## Installing with `npm`
30+
## Manual Installation
3131

32-
For more information on using `npm` check out the docs <a href="https://docs.npmjs.com/cli/install" target="_blank">here</a>.
32+
You can also install `@ngrx/effects` manually using one of the following commands:
3333

34-
```sh
35-
npm install @ngrx/effects --save
36-
```
37-
38-
## Installing with `yarn`
39-
40-
For more information on using `yarn` check out the docs <a href="https://yarnpkg.com/getting-started/usage#installing-all-the-dependencies" target="_blank">here</a>.
41-
42-
```sh
43-
yarn add @ngrx/effects
44-
```
34+
<ngrx-docs-install package-name="@ngrx/effects"></ngrx-docs-install>

projects/www/src/app/pages/guide/entity/install.md

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,8 @@ This command will automate the following steps:
1313
1. Update `package.json` > `dependencies` with `@ngrx/entity`.
1414
2. Run `npm install` to install those dependencies.
1515

16-
## Installing with `npm`
16+
## Manual Installation
1717

18-
For more information on using `npm` check out the docs <a href="https://docs.npmjs.com/cli/install" target="_blank">here</a>.
18+
You can also install `@ngrx/entity` manually using one of the following commands:
1919

20-
```sh
21-
npm install @ngrx/entity --save
22-
```
23-
24-
## Installing with `yarn`
25-
26-
For more information on using `yarn` check out the docs <a href="https://yarnpkg.com/getting-started/usage#installing-all-the-dependencies" target="_blank">here</a>.
27-
28-
```sh
29-
yarn add @ngrx/entity
30-
```
20+
<ngrx-docs-install package-name="@ngrx/entity"></ngrx-docs-install>

projects/www/src/app/pages/guide/eslint-plugin/install.md

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,8 @@ ng add @ngrx/eslint-plugin
1010

1111
The command will prompt you to select which config you would like to have preconfigured; you can read the detailed list of available configs [here](guide/eslint-plugin/#configurations).
1212

13-
## Installing with `npm`
13+
## Manual Installation
1414

15-
For more information on using `npm` check out the docs <a href="https://docs.npmjs.com/cli/install" target="_blank">here</a>.
15+
You can also install `@ngrx/eslint-plugin` manually using one of the following commands:
1616

17-
```sh
18-
npm install @ngrx/eslint-plugin --save-dev
19-
```
20-
21-
## Installing with `yarn`
22-
23-
For more information on using `yarn` check out the docs <a href="https://yarnpkg.com/getting-started/usage#installing-all-the-dependencies" target="_blank">here</a>.
24-
25-
```sh
26-
yarn add @ngrx/eslint-plugin -D
27-
```
17+
<ngrx-docs-install package-name="@ngrx/eslint-plugin" npm-flags="--save-dev" yarn-flags="-D"></ngrx-docs-install>

0 commit comments

Comments
 (0)