Transforming the indicator of the React responsive carousel to full-width rectangles

I am working on customizing the indicators to appear rectangular and cover the full width based on the length of the images, similar to this example:

https://i.sstatic.net/j4yov.png

However, I am currently facing an issue where the divs are always displayed as columns instead of side by side:

import 'react-responsive-carousel/lib/styles/carousel.min.css'
import { Carousel } from 'react-responsive-carousel'

<Carousel
          className="flex relative w-full h-[328px]  overflow-hidden bg-black mb-[17px]"
          showArrows={false}
          showThumbs={false}
          showStatus={false}
          autoPlay
          infiniteLoop
          renderIndicator={(_, selected, indIndex) => {
            console.log('called')
            return (
              <div className="flex flex-row gap-2">
                <div
                  className="w-[100px] h-[2px]"
                  style={{
                    background: selected ? 'red' : 'blue',
                  }}
                ></div>
              </div>
            )
          }}
        >
          {images.map((URL, index) => (
            <div className="object-cover h-full w-full">
              <img src={URL} key={index} />
            </div>
          ))}
        </Carousel>

In the image provided, there are 3 divs - the red one represents the selected indicator, while the blue ones represent the unselected indicators.

https://i.sstatic.net/PuT0b.png

Answer №1

Here is the response:

 <Gallery
          className="flex relative w-full h-[328px]  overflow-hidden bg-black mb-[17px]"
          showArrows={false}
          showThumbs={false}
          showStatus={false}
          autoPlay
          infiniteLoop
          renderIndicator={(_, selected, index) => {
            const numIndicators = pictures.length
            const margin = '5px'
            const indicatorWidth = `calc((100% - ${margin} * ${numIndicators - 1}) / ${numIndicators})`

            return (
              <div
                className="inline-block"
                style={{
                  width: indicatorWidth,
                  height: '5px',
                  background: selected ? 'white' : 'grey',
                  marginRight: index !== numIndicators - 1 ? margin : '0',
                }}
              />
            )
          }}
        >
          {pictures.map((picURL, index) => (
            <div className="object-cover h-full w-full">
              <img src={picURL} key={index} />
            </div>
          ))}
        </Gallery>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Mobile devices are experiencing an issue with extra white space appearing on the right side of websites

Having trouble with my website's mobile view... The issue is that on every mobile device, the site looks exactly like it does on desktop (which is good), but I can't seem to debug and find the CSS error causing a white space on the right side of ...

How can you insert an image in HTML without a set path?

Converting a report from HTML to *.rtf / *.doc format <header> <img class="img" src="C:/Users/????/Desktop/Test/img/header.png" alt="img"> </header> Upon downloading the *.rtf or *.doc file, the image link may not work if there is n ...

What is the best way to change the orientation of the Product List in WooCommerce to landscape

Is there a way to change our product list display to landscape orientation? The current portrait layout is not visually appealing due to excessive white space. I would greatly appreciate any guidance on how to resolve this issue. You can view our website ...

Determine the number of elements in a Css selector and restart the counter whenever an element

Need help with counting elements that are not part of a regular list structure. Here is a code example to clarify: Fiddle I don't have much control over the HTML. The DOM structure looks like this: <div class="body"> <div><p clas ...

The scrolling feature induces a contraction to the left side

Recently, I implemented the code below to fix my menu when scrolling the page: var num = 5; $(window).bind('scroll', function () { if ($(window).scrollTop() > num) { $('.scroll').css({'position':'fixed&apo ...

Tips for accessing the StaticRouterContext in Typescript with react-router-dom

Currently, I am implementing SSR for my app specifically targeting robots. There is a possibility that the render of the <App/> component may lead to a route not being found. In order to handle this scenario, I need to identify when the render ends ...

Utilize react-native-image-picker and axios to effortlessly upload an image to S3 via a presigned URL

I am currently working on implementing a function to upload an image using a pre-signed URL. The issue I am facing is that although the upload process is successful when selecting an image from the IOS simulator, the file appears to be corrupted and cannot ...

Unable to adjust the size of the font within a text field component in Material UI

I'm currently delving into learning Material UI and am faced with the task of enlarging the text field on my webpage. Despite embedding styles along with the field, the height, width, and other properties change except for the size. Here's the sn ...

Error occurred during SCSS rendering process: [Internal Error: Unable to locate or read the specified file.]

When trying to create a website using scss, I encounter an error every time I save the scss file. Strangely, after saving it multiple times, the file will render properly. Although this issue is minor, it really bothers me. I have searched for a solution ...

`More than one path from a single location in NextJs`

Currently, I am in the process of developing a marketing/consumer website for my company. We are making a shift away from WordPress to a combination of Next and Prismic, which is a move we are excited about. Our consumer site consists of approximately 600 ...

Insert straight lines between elements in an inline list

I am working on building a step progress bar using the HTML code below: .fa-check-circle { color: #5EB4FF; } .fa-circle { color: #CFD7E6; font-size: 14px; } .container { width: 100%; position: absolute; z-index: 1; margin-top: 20px; } . ...

What is the reason for a React component returning multiple elements?

What is the number of elements a React component returns? Is it one or multiple? I'm confused because my professor mentioned multiple but I am not understanding why. ...

The visibility of the Bootstrap modal may vary depending on the version of Bootstrap being used

I am new to web programming and utilized various Twitter Bootstrap templates to build my website. The login page displays Bootstrap modals correctly with the following imports: <link rel="stylesheet" href="css/bootstrap.css" /> <link rel="styles ...

The action creator is not being triggered when the onClick event is called on a material-ui button

Upon calling the action creator for an onClick event on a material ui RaisedButton, I encountered the following error Failed prop type: The onClick prop of type object was provided to RaisedButton, but it was expected to be of type function. This is my c ...

Increase the object using JavaScript

I currently have an object collection: var obj = { ref01:{ test:"abc" }, ref02:{ test:"xyz" }, ref03:{ test:"pqr" } } and I also have a new object: const test = { test:"def" } My goal is to update the existin ...

Having trouble with the installation of styled-components from npm?

Having trouble installing styled-components using npm install. Can anyone provide assistance or suggest an alternative method for installation? I tried the command: npm i styled-components -g, but it is not working for me. Is there another way to install ...

Paste the URL into your clipboard without relying on JavaScript

Is there a way to implement a copy to clipboard function for email templates without relying on JavaScript? ...

Is there a way to align the sort and search buttons to the right in the Antd Table header?

In my React application, I am utilizing Antd Table and I am interested in repositioning the sort and search buttons to the right side of the Table header. These buttons typically appear on the left side by default, but I have not been able to find a soluti ...

What are some solutions for resolving an infinite loop of axios requests?

I am currently in the process of developing a web app for Spotify using its API. I have encountered an issue where the handleClick function in Albums.js is being called repeatedly when trying to make a get request for specific artist album data. Could this ...

Removing characters from a string with regular expressions

I need to eliminate instances of << any words #_ from the given text. stringVal = "<<Start words#_ I <<love#_ kind <<man>>, <<john#_ <<kind man>> is really <<great>> <<end words#_ "; The d ...