diff --git a/core/api.txt b/core/api.txt index e215126378..499de5e3c3 100644 --- a/core/api.txt +++ b/core/api.txt @@ -636,6 +636,13 @@ ion-modal,event,ionModalDidPresent,void,true ion-modal,event,ionModalDidUnload,void,true ion-modal,event,ionModalWillDismiss,OverlayEventDetail,true ion-modal,event,ionModalWillPresent,void,true +ion-modal,css-prop,--background +ion-modal,css-prop,--border-color +ion-modal,css-prop,--border-radius +ion-modal,css-prop,--border-style +ion-modal,css-prop,--border-width +ion-modal,css-prop,--height +ion-modal,css-prop,--width ion-nav-pop diff --git a/core/src/components/button/button.scss b/core/src/components/button/button.scss index f9011a42a8..9bc3c4ad7a 100644 --- a/core/src/components/button/button.scss +++ b/core/src/components/button/button.scss @@ -41,6 +41,9 @@ --width: auto; --overflow: hidden; --ripple-color: currentColor; + --border-width: initial; + --border-color: initial; + --border-style: initial; display: inline-block; diff --git a/core/src/components/modal/modal.ios.scss b/core/src/components/modal/modal.ios.scss index 8262155797..8c8770d979 100644 --- a/core/src/components/modal/modal.ios.scss +++ b/core/src/components/modal/modal.ios.scss @@ -4,14 +4,13 @@ // iOS Modals // -------------------------------------------------- -.modal-wrapper-ios { - // hidden by default to prevent flickers, the animation will show it - - @include transform(translate3d(0, 100%, 0)); - - @media only screen and (min-width: $modal-inset-min-width) and (min-height: $modal-inset-min-height-small) { - @include border-radius($modal-ios-border-radius); - - overflow: hidden; +@media only screen and (min-width: $modal-inset-min-width) and (min-height: $modal-inset-min-height-small) { + :host { + --border-radius: #{$modal-ios-border-radius}; } } + +.modal-wrapper { + // hidden by default to prevent flickers, the animation will show it + @include transform(translate3d(0, 100%, 0)); +} diff --git a/core/src/components/modal/modal.md.scss b/core/src/components/modal/modal.md.scss index af2fe9aef8..aabfa3d6f7 100644 --- a/core/src/components/modal/modal.md.scss +++ b/core/src/components/modal/modal.md.scss @@ -5,16 +5,15 @@ // Material Design Modals // -------------------------------------------------- -.modal-wrapper-md { +@media only screen and (min-width: $modal-inset-min-width) and (min-height: $modal-inset-min-height-small) { + :host { + --border-radius: 2px; + --box-shadow: #{$modal-inset-box-shadow}; + } +} + +.modal-wrapper { @include transform(translate3d(0, 40px, 0)); - @media only screen and (min-width: $modal-inset-min-width) and (min-height: $modal-inset-min-height-small) { - @include border-radius(2px); - - box-shadow: $modal-inset-box-shadow; - overflow: hidden; - } - opacity: .01; - } diff --git a/core/src/components/modal/modal.scss b/core/src/components/modal/modal.scss index 9510f46f9b..99d94c41eb 100644 --- a/core/src/components/modal/modal.scss +++ b/core/src/components/modal/modal.scss @@ -3,7 +3,25 @@ // Modals // -------------------------------------------------- -ion-modal { +:host { + /** + * @prop --background: Background of the modal content + * @prop --border-color: Border color of the modal content + * @prop --border-radius: Border radius of the modal content + * @prop --border-width: Border width of the modal content + * @prop --border-style: Border style of the modal content + * @prop --height: Height of the modal content + * @prop --width: Width of the modal content + */ + --width: 100%; + --height: 100%; + --overflow: hidden; + --border-radius: 0; + --border-width: 0; + --border-style: none; + --border-color: transparent; + --background: #{$background-color}; + @include position(0, 0, 0, 0); display: flex; @@ -15,32 +33,36 @@ ion-modal { contain: strict; } -ion-modal-controller { - display: none; -} - - -@media not all and (min-width: $modal-inset-min-width) and (min-height: $modal-inset-min-height-small) { - ion-modal ion-backdrop { - display: none; - } -} - .modal-wrapper { - @media only screen and (min-width: $modal-inset-min-width) and (min-height: $modal-inset-min-height-small) { - width: $modal-inset-width; - height: $modal-inset-height-small; - } + @include border-radius(var(--border-radius)); - @media only screen and (min-width: $modal-inset-min-width) and (min-height: $modal-inset-min-height-large) { - width: $modal-inset-width; - height: $modal-inset-height-large; - } + width: var(--width); + height: var(--height); - width: 100%; - height: 100%; + border-width: var(--border-width); + border-style: var(--border-style); + border-color: var(--border-color); - contain: strict; + background: var(--background); + + overflow: var(--overflow); z-index: 10; } +@media only screen and (min-width: $modal-inset-min-width) and (min-height: $modal-inset-min-height-small) { + :host { + --width: #{$modal-inset-width}; + --height: #{$modal-inset-height-small}; + --ion-safe-area-top: 0px; + --ion-safe-area-bottom: 0px; + --ion-safe-area-right: 0px; + --ion-safe-area-left: 0px; + } +} + +@media only screen and (min-width: $modal-inset-min-width) and (min-height: $modal-inset-min-height-large) { + :host { + --width: #{$modal-inset-width}; + --height: #{$modal-inset-height-large}; + } +} diff --git a/core/src/components/modal/modal.tsx b/core/src/components/modal/modal.tsx index c9309e1021..2da4ee967b 100644 --- a/core/src/components/modal/modal.tsx +++ b/core/src/components/modal/modal.tsx @@ -16,7 +16,8 @@ import { mdLeaveAnimation } from './animations/md.leave'; styleUrls: { ios: 'modal.ios.scss', md: 'modal.md.scss' - } + }, + scoped: true }) export class Modal implements ComponentInterface, OverlayInterface { @@ -29,6 +30,7 @@ export class Modal implements ComponentInterface, OverlayInterface { @Prop({ connect: 'ion-animation-controller' }) animationCtrl!: HTMLIonAnimationControllerElement; @Prop({ context: 'config' }) config!: Config; + /** @internal */ @Prop() overlayIndex!: number; diff --git a/core/src/components/modal/readme.md b/core/src/components/modal/readme.md index 2c6c43b241..cf27eabc19 100644 --- a/core/src/components/modal/readme.md +++ b/core/src/components/modal/readme.md @@ -156,6 +156,19 @@ Type: `Promise` +## CSS Custom Properties + +| Name | Description | +| ----------------- | ---------------------------------- | +| `--background` | Background of the modal content | +| `--border-color` | Border color of the modal content | +| `--border-radius` | Border radius of the modal content | +| `--border-style` | Border style of the modal content | +| `--border-width` | Border width of the modal content | +| `--height` | Height of the modal content | +| `--width` | Width of the modal content | + + ---------------------------------------------- *Built with [StencilJS](https://stenciljs.com/)* diff --git a/core/src/components/modal/test/basic/index.html b/core/src/components/modal/test/basic/index.html index 6ef7261f6a..0e31026fde 100644 --- a/core/src/components/modal/test/basic/index.html +++ b/core/src/components/modal/test/basic/index.html @@ -8,6 +8,15 @@ + + diff --git a/core/src/components/modal/test/custom/e2e.ts b/core/src/components/modal/test/custom/e2e.ts new file mode 100644 index 0000000000..9e80e6ad2d --- /dev/null +++ b/core/src/components/modal/test/custom/e2e.ts @@ -0,0 +1,16 @@ +import { newE2EPage } from '@stencil/core/testing'; + +test('modal: custom', async () => { + const page = await newE2EPage({ + url: '/src/components/modal/test/custom?ionic:_testing=true' + }); + + await page.click('.e2ePresentModal'); + + const modal = await page.find('ion-modal'); + await modal.waitForVisible(); + await page.waitFor(250); + + const compare = await page.compareScreenshot(); + expect(compare).toMatchScreenshot(); +}); diff --git a/core/src/components/modal/test/custom/index.html b/core/src/components/modal/test/custom/index.html new file mode 100644 index 0000000000..c139004b71 --- /dev/null +++ b/core/src/components/modal/test/custom/index.html @@ -0,0 +1,98 @@ + + + + + + Modal - Basic + + + + + + + + + + + + + + Modal - Basic + + + + +

+ Present modal +

+
+ + +
+ + + + + diff --git a/core/src/components/modal/test/standalone/index.html b/core/src/components/modal/test/standalone/index.html index eca8049f39..7d95c0f237 100644 --- a/core/src/components/modal/test/standalone/index.html +++ b/core/src/components/modal/test/standalone/index.html @@ -30,6 +30,11 @@