Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(toast): add swipeGesture playground #3247

Merged
merged 2 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/api/toast.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ import PositionAnchor from '@site/static/usage/v7/toast/position-anchor/index.md

<PositionAnchor />

## Swipe to Dismiss

Toasts can be swiped to dismiss by using the `swipeGesture` property. This feature is position-aware, meaning the direction that users need to swipe will change based on the value of the `position` property. Additionally, the distance users need to swipe may be impacted by the `positionAnchor` property.

import SwipeGesture from '@site/static/usage/v7/toast/swipe-gesture/index.md';

<SwipeGesture />

## Layout

Button containers within the toast can be displayed either on the same line as the message or stacked on separate lines using the `layout` property. The stacked layout should be used with buttons that have long text values. Additionally, buttons in a stacked toast layout can use a `side` value of either `start` or `end`, but not both.
Expand Down
17 changes: 17 additions & 0 deletions static/usage/v7/toast/swipe-gesture/angular.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
```html
<ion-content class="ion-padding">
<ion-button id="open-toast">Open Toast</ion-button>
<ion-toast
message="This toast can be swiped to dismiss"
trigger="open-toast"
swipeGesture="vertical"
position="bottom"
positionAnchor="footer"
></ion-toast>
</ion-content>
<ion-footer id="footer">
<ion-toolbar>
<ion-title>Footer</ion-title>
</ion-toolbar>
</ion-footer>
```
35 changes: 35 additions & 0 deletions static/usage/v7/toast/swipe-gesture/demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Toast</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" />
</head>

<body>
<ion-app>
<ion-content>
<div class="container">
<ion-button id="open-toast">Open Toast</ion-button>
<ion-toast
message="This toast can be swiped to dismiss"
trigger="open-toast"
swipe-gesture="vertical"
position="bottom"
position-anchor="footer"
></ion-toast>
</div>
</ion-content>

<ion-footer id="footer">
<ion-toolbar>
<ion-title>Footer</ion-title>
</ion-toolbar>
</ion-footer>
</ion-app>
</body>
</html>
19 changes: 19 additions & 0 deletions static/usage/v7/toast/swipe-gesture/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Playground from '@site/src/components/global/Playground';

import javascript from './javascript.md';
import react from './react.md';
import vue from './vue.md';
import angular from './angular.md';

<Playground
version="7"
code={{
javascript,
react,
vue,
angular,
}}
src="usage/v7/toast/swipe-gesture/demo.html"
devicePreview={true}
includeIonContent={false}
/>
17 changes: 17 additions & 0 deletions static/usage/v7/toast/swipe-gesture/javascript.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
```html
<ion-content class="ion-padding">
<ion-button id="open-toast">Open Toast</ion-button>
<ion-toast
message="This toast can be swiped to dismiss"
trigger="open-toast"
swipe-gesture="vertical"
position="bottom"
position-anchor="footer"
></ion-toast>
</ion-content>
<ion-footer id="footer">
<ion-toolbar>
<ion-title>Footer</ion-title>
</ion-toolbar>
</ion-footer>
```
27 changes: 27 additions & 0 deletions static/usage/v7/toast/swipe-gesture/react.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
```tsx
import React from 'react';
import { IonButton, IonContent, IonFooter, IonTitle, IonToast, IonToolbar } from '@ionic/react';

function Example() {
return (
<>
<IonContent className="ion-padding">
<IonButton id="open-toast">Open Toast</IonButton>
<IonToast
message="This toast can be swiped to dismiss"
trigger="open-toast"
swipeGesture="vertical"
position="bottom"
positionAnchor="footer"
></IonToast>
</IonContent>
<IonFooter id="footer">
<IonToolbar>
<IonTitle>Footer</IonTitle>
</IonToolbar>
</IonFooter>
</>
);
}
export default Example;
```
35 changes: 35 additions & 0 deletions static/usage/v7/toast/swipe-gesture/vue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
```html
<template>
<ion-content class="ion-padding">
<ion-button id="open-toast">Open Toast</ion-button>
<ion-toast
message="This toast can be swiped to dismiss"
trigger="open-toast"
swipe-gesture="vertical"
position="bottom"
position-anchor="footer"
></ion-toast>
</ion-content>
<ion-footer id="footer">
<ion-toolbar>
<ion-title>Footer</ion-title>
</ion-toolbar>
</ion-footer>
</template>

<script lang="ts">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Examples look good, should we be using <script setup> on new playground examples so we don't need to migrate them later?

e.g.:

<template>
  <ion-content class="ion-padding">
    <ion-button id="open-toast">Open Toast</ion-button>
    <ion-toast
      message="This toast can be swiped to dismiss"
      trigger="open-toast"
      swipe-gesture="vertical"
      position="bottom"
      position-anchor="footer"
    ></ion-toast>
  </ion-content>
  <ion-footer id="footer">
    <ion-toolbar>
      <ion-title>Footer</ion-title>
    </ion-toolbar>
  </ion-footer>
</template>

<script setup lang="ts">
import {
  IonButton,
  IonContent,
  IonFooter,
  IonTitle,
  IonToast,
  IonToolbar,
} from '@ionic/vue';
</script>

https://stackblitz.com/edit/8hheka?file=src%2Fcomponents%2FExample.vue

Cuts down on a little of the boilerplate required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! cce5dc8

import { IonButton, IonContent, IonFooter, IonTitle, IonToast, IonToolbar } from '@ionic/vue';
import { defineComponent } from 'vue';

export default defineComponent({
components: {
IonButton,
IonContent,
IonFooter,
IonTitle,
IonToast,
IonToolbar,
},
});
</script>
```
Loading