-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(modal): playground example to prevent swipe to dismiss (#2820)
- Loading branch information
1 parent
95c4f23
commit 3bd16bc
Showing
16 changed files
with
556 additions
and
2 deletions.
There are no files selected for viewing
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
30 changes: 30 additions & 0 deletions
30
...e/v6/modal/can-dismiss/prevent-swipe-to-close/angular/example_component_html.md
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,30 @@ | ||
```html | ||
<div class="ion-page" #page> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>App</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content class="ion-padding"> | ||
<ion-button id="open-modal" expand="block">Open</ion-button> | ||
<ion-modal #modal trigger="open-modal" [canDismiss]="canDismiss" [presentingElement]="page"> | ||
<ng-template> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>Modal</ion-title> | ||
<ion-buttons slot="end"> | ||
<ion-button (click)="modal.dismiss()">Close</ion-button> | ||
</ion-buttons> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content class="ion-padding"> | ||
<p> | ||
To close this modal, please use the "Close" button provided. Note that swiping the modal will not dismiss | ||
it. | ||
</p> | ||
</ion-content> | ||
</ng-template> | ||
</ion-modal> | ||
</ion-content> | ||
</div> | ||
``` |
13 changes: 13 additions & 0 deletions
13
...age/v6/modal/can-dismiss/prevent-swipe-to-close/angular/example_component_ts.md
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,13 @@ | ||
```ts | ||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-example', | ||
templateUrl: 'example.component.html', | ||
}) | ||
export class ExampleComponent { | ||
async canDismiss(data?: any, role?: string) { | ||
return role !== 'gesture'; | ||
} | ||
} | ||
``` |
57 changes: 57 additions & 0 deletions
57
static/usage/v6/modal/can-dismiss/prevent-swipe-to-close/demo.html
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,57 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Modal | Can Dismiss</title> | ||
<link rel="stylesheet" href="../../../../common.css" /> | ||
<script src="../../../../common.js"></script> | ||
<script type="module" src="https://cdn.jsdelivr.net/npm/@ionic/core@6/dist/ionic/ionic.esm.js"></script> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@ionic/core@6/css/ionic.bundle.css" /> | ||
|
||
</head> | ||
|
||
<body> | ||
<ion-app> | ||
<div class="ion-page"> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>App</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content class="ion-padding"> | ||
<ion-button id="open-modal" expand="block">Open</ion-button> | ||
|
||
<ion-modal trigger="open-modal"> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>Modal</ion-title> | ||
<ion-buttons slot="end"> | ||
<ion-button onclick="dismiss()">Close</ion-button> | ||
</ion-buttons> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content class="ion-padding"> | ||
<p>To close this modal, please use the "Close" button provided. Note that swiping the modal will not dismiss | ||
it.</p> | ||
</ion-content> | ||
</ion-modal> | ||
</ion-content> | ||
</div> | ||
</ion-app> | ||
|
||
<script> | ||
const modal = document.querySelector('ion-modal'); | ||
|
||
modal.canDismiss = (data, role) => role !== 'gesture'; | ||
modal.presentingElement = document.querySelector('.ion-page'); | ||
|
||
function dismiss() { | ||
modal.dismiss(); | ||
} | ||
|
||
</script> | ||
</body> | ||
|
||
</html> |
27 changes: 27 additions & 0 deletions
27
static/usage/v6/modal/can-dismiss/prevent-swipe-to-close/index.md
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,27 @@ | ||
import Playground from '@site/src/components/global/Playground'; | ||
|
||
import javascript from './javascript.md'; | ||
import vue from './vue.md'; | ||
|
||
import react from './react.md'; | ||
|
||
import angular_example_component_html from './angular/example_component_html.md'; | ||
import angular_example_component_ts from './angular/example_component_ts.md'; | ||
|
||
<Playground | ||
version="6" | ||
code={{ | ||
javascript, | ||
react, | ||
vue, | ||
angular: { | ||
files: { | ||
'src/app/example.component.html': angular_example_component_html, | ||
'src/app/example.component.ts': angular_example_component_ts, | ||
}, | ||
}, | ||
}} | ||
src="usage/v6/modal/can-dismiss/prevent-swipe-to-close/demo.html" | ||
devicePreview | ||
mode="ios" | ||
/> |
39 changes: 39 additions & 0 deletions
39
static/usage/v6/modal/can-dismiss/prevent-swipe-to-close/javascript.md
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,39 @@ | ||
```html | ||
<div class="ion-page"> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>App</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content class="ion-padding"> | ||
<ion-button id="open-modal" expand="block">Open</ion-button> | ||
|
||
<ion-modal trigger="open-modal"> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>Modal</ion-title> | ||
<ion-buttons slot="end"> | ||
<ion-button onclick="dismiss()">Close</ion-button> | ||
</ion-buttons> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content class="ion-padding"> | ||
<p> | ||
To close this modal, please use the "Close" button provided. Note that swiping the modal will not dismiss it. | ||
</p> | ||
</ion-content> | ||
</ion-modal> | ||
</ion-content> | ||
</div> | ||
|
||
<script> | ||
var modal = document.querySelector('ion-modal'); | ||
modal.canDismiss = (data, role) => role !== 'gesture'; | ||
modal.presentingElement = document.querySelector('.ion-page'); | ||
function dismiss() { | ||
modal.dismiss(); | ||
} | ||
</script> | ||
``` |
56 changes: 56 additions & 0 deletions
56
static/usage/v6/modal/can-dismiss/prevent-swipe-to-close/react.md
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,56 @@ | ||
```tsx | ||
import React, { useState, useRef, useEffect } from 'react'; | ||
import { IonButtons, IonButton, IonModal, IonHeader, IonContent, IonToolbar, IonTitle, IonPage } from '@ionic/react'; | ||
|
||
function Example() { | ||
const modal = useRef<HTMLIonModalElement>(null); | ||
const page = useRef(null); | ||
|
||
const [presentingElement, setPresentingElement] = useState<HTMLElement | null>(null); | ||
|
||
useEffect(() => { | ||
setPresentingElement(page.current); | ||
}, []); | ||
|
||
function dismiss() { | ||
modal.current?.dismiss(); | ||
} | ||
|
||
async function canDismiss(data?: any, role?: string) { | ||
return role !== 'gesture'; | ||
} | ||
|
||
return ( | ||
<IonPage ref={page}> | ||
<IonHeader> | ||
<IonToolbar> | ||
<IonTitle>App</IonTitle> | ||
</IonToolbar> | ||
</IonHeader> | ||
<IonContent className="ion-padding"> | ||
<IonButton id="open-modal" expand="block"> | ||
Open | ||
</IonButton> | ||
<IonModal ref={modal} trigger="open-modal" canDismiss={canDismiss} presentingElement={presentingElement!}> | ||
<IonHeader> | ||
<IonToolbar> | ||
<IonTitle>Modal</IonTitle> | ||
<IonButtons slot="end"> | ||
<IonButton onClick={() => dismiss()}>Close</IonButton> | ||
</IonButtons> | ||
</IonToolbar> | ||
</IonHeader> | ||
<IonContent className="ion-padding"> | ||
<p> | ||
To close this modal, please use the "Close" button provided. Note that swiping the modal will not dismiss | ||
it. | ||
</p> | ||
</IonContent> | ||
</IonModal> | ||
</IonContent> | ||
</IonPage> | ||
); | ||
} | ||
|
||
export default Example; | ||
``` |
47 changes: 47 additions & 0 deletions
47
static/usage/v6/modal/can-dismiss/prevent-swipe-to-close/vue.md
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,47 @@ | ||
```html | ||
<template> | ||
<ion-page ref="page"> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>App</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content class="ion-padding"> | ||
<ion-button id="open-modal" expand="block">Open</ion-button> | ||
|
||
<ion-modal ref="modal" trigger="open-modal" :can-dismiss="canDismiss" :presenting-element="page?.$el"> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>Modal</ion-title> | ||
<ion-buttons slot="end"> | ||
<ion-button @click="dismiss">Close</ion-button> | ||
</ion-buttons> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content class="ion-padding"> | ||
<p> | ||
To close this modal, please use the "Close" button provided. Note that swiping the modal will not dismiss | ||
it. | ||
</p> | ||
</ion-content> | ||
</ion-modal> | ||
</ion-content> | ||
</ion-page> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { IonButtons, IonButton, IonModal, IonHeader, IonContent, IonToolbar, IonTitle, IonPage } from '@ionic/vue'; | ||
import { ref } from 'vue'; | ||
const page = ref(null); | ||
const modal = ref(null); | ||
function dismiss() { | ||
modal.value.$el.dismiss(); | ||
} | ||
async function canDismiss(data?: any, role?: string) { | ||
return role !== 'gesture'; | ||
} | ||
</script> | ||
``` |
30 changes: 30 additions & 0 deletions
30
...e/v7/modal/can-dismiss/prevent-swipe-to-close/angular/example_component_html.md
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,30 @@ | ||
```html | ||
<div class="ion-page" #page> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>App</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content class="ion-padding"> | ||
<ion-button id="open-modal" expand="block">Open</ion-button> | ||
<ion-modal #modal trigger="open-modal" [canDismiss]="canDismiss" [presentingElement]="page"> | ||
<ng-template> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>Modal</ion-title> | ||
<ion-buttons slot="end"> | ||
<ion-button (click)="modal.dismiss()">Close</ion-button> | ||
</ion-buttons> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content class="ion-padding"> | ||
<p> | ||
To close this modal, please use the "Close" button provided. Note that swiping the modal will not dismiss | ||
it. | ||
</p> | ||
</ion-content> | ||
</ng-template> | ||
</ion-modal> | ||
</ion-content> | ||
</div> | ||
``` |
13 changes: 13 additions & 0 deletions
13
...age/v7/modal/can-dismiss/prevent-swipe-to-close/angular/example_component_ts.md
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,13 @@ | ||
```ts | ||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-example', | ||
templateUrl: 'example.component.html', | ||
}) | ||
export class ExampleComponent { | ||
async canDismiss(data?: any, role?: string) { | ||
return role !== 'gesture'; | ||
} | ||
} | ||
``` |
Oops, something went wrong.
3bd16bc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
ionic-docs – ./
ionic-docs-ionic1.vercel.app
ionic-docs-gqykycf8t.vercel.app
ionic-docs-git-main-ionic1.vercel.app