-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(gesture): add playground example for basic usage (#3038)
Co-authored-by: dillionmegida <dillionmegida@gmail.com>
- Loading branch information
1 parent
99b5f8a
commit 614519f
Showing
10 changed files
with
408 additions
and
130 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
14 changes: 14 additions & 0 deletions
14
static/usage/v7/gestures/basic/angular/example_component_css.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,14 @@ | ||
```css | ||
ion-card { | ||
position: absolute; | ||
|
||
left: 0; | ||
right: 0; | ||
|
||
user-select: none; | ||
} | ||
|
||
ion-card.active { | ||
box-shadow: var(--ion-color-warning) 0px 4px 16px; | ||
} | ||
``` |
10 changes: 10 additions & 0 deletions
10
static/usage/v7/gestures/basic/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,10 @@ | ||
```html | ||
<ion-card [class.active]="isCardActive"> | ||
<ion-card-header> | ||
<ion-card-subtitle>Pan the Screen</ion-card-subtitle> | ||
</ion-card-header> | ||
<ion-card-content> | ||
<p #debug>Gesture information will display after interaction.</p> | ||
</ion-card-content> | ||
</ion-card> | ||
``` |
50 changes: 50 additions & 0 deletions
50
static/usage/v7/gestures/basic/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,50 @@ | ||
```ts | ||
import { ChangeDetectorRef, Component, ElementRef, ViewChild } from '@angular/core'; | ||
import type { GestureDetail } from '@ionic/angular'; | ||
import { GestureController, IonCard } from '@ionic/angular'; | ||
|
||
@Component({ | ||
selector: 'app-example', | ||
templateUrl: 'example.component.html', | ||
styleUrls: ['example.component.css'], | ||
}) | ||
export class ExampleComponent { | ||
@ViewChild(IonCard, { read: ElementRef }) card: ElementRef<HTMLIonCardElement>; | ||
@ViewChild('debug', { read: ElementRef }) debug: ElementRef<HTMLParagraphElement>; | ||
|
||
isCardActive = false; | ||
|
||
constructor(private el: ElementRef, private gestureCtrl: GestureController, private cdRef: ChangeDetectorRef) {} | ||
|
||
ngAfterViewInit() { | ||
const gesture = this.gestureCtrl.create({ | ||
el: this.el.nativeElement.closest('ion-content'), | ||
onStart: () => this.onStart(), | ||
onMove: (detail) => this.onMove(detail), | ||
onEnd: () => this.onEnd(), | ||
gestureName: 'example', | ||
}); | ||
|
||
gesture.enable(); | ||
} | ||
|
||
private onStart() { | ||
this.isCardActive = true; | ||
this.cdRef.detectChanges(); | ||
} | ||
|
||
private onMove(detail: GestureDetail) { | ||
const { type, currentX, deltaX, velocityX } = detail; | ||
this.debug.nativeElement.innerHTML = ` | ||
<div>Type: ${type}</div> | ||
<div>Current X: ${currentX}</div> | ||
<div>Delta X: ${deltaX}</div> | ||
<div>Velocity X: ${velocityX}</div>`; | ||
} | ||
|
||
private onEnd() { | ||
this.isCardActive = false; | ||
this.cdRef.detectChanges(); | ||
} | ||
} | ||
``` |
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,81 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Gesture</title> | ||
<link rel="stylesheet" href="../../../common.css" /> | ||
<script src="../../../common.js"></script> | ||
<script type="module" src="https://cdn.jsdelivr.net/npm/@ionic/core@7/dist/ionic/ionic.esm.js"></script> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@ionic/core@7/css/ionic.bundle.css" /> | ||
<script type="module"> | ||
import { createGesture } from 'https://cdn.jsdelivr.net/npm/@ionic/core@7/dist/ionic/index.esm.js'; | ||
window.createGesture = createGesture; | ||
|
||
const p = document.querySelector('#debug'); | ||
const target = document.querySelector('ion-content'); | ||
const card = document.querySelector('ion-card'); | ||
|
||
const onMove = (detail) => { | ||
const { type, currentX, deltaX, velocityX } = detail; | ||
p.innerHTML = ` | ||
<div>Type: ${type}</div> | ||
<div>Current X: ${currentX}</div> | ||
<div>Delta X: ${deltaX}</div> | ||
<div>Velocity X: ${velocityX}</div>`; | ||
}; | ||
|
||
const onStart = () => { | ||
card.classList.add('active'); | ||
}; | ||
|
||
const onEnd = () => { | ||
card.classList.remove('active'); | ||
}; | ||
|
||
const gesture = createGesture({ | ||
el: target, | ||
onStart, | ||
onMove, | ||
onEnd, | ||
gestureName: 'example', | ||
}); | ||
|
||
gesture.enable(); | ||
</script> | ||
|
||
<style> | ||
.container { | ||
flex-direction: column; | ||
} | ||
|
||
ion-card { | ||
position: absolute; | ||
|
||
left: 0; | ||
right: 0; | ||
|
||
user-select: none; | ||
} | ||
|
||
ion-card.active { | ||
box-shadow: var(--ion-color-warning) 0px 4px 16px; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div class="container"> | ||
<ion-content> | ||
<ion-card> | ||
<ion-card-header> | ||
<ion-card-subtitle>Pan the Screen</ion-card-subtitle> | ||
</ion-card-header> | ||
<ion-card-content> | ||
<p id="debug">Gesture information will display after interaction.</p> | ||
</ion-card-content> | ||
</ion-card> | ||
</ion-content> | ||
</div> | ||
</body> | ||
</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,34 @@ | ||
import Playground from '@site/src/components/global/Playground'; | ||
|
||
import javascript from './javascript.md'; | ||
|
||
import react_main_css from './react/main_css.md'; | ||
import react_main_tsx from './react/main_tsx.md'; | ||
|
||
import vue from './vue.md'; | ||
|
||
import angular_example_component_html from './angular/example_component_html.md'; | ||
import angular_example_component_ts from './angular/example_component_ts.md'; | ||
import angular_example_component_css from './angular/example_component_css.md'; | ||
|
||
<Playground | ||
version="7" | ||
code={{ | ||
javascript, | ||
react: { | ||
files: { | ||
'src/main.tsx': react_main_tsx, | ||
'src/main.css': react_main_css, | ||
}, | ||
}, | ||
vue, | ||
angular: { | ||
files: { | ||
'src/app/example.component.html': angular_example_component_html, | ||
'src/app/example.component.ts': angular_example_component_ts, | ||
'src/app/example.component.css': angular_example_component_css, | ||
}, | ||
}, | ||
}} | ||
src="usage/v7/gestures/basic/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,58 @@ | ||
```html | ||
<style> | ||
ion-card { | ||
position: absolute; | ||
left: 0; | ||
right: 0; | ||
user-select: none; | ||
} | ||
ion-card.active { | ||
box-shadow: var(--ion-color-warning) 0px 4px 16px; | ||
} | ||
</style> | ||
|
||
<ion-card> | ||
<ion-card-header> | ||
<ion-card-subtitle>Pan the Screen</ion-card-subtitle> | ||
</ion-card-header> | ||
<ion-card-content> | ||
<p id="debug">Gesture information will display after interaction.</p> | ||
</ion-card-content> | ||
</ion-card> | ||
|
||
<script> | ||
const p = document.querySelector('#debug'); | ||
const target = document.querySelector('ion-content'); | ||
const card = document.querySelector('ion-card'); | ||
const onMove = (detail) => { | ||
const { type, currentX, deltaX, velocityX } = detail; | ||
p.innerHTML = ` | ||
<div>Type: ${type}</div> | ||
<div>Current X: ${currentX}</div> | ||
<div>Delta X: ${deltaX}</div> | ||
<div>Velocity X: ${velocityX}</div>`; | ||
}; | ||
const onStart = () => { | ||
card.classList.add('active'); | ||
}; | ||
const onEnd = () => { | ||
card.classList.remove('active'); | ||
}; | ||
const gesture = createGesture({ | ||
el: target, | ||
onStart, | ||
onMove, | ||
onEnd, | ||
gestureName: 'example', | ||
}); | ||
gesture.enable(); | ||
</script> | ||
``` |
Oops, something went wrong.
614519f
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