diff --git a/packages/components/src/components/modal/modal.e2e.ts b/packages/components/src/components/modal/modal.e2e.ts index 7f4102bcc1..bdd470d4db 100644 --- a/packages/components/src/components/modal/modal.e2e.ts +++ b/packages/components/src/components/modal/modal.e2e.ts @@ -114,4 +114,29 @@ test.describe('kol-modal', () => { await expect(eventPromise).resolves.toBeUndefined(); }); }); + + test.describe('kol-modal - variant', () => { + test('it renders the close button in card variant', async ({ page }) => { + await page.setContent('Modal content'); + const kolModal = page.locator('kol-modal'); + const dialog = page.locator('dialog'); + await expect(dialog).toBeHidden(); + await kolModal.evaluate((element: HTMLKolModalElement) => element.openModal()); + await expect(dialog).toBeVisible(); + const closeButton = page.locator('.kol-modal__close-button'); + await expect(closeButton).toBeVisible(); + await closeButton.click(); + await expect(dialog).toBeHidden(); + }); + + test('it does not render the close button in blank variant', async ({ page }) => { + await page.setContent('Modal content'); + const kolModal = page.locator('kol-modal'); + const dialog = page.locator('dialog'); + const closeButton = page.locator('.kol-modal__close-button'); + await kolModal.evaluate((element: HTMLKolModalElement) => element.openModal()); + await expect(dialog).toBeVisible(); + await expect(closeButton).toBeHidden(); + }); + }); }); diff --git a/packages/components/src/components/modal/shadow.tsx b/packages/components/src/components/modal/shadow.tsx index a57fb50fc6..6e5ea0a265 100644 --- a/packages/components/src/components/modal/shadow.tsx +++ b/packages/components/src/components/modal/shadow.tsx @@ -3,6 +3,10 @@ import { setState, validateLabel, watchString } from '../../schema'; import type { JSX } from '@stencil/core'; import { Component, Element, h, Method, Prop, State, Watch } from '@stencil/core'; import { dispatchDomEvent, KolEvent } from '../../utils/events'; +import { ModalVariantPropType, validateModalVariant } from '../../schema/props/variant/modal'; +import { KolButtonWcTag } from '../../core/component-names'; +import { translate } from '../../i18n'; +import clsx from 'clsx'; /** * https://en.wikipedia.org/wiki/Modal_window @@ -44,10 +48,16 @@ export class KolModal implements ModalAPI { this.refDialog?.close?.(); } + private readonly on = { + onClick: async () => { + await this.closeModal(); + }, + }; + public render(): JSX.Element { return ( { this.refDialog = el; }} @@ -58,9 +68,24 @@ export class KolModal implements ModalAPI { onClose={this.handleNativeCloseEvent.bind(this)} > {/* It's necessary to have a block element container for cross-browser compatibility. The display property for the slot content is unknown and could be inline. */} -
+
+ {this.state._variant === 'card' && ( + + )}
); } @@ -80,6 +105,11 @@ export class KolModal implements ModalAPI { */ @Prop() public _width?: string = '100%'; + /** + * Defines the variant of the modal. + */ + @Prop() public _variant?: ModalVariantPropType = 'blank'; + @State() public state: ModalStates = { _label: '', // ⚠ required _width: '100%', @@ -110,9 +140,15 @@ export class KolModal implements ModalAPI { }); } + @Watch('_variant') + public validateVariant(value?: ModalVariantPropType): void { + validateModalVariant(this, value); + } + public componentWillLoad(): void { this.validateLabel(this._label); this.validateOn(this._on); this.validateWidth(this._width); + this.validateVariant(this._variant); } } diff --git a/packages/components/src/components/modal/style.scss b/packages/components/src/components/modal/style.scss index 36426e61b3..64730614ec 100644 --- a/packages/components/src/components/modal/style.scss +++ b/packages/components/src/components/modal/style.scss @@ -1,14 +1,23 @@ @import '../@shared/mixins'; @import '../../styles/global'; +@import '../tooltip/style.scss'; @layer kol-component { .kol-modal { border: 0; padding: 0; font-size: rem(16); + position: relative; &::backdrop { background-color: rgba(0, 0, 0, 0.33); } + + &__close-button { + position: absolute; + top: rem(1); + right: rem(1); + z-index: 1; + } } -} +} \ No newline at end of file diff --git a/packages/components/src/components/modal/test/__snapshots__/snapshot.spec.tsx.snap b/packages/components/src/components/modal/test/__snapshots__/snapshot.spec.tsx.snap index 093b906bf2..e039b3ba72 100644 --- a/packages/components/src/components/modal/test/__snapshots__/snapshot.spec.tsx.snap +++ b/packages/components/src/components/modal/test/__snapshots__/snapshot.spec.tsx.snap @@ -4,7 +4,7 @@ exports[`kol-modal should render with _label="Label" _width="80%" 1`] = `