mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 03:34:40 +00:00
improved interface tab transitions
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import React, { useState, useRef, useEffect } from 'react';
|
import React, { useState, useRef, useEffect } from 'react';
|
||||||
import { motion } from 'framer-motion';
|
import { motion, AnimatePresence } from 'framer-motion';
|
||||||
import type { TabbedContainerProps } from '../types/TabbedContainerProps';
|
import type { TabbedContainerProps } from '../types/TabbedContainerProps';
|
||||||
import { useSettingsContext } from '../SettingsContext';
|
import { useSettingsContext } from '../SettingsContext';
|
||||||
|
|
||||||
@@ -21,6 +21,13 @@ const TabbedContainer: React.FC<TabbedContainerProps> = ({ tabs }) => {
|
|||||||
|
|
||||||
const springTransition = { type: 'spring', stiffness: 250, damping: 25 };
|
const springTransition = { type: 'spring', stiffness: 250, damping: 25 };
|
||||||
|
|
||||||
|
const contentVariants = {
|
||||||
|
hidden: { opacity: 0 },
|
||||||
|
visible: { opacity: 1 },
|
||||||
|
};
|
||||||
|
|
||||||
|
const fastOpacityTransition = { duration: 0.2 };
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (containerRef.current) {
|
if (containerRef.current) {
|
||||||
// @ts-expect-error for some reason its giving an error in TS but it works...
|
// @ts-expect-error for some reason its giving an error in TS but it works...
|
||||||
@@ -61,23 +68,32 @@ const TabbedContainer: React.FC<TabbedContainerProps> = ({ tabs }) => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="h-full px-4 overflow-y-scroll overflow-x-clip">
|
<div className="h-full px-4 overflow-y-scroll overflow-x-clip">
|
||||||
<motion.div
|
<motion.div
|
||||||
initial={false}
|
initial={false}
|
||||||
animate={{ x: `${position}%` }}
|
animate={{ x: `${position}%` }}
|
||||||
transition={springTransition}
|
transition={springTransition}
|
||||||
>
|
>
|
||||||
<div className="absolute flex w-full" style={{ left: `${-position}%` }}>
|
<div className="absolute flex w-full" style={{ left: `${-position}%` }}>
|
||||||
{tabs.map((tab, index) => (
|
<AnimatePresence>
|
||||||
<div
|
{tabs.map((tab, index) => (
|
||||||
key={index}
|
activeTab === index && (
|
||||||
className={`w-full ${activeTab === index ? '' : 'hidden'}`}
|
<motion.div
|
||||||
>
|
key={index}
|
||||||
{tab.content}
|
className="absolute w-full"
|
||||||
</div>
|
initial="hidden"
|
||||||
))}
|
animate="visible"
|
||||||
</div>
|
exit="hidden"
|
||||||
</motion.div>
|
transition={fastOpacityTransition}
|
||||||
</div>
|
variants={contentVariants}
|
||||||
|
>
|
||||||
|
{tab.content}
|
||||||
|
</motion.div>
|
||||||
|
)
|
||||||
|
))}
|
||||||
|
</AnimatePresence>
|
||||||
|
</div>
|
||||||
|
</motion.div>
|
||||||
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user