Skip to content

Commit

Permalink
Merge pull request #79 from Front-znad-zatoki/feature/#72-win-modal
Browse files Browse the repository at this point in the history
UI Component/#72 - WinModal
  • Loading branch information
Enessetere authored Feb 1, 2021
2 parents 158d87b + 26f09b4 commit 6f31cc1
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/app/components/ModalBasic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,26 @@ export class ModalBasic {
createAndAppendButtonsRow(
leftButtonText: string,
leftButtonAction: () => void,
rightButtonText: string,
rightButtonAction: () => void,
rightButtonText?: string,
rightButtonAction?: () => void,
): ModalBasic {
const leftButton: HTMLElement = new Button().create(
leftButtonText,
);
const rightButton: HTMLElement = new Button().create(
rightButtonText,
);
const rightButton: HTMLElement | null = rightButtonText
? new Button().create(rightButtonText)
: null;
if (rightButton && rightButtonAction) {
rightButton.addEventListener('click', rightButtonAction);
}
leftButton.addEventListener('click', leftButtonAction);
rightButton.addEventListener('click', rightButtonAction);
const buttonsRow = Render.elementFactory(
'div',
{
className: 'modal__buttons',
},
leftButton,
rightButton,
rightButton ? rightButton : '',
);
Render.childrenInjector(this.modalContainer, buttonsRow);
return this;
Expand Down
28 changes: 28 additions & 0 deletions src/app/components/WinModal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Player } from '~src/Player';
import { Render } from '../utils/Render';
import { ModalBasic } from './ModalBasic';

export class WinModal extends ModalBasic {
create(player: Player): void {
this.renderBasicModal(
'CONGRATULATIONS!',
`${player.theName} has won!`,
this.createImage(player),
) as WinModal;
}

addButton(): void {
const handleEnd = () => Render.removeElement('.modal');
this.createAndAppendButtonsRow(
'End game - back to menu',
handleEnd,
);
}

private createImage({ theName, theAvatar }: Player): HTMLElement {
return Render.elementFactory('img', {
src: theAvatar,
alt: `${theName}-avatar`,
});
}
}
16 changes: 16 additions & 0 deletions src/app/manuals/WinModalDemo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Player } from '../../Player';
import { WinModal } from '../components/WinModal';
import { Render } from '../utils/Render';

export class WinModalDemo {
static playDemo(): void {
const modal = new WinModal();
const player = new Player(
'player',
'./static/images/avatars/dog.png',
);
modal.create(player);
modal.addButton();
Render.render('#sf-app', modal.modal);
}
}

0 comments on commit 6f31cc1

Please sign in to comment.