Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to this project will be documented in this file.

## 2026-11-21 - version 1.4.1

- **Angular guide, lesson 02: components** (`/thoughts/angular-02-components`). Covers standalone components, `input()`, `output()`, `model()`, content projection, dynamic components and view encapsulation. The live demo is a badge whose label and tone flow in through inputs, whose count is two-way through `[(count)]`, and whose dismiss button emits an output into an event log
- **Lesson building blocks**: the layout, demo frame, callouts and interview questions that lesson 01 had inline are now components (`Lesson`, `LessonDemo`, `Callout`, `InterviewQuestions`), and lesson 01 is rebuilt on them. `Lesson` is the only `ViewEncapsulation.None` component in the app, because it has to style projected content. It scopes every selector under `.lesson` by hand
- **Copy button on code samples**: `CodeBlock` copies to the clipboard and announces "Copied" through a live region. If clipboard access is denied it says so instead of failing silently
- Callouts name their kind in text ("Pitfall", "Tip", "Expert note"), so the colour bar is never the only signal
- Initial bundle 372.98 kB → 375.71 kB. Nothing lesson-specific is eager; the growth is the `@angular/core` code behind `model()` and `output()`, which esbuild hoists into the shared core chunk once a lazy chunk uses it

## 2026-11-21 - version 1.4.0

- **Interactive lessons in Thoughts**: a thought can now carry a lazily loaded lesson page under its prose. `thoughts-content/lessons/lessons.ts` maps slugs to loaders, and the reader loads the page through a `resource()` so SSR waits for it. The prerendered `/thoughts/angular-01-project-structure` HTML contains the whole lesson, demo included, not an empty slot. Each lesson is its own lazy chunk (lesson 01 is 13 kB), and the initial bundle is unchanged at 372.98 kB
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-paul",
"version": "1.4.0",
"version": "1.4.1",
"scripts": {
"ng": "ng",
"start": "ng serve",
Expand Down
59 changes: 59 additions & 0 deletions src/app/thoughts-content/lessons/callout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Component, input } from '@angular/core';

export type CalloutKind = 'tip' | 'pitfall' | 'expert';

const LABELS: Record<CalloutKind, string> = {
tip: 'Tip',
pitfall: 'Pitfall',
expert: 'Expert note',
};

/**
* [ng-02 components] A presentational component: data in through inputs,
* markup in through content projection, no services, no side effects.
*
* <app-callout kind="pitfall"><p>…</p></app-callout>
*
* `host` metadata binds attributes and classes onto <app-callout> itself, so
* there's no extra wrapper div. It's the modern replacement for @HostBinding.
*/
@Component({
selector: 'app-callout',
host: {
role: 'note',
'[class]': '"callout callout--" + kind()',
},
template: `
<!-- The kind is spelled out in text so colour is never the only signal. -->
<strong class="callout-label">{{ labels[kind()] }}</strong>
<ng-content />
`,
styles: `
:host {
display: block;
margin: 12px 0;
padding: 10px 14px;
border-radius: 8px;
border-left: 4px solid var(--callout-colour);
background: var(--surface-secondary, rgba(255, 255, 255, 0.04));
}
:host(.callout--tip) {
--callout-colour: #34c759;
}
:host(.callout--pitfall) {
--callout-colour: #ff6b6b;
}
:host(.callout--expert) {
--callout-colour: #bf5af2;
}
.callout-label {
display: block;
font-size: 12px;
color: var(--text-primary, #fff);
}
`,
})
export class Callout {
readonly kind = input.required<CalloutKind>();
protected readonly labels = LABELS;
}
56 changes: 48 additions & 8 deletions src/app/thoughts-content/lessons/code-block.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, input } from '@angular/core';
import { Component, input, output, signal } from '@angular/core';

