Skip to content

Commit ecec524

Browse files
edonehoojenny-s51
andauthored
docs(motion): Updates dev guide with animationsprovider details. (#4801)
* docs(motion): Updates dev guide with animationsprovider details. * Update packages/documentation-site/patternfly-docs/content/design-guidelines/styles/motion/motion-development.md Co-authored-by: Jenny <32821331+jenny-s51@users.noreply.github.com> --------- Co-authored-by: Jenny <32821331+jenny-s51@users.noreply.github.com>
1 parent e82225d commit ecec524

File tree

1 file changed

+89
-30
lines changed

1 file changed

+89
-30
lines changed

packages/documentation-site/patternfly-docs/content/design-guidelines/styles/motion/motion-development.md

Lines changed: 89 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,113 @@ section: design-foundations
44
source: development-guide
55
---
66

7-
## Opt-in animations
7+
## Enabling opt-in animations
88

9-
We try to support animations by default in our components, but&mdash;to avoid introducing breaking changes&mdash;some animations require you to manually opt in. In order to function properly, opt-in animations require additional updates to your codebase. Depending on how your testing is set up, opt-in animation could cause test failures, so you must manually configure them appropriately.
9+
We try to support animations by default in our components, but&mdash;to avoid introducing breaking changes&mdash;some animations require you to manually opt in. Opt-in animations require additional updates to your codebase and, depending on your testing setup, could cause test failures if not configured appropriately.
1010

11-
**Note:** In some edge cases, resource-intensive pages can cause browser memory issues where animations will fail to run correctly. For example, animated spinners are particularly memory intensive, so adding multiple spinners to a page might consume too much memory and disable all animations.
11+
The following components contain opt-in animations, with links to examples for proper implementation:
1212

13-
The following components contain opt-in animations. To understand the opt-in implementation, view the linked example code.
13+
- [Alert (within alert groups)](/components/alert/#dynamic-alert-groups)
14+
- [Dual list selector (with tree)](/components/dual-list-selector#with-tree)
15+
- [Form field groups](/components/forms/form/#field-groups)
16+
- [Navigation (expandable)](/components/navigation#expandable)
17+
- [Notification badge](/components/notification-badge/#with-animation)
18+
- [Search input (expandable)](/components/search-input#with-expandable-button)
19+
- [Table (expandable)](/components/table/#expandable) (in beta)
20+
- [Table (compound expandable)](/components/table/#compound-expandable) (in beta)
21+
- [Tabs (HTML-only implementations)](/components/tabs#animate-current-tab-accent)
22+
- [Tree view (all examples)](/components/tree-view/)
1423

15-
- Alert (within alert groups): [Example](/components/alert/#dynamic-alert-groups)
16-
- Dual list selector (with tree): [Example](/components/dual-list-selector#with-tree)
17-
- Form field groups: [Example](/components/forms/form/#field-groups)
18-
- Navigation (expandable): [Example](/components/navigation#expandable)
19-
- Notification badge: [Example](/components/notification-badge/#with-animation)
20-
- Search input (expandable): [Example](/components/search-input#with-expandable-button)
21-
- Table (expandable): [Example](/components/table/#expandable) (in beta)
22-
- Table (compound expandable): [Example](/components/table/#compound-expandable) (in beta)
23-
- Tabs (HTML-only implementations): [Example](/components/tabs#animate-current-tab-accent)
24-
- Tree view: [Example](/components/tree-view/) (all examples)
24+
**Note:** In some edge cases, resource-intensive pages can cause browser memory issues where animations fail to run correctly. For example, animated spinners are particularly memory intensive, so a page with multiple spinners might consume too much memory and disable all animations.
2525

26-
### enable-animations codemod
26+
### Bulk-enabling animations
2727

28-
We have also created an [enable-animations codemod](https://github.com/patternfly/pf-codemods/tree/main/packages/eslint-plugin-pf-codemods/src/rules/v6/enableAnimations), which adds the `hasAnimations` prop to components that require opt-in animations.
28+
We offer the [enable-animations codemod](https://github.com/patternfly/pf-codemods/tree/main/packages/eslint-plugin-pf-codemods/src/rules/v6/enableAnimations) that automatically adds the `hasAnimations` prop to components that require opt-in.
2929

30-
Keep in mind that, depending on your codebase, this codemod could introduce breaking changes that require further attention. In particular, when you run the codemod you will be asked whether you want to opt into animations for table components, or just for the react-core package.
30+
Be aware that, depending on your codebase, this codemod could introduce breaking changes that require further attention. When you run the codemod you will be asked whether to opt into animations only for the [@patternfly/react-core](https://www.npmjs.com/package/@patternfly/react-core) package or for [@patternfly/react-table](https://www.npmjs.com/package/@patternfly/react-table) as well.
3131

32-
To enable the optional animations run the following command:
32+
To enable opt-in animations run the following command:
3333

3434
`npx @patternfly/pf-codemods --only enable-animations /path-to-src`
3535

36+
### Global animation control
37+
38+
The `AnimationsProvider` is a React context provider that gives you global control over animation behavior in your application. Using it allows you to centrally manage animations across all PatternFly components in your codebase, making it easy to disable them for users who prefer reduced motion or to optimize performance.
39+
40+
#### Recommended setup and usage
41+
42+
Place the `AnimationsProvider` at the root of your application to provide global animation configuration for all PatternFly components, either passing in `hasAnimations: true` or `hasAnimations: false`:
43+
44+
```tsx
45+
// App.tsx or index.tsx
46+
import React from 'react';
47+
import { AnimationsProvider } from '@patternfly/react-core';
48+
import { MyApplication } from './MyApplication';
49+
50+
const App: React.FunctionComponent = () => {
51+
return (
52+
<AnimationsProvider config={{ hasAnimations: true }}>
53+
<MyApplication />
54+
</AnimationsProvider>
55+
);
56+
};
57+
58+
export default App;
59+
```
60+
61+
#### Component overrides
62+
63+
When using the `AnimationsProvider`, you can still pass `hasAnimations` directly to a component to override the global setting of `true` or `false`. For example: `<AlertGroup isToast hasAnimations={false}>` will override a global setting of `true`.
64+
65+
You can also wrap components with the `AnimationsProvider` and control animations there:
66+
67+
```tsx
68+
<AnimationsProvider config={{ hasAnimations: false }}>
69+
<AlertGroup isToast>
70+
{criticalAlerts.map(alert => (
71+
<Alert key={alert.id} title={alert.title} variant={alert.variant} />
72+
))}
73+
</AlertGroup>
74+
</AnimationsProvider>
75+
```
76+
77+
#### Conditional animations
78+
79+
You can enable animations conditionally, based on user preferences or system settings:
80+
81+
```tsx
82+
// App.tsx - Respect user's motion preferences
83+
import React from 'react';
84+
import { AnimationsProvider } from '@patternfly/react-core';
85+
import { MyApplication } from './MyApplication';
86+
87+
const App: React.FunctionComponent = () => {
88+
// Respect user's reduced motion preference
89+
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
90+
91+
return (
92+
<AnimationsProvider config={{ hasAnimations: !prefersReducedMotion }}>
93+
<MyApplication />
94+
</AnimationsProvider>
95+
);
96+
};
97+
```
98+
3699
## Custom motion
37100

38-
For some scenarios, like creating a new [PatternFly extension](/extensions/about-extensions), you may need to implement custom motion behavior that doesn't already exist in PatternFly components. When you're creating a new animation, make sure that:
101+
For some scenarios, like creating a new [PatternFly extension](/extensions/about-extensions), you might need to implement custom motion behavior. When creating a new animation, ensure the following:
39102
- There is no existing support for the animation.
40-
- The animation adheres to our motion principles and respects users' [`prefers-reduced-motion` settings.](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion)
103+
- The animation adheres to our motion principles and respects [`prefers-reduced-motion` settings.](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion)
41104
- Your implementation uses appropriate semantic motion tokens, as detailed in the following section.
42105

43106
## Motion tokens
44107

45-
PatternFly component animations are created using design tokens that cover the different elements of an animation, including duration, delay, and timing. Like we do with color tokens, we implement motion by using semantic tokens, which are built off of base tokens. Motion tokens begin with `--pf-t--global--motion--`
108+
PatternFly component animations are created using design tokens that specify duration, delay, and timing. We implement motion by using semantic tokens, which are built off of base tokens. Semantic motion tokens begin with `--pf-t--global--motion--`
46109

47-
You can [search for motion tokens here.](/tokens/all-patternfly-tokens)
48-
49-
If you aren't familiar with our token system, [refer to this overview](/tokens/about-tokens).
110+
When implementing custom motion, you should [familiarize yourself with our token system](/tokens/about-tokens) and [use the motion tokens outlined in our documentation.](/tokens/all-patternfly-tokens)
50111

51112
### Duration
52-
Duration tokens specify the length of time that different animation should take to complete. There are predefined duration tokens based on the type of animation, shown in the following table;
113+
Duration tokens specify the length of time that different animation should take to complete. We offer predefined duration tokens based on each type of animation.
53114

54115
| **Animation** | **Description** | **Tokens** |
55116
| --- | --- | --- |
@@ -60,7 +121,7 @@ Duration tokens specify the length of time that different animation should take
60121
<br />
61122

62123
### Delay
63-
Delay tokens specify the length of time that should pass before an animation begins. Delay options include none, short, default, and long.
124+
Delay tokens specify the length of time that should pass before an animation begins, including "none", "short", "default", and "long".
64125

65126
| **Token** | **Value** |
66127
| --- | --- |
@@ -71,9 +132,7 @@ Delay tokens specify the length of time that should pass before an animation beg
71132
<br />
72133

73134
### Timing
74-
Timing-function tokens specify the easing path that an animation takes. These paths are defined by [cubic Bezier curves,](https://developer.mozilla.org/en-US/docs/Web/CSS/easing-function#cubic_b%C3%A9zier_easing_function) which define the start and end points of a curve, as well as its initial and final times and states.
75-
76-
The available options for timing are described in the following table:
135+
Timing tokens specify the easing path that an animation takes, defined as [cubic Bezier curves,](https://developer.mozilla.org/en-US/docs/Web/CSS/easing-function#cubic_b%C3%A9zier_easing_function) that indicate the start and end points of a curve, as well as the initial and final times and states.
77136

78137
| **Timing function** | **Description** | **Token** | **Value** |
79138
| --- | --- | --- | --- |
@@ -83,7 +142,7 @@ The available options for timing are described in the following table:
83142

84143
## Testing reduced motion
85144

86-
You can manually test for reduced motion in 2 primary ways:
145+
You can manually test for reduced motion in 2 ways:
87146

88147
1. In your browser:
89148
- [Chrome](https://developer.chrome.com/docs/devtools/rendering/emulate-css#emulate_css_media_feature_prefers-reduced-motion)

0 commit comments

Comments
 (0)