almond-bongbong / react-slot-counter

🚀 Elevate Your UI with Dynamic, Eye-Catching Counters
https://almond-bongbong.github.io/react-slot-counter/
112 stars 12 forks source link

Added props to show a infinite list effect to the slot #3

Closed blzpedro closed 1 year ago

blzpedro commented 1 year ago

These changes have already worked for me.

E.g.: if you add some padding or increase the height from the char elements you wouldn't have the infinite dummy list effect. Adding the prop hasInfiniteList={true}, you will see the behavior correctly.

Feel free to change or improve!

Thanks

almond-bongbong commented 1 year ago

What do you think about defining the hasInfiniteList option as the default behavior instead of providing it as an option? In my opinion, this would be more useful in most cases.

blzpedro commented 1 year ago

I agree, and actually, I expected this as the default behavior when I got the package. 😂

But I think the changes that I made wouldn't work for all the cases that you provided.

E.g: the slots that are used with any separator.

blzpedro commented 1 year ago

I've thought of a solution for this edge case with values containing separators. We can avoid a if (SEPARATOR.includes(v)) and threat this directly into the dummyList prop. What do you think?

Note: this would change the previous behavior where you had a separatorClassName. Maybe you can improve this?

<Slot
    key={valueRefList.length - i - 1}
    fontHeight={fontHeight}
    numbersRef={numbersRef}
    active={active}
    isChanged={isChanged}
    charClassName={charClassName}
    slotNumbersHeight={slotNumbersHeight}
    effectiveDuration={effectiveDuration}
    delay={delay}
    value={v}
    dummyList={SEPARATOR.includes(v) ? dummyList.map(() => v) : dummyList}
    hasInfiniteList={hasInfiniteList}
/>
almond-bongbong commented 1 year ago

How about adding an "animateSeparator" option? 😆

blzpedro commented 1 year ago

Yeah, it can be, to improve this you can add the animateSeparator depending on the hasInfiniteList to avoid the following behavior: if you increase the height or add some paddingY to the chars(with the prop hasInfiniteList as true), the separator will not follow the centralized value.