/**
* A labelled, scrollable code sample for lesson pages.
Expand All @@ -7,12 +7,20 @@ import { Component, input } from '@angular/core';
* Angular would try to compile `{{ }}`, `@if` and `<tags>` inside a template,
* so a code sample has to be data, not markup. Interpolating a string is also
* safe by default — Angular escapes it, so nothing in a sample can inject HTML.
*
* [ng-02 components] The whole public API is three members: two inputs and one
* output. Keep a component's surface that small and it stays reusable.
*/
@Component({
selector: 'app-code-block',
template: `
<figure class="code-block">
<figcaption class="code-block-label">{{ label() }}</figcaption>
<figcaption class="code-block-bar">
<span>{{ label() }}</span>
<!-- Live region exists from the start; screen readers only announce changes to one already in the DOM. -->
<span role="status" class="code-block-status">{{ status() }}</span>
<button type="button" (click)="copy()" [attr.aria-label]="'Copy ' + label()">Copy</button>
</figcaption>
<!-- tabindex makes a horizontally scrollable region reachable by keyboard (axe: scrollable-region-focusable) -->
<pre tabindex="0"><code>{{ code() }}</code></pre>
</figure>
Expand All @@ -25,12 +33,32 @@ import { Component, input } from '@angular/core';
overflow: hidden;
background: var(--surface-secondary, rgba(0, 0, 0, 0.25));
}
.code-block-label {
padding: 4px 12px;
.code-block-bar {
display: flex;
align-items: center;
gap: 8px;
padding: 4px 6px 4px 12px;
font-size: 11px;
color: var(--text-secondary, rgba(255, 255, 255, 0.6));
border-bottom: 1px solid var(--border-primary, rgba(255, 255, 255, 0.1));
}
.code-block-status {
margin-left: auto;
}
button {
font: inherit;
padding: 2px 8px;
border: 1px solid var(--border-primary, rgba(255, 255, 255, 0.15));
border-radius: 5px;
background: none;
color: var(--text-primary, #fff);
cursor: pointer;
}
button:focus-visible,
pre:focus-visible {
outline: 2px solid var(--focus-ring, #4da3ff);
outline-offset: -2px;
}
pre {
margin: 0;
padding: 12px;
Expand All @@ -40,13 +68,25 @@ import { Component, input } from '@angular/core';
line-height: 1.55;
color: var(--text-primary, #fff);
}
pre:focus-visible {
outline: 2px solid var(--focus-ring, #4da3ff);
outline-offset: -2px;
}
`,
})
export class CodeBlock {
readonly code = input.required<string>();
readonly label = input('TypeScript');
/** Emits the copied text, so a parent can react without reaching into this component. */
readonly copied = output<string>();

protected readonly status = signal('');

protected async copy(): Promise<void> {
try {
await navigator.clipboard.writeText(this.code());
this.status.set('Copied');
this.copied.emit(this.code());
} catch {
// Clipboard access is denied on insecure origins and in some iframes.
// Say so rather than pretending it worked.
this.status.set('Copy failed. Select the code instead');
}
}
}
38 changes: 38 additions & 0 deletions src/app/thoughts-content/lessons/interview-questions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Component, input } from '@angular/core';

export interface InterviewQuestion {
q: string;
a: string;
}

