-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add code examples for help key (#2903)
- Loading branch information
1 parent
8518e6b
commit a9bacda
Showing
67 changed files
with
2,184 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...es/src/app/code-examples/angular-tree-component/angular-tree/help-key/demo.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<sky-angular-tree-wrapper> | ||
<tree-root #tree [nodes]="nodes"> | ||
<ng-template | ||
#treeNodeFullTemplate | ||
let-index="index" | ||
let-node | ||
let-templates="templates" | ||
> | ||
<sky-angular-tree-node | ||
[attr.data-sky-id]="'node-' + node.data.name" | ||
[helpKey]="node.data.helpKey" | ||
[helpPopoverContent]="node.data.helpPopoverContent" | ||
[helpPopoverTitle]="node.data.helpPopoverTitle" | ||
[index]="index" | ||
[node]="node" | ||
[templates]="templates" | ||
/> | ||
</ng-template> | ||
</tree-root> | ||
</sky-angular-tree-wrapper> |
46 changes: 46 additions & 0 deletions
46
...ples/src/app/code-examples/angular-tree-component/angular-tree/help-key/demo.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { ChangeDetectionStrategy, Component } from '@angular/core'; | ||
import { TreeModule } from '@blackbaud/angular-tree-component'; | ||
import { SkyAngularTreeModule } from '@skyux/angular-tree-component'; | ||
import { SkyHelpInlineModule } from '@skyux/help-inline'; | ||
|
||
@Component({ | ||
standalone: true, | ||
selector: 'app-demo', | ||
templateUrl: './demo.component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
imports: [SkyAngularTreeModule, SkyHelpInlineModule, TreeModule], | ||
}) | ||
export class DemoComponent { | ||
protected nodes = [ | ||
{ | ||
name: 'Animals', | ||
isExpanded: true, | ||
helpPopoverContent: 'Example help content for animals.', | ||
children: [ | ||
{ | ||
name: 'Cats', | ||
isExpanded: true, | ||
helpPopoverContent: 'Example help content for cats.', | ||
helpPopoverTitle: 'What is a cat?', | ||
children: [ | ||
{ name: 'Burmese', helpKey: 'cat-burmese' }, | ||
{ name: 'Persian', helpKey: 'cat-persian' }, | ||
{ name: 'Tabby', helpKey: 'cat-tabby' }, | ||
], | ||
}, | ||
{ | ||
name: 'Dogs', | ||
isExpanded: true, | ||
children: [ | ||
{ | ||
name: 'Beagle', | ||
helpPopoverContent: 'Example help content for beagles.', | ||
}, | ||
{ name: 'German shepherd', helpKey: 'dog-shepherd' }, | ||
{ name: 'Labrador retriever', helpKey: 'dog-lab' }, | ||
], | ||
}, | ||
], | ||
}, | ||
]; | ||
} |
26 changes: 26 additions & 0 deletions
26
.../code-examples/src/app/code-examples/colorpicker/colorpicker/help-key/demo.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<form [formGroup]="formGroup" (ngSubmit)="submit()"> | ||
<sky-colorpicker | ||
#colorPicker | ||
data-sky-id="favorite-color" | ||
labelText="What is your favorite color?" | ||
helpKey="color-help" | ||
hintText="Pick a color with at least 80% opacity." | ||
[stacked]="true" | ||
(selectedColorChanged)="onSelectedColorChanged($event)" | ||
> | ||
<input | ||
formControlName="favoriteColor" | ||
type="text" | ||
[presetColors]="swatches" | ||
[skyColorpickerInput]="colorPicker" | ||
/> | ||
@if (favoriteColor.errors?.['opaque']) { | ||
<sky-form-error | ||
errorName="opaque" | ||
errorText="Color must have at least 80% opacity." | ||
/> | ||
} | ||
</sky-colorpicker> | ||
|
||
<button class="sky-btn sky-btn-primary" type="submit">Submit</button> | ||
</form> |
74 changes: 74 additions & 0 deletions
74
...de-examples/src/app/code-examples/colorpicker/colorpicker/help-key/demo.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { SkyColorpickerHarness } from '@skyux/colorpicker/testing'; | ||
import { | ||
SkyHelpTestingController, | ||
SkyHelpTestingModule, | ||
} from '@skyux/core/testing'; | ||
|
||
import { DemoComponent } from './demo.component'; | ||
|
||
describe('Basic colorpicker demo', () => { | ||
async function setupTest(options: { dataSkyId: string }): Promise<{ | ||
harness: SkyColorpickerHarness; | ||
fixture: ComponentFixture<DemoComponent>; | ||
helpController: SkyHelpTestingController; | ||
}> { | ||
const fixture = TestBed.createComponent(DemoComponent); | ||
const loader = TestbedHarnessEnvironment.loader(fixture); | ||
const helpController = TestBed.inject(SkyHelpTestingController); | ||
|
||
const harness = await loader.getHarness( | ||
SkyColorpickerHarness.with({ dataSkyId: options.dataSkyId }), | ||
); | ||
|
||
fixture.detectChanges(); | ||
await fixture.whenStable(); | ||
|
||
return { harness, fixture, helpController }; | ||
} | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [DemoComponent, SkyHelpTestingModule], | ||
}); | ||
}); | ||
|
||
it('should have the initial values set', async () => { | ||
const { harness } = await setupTest({ dataSkyId: 'favorite-color' }); | ||
|
||
await expectAsync(harness.getLabelText()).toBeResolvedTo( | ||
'What is your favorite color?', | ||
); | ||
await expectAsync(harness.getHintText()).toBeResolvedTo( | ||
'Pick a color with at least 80% opacity.', | ||
); | ||
}); | ||
|
||
it('should throw an error if a low opacity color is selected', async () => { | ||
const { harness, fixture } = await setupTest({ | ||
dataSkyId: 'favorite-color', | ||
}); | ||
|
||
await harness.clickColorpickerButton(); | ||
await expectAsync(harness.isColorpickerOpen()).toBeResolvedTo(true); | ||
|
||
const dropdown = await harness.getColorpickerDropdown(); | ||
|
||
await dropdown.setAlphaValue('.2'); | ||
await dropdown.clickApplyButton(); | ||
fixture.detectChanges(); | ||
|
||
await expectAsync(harness.hasError('opaque')).toBeResolvedTo(true); | ||
}); | ||
|
||
it('should have the correct help key', async () => { | ||
const { harness, helpController } = await setupTest({ | ||
dataSkyId: 'favorite-color', | ||
}); | ||
|
||
await harness.clickHelpInline(); | ||
|
||
helpController.expectCurrentHelpKey('color-help'); | ||
}); | ||
}); |
68 changes: 68 additions & 0 deletions
68
apps/code-examples/src/app/code-examples/colorpicker/colorpicker/help-key/demo.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { Component, inject } from '@angular/core'; | ||
import { | ||
FormBuilder, | ||
FormControl, | ||
FormGroup, | ||
ReactiveFormsModule, | ||
ValidationErrors, | ||
} from '@angular/forms'; | ||
import { SkyColorpickerModule, SkyColorpickerOutput } from '@skyux/colorpicker'; | ||
|
||
interface DemoForm { | ||
favoriteColor: FormControl<SkyColorpickerOutput | string>; | ||
} | ||
|
||
function isColorpickerOutput(value: unknown): value is SkyColorpickerOutput { | ||
return !!(value && typeof value === 'object' && 'rgba' in value); | ||
} | ||
|
||
@Component({ | ||
standalone: true, | ||
selector: 'app-demo', | ||
templateUrl: './demo.component.html', | ||
imports: [ReactiveFormsModule, SkyColorpickerModule], | ||
}) | ||
export class DemoComponent { | ||
protected favoriteColor: FormControl<SkyColorpickerOutput | string>; | ||
protected formGroup: FormGroup<DemoForm>; | ||
|
||
protected swatches: string[] = [ | ||
'#BD4040', | ||
'#617FC2', | ||
'#60AC68', | ||
'#3486BA', | ||
'#E87134', | ||
'#DA9C9C', | ||
]; | ||
|
||
constructor() { | ||
this.favoriteColor = new FormControl('#f00', { | ||
nonNullable: true, | ||
validators: [ | ||
(control): ValidationErrors | null => { | ||
return isColorpickerOutput(control.value) && | ||
control.value.rgba.alpha < 0.8 | ||
? { opaque: true } | ||
: null; | ||
}, | ||
], | ||
}); | ||
|
||
this.formGroup = inject(FormBuilder).group<DemoForm>({ | ||
favoriteColor: this.favoriteColor, | ||
}); | ||
} | ||
|
||
protected onSelectedColorChanged(args: SkyColorpickerOutput): void { | ||
console.log('Reactive form color changed:', args); | ||
} | ||
|
||
protected submit(): void { | ||
const controlValue = this.favoriteColor.value; | ||
const favoriteColor = isColorpickerOutput(controlValue) | ||
? controlValue.hex | ||
: controlValue; | ||
|
||
alert('Your favorite color is: \n' + favoriteColor); | ||
} | ||
} |
34 changes: 16 additions & 18 deletions
34
.../code-examples/src/app/code-examples/datetime/date-range-picker/basic/demo.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 18 additions & 20 deletions
38
...es/src/app/code-examples/datetime/date-range-picker/custom-calculator/demo.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...de-examples/src/app/code-examples/datetime/date-range-picker/help-key/demo.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<div class="sky-padding-even-lg"> | ||
<form [formGroup]="formGroup"> | ||
<sky-date-range-picker | ||
data-sky-id="last-donation" | ||
formControlName="lastDonation" | ||
helpKey="dates-help" | ||
[dateFormat]="dateFormat" | ||
[hintText]="hintText" | ||
[labelText]="labelText" | ||
[required]="required" | ||
> | ||
@if (lastDonation.errors?.['dateWeekend']) { | ||
<sky-form-error | ||
errorName="dateWeekend" | ||
errorText="Do not pick a weekend." | ||
/> | ||
} | ||
</sky-date-range-picker> | ||
</form> | ||
</div> |
Oops, something went wrong.