-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update presentation object page (#418)
* feat: first implementation of new object overview page WIP * feat: created PopupComponent WIP * fix: updated styling for image popup WIP * test: updated tests * feat: added menu items to object root page * test: updated tests
- Loading branch information
Showing
19 changed files
with
636 additions
and
525 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
packages/solid-crs-components/lib/alerts/popup.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,86 @@ | ||
import { PopupComponent } from './popup.component'; | ||
|
||
describe('PopupComponent', () => { | ||
|
||
let component: PopupComponent; | ||
|
||
beforeEach(() => { | ||
|
||
component = window.document.createElement('nde-popup') as PopupComponent; | ||
|
||
}); | ||
|
||
afterEach(() => { | ||
|
||
document.getElementsByTagName('html')[0].innerHTML = ''; | ||
|
||
}); | ||
|
||
it('should be correctly instantiated', () => { | ||
|
||
expect(component).toBeTruthy(); | ||
|
||
}); | ||
|
||
it('should add correct class when this.dark is set', async () => { | ||
|
||
window.document.body.appendChild(component); | ||
await component.updateComplete; | ||
|
||
const div = window.document.body.getElementsByTagName('nde-popup')[0].shadowRoot.querySelector<HTMLDivElement>('div.overlay'); | ||
expect(div.className).not.toMatch('dark'); | ||
|
||
component.dark = true; | ||
await component.updateComplete; | ||
expect(div.className).toMatch('dark'); | ||
|
||
}); | ||
|
||
it('should hide the component when the background is clicked', async () => { | ||
|
||
window.document.body.appendChild(component); | ||
await component.updateComplete; | ||
component.show(); | ||
expect(component.hidden).toBeFalsy(); | ||
|
||
const div = window.document.body.getElementsByTagName('nde-popup')[0].shadowRoot.querySelector<HTMLDivElement>('div.overlay'); | ||
div.click(); | ||
|
||
await component.updateComplete; | ||
expect(component.hidden).toBeTruthy(); | ||
|
||
}); | ||
|
||
it('should not hide the component when the content is clicked', async () => { | ||
|
||
window.document.body.appendChild(component); | ||
await component.updateComplete; | ||
component.show(); | ||
expect(component.hidden).toBeFalsy(); | ||
|
||
const content = window.document.body.getElementsByTagName('nde-popup')[0].shadowRoot.querySelector<HTMLSlotElement>('slot'); | ||
content.click(); | ||
|
||
await component.updateComplete; | ||
expect(component.hidden).toBeFalsy(); | ||
|
||
}); | ||
|
||
describe('toggle', () => { | ||
|
||
it('should toggle this.hidden', async () => { | ||
|
||
window.document.body.appendChild(component); | ||
await component.updateComplete; | ||
|
||
expect(component.hidden).toEqual(true); | ||
component.toggle(); | ||
expect(component.hidden).toEqual(false); | ||
component.toggle(); | ||
expect(component.hidden).toEqual(true); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); |
102 changes: 102 additions & 0 deletions
102
packages/solid-crs-components/lib/alerts/popup.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,102 @@ | ||
|
||
import { css, CSSResult, html, property, query, TemplateResult, unsafeCSS } from 'lit-element'; | ||
import { Theme } from '@netwerk-digitaal-erfgoed/solid-crs-theme'; | ||
import { RxLitElement } from 'rx-lit'; | ||
|
||
/** | ||
* A component that displays any content over the whole webpage | ||
* Hide by toggling this.hidden | ||
*/ | ||
export class PopupComponent extends RxLitElement { | ||
|
||
/** | ||
* The content element of this component | ||
*/ | ||
@query('slot[name="content"]') | ||
content: HTMLSlotElement; | ||
|
||
/** | ||
* Decides whether the component has a dark background | ||
*/ | ||
@property({ type: Boolean }) | ||
public dark = false; | ||
|
||
/** | ||
* Hides/shows the component | ||
*/ | ||
toggle(): void { | ||
|
||
this.hidden ? this.show() : this.hide(); | ||
|
||
} | ||
|
||
/** | ||
* Shows the component | ||
*/ | ||
show(): void { | ||
|
||
this.hidden = false; | ||
|
||
} | ||
|
||
/** | ||
* Hides the component | ||
*/ | ||
hide(): void { | ||
|
||
this.hidden = true; | ||
|
||
} | ||
|
||
/** | ||
* Renders the component as HTML. | ||
* | ||
* @returns The rendered HTML of the component. | ||
*/ | ||
render(): TemplateResult { | ||
|
||
// initially, always hide the component | ||
this.hide(); | ||
|
||
return html` | ||
<div class="overlay${ this.dark ? ' dark' : ''}" @click="${ () => this.hide() }"> | ||
<slot name="content" @click="${ (event: MouseEvent) => event.stopPropagation() }"></slot> | ||
</div> | ||
`; | ||
|
||
} | ||
|
||
/** | ||
* The styles associated with the component. | ||
*/ | ||
static get styles(): CSSResult[] { | ||
|
||
return [ | ||
unsafeCSS(Theme), | ||
css` | ||
:host { | ||
height: 100%; | ||
width: 100%; | ||
top: 0; | ||
left: 0; | ||
position: fixed; | ||
} | ||
.overlay { | ||
height: 100%; | ||
width: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
.dark { | ||
background-color: rgba(0, 0, 0, 0.8); | ||
} | ||
`, | ||
]; | ||
|
||
} | ||
|
||
} | ||
|
||
export default PopupComponent; |
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
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
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
Oops, something went wrong.