Steps for embedding the code into your website

I'm facing an issue with integrating a .jsx file into my website. I tried testing it on a single-page demo site, but nothing is showing up. Can someone guide me through the steps to successfully integrate it onto my site? I've also attached the .CSS file for reference. The goal is to create a floating widget, but I'm struggling to implement it effectively. Any suggestions?

import React from "react";
import "./index.css";

export default function FloatingIcons() {
  function handleActiveClass() {
    document.getElementById("circularMenu").classList.toggle("active");
  }
  return (
    <div id="circularMenu" className="circular-menu">
      <a className="floating-btn" onClick={handleActiveClass}>
        <i class="fa fa-question" style={{ fontSize: "30px" }} />
      </a>
      <menu className="items-wrapper">
        <a href="/" className="menu-item">
          <i className="fa fa-comments" />
        </a>
        <a href="/" className="menu-item">
          <i className="fa fa-bug" />
        </a>
        <a href="/" className="menu-item">
          <i className="fa fa-search" />
        </a>
      </menu>
    </div>
  );
}

The CSS File:

@import "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css";

.circular-menu {
  position: fixed;
  bottom: 1em;
  right: 1em;
}

.circular-menu .floating-btn {
  display: block;
  width: 3.5em;
  height: 3.5em;
  border-radius: 50%;
  background-color: hsl(4, 98%, 60%);
  box-shadow: 0 2px 5px 0 hsla(0, 0%, 0%, 0.26);
  color: #fff;
  text-align: center;
  line-height: 4.1;
  cursor: pointer;
  outline: 0;
}

.circular-menu .floating-btn i {
  font-size: 1.3em;
  transition: transform 0.2s;
}

.circular-menu:after {
  display: block;
  content: " ";
  width: 3.5em;
  height: 3.5em;
  border-radius: 50%;
  position: absolute;
  top: 0;
  right: 0;
  z-index: -2;
  background-color: transparent;
  transition: all 0.3s ease;
}

.circular-menu.active:after {
  transform: scale3d(5.5, 5.5, 1);
  transition-timing-function: cubic-bezier(0.68, 1.55, 0.265, 1);
}

.circular-menu .items-wrapper {
  padding: 0;
  margin: 0;
}

.circular-menu .menu-item {
  position: absolute;
  top: 0.2em;
  right: 0.2em;
  z-index: -1;
  display: block;
  text-decoration: none;
  color: hsl(0, 0%, 100%);
  font-size: 1em;
  width: 3em;
  height: 3em;
  border-radius: 50%;
  text-align: center;
  line-height: 3;
  background-color: #008cff;
  transition: transform 0.3s ease, background 0.2s ease;
}

.circular-menu .menu-item:hover {
  background-color: #2b80c5;
}

