Home > Back-end >  How can I add a (CSS) cursor: property to elements in an array?
How can I add a (CSS) cursor: property to elements in an array?

Time:04-28

I am trying to style the data array, so that when you hover over it the cursor is set to cursor: grab;. I tried using different elements to make it happen none worked , .li{}, .ol{}, MediaComponent{},img{},imgSrc{},data{},div{}. The only one that worked for me was *.{}, however the problem with this is that the cursor remains on the grab property for the rest of the elements on the page. I'm trying to code it so that the cursor:grab; element only pertains to the data array.

import React, { Component,useRef, setStatus, status } from 'react';
import './Turkish.css';

import turk1 from "./music/turk1.mp3";
import turk2 from "./music/turk2.mp3"
import turk3 from "./music/turk3.mp3"
import turk4 from "./music/turk4.mp3"

const data = [
    { imgSrc: 'turk1.png', audioSrc: turk1 },
    { imgSrc: 'turk2.png', audioSrc: turk3 },
    { imgSrc: 'turk3.png', audioSrc: turk4 },
    { imgSrc: 'turk4.png', audioSrc: turk2 },
  ];
  
  export default class Turkish extends Component {
    render() {
      return (
        <div>
          <ol>
            {data.map(({ imgSrc, audioSrc }) => (
              <MediaComponent imgSrc={imgSrc} audioSrc={audioSrc} />
            ))}
          </ol>
        </div>
      );
    }
  }
  
  const MediaComponent = ({ imgSrc, audioSrc }) => {
    const audioRef = useRef(null);
    const toggleAudio = () =>
      audioRef.current === null
        ? console.log("Audio component is not loaded yet.")
        : audioRef.current.paused
        ? audioRef.current.play()
        : audioRef.current.pause();

        
            return (
              <li>
                <img src={imgSrc} onClick={toggleAudio} />
                <audio
                  ref={audioRef}
                  src={audioSrc}
                  onl oad={() => setStatus({ ...status, isLoaded: true })}
                  onPlay={() => setStatus({ ...status, isPlaying: true })}
                  onPause={() => setStatus({ ...status, isPlaying: false })}
                  one rror={() => setStatus({ ...status, error: true })}
                />
              </li>
            );
          };

Any thoughts?

Thank You

-Zpo

CodePudding user response:

It should work with ol, I guess you are making mistake in your CSS file. To be sure give className to your ol and pass cursor: grab in CSS

<ol className="olGrab">
   {data.map(({ imgSrc, audioSrc }) => (
    <MediaComponent imgSrc={imgSrc} audioSrc={audioSrc} />
   ))}
</ol>

In CSS

.olGrab { cursor: grab;}
  • Related