JSFiddle - React, Tailwind, and code Playground

by velo_ninja

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dynamic Round Menu with Tooltip and Submenus</title>
    <style>
        /* Styles for the radial menu and submenu */
        .circle-menu {
            position: relative;
            background-color: transparent;
            width: 100%;
            height: 100%;
            display: flex;
            justify-content: center;
            align-items: center;
            border-radius: 50%;
        }

        .menu-container {
            position: absolute;
            display: flex;
            justify-content: center;
            align-items: center;
            transform-origin: center;
            border-radius: 25px;
            background-color: red;
        }

        .menu-item {
            position: absolute;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .menu-text {
            font-size: 14px;
            color: #fff;
        }

        .tooltip {
            position: absolute;
            background: rgba(51, 151, 51, 0.8);
            color: white;
            padding: 5px;
            border-radius: 3px;
            z-index: 9999;
        }

        .submenu {
            position: absolute;
            padding: 10px;
            background-color: #e0e0e0;
            border-radius: 10px;
            margin-top: 10px;
            display: none;
            z-index: 1000;
        }

        .submenu-item {
            cursor: pointer;
            padding: 5px;
            border-bottom: 1px solid #ccc;
        }
    </style>
    <script>
        let isLeftMouseButtonDown = false;
        let currentRotation = 0;
        let radiusChangeSpeed = 25;
        let currentSelectedItem = null;
        let mainMenuData = [];
        let activeMenu = null;

        document.addEventListener('mousedown', (event) => {
            if...

CSS

/* Base styles for all menu items */
.menu-item {
  position: absolute;
  background: linear-gradient(145deg, #3a7bd5, #3a6073);
  width: 60px;
  height: 60px;
  color: #fff;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2), 
              inset 0 2px 4px rgba(255, 255, 255, 0.1);
  transition: transform 0.3s ease, box-shadow 0.3s ease, border 0.3s ease;
}
.menu-item:hover {
  background: linear-gradient(145deg, #4caf50, #388e3c); /* Green gradient on hover */
  transform: scale(1.1); /* Slight scale-up on hover */
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3),
              inset 0 3px 6px rgba(255, 255, 255, 0.15);
}


.menu-text {text-align: center;}

.tooltip {      
  color: #fff;
  padding: 5px;
  border-radius: 3px;
  font-size: 16px;
  display: none;
  pointer-events: none;
  background-color: orange;
}

.tooltip.show {display: block;}