.circular-menu.active .menu-item {
  transition-timing-function: cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.circular-menu.active .menu-item:nth-child(1) {
  transform: translate3d(-0.8em, -6.5em, 0);
}

.circular-menu.active .menu-item:nth-child(2) {
  transform: translate3d(-4.5em, -4em, 0);
}

.circular-menu.active .menu-item:nth-child(3) {
  transform: translate3d(-5.5em, 0.3em, 0);
}

Answer №1

Initially, you need to update your CSS @import statement to

@import url("https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css");

in order for it to function within ./index.css with JS import "./index.css";

It appears that you have been working on the content of an App.js file and are now attempting to utilize it as an index.js? It would be best to keep App.js separate and intact while using the index.js (presumably created by react app) which includes the necessary ReactDOM.render. Alternatively, you can copy the first two and last lines of index.js into your JSX, like so:

import React from "react";
import ReactDOM from "react-dom";

at the beginning and

ReactDOM.render(<FloatingIcons />, document.getElementById("root"));

at the end, replacing the default App in the last line with your own FloatingIcons, assuming there is an element with the id "root" in your HTML. Keep in mind that you can retain your "import React" statement as importing it again will not cause any issues, however, ensure that "React" is imported before "ReactDOM" since it depends on it.

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

After implementing two hooks with null properties, the code fails to execute

Recently, I encountered an issue with this section of the code after upgrading react scripts from version 2.0 to 5.0. const { user, dispatch } = useContext(AuthContext); const { data } = useFetch(`/contracts/${user.contractType}`); if (!user) { ...

PHP Administrator Access

When a user logs in as an admin on my website, I want certain options to be available. My concern is ensuring the security of this admin account. Currently, after the login process is authenticated, I set $_SESSION['status'] = 'authorized&ap ...

Is there a way for me to automatically go back to the home page when I press the back button on the browser?

My ecommerce website has a shopping cart page where customers can purchase products and make payments. After the payment is completed, they are directed to a thank you page. The flow of the website is as follows: Home page => Products => Shopping cart => ...

What is preventing me from translating an element using transform: translateY()?

I attempted to move the letter 'h' down by 40px on its own, but the translation only seems to work if I relocate the entire word. I also experimented with positioning 'h' absolutely relative to the parent element, but then 'ello&ap ...

Customize the border style for the span element

I attempted to use the code below in JavaScript/jQuery to adjust the border thickness. Unfortunately, it seems to be ineffective. Can someone please assist me? //$("span").css({"border":"4px solid green"}); document.getElementById("192.168.42.151:8984_ ...

Incorporate and interpret a custom JSON object within my Shopify Liquid theme

In an attempt to integrate custom data into my Shopify liquid theme, I stored a JSON file in the assets folder. My goal is to retrieve and parse this JSON object within a jQuery method from a JavaScript file also located in the assets folder. Despite try ...

Troubleshooting SCSS Issues in NextJS

Can anyone help me with debugging SCSS in NEXT.JS? I've been trying to figure it out but haven't had any luck. When I use @debug on a SCSS module, nothing shows up in the console. Do I need to configure something in the next.config.js file or is ...

Does the CSS :not() selector function properly when used with distant descendants?

Check out the official documentation for the CSS3 :not() pseudo-class at this link: http://www.w3.org/TR/css3-selectors/#negation Additionally, you may be interested in the proposed enhancement for CSS Selectors Level 4 found here: http://dev.w3.org ...

After changing pages, the checkbox's state is reset to empty

I am currently working with an array of objects structured as follows: const columns = [ { key: "Source_campname", title: "TS Camp Name", customElement: function (row) { return ( <FormControlL ...

Comparing SSR and CSR Approaches to Handling getInitialProps in _app.js with Next JS

I am currently working on developing a Next JS application that manages authentication and initial routing within the getInitialProps function. I have found that this method can be executed either server-side or client-side. My current approach involves ...

Combining Python Bottle with Polymer Paper Elements

My website currently has a variety of forms where users input information, which is then used to calculate and display new content using Javascript. I rely on Python Bottle for user registration, form auto-filling from the backend and database management. ...

Issue with Material-UI's DataGrid scrollbar not displaying on the screen

I have a DataGrid set up with at least 20 rows. My goal is to limit its height and allow users to navigate through the remaining rows using the scroll bar within the component. However, I'm facing an issue as the scrollbar for the DataGrid itself is n ...

Utilize identical animations across various elements

I have a canvas animation in JavaScript that is currently limited to one canvas element with the id "stars". I want to be able to use this animation multiple times without repeating the code. Is there a way to add a class for the canvas elements instead of ...

Customize a React image carousel for NextJS integrations

Here's the image slider code in React that is functioning properly: import React, { useState, useEffect } from "react"; import item1 from "./../assets/images/items/1.jpg"; import item2 from "./../assets/images/items/2.gif" ...

The object's key values were unexpectedly empty despite containing data

There's an issue with my object - it initially gets key values, but then suddenly loses them all. All the key values become empty and a message appears in the console for the object: "this value was evaluated upon first expanding. it may have ch ...

Flow error: Unable to access the value of this.props.width as the property width is not defined in T

In my React Native project, I am utilizing Flow for type checking. For more information, visit: I currently have two files named SvgRenderer.js and Cartoon.js where: Cartoon extends SvgRenderer Below is the source code for both of these files: SvgRend ...

I am in the process of troubleshooting why the header does not redirect correctly when clicked

As I work on developing a user authentication script for my database, I encounter an issue when trying to match the information in my MySQL database upon clicking a button. For some reason, nothing seems to happen regardless of whether the login informatio ...

Running two different wdio.config.js files consecutively

Is it possible to run two wdio.config.js files with different configurations, one after another? Here is how the first configuration file is defined in the code: const { join } = require('path'); require('@babel/register') exports.co ...

The routing feature functions properly on localhost but encounters issues on the live server

There seems to be an issue with this code. While it works perfectly on localhost, it doesn't function as expected on a live Apache server. I have already specified the homepage in the package JSON file and included an htaccess file. However, when acce ...

A guide to placing tooltips dynamically in highcharts column charts

I am encountering an issue with tooltips in Highcharts column charts. The problem arises when the series fill up my chart, causing the tooltip to be hidden below the series and cut off by the end of the div. You can see an example here: https://i.stack.i ...