In the current carousel, there are arrow buttons that allow navigation to the previous and next pages. I will move these arrow buttons to the navigation bar. It seems better for the navigation bar below to be responsible for all carousel movements.
However, the existing carousel navigation component already handles navigation to the page corresponding to each navigation item when clicked. This means it already has the functionality to control the carousel pages, as confirmed by the props carouselIndex and setCarouselIndex.
Therefore, there is no need to change any props. All that needs to be done is to move the existing prevClick and nextClick functions, along with the buttons that triggered those functions on click events, to the carousel navigation component.
The modified CarouselNavigation component now appears as follows:
Let’s move the determineCarouselItemState function outside the component as well. The function will be modified and moved outside the component, adjusting its arguments appropriately when used in the CarouselNavigationItem component.
Next, we will remove the prevClick and nextClick functions as well as the arrow buttons that triggered these functions from the carousel component. When rendering the carousel now, the arrow buttons will be integrated into the navigation bar and the page transition functionality will also work seamlessly.
2. Carousel Navigation Design Renewal
2.1 Navigation Bar Design
The current navigation bar looks quite unattractive. Therefore, I plan to renew it as much as possible, referring to the carousel design on the MapleStory main page.
First, I will include the navigation bar inside the carousel. Since the current carousel page components are managed with absolute positioning, they do not take up space within the layout, so we can think of just placing the navigation bar.
Thus, we will introduce the CarouselNavigation component inside the div element wrapping the carousel and add the items-center class to position it at the bottom. The structure of the carousel component will look as follows:
Next, we will change the color of the carousel navigation bar and add opacity so that the images displayed in the carousel slightly show beyond the navigation bar. This will help indicate that the navigation bar is part of the carousel. Consequently, the color of the arrows will also be modified, and the height of the navigation bar will be set to be relative to the height of the carousel. Additionally, we will set the z-index to prevent the carousel images from obscuring the navigation bar.
The dl tag will have the classes h-[10%] bg-gray-400/70 z-20, and the color of the arrow buttons will be set to the text-gray-300 class. The completed navigation bar component is as follows:
2.2 CarouselNavigationItem Design
Next, I will design each item in the navigation. First, I will remove the unattractive borders from all navigation items and position them appropriately with proper spacing within the navigation bar. Additionally, for the active item, I will make the image brighter and add a green border to emphasize it. The text color will also be modified.
The updated CarouselNavigationItem component will look like this:
Now, we can observe a better appearance of the carousel navigation.
2.3 Mobile View Adjustment
However, there is still an issue with the navigation bar. The view varies too much depending on the screen size. For example, on larger screens, the navigation appears less attractive.
While I can overlook the issues that arise on large screens, the most significant problem is with mobile screens. The navigation bar is too small to properly view the items.
This was resolved in a simple but less sophisticated way by preventing the images from being displayed in the navigation bar on mobile screens. Tailwind provides an easy way to implement responsive design, which allowed for a straightforward solution.
In the CarouselNavigationItem, I set the dt tag containing the images to be hidden by default (equivalent to display: none) and configured it to be visible only when the screen width is 768px or more. Here is the relevant code, with changes only appearing in the dt tag.
With this change, images will no longer be visible in the navigation bar on mobile screens. Although it may appear less attractive, it is better than having text overflow beyond the navigation bar.
3. Display Page Numbers on the Navigation Bar
This can be easily implemented since the carousel navigation receives the current index and total items as props. Positioning can be handled using absolute positioning, and the rest of the design can match the style and size of the navigation bar items.
The following button can be added inside the dl tag of the CarouselNavigation component.
This will display the page number as follows.
4. Automatic Transition Every Few Seconds
This can be easily achieved using the setInterval function. By setting an interval in the useEffect of the carousel component, the carousel can automatically transition to the next index at set intervals.
The following code should be added to the Carousel component. This will transition the carousel screen every 3 seconds.