-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract checklist item as a component
- Loading branch information
Showing
7 changed files
with
192 additions
and
138 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
@if (item) { | ||
<mat-icon | ||
cdkDragHandle | ||
class="mat-icon-rtl-mirror item-icon drag-icon" | ||
fontIcon="drag_handle" /> | ||
<button | ||
mat-icon-button | ||
mat-medium-icon-button | ||
class="item-icon" | ||
(click)="promptInput.edit(); expectationInput.edit()" | ||
[attr.aria-label]="'Edit ' + item.prompt"> | ||
<mat-icon fontIcon="edit" /> | ||
</button> | ||
<button | ||
mat-icon-button | ||
mat-medium-icon-button | ||
class="item-icon" | ||
[attr.aria-label]="'Indent ' + item.prompt + ' left'" | ||
[disabled]="item.indent == 0" | ||
(click)="onIndent(item, -1)"> | ||
<mat-icon fontIcon="format_indent_decrease" /> | ||
</button> | ||
<button | ||
mat-icon-button | ||
mat-medium-icon-button | ||
class="item-icon" | ||
[attr.aria-label]="'Indent ' + item.prompt + ' right'" | ||
[disabled]="item.indent == 4" | ||
(click)="onIndent(item, 1)"> | ||
<mat-icon fontIcon="format_indent_increase" /> | ||
</button> | ||
<span | ||
class="item" | ||
[class.item-prompt]="item.type == ChecklistItem_Type.ITEM_PROMPT" | ||
[class.item-title]="item.type == ChecklistItem_Type.ITEM_TITLE" | ||
[class.item-warning]="item.type == ChecklistItem_Type.ITEM_WARNING" | ||
[class.item-caution]="item.type == ChecklistItem_Type.ITEM_CAUTION" | ||
[class.item-note]="item.type == ChecklistItem_Type.ITEM_NOTE" | ||
[class.item-space]="item.type == ChecklistItem_Type.ITEM_SPACE" | ||
[style.padding-left]="item.indent*25 + 'px'"> | ||
<!-- TODO: Find a better solution than to save/cancel independent fields together --> | ||
<editable-label | ||
#promptInput | ||
class="prompt-input" | ||
label="Prompt text" | ||
[value]="item.prompt" | ||
(valueChanged)="item.prompt = promptInput.value; onItemUpdated(item); expectationInput.cancel();" | ||
(cancelled)="expectationInput.cancel()" /> | ||
</span> | ||
<span [hidden]="item.type !== ChecklistItem_Type.ITEM_PROMPT"> | ||
<!-- TODO: Make the dots fill the center space and nothing more --> | ||
<span class="prompt-spacer" *ngIf="!expectationInput.editing">........................</span> | ||
<span class="prompt-expectation"> | ||
<editable-label | ||
#expectationInput | ||
class="expectation-input" | ||
label="Expectation text" | ||
[value]="item.expectation" | ||
(valueChanged)="item.expectation = expectationInput.value; onItemUpdated(item); promptInput.cancel();" | ||
(cancelled)="promptInput.cancel()" /> | ||
</span> | ||
</span> | ||
} |
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,62 @@ | ||
.item { | ||
vertical-align: middle; | ||
} | ||
|
||
.item-title { | ||
color: white; | ||
} | ||
|
||
.item-caution { | ||
color: red; | ||
} | ||
|
||
.item-caution:before { | ||
padding: 10px; | ||
content: "CAUTION:" | ||
} | ||
|
||
.item-warning { | ||
color: yellow; | ||
} | ||
|
||
.item-warning:before { | ||
padding: 10px; | ||
content: "WARNING:" | ||
} | ||
|
||
.item-note { | ||
color: gray; | ||
} | ||
|
||
.item-note:before { | ||
padding: 10px; | ||
content: "NOTE:" | ||
} | ||
|
||
.prompt-spacer { | ||
text-wrap: nowrap; | ||
overflow: hidden; | ||
letter-spacing: 10px; | ||
} | ||
|
||
.prompt-expectation { | ||
float: right; | ||
color: cyan; | ||
} | ||
|
||
// TODO: Make this work without ng-deep | ||
::ng-deep .prompt-input mat-form-field { | ||
width: 400px; | ||
} | ||
::ng-deep .prompt-expectation mat-form-field { | ||
width: 300px; | ||
} | ||
|
||
.item-icon { | ||
vertical-align: middle; | ||
} | ||
|
||
.drag-icon { | ||
cursor: move; | ||
} | ||
|
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,23 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { ChecklistItemComponent } from './item.component'; | ||
|
||
describe('ChecklistItemComponent', () => { | ||
let component: ChecklistItemComponent; | ||
let fixture: ComponentFixture<ChecklistItemComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [ChecklistItemComponent] | ||
}) | ||
.compileComponents(); | ||
|
||
fixture = TestBed.createComponent(ChecklistItemComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
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,37 @@ | ||
import { CdkDragHandle } from '@angular/cdk/drag-drop'; | ||
import { Component, EventEmitter, Input, Output } from '@angular/core'; | ||
import { MatButtonModule } from '@angular/material/button'; | ||
import { MatIconModule } from '@angular/material/icon'; | ||
import { MatIconButtonSizesModule } from 'mat-icon-button-sizes'; | ||
import { EditableLabelComponent } from '../editable-label/editable-label.component'; | ||
import { NgIf } from '@angular/common'; | ||
import { ChecklistItem, ChecklistItem_Type } from '../../../../../gen/ts/checklist'; | ||
|
||
@Component({ | ||
selector: 'checklist-item', | ||
standalone: true, | ||
imports: [ | ||
CdkDragHandle, | ||
EditableLabelComponent, | ||
MatButtonModule, | ||
MatIconButtonSizesModule, | ||
MatIconModule, | ||
NgIf, | ||
], | ||
templateUrl: './item.component.html', | ||
styleUrl: './item.component.scss' | ||
}) | ||
export class ChecklistItemComponent { | ||
@Input() item!: ChecklistItem; | ||
@Output() itemChanged = new EventEmitter<ChecklistItem>(); | ||
readonly ChecklistItem_Type = ChecklistItem_Type; | ||
|
||
onIndent(item: ChecklistItem, delta: number) { | ||
item.indent += delta; | ||
this.onItemUpdated(item); | ||
} | ||
|
||
onItemUpdated(item: ChecklistItem) { | ||
this.itemChanged.emit(this.item); | ||
} | ||
} |
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
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
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