Skip to content

Commit 8f9d11f

Browse files
committed
docs(modal): update playgrounds and add interface
1 parent 1befa48 commit 8f9d11f

5 files changed

Lines changed: 68 additions & 17 deletions

File tree

docs/api/modal.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,59 @@ interface ModalCustomEvent extends CustomEvent {
265265
}
266266
```
267267

268+
### ModalDragEventDetail
269+
270+
When using the `ionDragMove` and `ionDragEnd` events, the event detail contains the following properties:
271+
272+
```typescript
273+
interface ModalDragEventDetail {
274+
/**
275+
* The current Y position of the modal.
276+
*
277+
* This can be used to determine how far the modal has been dragged.
278+
*/
279+
currentY: number;
280+
/**
281+
* The change in Y position since the last event.
282+
*
283+
* This can be used to determine the direction of the drag.
284+
*/
285+
deltaY: number;
286+
/**
287+
* The velocity of the drag in the Y direction.
288+
*
289+
* This can be used to determine how fast the modal is being dragged.
290+
*/
291+
velocityY: number;
292+
/**
293+
* A number between 0 and 1.
294+
*
295+
* In a sheet modal, progress represents the relative position between
296+
* the lowest and highest defined breakpoints.
297+
*
298+
* In a card modal, it measures the relative position between the
299+
* bottom of the screen and the top of the modal when it is fully
300+
* open.
301+
*
302+
* This can be used to style content based on how far the modal has
303+
* been dragged.
304+
*/
305+
progress: number;
306+
/**
307+
* If the modal is a sheet modal, this will be the breakpoint that
308+
* the modal will snap to if the user lets go of the modal at the
309+
* current moment.
310+
*
311+
* If it's a card modal, this property will not be included in the
312+
* event payload.
313+
*
314+
* This can be used to style content based on where the modal will
315+
* snap to upon release.
316+
*/
317+
currentBreakpoint?: number;
318+
}
319+
```
320+
268321
## Accessibility
269322

270323
### Keyboard Interactions

static/usage/v8/modal/card/drag-events/angular/example_component_ts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
```ts
22
import { Component, ElementRef, ViewChild, OnInit } from '@angular/core';
33
import { IonHeader, IonToolbar, IonTitle, IonContent, IonButton, IonModal, IonLabel } from '@ionic/angular/standalone';
4-
import type { ModalDragEventDetail } from '@ionic/core';
4+
import type { ModalDragEventDetail } from '@ionic/angular/standalone';
55

