From e24945d0683f34bbcd247e49d2ac0bd71f3c0136 Mon Sep 17 00:00:00 2001 From: Maria Hutt Date: Wed, 12 Jul 2023 10:45:49 -0700 Subject: [PATCH 1/6] docs(animations): add playground for preference based Co-authored-by: dillionmegida --- docs/utilities/animations.md | 97 +------------------ .../angular/example_component_css.md | 16 +++ .../angular/example_component_html.md | 9 ++ .../angular/example_component_ts.md | 41 ++++++++ .../v7/animations/preference-based/demo.html | 72 ++++++++++++++ .../v7/animations/preference-based/index.md | 35 +++++++ .../animations/preference-based/javascript.md | 35 +++++++ .../preference-based/react/main_css.md | 16 +++ .../preference-based/react/main_tsx.md | 53 ++++++++++ .../v7/animations/preference-based/vue.md | 68 +++++++++++++ 10 files changed, 348 insertions(+), 94 deletions(-) create mode 100644 static/usage/v7/animations/preference-based/angular/example_component_css.md create mode 100644 static/usage/v7/animations/preference-based/angular/example_component_html.md create mode 100644 static/usage/v7/animations/preference-based/angular/example_component_ts.md create mode 100644 static/usage/v7/animations/preference-based/demo.html create mode 100644 static/usage/v7/animations/preference-based/index.md create mode 100644 static/usage/v7/animations/preference-based/javascript.md create mode 100644 static/usage/v7/animations/preference-based/react/main_css.md create mode 100644 static/usage/v7/animations/preference-based/react/main_tsx.md create mode 100644 static/usage/v7/animations/preference-based/vue.md diff --git a/docs/utilities/animations.md b/docs/utilities/animations.md index 3ebcddb2835..31561f7777b 100644 --- a/docs/utilities/animations.md +++ b/docs/utilities/animations.md @@ -773,104 +773,13 @@ In this example we are creating a track along which we can drag the `.square` el Developers can also tailor their animations to user preferences such as `prefers-reduced-motion` and `prefers-color-scheme` using CSS Variables. -### Usage - -```css -.square { - width: 100px; - height: 100px; - opacity: 0.5; - background: blue; - margin: 10px; - - --background: red; -} - -@media (prefers-color-scheme: dark) { - .square { - --background: green; - } -} -``` - -````mdx-code-block - - - -```javascript -createAnimation() - .addElement(document.querySelector('.square')) - .duration(1500) - .iterations(Infinity) - .direction('alternate') - .fromTo('background', 'blue', 'var(--background)'); -``` - - - -```javascript -this.animationCtrl.create() - .addElement(this.square.nativeElement) - .duration(1500) - .iterations(Infinity) - .direction('alternate') - .fromTo('background', 'blue', 'var(--background)'); -``` - - - -```tsx - -
-
-``` -
- - -```javascript -import { createAnimation } from '@ionic/vue'; -import { ref } from 'vue'; - -... - -const squareRef = ref(); - -... - -createAnimation() - .addElement(squareRef.value) - .duration(1500) - .iterations(Infinity) - .direction('alternate') - .fromTo('background', 'blue', 'var(--background)'); -``` - -
-```` - This method works in all supported browsers when creating animations for the first time. Most browsers are also capable of dynamically updating keyframe animations as the CSS Variables change. Safari does not currently support dynamically updating keyframe animations. For developers who need this kind of support in Safari, they can use [MediaQueryList.addListener()](https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList/addListener). - +import PreferenceBased from '@site/static/usage/v7/animations/preference-based/index.md'; + + ## Overriding Ionic Component Animations diff --git a/static/usage/v7/animations/preference-based/angular/example_component_css.md b/static/usage/v7/animations/preference-based/angular/example_component_css.md new file mode 100644 index 00000000000..eb219f43513 --- /dev/null +++ b/static/usage/v7/animations/preference-based/angular/example_component_css.md @@ -0,0 +1,16 @@ +```css +ion-card { + color: white; + opacity: 0.5; + background: blue; + margin: 10px; + + --background: red; +} + +@media (prefers-color-scheme: dark) { + ion-card { + --background: green; + } +} +``` diff --git a/static/usage/v7/animations/preference-based/angular/example_component_html.md b/static/usage/v7/animations/preference-based/angular/example_component_html.md new file mode 100644 index 00000000000..3a27660393a --- /dev/null +++ b/static/usage/v7/animations/preference-based/angular/example_component_html.md @@ -0,0 +1,9 @@ +```html + + Card + + +Play +Pause +Stop +``` diff --git a/static/usage/v7/animations/preference-based/angular/example_component_ts.md b/static/usage/v7/animations/preference-based/angular/example_component_ts.md new file mode 100644 index 00000000000..c0e383d5ec0 --- /dev/null +++ b/static/usage/v7/animations/preference-based/angular/example_component_ts.md @@ -0,0 +1,41 @@ +```ts +import { Component, ElementRef, ViewChildren, ViewChild } from '@angular/core'; +import type { QueryList } from '@angular/core'; +import type { Animation } from '@ionic/angular'; +import { AnimationController, 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; + + private animation: Animation; + + constructor(private animationCtrl: AnimationController) {} + + ngAfterViewInit() { + this.animation = this.animationCtrl + .create() + .addElement(this.card.nativeElement) + .duration(1500) + .iterations(Infinity) + .direction('alternate') + .fromTo('background', 'blue', 'var(--background)'); + } + + play() { + this.animation.play(); + } + + pause() { + this.animation.pause(); + } + + stop() { + this.animation.stop(); + } +} +``` diff --git a/static/usage/v7/animations/preference-based/demo.html b/static/usage/v7/animations/preference-based/demo.html new file mode 100644 index 00000000000..3eb962c0c8c --- /dev/null +++ b/static/usage/v7/animations/preference-based/demo.html @@ -0,0 +1,72 @@ + + + + + + Animation + + + + + + + + + + +
+ + Card + + +
+ Play + Pause + Stop +
+
+ + diff --git a/static/usage/v7/animations/preference-based/index.md b/static/usage/v7/animations/preference-based/index.md new file mode 100644 index 00000000000..e4f2597a6df --- /dev/null +++ b/static/usage/v7/animations/preference-based/index.md @@ -0,0 +1,35 @@ +import Playground from '@site/src/components/global/Playground'; + +import javascript from './javascript.md'; + +import react_main_tsx from './react/main_tsx.md'; +import react_main_css from './react/main_css.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'; + + diff --git a/static/usage/v7/animations/preference-based/javascript.md b/static/usage/v7/animations/preference-based/javascript.md new file mode 100644 index 00000000000..6802f50726f --- /dev/null +++ b/static/usage/v7/animations/preference-based/javascript.md @@ -0,0 +1,35 @@ +```html + + Card + + +Play +Pause +Stop + + + + +``` diff --git a/static/usage/v7/animations/preference-based/react/main_css.md b/static/usage/v7/animations/preference-based/react/main_css.md new file mode 100644 index 00000000000..eb219f43513 --- /dev/null +++ b/static/usage/v7/animations/preference-based/react/main_css.md @@ -0,0 +1,16 @@ +```css +ion-card { + color: white; + opacity: 0.5; + background: blue; + margin: 10px; + + --background: red; +} + +@media (prefers-color-scheme: dark) { + ion-card { + --background: green; + } +} +``` diff --git a/static/usage/v7/animations/preference-based/react/main_tsx.md b/static/usage/v7/animations/preference-based/react/main_tsx.md new file mode 100644 index 00000000000..5586af54542 --- /dev/null +++ b/static/usage/v7/animations/preference-based/react/main_tsx.md @@ -0,0 +1,53 @@ +```tsx +import React, { useEffect, useRef } from 'react'; +import { IonButton, IonCard, IonCardContent, createAnimation } from '@ionic/react'; +import type { Animation } from '@ionic/react'; + +import './main.css'; + +function Example() { + const cardEl = useRef(null); + + const animation = useRef(null); + + useEffect(() => { + if (animation.current === null) { + animation.current = createAnimation() + .addElement(cardEl.current!) + .duration(1500) + .iterations(Infinity) + .direction('alternate') + .fromTo('background', 'blue', 'var(--background)'); + } + }, [cardEl]); + + const play = () => { + animation.current?.play(); + }; + const pause = () => { + animation.current?.pause(); + }; + const stop = () => { + animation.current?.stop(); + }; + + return ( + <> + + Card + + + + Play + + + Pause + + + Stop + + + ); +} +export default Example; +``` diff --git a/static/usage/v7/animations/preference-based/vue.md b/static/usage/v7/animations/preference-based/vue.md new file mode 100644 index 00000000000..de6857565aa --- /dev/null +++ b/static/usage/v7/animations/preference-based/vue.md @@ -0,0 +1,68 @@ +```html + + + + + +``` From c244db2d7c07f636455845b8843e0e5ca643fb21 Mon Sep 17 00:00:00 2001 From: Maria Hutt Date: Wed, 12 Jul 2023 12:19:04 -0700 Subject: [PATCH 2/6] docs(animations): removed unused ids --- .../preference-based/angular/example_component_html.md | 6 +++--- static/usage/v7/animations/preference-based/javascript.md | 6 +++--- .../usage/v7/animations/preference-based/react/main_tsx.md | 6 +++--- static/usage/v7/animations/preference-based/vue.md | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/static/usage/v7/animations/preference-based/angular/example_component_html.md b/static/usage/v7/animations/preference-based/angular/example_component_html.md index 3a27660393a..1bd8875b1b3 100644 --- a/static/usage/v7/animations/preference-based/angular/example_component_html.md +++ b/static/usage/v7/animations/preference-based/angular/example_component_html.md @@ -3,7 +3,7 @@ Card -Play -Pause -Stop +Play +Pause +Stop ``` diff --git a/static/usage/v7/animations/preference-based/javascript.md b/static/usage/v7/animations/preference-based/javascript.md index 6802f50726f..8ad151afcf7 100644 --- a/static/usage/v7/animations/preference-based/javascript.md +++ b/static/usage/v7/animations/preference-based/javascript.md @@ -3,9 +3,9 @@ Card -Play -Pause -Stop +Play +Pause +Stop