Motion safe by default #12864
Replies: 2 comments
-
You could create a Tailwind plugin which is a copy of the the core tailwindcss/src/corePlugins.js Lines 993 to 1023 in 7361468 And add the |
Beta Was this translation helpful? Give feedback.
-
I think wrapping transition and animation related classes in the I implemented this plugin (using tw v3). Since I couldnt find a way to make tw not add the default non mq version I had to add non mq overrides that set them to If someone knows of a way to stop tw from adding the default non mq wrapped transition and animation classes, let me know. plugins: [
plugin(function ({ addUtilities, theme }) {
const config = theme('transitionDuration');
const transitions = theme('transitionProperty');
const animations = theme('animation');
const timingFunctions = theme('transitionTimingFunction');
const newUtilities = {};
const initialUtilities = {}; // To store the non-media query versions
const resetVal = 'initial';
Object.keys(transitions).forEach((key) => {
const cssKey =
key === 'DEFAULT' ? 'transitionProperty' : `transition-${key}`;
newUtilities[`.${cssKey}`] = {
'@media (prefers-reduced-motion: no-preference)': {
'transition-property': transitions[key],
'transition-timing-function': timingFunctions['DEFAULT'],
'transition-duration': config['DEFAULT'],
},
};
initialUtilities[`.${cssKey}`] = {
'transition-property': resetVal,
'transition-timing-function': resetVal,
'transition-duration': resetVal,
};
});
Object.keys(animations).forEach((key) => {
newUtilities[`.animate-${key}`] = {
'@media (prefers-reduced-motion: no-preference)': {
animation: animations[key],
},
};
initialUtilities[`.animate-${key}`] = {
animation: resetVal,
};
});
Object.keys(config).forEach((key) => {
const cssKey =
key === 'DEFAULT' ? 'transitionDuration' : `duration-${key}`;
newUtilities[`.${cssKey}`] = {
'@media (prefers-reduced-motion: no-preference)': {
'transition-duration': config[key],
},
};
initialUtilities[`.${cssKey}`] = {
'transition-duration': resetVal,
};
});
const defaultTimingFunction = timingFunctions['DEFAULT'];
newUtilities['.ease-default'] = {
'@media (prefers-reduced-motion: no-preference)': {
'transition-timing-function': defaultTimingFunction,
},
};
initialUtilities['.ease-default'] = {
'transition-timing-function': resetVal,
};
addUtilities(initialUtilities); // Add the non-media query versions with reset values
addUtilities(newUtilities, {
variants: ['responsive', 'hover', 'focus'],
});
})
] |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Is there a way to use
motion-safe
by default when using animations? i.e. by adding it to the theme?I'd prefer not to have to remember to add it every time I add an animation to an element.
Apologies if this is in the docs, I couldn't see any obvious answer from looking around.
Beta Was this translation helpful? Give feedback.
All reactions