/**
* [ng-02 components] Native <details>/<summary> gives a keyboard-operable,
* screen-reader-announced disclosure for free. No open/closed state to manage,
* no ARIA to get wrong. Reach for the platform before writing a toggle.
*/
@Component({
selector: 'app-interview-questions',
template: `
@for (item of questions(); track item.q) {
<details class="qa">
<summary>{{ item.q }}</summary>
<p>{{ item.a }}</p>
</details>
}
`,
styles: `
.qa {
margin-bottom: 8px;
padding: 8px 12px;
border: 1px solid var(--border-primary, rgba(255, 255, 255, 0.1));
border-radius: 8px;
}
summary {
cursor: pointer;
color: var(--text-primary, #fff);
}
`,
})
export class InterviewQuestions {
readonly questions = input.required<readonly InterviewQuestion[]>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('Lesson01Structure', () => {
to.dispatchEvent(new Event('change'));
await fixture.whenStable();

expect(el.querySelector('[role="status"]')?.textContent).toContain('Not allowed');
expect(el.querySelector('.lesson-verdict[role="status"]')?.textContent).toContain('Not allowed');
});

it('has no axe violations', async () => {
Expand Down
83 changes: 13 additions & 70 deletions src/app/thoughts-content/lessons/lesson-01-structure.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Component, computed, signal } from '@angular/core';
import { CodeBlock } from './code-block';
import { InterviewQuestions } from './interview-questions';
import { Lesson } from './lesson';
import { LessonDemo } from './lesson-demo';

export type Layer = 'shell' | 'shared' | 'feature' | 'other-feature';

Expand Down Expand Up @@ -49,10 +52,9 @@ const LAYER_LABELS: Record<Layer, string> = {

@Component({
selector: 'app-lesson-01-structure',
imports: [CodeBlock],
imports: [Lesson, LessonDemo, CodeBlock, InterviewQuestions],
template: `
<article class="lesson">
<p class="lesson-kicker">Angular guide · 01 of 13</p>
<app-lesson part="01">

<h2>Simple</h2>
<p>
Expand Down Expand Up @@ -87,25 +89,24 @@ const LAYER_LABELS: Record<Layer, string> = {
how a feature becomes a lazy chunk.
</p>

<section class="lesson-demo" aria-labelledby="checker-heading">
<h3 id="checker-heading">Try it: may this file import that one?</h3>
<div class="lesson-demo-row">
<app-lesson-demo heading="Try it: may this file import that one?">
<div class="demo-row">
<label for="import-from">A file in</label>
<select id="import-from" (change)="from.set(asLayer($event))">
@for (layer of layers; track layer) {
<option [value]="layer" [selected]="layer === from()">{{ layerLabels[layer] }}</option>
}
</select>
</div>
<div class="lesson-demo-row">
<div class="demo-row">
<label for="import-to">imports from</label>
<select id="import-to" (change)="to.set(asLayer($event))">
@for (layer of layers; track layer) {
<option [value]="layer" [selected]="layer === to()">{{ layerLabels[layer] }}</option>
}
</select>
</div>
<div class="lesson-demo-row">
<div class="demo-row">
<input
id="import-lazy"
type="checkbox"
Expand All @@ -123,7 +124,7 @@ const LAYER_LABELS: Record<Layer, string> = {
<strong>{{ verdict().allowed ? '✓ Allowed' : '✗ Not allowed' }}.</strong>
{{ verdict().reason }}
</p>
</section>
</app-lesson-demo>

<h2>Expert</h2>
<p>
Expand Down Expand Up @@ -169,61 +170,13 @@ const LAYER_LABELS: Record<Layer, string> = {
</ul>

<h2>Interview questions</h2>
@for (qa of interview; track qa.q) {
<details class="lesson-qa">
<summary>{{ qa.q }}</summary>
<p>{{ qa.a }}</p>
</details>
}
</article>
<app-interview-questions [questions]="interview" />
</app-lesson>
`,
styles: `
.lesson {
margin-top: 24px;
font-size: 14px;
line-height: 1.7;
color: var(--text-secondary, rgba(255, 255, 255, 0.8));
}
.lesson-kicker {
font-size: 12px;
text-transform: uppercase;
letter-spacing: 0.06em;
color: var(--accent-color, #007aff);
}
h2 {
margin: 28px 0 8px;
font-size: 17px;
color: var(--text-primary, #fff);
}
h3 {
margin: 0 0 10px;
font-size: 14px;
color: var(--text-primary, #fff);
}
code {
font-family: var(--font-mono, ui-monospace, monospace);
font-size: 0.92em;
}
.lesson-demo {
margin: 16px 0;
padding: 16px;
border: 1px solid var(--accent-color, #007aff);
border-radius: 10px;
}
.lesson-demo-row {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
}
.lesson-demo-row label:first-child {
.demo-row label:first-child {
min-width: 96px;
}
select {
font: inherit;
padding: 4px 6px;
border-radius: 6px;
}
.lesson-verdict {
margin: 12px 0 0;
padding: 8px 12px;
Expand All @@ -236,16 +189,6 @@ const LAYER_LABELS: Record<Layer, string> = {
.lesson-verdict--bad {
border-color: #ff6b6b;
}
.lesson-qa {
margin-bottom: 8px;
padding: 8px 12px;
border: 1px solid var(--border-primary, rgba(255, 255, 255, 0.1));
border-radius: 8px;
}
.lesson-qa summary {
cursor: pointer;
color: var(--text-primary, #fff);
}
`,
})
export class Lesson01Structure {
Expand Down
Loading
Loading