Displaying only a specific amount of content
Answered
ihyd posted this in #help-forum
ihydOP
Let's say I have an example of a few cards that are associated with an account, like this:
I want to display let's say only 3 at the same time, and have a left arrow and right arrow that lets me cycle between them, how would I go about implementing this? I'm thinking of using something like mapping:
but I don't know if that would work for this, any ideas?
function getCards() {
return {
main: {
amount: "2,500,727.69"
},
loyalty: {
amount: "727"
},
usd: {
amount: "100,000"
},
euro: {
amount: "100,000"
},
secondary: {
amount: "100,000"
}
}
}I want to display let's say only 3 at the same time, and have a left arrow and right arrow that lets me cycle between them, how would I go about implementing this? I'm thinking of using something like mapping:
<section className="flex flex-row p-4 gap-4 border-b-2 w-[70%] overflow-scroll rounded">
<button className="text-black material-symbols-outlined text-[30px]">arrow_back</button>
{Cards.map((card, index) => (
<MainCard key={index} amount={card.main.amount} />))}
<button className="text-black material-symbols-outlined text-[30px]">arrow_forward</button>
</section>
but I don't know if that would work for this, any ideas?
13 Replies
ihydOP
I already have a Main Card element and loyalty card element which should be in position 1 and 2
but everything else should appear after, if it exists, and then cycle between them smoothly
ihydOP
for the sake of this, consider there's an element called Card that has an amount and currency prop
@ihyd Let's say I have an example of a few cards that are associated with an account, like this:
js
function getCards() {
return {
main: {
amount: "2,500,727.69"
},
loyalty: {
amount: "727"
},
usd: {
amount: "100,000"
},
euro: {
amount: "100,000"
},
secondary: {
amount: "100,000"
}
}
}
I want to display let's say only 3 at the same time, and have a left arrow and right arrow that lets me cycle between them, how would I go about implementing this? I'm thinking of using something like mapping:
js
<section className="flex flex-row p-4 gap-4 border-b-2 w-[70%] overflow-scroll rounded">
<button className="text-black material-symbols-outlined text-[30px]">arrow_back</button>
{Cards.map((card, index) => (
<MainCard key={index} amount={card.main.amount} />))}
<button className="text-black material-symbols-outlined text-[30px]">arrow_forward</button>
</section>
but I don't know if that would work for this, any ideas?
You are probably looking to build a carousel. Try https://ui.shadcn.com/docs/components/carousel. I haven’t had the need to build a carousel before so I can’t offer more support than this
ihydOP
fair enough haha thank you very much i'll look into it ^^
i never really understood shadcn but i guess now's the time
Not exactly necessary to use shadcn, can use any carousel-related libraries or code that you can find
The keyword is “carousel†and just search for it, there are tons of results
@joulev The keyword is “carousel†and just search for it, there are tons of results
ihydOP
I understand carousels and I did look around but none of them seemed to fit what I needed, but shadcn seems perfect
ihydOP
i'll try to work with that
Answer
ihydOP
works almost perfectly.. very wonky but, it does the job
thank you :)