Skip to content

Commit

Permalink
refactor: use Angular modern styles (#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
lacolaco authored Nov 29, 2024
1 parent d7bf9ac commit 75ff08e
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 51 deletions.
10 changes: 5 additions & 5 deletions src/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { provideHttpClient } from '@angular/common/http';
import { provideHttpClient, withFetch } from '@angular/common/http';
import { ApplicationConfig } from '@angular/core';
import { provideClientHydration } from '@angular/platform-browser';
import { provideClientHydration, withIncrementalHydration } from '@angular/platform-browser';
import { provideRouter, withComponentInputBinding, withInMemoryScrolling } from '@angular/router';

import { routes } from './app.routes';
import { provideAppTitleStrategy } from './app-title-strategy';
import { routes } from './app.routes';

export const appConfig: ApplicationConfig = {
providers: [
Expand All @@ -16,8 +16,8 @@ export const appConfig: ApplicationConfig = {
}),
withComponentInputBinding(),
),
provideHttpClient(),
provideClientHydration(),
provideHttpClient(withFetch()),
provideClientHydration(withIncrementalHydration()),
provideAppTitleStrategy('Angular Japan User Group'),
],
};
4 changes: 1 addition & 3 deletions src/app/pages/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ import { ICON_COMPONENTS } from '../../shared/icons';
@Component({
imports: [RouterLink, CardComponent, ICON_COMPONENTS],
templateUrl: './home.component.html',
styles: [
`
styles: `
:host {
display: block;
}
`,
],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class HomePageComponent {}
15 changes: 8 additions & 7 deletions src/app/pages/markdown/markdown-page.component.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { ChangeDetectionStrategy, Component, input } from '@angular/core';
import { MarkdownOutletComponent } from '../../shared/markdown-outlet/markdown-outlet.component';

@Component({
imports: [MarkdownOutletComponent],
template: `<app-markdown-outlet class="h-full" [content]="content" ngSkipHydration />`,
styles: [
`
template: `
@defer (hydrate never) {
<app-markdown-outlet class="h-full" [content]="content()" />
}
`,
styles: `
:host {
display: block;
}
`,
],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class MarkdownPageComponent {
@Input({ required: true })
readonly content!: string;
readonly content = input.required<string>();
}
9 changes: 0 additions & 9 deletions src/app/shared/card/card.component.html

This file was deleted.

13 changes: 11 additions & 2 deletions src/app/shared/card/card.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@ import { ChangeDetectionStrategy, Component } from '@angular/core';

@Component({
selector: 'app-card',
standalone: true,
templateUrl: './card.component.html',
template: `
<div class="h-full w-full bg-white rounded-md p-4 border border-gray-700 shadow">
<div class="flex flex-row items-center justify-start text-lg gap-2 mb-4">
<ng-content select="[card-icon]" />
<ng-content select="[card-title]" />
</div>
<div class="text-base">
<ng-content />
</div>
</div>
`,
styleUrls: ['./card.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
Expand Down
1 change: 0 additions & 1 deletion src/app/shared/icons/icon-book/icon-book.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ChangeDetectionStrategy, Component } from '@angular/core';

@Component({
selector: 'app-icon-book',
standalone: true,
template: `
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ChangeDetectionStrategy, Component } from '@angular/core';

@Component({
selector: 'app-icon-calendar',
standalone: true,
template: `
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ChangeDetectionStrategy, Component } from '@angular/core';

@Component({
selector: 'app-icon-external-link',
standalone: true,
template: `
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path
Expand Down
1 change: 0 additions & 1 deletion src/app/shared/icons/icon-home/icon-home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ChangeDetectionStrategy, Component } from '@angular/core';

@Component({
selector: 'app-icon-home',
standalone: true,
template: `
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path
Expand Down
1 change: 0 additions & 1 deletion src/app/shared/icons/icon-menu/icon-menu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ChangeDetectionStrategy, Component } from '@angular/core';

@Component({
selector: 'app-icon-menu',
standalone: true,
template: `
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16" />
Expand Down
1 change: 0 additions & 1 deletion src/app/shared/icons/icon-online/icon-online.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ChangeDetectionStrategy, Component } from '@angular/core';

@Component({
selector: 'app-icon-online',
standalone: true,
template: `
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path
Expand Down
1 change: 0 additions & 1 deletion src/app/shared/icons/icon-people/icon-people.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ChangeDetectionStrategy, Component } from '@angular/core';

@Component({
selector: 'app-icon-people',
standalone: true,
template: `
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path
Expand Down
26 changes: 10 additions & 16 deletions src/app/shared/markdown-outlet/markdown-outlet.component.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { AsyncPipe } from '@angular/common';
import { ChangeDetectionStrategy, Component, Input, inject, signal } from '@angular/core';
import { toObservable } from '@angular/core/rxjs-interop';
import { ChangeDetectionStrategy, Component, inject, input, resource } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
import { map, switchMap } from 'rxjs';
import { processMarkdown } from '../markdown';

@Component({
selector: 'app-markdown-outlet',
imports: [AsyncPipe],
template: `
@if (rendered$ | async; as html) {
@if (renderedContent.value(); as html) {
<div class="content-root" [innerHTML]="html"></div>
}
`,
Expand All @@ -22,14 +18,12 @@ import { processMarkdown } from '../markdown';
})
export class MarkdownOutletComponent {
readonly #sanitizer = inject(DomSanitizer);
readonly #content = signal<string | null>(null);
readonly rendered$ = toObservable(this.#content).pipe(
switchMap((content) => processMarkdown(content ?? '')),
map((html) => this.#sanitizer.bypassSecurityTrustHtml(html)),
);

@Input()
set content(value: string) {
this.#content.set(value);
}
readonly content = input.required<string | null>();
readonly renderedContent = resource({
request: () => this.content() ?? undefined,
loader: async ({ request: content }) => {
const html = await processMarkdown(content);
return this.#sanitizer.bypassSecurityTrustHtml(html);
},
});
}
2 changes: 0 additions & 2 deletions src/app/shared/nav-list/nav-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { RouterLinkActive } from '@angular/router';
@Directive({
// eslint-disable-next-line @angular-eslint/component-selector
selector: '[appNavListItem]',
standalone: true,
// eslint-disable-next-line @angular-eslint/no-host-metadata-property
host: {
class: 'flex items-center h-12 px-4 no-underline text-black hover:bg-gray-100',
Expand All @@ -22,7 +21,6 @@ export class NavListItemDirective {
@Directive({
// eslint-disable-next-line @angular-eslint/directive-selector
selector: '[appNavList]',
standalone: true,
// eslint-disable-next-line @angular-eslint/no-host-metadata-property
host: {
class: 'flex flex-col py-2',
Expand Down

0 comments on commit 75ff08e

Please sign in to comment.