So i made a carousel that show cards of 3 cards subscription. How to move selected card to the middle of the screen automatically. And if i the select card the first or the third, it will show just fully and no need to be in the middle?
Currently if I click the 6-month subs card, it got selected but not fully show up. I want to make it smoothly move to the left so it the card shows up fully like the second picture. I tried the translateX() on CSS but it didn’t make my second selected card straight in the middle.
I’m not sure how to implement this? Please help. Thank you!


import React, {useState} from 'react';
import {default as style} from './SubscriptionCard.scss.json';
import './SubscriptionCard.scss';
import {cl} from 'lincd/lib/utils/ClassNames';
interface SubscriptionCardProps {
review?: string;
month: number;
monthlyPrice: number;
totalPrice: number;
discount?: number;
isSelected: boolean;
onSelect?;
}
const SubscriptionCard = ({
review,
month,
monthlyPrice,
totalPrice,
discount,
isSelected,
onSelect,
}: SubscriptionCardProps) => {
return (
<div
className={cl(style.card, isSelected && style.selected)}
onClick={onSelect}
>
{isSelected && (
<img
className={style.checkmark}
src="images/checkmark_gold.svg"
alt="icon"
/>
)}
{review && <p className={style.review}>{review}</p>}
<div className={style.text}>
<p className={style.priceTitle}>{month} Month</p>
<div className={style.priceContainer}>
<p className={style.monthlyPrice}>${monthlyPrice}/mo</p>
<p className={style.totalPrice}>${totalPrice} total</p>
</div>
{discount && <p className={style.discount}>Save {discount}%</p>}
</div>
</div>
);
};
export default SubscriptionCard;
import CircularProgress from '@mui/material/CircularProgress';
import './UpgradeAccountAction.scss';
import {default as style} from './UpgradeAccountAction.scss.json';
import ActionSheet from './ui/forms/ActionSheet';
import {Button} from './ui/forms/Button';
import {Typography} from './ui/forms/Typography';
import {Server} from 'lincd-server-utils/lib/utils/Server';
import {packageName} from '../package';
import useState from 'react-usestateref';
import {useAuth} from 'lincd-auth/lib/hooks/useAuth';
import {FeatureCounter} from 'lincd-dating/lib/shapes/FeatureCounter';
import {on} from 'events';
import SubscriptionCard from './SubscriptionCard';
import Divider from './Divider';
const SUBSCRIPTION_DATA = [
{
id: 0,
month: 1,
monthlyPrice: 24.99,
totalPrice: 24.99,
},
{
id: 1,
month: 6,
monthlyPrice: 12.5,
totalPrice: 74.99,
discount: 50,
review: 'Popular',
},
{
id: 2,
month: 12,
monthlyPrice: 8.33,
totalPrice: 99.99,
discount: 67,
review: 'Best value',
},
];
interface UpgradeAccountActionProps {
isOpen: boolean;
onUpgraded: () => Promise<boolean>;
onClose: () => void;
}
export const UpgradeAccountAction = ({
isOpen,
onClose,
onUpgraded,
}: UpgradeAccountActionProps) => {
const defaultSelectedCard = SUBSCRIPTION_DATA[0];
const [selectedCard, setSelectedCard] = useState(defaultSelectedCard);
const auth = useAuth();
console.log('selectedCard', selectedCard);
return (
<ActionSheet isOpen={isOpen} onClose={onClose}>
<div className={style.pageContainer}>
<div className={style.header}>
<div className={style.iconContainer}>
<img src="images/sp-premium.svg" alt="sp premium icon" />
</div>
<h1>Spiritual Premium</h1>
</div>
<div className={style.contentContainer}>
<h2>
See Who Lies You and match with them instantly with Spiritual
Premium™️.
</h2>
<div className={style.carouselContainer}>
<p>Select a plan</p>
<div className={style.cardCarousel}>
{SUBSCRIPTION_DATA.map((data, i) => {
return (
<SubscriptionCard
isSelected={selectedCard.id === i}
onSelect={() => setSelectedCard(SUBSCRIPTION_DATA[i])}
month={data.month}
monthlyPrice={data.monthlyPrice}
totalPrice={data.totalPrice}
discount={data.discount}
review={data.review}
/>
);
})}
</div>
</div>
<Divider text="or" />
<div className={style.benefits}>
<h6>Included with Spiritual Premium™️</h6>
<ul>
<li>Unlimited Likes</li>
<li>See Who Likes You</li>
<li>1 Free Boost per month</li>
<li>5 Free Quantum Likes per week</li>
<li>
<p>Passport</p>
<p>Match and chat with people anywhere in the world.</p>
</li>
<li>
<p>Top Picks</p>
<p>Browse through a daily curated selection of profile.</p>
</li>
<li>
<p>Control Your Profile </p>
<p>Only show what you want them to know.</p>
</li>
<li>
<p>Control Who Sees You</p>
<p>Manage who you’re seen by.</p>
</li>
<li>
<p>Control Who You See</p>
<p>Choose the type of people you want to connect with.</p>
</li>
<li>Hide Ads</li>
</ul>
</div>
</div>
<footer className={style.footer}>
<div className={style.footerWrapper}>
<p className={style.footerWrapper__top}>
By tapping Continue, you will be charged, your subscription will
auto-renew for the same price and package length until you cancel
via App Store settings, and you agree to our <a href="#">Terms</a>
.
</p>
{/* fullwidth */}
{/* <Button fullWidth={true} className={style.continueBtn}>
Continue
</Button> */}
<div className={style.footerWrapper__bottom}>
<div className={style.footerWrapper__left}>
<img src="images/sp-premium.svg" alt="sp premium icon" />
<div className={style.text}>
<p>{selectedCard.month} Month</p>
<p>${selectedCard.totalPrice} total</p>
</div>
</div>
<Button
className={style.footerWrapper__right}
onClick={onUpgraded}
>
Continue
</Button>
</div>
</div>
</footer>
</div>
</ActionSheet>
);
};