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

[WNMGDS-3028] Updated Angular Example #3358

Merged
merged 40 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
8a9eb53
Initial addition of files
jack-ryan-nava-pbc Dec 18, 2024
9e3e210
Update package.json to latest
jack-ryan-nava-pbc Dec 18, 2024
31f9913
Consume scripts via angular.json file
jack-ryan-nava-pbc Dec 18, 2024
ba6426d
Listen to custom event on button
jack-ryan-nava-pbc Dec 18, 2024
a018cc5
Remove unneeded html file
jack-ryan-nava-pbc Dec 18, 2024
5a84e88
Add ds-drawer
jack-ryan-nava-pbc Dec 18, 2024
7e79ea3
Add ds-review
jack-ryan-nava-pbc Dec 18, 2024
90e0fa7
Consume ds-review and ds-drawer
jack-ryan-nava-pbc Dec 18, 2024
38f51fd
Enabled analytics events on alert
jack-ryan-nava-pbc Dec 19, 2024
95aac49
Enabled analytics events on button
jack-ryan-nava-pbc Dec 19, 2024
3ee4fc8
Enabled analytics events on dialog
jack-ryan-nava-pbc Dec 19, 2024
6cac2ca
Clean up button variation
jack-ryan-nava-pbc Dec 19, 2024
e78ae17
Fix typo
jack-ryan-nava-pbc Dec 19, 2024
db04eba
Drawer analytics?
jack-ryan-nava-pbc Dec 19, 2024
a8e99dc
Refer to local design system directly
jack-ryan-nava-pbc Dec 19, 2024
1403a58
Point to symlinked folders in node_modules because more like real life
jack-ryan-nava-pbc Dec 19, 2024
5f742c0
Readme update first pass
jack-ryan-nava-pbc Dec 19, 2024
5214d5d
Remove spec
jack-ryan-nava-pbc Dec 19, 2024
24ae485
Remove unneeded analytics event
jack-ryan-nava-pbc Dec 19, 2024
df02563
Merge main and remove unneeded css
jack-ryan-nava-pbc Jan 6, 2025
a97dea9
Removed top level unneeded css
jack-ryan-nava-pbc Jan 6, 2025
c83dc7d
Point schema to the right place
jack-ryan-nava-pbc Jan 6, 2025
b864554
Beef up accordions
jack-ryan-nava-pbc Jan 7, 2025
6098db0
Merge branch 'main' into jryan/wnmgds-3028-new-angular-example
jack-ryan-nava-pbc Jan 21, 2025
d05c483
Merge branch 'main' into jryan/wnmgds-3028-new-angular-example
jack-ryan-nava-pbc Jan 22, 2025
6fc48b5
Merge branch 'main' into jryan/wnmgds-3028-new-angular-example
jack-ryan-nava-pbc Jan 25, 2025
aeef24b
Update yarn lock deps
jack-ryan-nava-pbc Jan 27, 2025
92a284e
Remove uneeded @Input declaration fix close button on modal
jack-ryan-nava-pbc Jan 27, 2025
780c9f5
Merge branch 'main' into jryan/wnmgds-3028-new-angular-example
jack-ryan-nava-pbc Jan 27, 2025
4c5fde7
[WNMGDS-3175] Migrate yarn to npm (#3397)
pwolfert Jan 27, 2025
8fcecd3
Merge branch 'main' into jryan/wnmgds-3028-new-angular-example
jack-ryan-nava-pbc Jan 28, 2025
3753737
Merge branch 'main' into jryan/wnmgds-3028-new-angular-example
jack-ryan-nava-pbc Jan 30, 2025
f80fcc6
Updated package.lock
jack-ryan-nava-pbc Jan 28, 2025
bb3d3be
Simplify drawer close method
jack-ryan-nava-pbc Jan 30, 2025
a821d43
Add new accordion item containers
jack-ryan-nava-pbc Jan 31, 2025
c6848f7
Wrapped accordions found styling bug
jack-ryan-nava-pbc Jan 31, 2025
9541925
Merge branch 'main' into jryan/wnmgds-3028-new-angular-example
jack-ryan-nava-pbc Jan 31, 2025
e051286
Merge branch 'main' into jryan/wnmgds-3028-new-angular-example
jack-ryan-nava-pbc Jan 31, 2025
c68c2b8
Merge branch 'main' into jryan/wnmgds-3028-new-angular-example
jack-ryan-nava-pbc Feb 4, 2025
a636edc
refactor accordion
jack-ryan-nava-pbc Feb 6, 2025
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
11 changes: 9 additions & 2 deletions examples/angular/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
## Example: An Angular project with TypeScript

This shows the usage of CMS design system components in a TypeScript-enabled [Angular](https://angular.dev/) project.
This shows the usage of CMS design system components in a TypeScript-enabled [Angular](https://angular.dev/) project. This example contains a reduced set of our available web components.

In this project, the design system package is installed as an npm dependency. Refer to [install using npm](https://design.cms.gov/getting-started/for-developers/#option-1-install-using-npm) for instructions on how to install the design system as a dependency package.
In this project, the design system package is pulled from the local (symlinked) version of the Design System in the `angular.json` file under the "scripts" property. Please note that your team will likely implement a different import strategy that points to the actual location of your installed Design System.

From within this example you should be able to see how to:

1. Import the needed Javascript and styling to use in your application
2. Listen to our custom events, inlcuding analytics events
3. Pass inputs to our components as attributes so they can respond to changes in higher level state
4. Render web components nested within other web components

## Getting started

Expand Down
18 changes: 13 additions & 5 deletions examples/angular/angular.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"$schema": "../../node_modules/@angular/cli/lib/config/schema.json",
"cli": {
"analytics": "1e1de97b-a744-405a-8b5a-0397bb3d01ce"
},
Expand All @@ -26,14 +26,22 @@
}
},
"options": {
"assets": [],
"outputPath": "dist/demo",
"index": "src/index.html",
"browser": "src/main.ts",
"outputPath": "dist/demo",
"polyfills": ["zone.js"],
"scripts": [],
"tsConfig": "tsconfig.app.json",
"assets": [
{
"glob": "**/*",
"input": "public"
}
],
"styles": ["src/global_styles.css"],
"tsConfig": "tsconfig.app.json"
"scripts": [
"../../node_modules/@cmsgov/design-system/dist/web-components/bundle/base.js",
"../../node_modules/@cmsgov/design-system/dist/web-components/bundle/all.js"
]
}
},
"serve": {
Expand Down
35 changes: 19 additions & 16 deletions examples/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,28 @@
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build"
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"
},
"dependencies": {
"@angular/animations": "^18.1.0",
"@angular/common": "^18.1.0",
"@angular/compiler": "^18.1.0",
"@angular/core": "^18.1.0",
"@angular/forms": "^18.1.0",
"@angular/platform-browser": "^18.1.0",
"@angular/router": "^18.1.0",
"@cmsgov/design-system": "12.0.0",
"rxjs": "^7.8.1",
"tslib": "^2.5.0",
"zone.js": "~0.14.0"
"@angular/animations": "^19.0.0",
"@angular/common": "^19.0.0",
"@angular/compiler": "^19.0.0",
"@angular/core": "^19.0.0",
"@angular/forms": "^19.0.0",
"@angular/platform-browser": "^19.0.0",
"@angular/platform-browser-dynamic": "^19.0.0",
"@angular/router": "^19.0.0",
"@cmsgov/design-system": "^12.0.0",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.15.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "^18.1.0",
"@angular/cli": "^18.1.0",
"@angular/compiler-cli": "^18.1.0",
"typescript": "~5.5.0"
"@angular-devkit/build-angular": "^19.0.4",
"@angular/cli": "^19.0.4",
"@angular/compiler-cli": "^19.0.0",
"typescript": "~5.6.2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<ds-accordion-item>
<div slot="heading">
<ng-content select="item-heading"></ng-content>
</div>
<ng-content></ng-content>
</ds-accordion-item>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';

@Component({
selector: 'app-accordion-item',
standalone: true,
schemas: [CUSTOM_ELEMENTS_SCHEMA],
templateUrl: './accordionItem.component.html',
})
export class AccordionItemComponent {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<ds-accordion [attr.bordered]="bordered()">
<ng-content></ng-content>
</ds-accordion>
18 changes: 18 additions & 0 deletions examples/angular/src/app/accordionWrapper/accordion.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Component, CUSTOM_ELEMENTS_SCHEMA, ElementRef, input } from '@angular/core';

@Component({
selector: 'app-accordion',
standalone: true,
schemas: [CUSTOM_ELEMENTS_SCHEMA],
templateUrl: './accordion.component.html',
})
export class AccordionComponent {
constructor(elementRef: ElementRef) {
elementRef.nativeElement.addEventListener('ds-change', (event: Event) => {
console.log('Ds-change event fired', event);
});
}
bordered = input.required<string>();
items = input<{ title: string; content: string }[]>();
jack-ryan-nava-pbc marked this conversation as resolved.
Show resolved Hide resolved
headingLevel = input<string>();
}
12 changes: 12 additions & 0 deletions examples/angular/src/app/alertWrapper/alert.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<ds-alert
[attr.variation]="alertVariation()"
(ds-analytics-event)="analyticsEvent()"
analytics="true"
class="ds-u-margin-y--2"
>
<div slot="heading">{{ alertHeading() }}</div>
{{ alertMessage() }}
<div class="ds-u-margin-y--2">
<ng-content></ng-content>
</div>
</ds-alert>
17 changes: 17 additions & 0 deletions examples/angular/src/app/alertWrapper/alert.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Component, CUSTOM_ELEMENTS_SCHEMA, input } from '@angular/core';

@Component({
selector: 'app-alert',
standalone: true,
schemas: [CUSTOM_ELEMENTS_SCHEMA],
templateUrl: './alert.component.html',
})
export class AlertComponent {
alertHeading = input.required<string>();
alertMessage = input.required<string>();
alertVariation = input<string>();

analyticsEvent() {
console.log('Alert analytics event');
}
}
224 changes: 224 additions & 0 deletions examples/angular/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
<div class="ds-content ds-u-margin-x--0 ds-u-margin-bottom--2 full-height">
<ds-skip-nav href="#main"></ds-skip-nav>
<ds-usa-banner></ds-usa-banner>
<main class="ds-l-container">
<h1 class="ds-text-heading--5xl ds-u-margin-top--2">Web-component examples</h1>

<!-- Wrapped Alert -->
<h2 class="ds-text-heading--4xl ds-u-margin-top--2">Alert</h2>
<app-alert
[alertVariation]="wrappedAlertVariation"
[alertHeading]="wrappedAlertHeading"
[alertMessage]="wrappedAlertMessage"
>
<app-button (buttonClickEvent)="setToWarning($event)" [buttonVariation]="solidVariation">
{{ buttonText() }}
</app-button>
</app-alert>

<!-- Wrapped Accordion -->
<h2 class="ds-text-heading--4xl ds-u-margin-top--2">Accordion</h2>
<app-accordion [bordered]="bordered" [headingLevel]="headingLevel">
<app-accordion-item>
<item-heading>The First Ammendment</item-heading>
<ds-alert> This is an alert inside of an accordion item. </ds-alert>
<p>
The First Amendment provides several rights protections: to express ideas through speech
and the press, to assemble or gather with a group to protest or for other reasons, and to
ask the government to fix problems. It also protects the right to religious beliefs and
practices. It prevents the government from creating or favoring a religion.
</p>
<div class="ds-u-margin-top--2">
<ds-choice-list
(ds-change)="setLiked($event)"
class-name="ds-u-margin-bottom--2"
label="Did you like this content?"
name="likedIt"
type="radio"
>
<ds-choice label="Yes" default-checked="true" value="true" />
<ds-choice label="No" value="false" />
</ds-choice-list>
<ds-button (ds-click)="alertLiked()" variation="solid"
>Tell us what you though about this content.</ds-button
>
</div>
</app-accordion-item>
<app-accordion-item>
<item-heading>The Third Ammendment</item-heading>
<ds-alert variation="warn">
This is an alert inside of an accordion item that is warning you.</ds-alert
>
<p>
The Third Amendment prevents government from forcing homeowners to allow soldiers to use
their homes. Before the Revolutionary War, laws gave British soldiers the right to take
over private homes.
</p>
</app-accordion-item>
<app-accordion-item>
<item-heading>The Fourth Ammendment</item-heading>
<ds-alert variation="error">
This is an alert inside of an accordion item that informing you of an error.</ds-alert
>
<p>
The Fourth Amendment bars the government from unreasonable search and seizure of an
individual or their private property.
</p>
</app-accordion-item>
<div class="ds-u-margin-top--2">
<cite>
<a
href="https://www.archives.gov/founding-docs/bill-of-rights/what-does-it-say"
target="_blank"
>
Source Material</a
>
</cite>
</div>
</app-accordion>

<h2 class="ds-text-heading--4xl ds-u-margin-top--2">Month Picker</h2>
<ds-month-picker
requirement-label="Required."
hint="Select many."
name="fooPicker"
label="Select any months you want!"
>
<input type="checkbox" value="10" checked />
<input type="checkbox" value="11" checked disabled />
<input type="checkbox" value="12" disabled />
</ds-month-picker>

<h2 class="ds-text-heading--4xl ds-u-margin-top--2">Spinner</h2>
<ds-spinner aria-valuetext="aria sets spinner label!"
>children don't set spinner label</ds-spinner
>

<h2 class="ds-text-heading--4xl ds-u-margin-top--2">Checkbox</h2>
<h3 class="ds-text-heading--3xl ds-u-margin-top--2">DS Choice</h3>
<ds-choice type="checkbox" label="I agree to the terms and conditions" name="agree">
<div slot="checked-children">
<ds-alert class="ds-u-margin-top--1">Cool, we hoped you'd check this box.</ds-alert>
</div>
</ds-choice>

<h3 class="ds-text-heading--3xl ds-u-margin-top--2">DS Choicelist</h3>
<ds-choice-list type="radio" label="Choice list example" name="foo">
<ds-choice label="Choice without associated children" value="no children" />
<ds-choice
label="Checked children"
hint="Selecting this checkbox will reveal its associated children."
value="checked children"
>
<div slot="checked-children">
<div class="ds-c-choice__checkedChild">
<ds-alert heading="🫣 Tag! You're it!">
You can reveal content by applying <code>checked-children</code> to the
<code>slot</code> attribute of an HTML element. Do not forget to include a
<code>div</code> element with the class <code>ds-c-choice__checkedChild</code> to
whatever content you want to show/hide so it gets side border showing an association
with its choice parent.
</ds-alert>
</div>
</div>
</ds-choice>
<ds-choice
label="Unchecked children"
hint="Selecting this checkbox will hide its associated children."
value="unchecked children"
>
<div slot="unchecked-children">
<div class="ds-c-choice__checkedChild">
<ds-alert variation="warn" heading="I banish thee!">
You can hide content by applying <code>unchecked-children</code> to the
<code>slot</code> attribute of an HTML element. Do not forget to include a
<code>div</code> element with the class <code>ds-c-choice__checkedChild</code> to
whatever content you want to show/hide so it gets side border showing an association
with its choice parent.
</ds-alert>
</div>
</div>
</ds-choice>
</ds-choice-list>

<h2 class="ds-text-heading--4xl ds-u-margin-top--2">Modal Dialog</h2>
<app-button (buttonClickEvent)="openDialog()"> Open Dialog </app-button>
<app-dialog
[(isOpen)]="is_open"
[root_id]="root_id"
[size]="size"
[backdrop_click_exits]="backdrop_click_exits"
[heading]="dialogHeading"
(ds-exit)="closeDialog()"
>
<dialog-body>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed accumsan diam vitae metus
lacinia, eget tempor purus placerat.
</p>
</dialog-body>
<dialog-actions>
<form method="dialog" (submit)="closeDialog()">
<button class="ds-c-button ds-c-button--solid" type="submit" value="sbmBtn">
Confirm
</button>
</form>
</dialog-actions>
</app-dialog>

<h2 class="ds-text-heading--4xl ds-u-margin-top--2">Review</h2>
@for(elem of reviewElements; track elem.id) {
<app-review [edit_href]="href">
<review-heading>{{ elem.heading }}</review-heading>
<review-edit-text>{{ elem.editText }}</review-edit-text>
<p>{{ elem.content }}</p>
</app-review>
} @empty {
<app-review [edit_href]="href">
<review-heading>Please review the following content.</review-heading>
<review-edit-text>Hello. Edit me.</review-edit-text>
<p>Have you deeply considered your options?</p>
</app-review>
}

<h2 class="ds-text-heading--4xl ds-u-margin-top--2">Drawer</h2>
<app-drawer
[(isOpen)]="drawerOpen"
[footerBody]="footerBody"
[footerTitle]="footerTitle"
[drawerHeading]="drawerHeading"
(ds-close-click)="closeDrawer()"
>
<strong> An Explanation </strong>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem
ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem
ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem
ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</app-drawer>
<app-button
[additionalClasses]="toggleClasses"
[buttonVariation]="ghostVariation"
(buttonClickEvent)="openDrawer()"
>
Click to toggle drawer
</app-button>
</main>
</div>
Loading