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

feat: add reducedMotion setting to Provider #3470

Merged
merged 5 commits into from
Nov 17, 2024
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
5 changes: 5 additions & 0 deletions .changeset/pretty-parrots-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nextui-org/system": minor
jrgarciadev marked this conversation as resolved.
Show resolved Hide resolved
---

Add reducedMotion setting to Provider (#3395)
21 changes: 15 additions & 6 deletions apps/docs/content/docs/api-references/nextui-provider.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ interface AppProviderProps {
import {GregorianCalendar} from '@internationalized/date';

function createCalendar(identifier) {
switch (identifier) {
case 'gregory':
return new GregorianCalendar();
default:
throw new Error(`Unsupported calendar ${identifier}`);
}
switch (identifier) {
case 'gregory':
return new GregorianCalendar();
default:
throw new Error(`Unsupported calendar ${identifier}`);
}
}
```

Expand Down Expand Up @@ -167,6 +167,15 @@ or mark the field as required or invalid via ARIA.
- **Type**: `native | aria`
- **Default**: `aria`

`reducedMotion`

- **Description**: Controls the motion preferences for the entire application, allowing developers to respect user settings for reduced motion.
The available options are:
- `"user"`: Adapts to the user's device settings for reduced motion.
- `"always"`: Disables all animations.
- `"never"`: Keeps all animations active.
- **Type**: `"user" | "always" | "never"`
- **Default**: `"never"`
---

## Types
Expand Down
36 changes: 36 additions & 0 deletions packages/components/calendar/stories/calendar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {I18nProvider, useLocale} from "@react-aria/i18n";
import {Button, ButtonGroup} from "@nextui-org/button";
import {Radio, RadioGroup} from "@nextui-org/radio";
import {cn} from "@nextui-org/theme";
import {NextUIProvider, NextUIProviderProps} from "@nextui-org/system";

import {Calendar, CalendarProps, DateValue} from "../src";

Expand All @@ -38,6 +39,11 @@ export default {
},
options: ["narrow", "short", "long"],
},
disableAnimation: {
control: {
type: "boolean",
},
},
},
} as Meta<typeof Calendar>;

Expand Down Expand Up @@ -257,6 +263,30 @@ const CalendarWidthTemplate = (args: CalendarProps) => {
);
};

const ReducedMotionTemplate = (args: CalendarProps) => {
const [reducedMotion, setReducedMotion] =
React.useState<NextUIProviderProps["reducedMotion"]>("never");

return (
<NextUIProvider reducedMotion={reducedMotion}>
<RadioGroup
className="mb-4"
defaultValue={reducedMotion}
label="Reduced motion"
orientation="horizontal"
onValueChange={(value) => {
setReducedMotion(value as NextUIProviderProps["reducedMotion"]);
}}
>
<Radio value="user">user</Radio>
<Radio value="always">always</Radio>
<Radio value="never">never</Radio>
</RadioGroup>
<Calendar {...args} />
</NextUIProvider>
);
};

export const Default = {
render: Template,
args: {
Expand Down Expand Up @@ -375,3 +405,9 @@ export const CalendarWidth = {
...defaultProps,
},
};
export const ReducedMotion = {
render: ReducedMotionTemplate,
args: {
...defaultProps,
},
};
15 changes: 12 additions & 3 deletions packages/core/system/src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {I18nProvider, I18nProviderProps} from "@react-aria/i18n";
import {RouterProvider} from "@react-aria/utils";
import {OverlayProvider} from "@react-aria/overlays";
import {useMemo} from "react";
import {MotionGlobalConfig} from "framer-motion";
import {MotionConfig, MotionGlobalConfig} from "framer-motion";

import {ProviderContext} from "./provider-context";

Expand All @@ -21,6 +21,12 @@ export interface NextUIProviderProps
* animations in NextUI Components are still omitted if the `disableAnimation` prop is `true`.
*/
skipFramerMotionAnimations?: boolean;
/**
* Defines a new default transition for the entire tree.
* @default "never"
* See: https://www.framer.com/motion/motion-config/#props
*/
reducedMotion?: "user" | "always" | "never";
/**
* The locale to apply to the children.
* @default "en-US"
Expand All @@ -36,9 +42,10 @@ export interface NextUIProviderProps
export const NextUIProvider: React.FC<NextUIProviderProps> = ({
children,
navigate,
disableAnimation = false,
disableAnimation,
disableRipple = false,
skipFramerMotionAnimations = disableAnimation,
reducedMotion = "never",
validationBehavior = "aria",
locale = "en-US",
// if minDate / maxDate are not specified in `defaultDates`
Expand Down Expand Up @@ -77,7 +84,9 @@ export const NextUIProvider: React.FC<NextUIProviderProps> = ({
return (
<ProviderContext value={context}>
<I18nProvider locale={locale}>
<OverlayProvider {...otherProps}>{contents}</OverlayProvider>
<MotionConfig reducedMotion={reducedMotion}>
<OverlayProvider {...otherProps}>{contents}</OverlayProvider>
</MotionConfig>
</I18nProvider>
</ProviderContext>
);
Expand Down