66
@Component({
77
selector: 'app-example',

static/usage/v8/modal/card/drag-events/vue.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
<ion-button id="open-modal" expand="block">Open Card Modal</ion-button>
1111
1212
<ion-modal
13-
ref="modal"
1413
trigger="open-modal"
1514
:presenting-element="presentingElement"
1615
@willPresent="onWillPresent()"
@@ -39,30 +38,29 @@ import { ref, onMounted } from 'vue';
3938
import { IonPage, IonModal, IonHeader, IonToolbar, IonTitle, IonContent, IonButton, IonLabel } from '@ionic/vue';
4039
import type { ModalDragEventDetail } from '@ionic/vue';
4140
42-
const modal = ref();
43-
const page = ref<HTMLDivElement | null>(null);
44-
const presentingElement = ref<HTMLElement | null>(null);
41+
const page = ref<InstanceType<typeof IonPage>>();
42+
const presentingElement = ref<HTMLElement>();
4543
4644
const DARKEST_PERCENT = 50;
4745
const BRIGHTNESS_RANGE = 100 - DARKEST_PERCENT;
4846
4947
onMounted(() => {
50-
presentingElement.value = page.value.$el;
48+
presentingElement.value = page.value!.$el;
5149
});
5250
5351
/**
5452
* Sync the background dimming with the modal's entry animation.
5553
*/
5654
const onWillPresent = () => {
57-
const appEl = page.value.$el;
55+
const appEl = page.value!.$el;
5856
5957
appEl.style.transition = 'filter 0.4s ease';
6058
// Set to max darkness immediately
6159
appEl.style.setProperty('filter', `brightness(${DARKEST_PERCENT}%)`, 'important');
6260
};
6361
6462
const onDragStart = () => {
65-
const appEl = page.value.$el;
63+
const appEl = page.value!.$el;
6664
6765
// Ensure transitions are off during the active drag
6866
appEl.style.transition = 'none';
@@ -72,7 +70,7 @@ const onDragMove = (event: CustomEvent<ModalDragEventDetail>) => {
7270
// `progress` is a value from 1 (top) to 0 (bottom)
7371
const { progress } = event.detail;
7472
75-
const appEl = page.value.$el;
73+
const appEl = page.value!.$el;
7674
/**
7775
* Calculate the current brightness based on how far the user has
7876
* dragged.
@@ -90,7 +88,7 @@ const onDragEnd = (event: CustomEvent<ModalDragEventDetail>) => {
9088
// `progress` is a value from 1 (top) to 0 (bottom)
9189
const { progress } = event.detail;
9290
93-
const appEl = page.value.$el;
91+
const appEl = page.value!.$el;
9492
/**
9593
* Snap the background brightness based on the user's drag intent.
9694
* Progress > 0.4 implies an intent to open (snap dark),
@@ -106,7 +104,7 @@ const onDragEnd = (event: CustomEvent<ModalDragEventDetail>) => {
106104
};
107105
108106
const onWillDismiss = () => {
109-
const appEl = page.value.$el;
107+
const appEl = page.value!.$el;
110108
111109
// Clean up styles when the modal is dismissed
112110
appEl.style.removeProperty('filter');

static/usage/v8/modal/sheet/drag-events/angular/example_component_ts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
```ts
22
import { Component, ElementRef, ViewChild } from '@angular/core';
33
import { IonButton, IonContent, IonHeader, IonLabel, IonModal, IonTitle, IonToolbar } from '@ionic/angular/standalone';
4-
import type { ModalDragEventDetail } from '@ionic/core';
4+
import type { ModalDragEventDetail } from '@ionic/angular/standalone';
55

66
@Component({
77
selector: 'app-example',

static/usage/v8/modal/sheet/drag-events/vue.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ import { ref } from 'vue';
3131
import { IonButton, IonModal, IonHeader, IonContent, IonToolbar, IonTitle, IonLabel } from '@ionic/vue';
3232
import type { ModalDragEventDetail } from '@ionic/vue';
3333
34-
const modal = ref();
34+
const modal = ref<InstanceType<typeof IonModal>>();
3535
3636
let baseOpacity: number;
3737
const MAX_OPACITY = 0.8;
3838
3939
const onDragStart = () => {
40-
const modalEl = modal.value.$el;
40+
const modalEl = modal.value!.$el;
4141
const style = window.getComputedStyle(modalEl);
4242
4343
// Fetch the current variable value
@@ -50,7 +50,7 @@ const onDragStart = () => {
5050
const onDragMove = (event: CustomEvent<ModalDragEventDetail>) => {
5151
// `progress` is a value from 1 (top) to 0 (bottom)
5252
const { progress } = event.detail;
53-
const modalEl = modal.value.$el;
53+
const modalEl = modal.value!.$el;
5454
const initialBreakpoint = modalEl.initialBreakpoint || 0.25;
5555
let dynamicOpacity: number;
5656
@@ -99,7 +99,7 @@ const onDragMove = (event: CustomEvent<ModalDragEventDetail>) => {
9999
const onDragEnd = (event: CustomEvent<ModalDragEventDetail>) => {
100100
// `currentBreakpoint` tells us which snap point the modal will animate to after the drag ends
101101
const { currentBreakpoint } = event.detail;
102-
const modalEl = modal.value.$el;
102+
const modalEl = modal.value!.$el;
103103
104104
/**
105105
* If the modal is snapping to the closed state (0), reset the
@@ -117,7 +117,7 @@ const onDragEnd = (event: CustomEvent<ModalDragEventDetail>) => {
117117
* visual effect.
118118
*/
119119
if (currentBreakpoint === 1) {
120-
targetOpacity = this.MAX_OPACITY;
120+
targetOpacity = MAX_OPACITY;
121121
}
122122
123123
// Re-enable transition for a smooth snap-back

0 commit comments

Comments
 (0)