-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(design): create DaffModalCloseDirective (#2832)
This adds a close button to the DaffModalCHeaderComponent and allows the close button to be reusable
- Loading branch information
1 parent
fd838fd
commit 3140fee
Showing
14 changed files
with
212 additions
and
27 deletions.
There are no files selected for viewing
4 changes: 0 additions & 4 deletions
4
libs/design/modal/src/modal-actions/modal-actions.component.scss
This file was deleted.
Oops, something went wrong.
6 changes: 4 additions & 2 deletions
6
libs/design/modal/src/modal-actions/modal-actions.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 |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import { | ||
ChangeDetectionStrategy, | ||
Component, | ||
HostBinding, | ||
} from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'daff-modal-actions', | ||
template: '<ng-content></ng-content>', | ||
styleUrls: ['./modal-actions.component.scss'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class DaffModalActionsComponent { } | ||
export class DaffModalActionsComponent { | ||
@HostBinding('class.daff-modal-actions') class = true; | ||
} |
54 changes: 54 additions & 0 deletions
54
libs/design/modal/src/modal-close/modal-close.directive.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,54 @@ | ||
import { | ||
Component, | ||
DebugElement, | ||
} from '@angular/core'; | ||
import { | ||
waitForAsync, | ||
ComponentFixture, | ||
TestBed, | ||
} from '@angular/core/testing'; | ||
import { By } from '@angular/platform-browser'; | ||
|
||
import { DaffModalCloseDirective } from './modal-close.directive'; | ||
import { DaffModalService } from '../service/modal.service'; | ||
|
||
@Component({ | ||
template: ` | ||
<button daffModalClose></button> | ||
`, | ||
}) | ||
class WrapperComponent {} | ||
|
||
describe('@daffodil/design/modal | DaffModalCloseDirective', () => { | ||
let wrapper: WrapperComponent; | ||
let de: DebugElement; | ||
let fixture: ComponentFixture<WrapperComponent>; | ||
|
||
beforeEach(waitForAsync(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ | ||
DaffModalCloseDirective, | ||
WrapperComponent, | ||
], | ||
providers: [ | ||
DaffModalService, | ||
], | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(WrapperComponent); | ||
wrapper = fixture.componentInstance; | ||
de = fixture.debugElement.query(By.css('button[daffModalClose]')); | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(wrapper).toBeTruthy(); | ||
}); | ||
|
||
it('should set the type to button', () => { | ||
expect(de.attributes['type']).toBe('button'); | ||
}); | ||
}); |
41 changes: 41 additions & 0 deletions
41
libs/design/modal/src/modal-close/modal-close.directive.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,41 @@ | ||
import { | ||
Directive, | ||
HostBinding, | ||
HostListener, | ||
Optional, | ||
} from '@angular/core'; | ||
|
||
import { DaffModalComponent } from '../modal/modal.component'; | ||
import { DaffModalService } from '../service/modal.service'; | ||
|
||
/** | ||
* The DaffModalCloseDirective is a helper directive that passes a click | ||
* event to the button it's used with to close a modal. It needs to be | ||
* implemented with the `<button>` HTML element to work. This helps to | ||
* reduce code duplication. | ||
*/ | ||
@Directive({ | ||
selector: 'button[daffModalClose]', | ||
}) | ||
|
||
export class DaffModalCloseDirective { | ||
constructor( | ||
private modalService: DaffModalService, | ||
@Optional() private modal: DaffModalComponent, | ||
) {} | ||
|
||
/** | ||
* Event fired when the button the directive is attached to is clicked. This is used to close a modal. | ||
*/ | ||
@HostListener('click') | ||
_onCloseModal(event: MouseEvent) { | ||
if(this.modal) { | ||
this.modalService.close(this.modal); | ||
} | ||
} | ||
|
||
/** | ||
* Sets the button type attribute to button. | ||
*/ | ||
@HostBinding('attr.type') typeAttribute = 'button'; | ||
} |
7 changes: 0 additions & 7 deletions
7
libs/design/modal/src/modal-content/modal-content.component.scss
This file was deleted.
Oops, something went wrong.
6 changes: 4 additions & 2 deletions
6
libs/design/modal/src/modal-content/modal-content.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 |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import { | ||
Component, | ||
ChangeDetectionStrategy, | ||
HostBinding, | ||
} from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'daff-modal-content', | ||
template: '<ng-content></ng-content>', | ||
styleUrls: ['./modal-content.component.scss'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class DaffModalContentComponent {} | ||
export class DaffModalContentComponent { | ||
@HostBinding('class.daff-modal-content') class = true; | ||
} |
8 changes: 8 additions & 0 deletions
8
libs/design/modal/src/modal-header/modal-header.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 |
---|---|---|
@@ -1 +1,9 @@ | ||
<ng-content select="[daffModalTitle]"></ng-content> | ||
<ng-container *ngIf="dismissible"> | ||
<button daff-icon-button color="theme-contrast" | ||
daffModalClose | ||
class="daff-modal-header__dismiss-button" | ||
aria-label="Close modal"> | ||
<fa-icon [icon]="faXmark" size="lg"></fa-icon> | ||
</button> | ||
</ng-container> |
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
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 |
---|---|---|
@@ -1,15 +1,67 @@ | ||
@use '../../../scss/typography' as t; | ||
@use '../../../scss/layout'; | ||
|
||
:host { | ||
display: block; | ||
.daff-modal { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: space-between; | ||
border-radius: 4px; | ||
height: 100%; | ||
max-width: 80vw; | ||
max-height: 90vh; | ||
max-width: 90vw; | ||
overflow: hidden; | ||
padding: 24px; | ||
z-index: 3; | ||
|
||
@include layout.breakpoint(mobile) { | ||
height: auto; | ||
max-height: 80vh; | ||
max-width: 80vw; | ||
} | ||
} | ||
|
||
.daff-modal-header { | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
padding: 24px; | ||
position: relative; | ||
|
||
.daff-modal-title { | ||
@include t.text-truncate(); | ||
font-size: 1.25rem; | ||
font-weight: 500; | ||
line-height: 1.5rem; | ||
margin: 0; | ||
padding: 0 32px 0 0; | ||
} | ||
|
||
&__dismiss-button { | ||
position: absolute; | ||
right: 7px; | ||
top: 12px; | ||
} | ||
} | ||
|
||
|
||
.daff-modal-content { | ||
display: block; | ||
flex-grow: 1; | ||
max-height: 60vh; | ||
overflow-y: auto; | ||
padding: 24px; | ||
} | ||
|
||
.daff-modal-actions { | ||
display: flex; | ||
align-items: center; | ||
flex-wrap: wrap; | ||
justify-content: flex-end; | ||
gap: 8px; | ||
padding: 24px; | ||
} | ||
|
||
.daff-modal-content + .daff-modal-actions { | ||
padding: 0 24px 24px; | ||
} | ||
|
||
.daff-modal-header + .daff-modal-content { | ||
padding-top: 0; | ||
} |
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