React app stops working when I add textfield - html

I'm a beginner in React and I'm trying to create a web application's front end UI part and I'm trying to add a text field in the box that I've added but every time i do that, the app does not render anything other than a blank color filled to the screen.
without the text field:
with the text field:
My code:
App.js:
import React, { Component} from 'react'
import 'bootstrap/dist/css/bootstrap.min.css';
import './App.css';
import Text1 from './Text1';
import Helmet from 'react-helmet';
import HRLOGO from './images/logo.png';
import ABCLOGO from './images/Group 20399.png';
export default class App extends Component
{
state = {};
render()
{
return (
<div className="hr">
<div>
<img src={HRLOGO} alt="" className="container-div"/>
</div>
<div>
<img src={ABCLOGO} alt="" className="container-div2"/>
</div>
<Helmet>
<style>{'body { background-color: #2d4250; }'}</style>
</Helmet>
<div>
<h1 className="InvoiceStyle">Invoice List</h1>
</div>
<div className="Rectangle">
</div>
<div className="search">
<Text1></Text1>
</div>
<footer className="Privacy">
<p>
Privacy Policy
| ©Highradius Corporation. All rights reserved.
</p>
</footer >
</div>
);
}
}
The css File App.css:
.App {
text-align: center;
}
.App-logo {
height: 40vmin;
pointer-events: none;
margin:auto;
}
#media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
margin:auto;
}
}
.Rectangle {
width: 2000px;
height: 570px;
background: #2e4551;
position: fixed;
top: 130px;
}
.container-div {
display: flex;
height: 50px;
width: 235px;
position: fixed;
top: 8px;
right: 600px;
text-align: center;
}
.InvoiceStyle {
display: flex;
color: #fff;
font-family: 'Open Sans';
font-size: x-large;
position: fixed;
top: 90px;
left: 25px;
}
.container-div2 {
display: flex;
height: 50px;
width: 312px;
position: fixed;
top: 7px;
left: 15px;
}
.Privacy {
display: flex;
position: fixed;
top: 720px;
left: 600px;
color: white;
}
.search {
position: fixed;
top: 155px;
left: 690px;
width: 16%;
height: 40px;
background-color: #fff;
border: none;
border-top-left-radius: 10px !important;
border-bottom-left-radius: 10px !important;
border-top-right-radius: 10px !important;
border-bottom-right-radius: 10px !important;
}
.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: rgb(11, 68, 253);
}
.App-link {
color: #ff0000;
}
#keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
Text1.js:
import TextField from "#mui/material/TextField";
const Text1 = () => {
return (
<form noValidate autoComplete = "off">
<TextField id="outlined-basic" label="Outlined" variant="outlined" />
</form>
);
}
export default Text1;
Like the page just goes blank, How do I fix this?
Edit:
Browser Console:

The primary error appears to be Cannot read properties of null (reading 'useContext'). React has the concept of ambient Context to simplify passing values down through your Component hierarchy. In this particular case, the TextField component has been assigned a variant theme. In order to lookup and apply that theme, it is expecting to find somewhere in it's parent component hierarchy a ThemeProvider. https://mui.com/material-ui/customization/theming/#theme-provider
Solution: Add a ThemeProvider as a parent component within the render section of your App component.
function render() {
return (<ThemeProvider ...>
...
</ThemeProvider>);
}
After you do this, the TextField component should be able to properly retrieve the context via it's call to the useContext hook. If you run into further issues, make sure you carefully review the basic installation and usage documentation for that library: https://mui.com/material-ui/getting-started/usage/

Related

Z-index does not works

Codesandbox: https://codesandbox.io/s/colorful-tooltip-antd-4-21-0-forked-dctrww?file=/Tooltip.js
I can not press {children} element because tooltip has an padding-bottom. I tried in dev tools browser set z-index on children but this does not helps. How should I set children to be always 'above' tooltip padding - so i will able to click on {children}
Tooltip:
import React from "react";
import "antd/dist/antd.css";
import "./index.css";
import { Tooltip } from "antd";
import styled from "styled-components";
export const Tool = ({ children, title, left, top }) => (
<Custom
visible
left={left}
top={top}
title={title}
getPopupContainer={(triggerNode) => triggerNode}
>
<Children>{children}</Children>
</Custom>
);
const Children = styled.div`
position: relative;
display: inline;
> * {
position: relative;
display: inline;
}
`;
const Custom = styled(Tooltip)`
.ant-tooltip-arrow {
display: none;
}
.ant-tooltip {
left: ${(props) => props.left || 0} !important;
top: ${(props) => props.top || "-70px"} !important;
}
.ant-tooltip-content {
position: relative;
overflow-x: hidden;
overflow-y: visible;
padding-bottom: 20px;
display: inline-block;
}
.ant-tooltip-inner {
padding: 10px 15px;
background: white;
top: 0;
display: inline-block;
border-radius: 10px;
border: 3px solid red;
border-bottom-right-radius: 0px;
z-index: 2;
max-width: 200px;
box-shadow: none;
color: black;
word-wrap: break-word;
}
.ant-tooltip-content:before {
content: "";
position: absolute;
width: 25px;
height: 25px;
background: white;
bottom: 14px;
right: -6px;
transform: rotate(25deg);
border-bottom: 3px solid red;
}
.ant-tooltip-content:after {
content: "";
width: 3px;
background: red;
height: 50%;
position: absolute;
right: 0;
bottom: 13px;
}
`;
import React from "react";
import "antd/dist/antd.css";
import "./index.css";
import { Tool } from "./Tooltip";
const App = () => {
return (
<Tool title="Tooltip">
<p>Button</p>
</Tool>
);
};
export default App;
Keep in mind that the antd library also has its own styles that it adds in the DOM, so I recommend starting codesandbox and checking there

How to change placement of element for mobile version of React App?

currently I have this desktop application. This is basically what the header looks like, a logo on the left and then the calendar box in the middle.
I want to make this mobile friendly, and have it look more like this, ONCE the screen resolution is detected to be a mobile device:
Here's what my code looks like currently (I only have the desktop version of it working):
import React from 'react';
import { HeaderWrap } from './headerStyles';
import calendar from "../images/calendar.png";
import btc from "../images/btc.png";
function Header() {
return (
<HeaderWrap>
<img style={{marginLeft:'1%', width:'140px', height:'140px', float:'left'}} src={btc} alt="logo"/>
<div className="boxWrap">
<img style={{marginLeft:'15px', marginTop:"4%", width:'35px', height:'35px', float:'left'}} src={calendar} alt="calendar"/>
<h1 style={{
marginLeft: "50px",
marginBottom: "10px",
color:"black",
fontSize:"12px",}}> Tuesday 27, March, 2021 </h1>
</div>
</HeaderWrap>
);
}
export default Header;
Here's what's inside headerStyles.js:
import styled from 'styled-components';
const media = {
desktop: `#media(min-width: 1000px)`
}
export const HeaderWrap = styled.div`
width: 100%;
border: 1px solid blue;
padding: 14px 0;
.boxWrap{
width: 30%;
margin: auto;
margin-top: 40px;
height: 60px;
border: 1px solid blue;
${media.desktop}{
align-items: center;
}
.calendar{
box-shadow: 0 0 5px 1px lightgrey;
width: 100%;
height: 100px;
${media.desktop}{
width: 48%;
}
}
}
h1{
margin-left: 10px;
color: #fff;
}
`
Any help would be absolutely appreciated, thank you!
Using flex instead of float to arrange the elements will be easier for you.
You're also using styled-components so you can remove the inline styling to properly separate your concerns.
import React from 'react';
import { HeaderWrap } from './headerStyles';
import calendar from "../images/calendar.png";
import btc from "../images/btc.png";
function Header() {
return (
<HeaderWrap>
<img className="btc" src={btc} alt="logo"/>
<div className="boxWrap">
<img src={calendar} alt="calendar"/>
<h1> Tuesday 27, March, 2021 </h1>
</div>
</HeaderWrap>
);
}
export default Header;
and
const media = {
desktop: `#media(min-width: 1000px)`
}
export const HeaderWrap = styled.div`
width: 100%;
border: 1px solid blue;
padding: 14px 0;
display: flex;
align-items: center;
justify-items: space-between;
.btc {
width: 140px;
height: 140px;
}
.boxWrap {
width: 30%;
height: 60px;
border: 1px solid blue;
justify-self: center;
display: flex;
align-items: center;
justify-items: space-around;
img {
height: 35px;
width: 35px;
}
.calendar{
box-shadow: 0 0 5px 1px lightgrey;
width: 100%;
height: 100px;
${media.desktop}{
width: 48%;
}
}
}
h1{
color: #fff;
}
${media.desktop}{
flex-direction: column;
align-items: flex-start;
}
`
This is the closest I can get at the moment without running it locally, if you have problems with the implementation just add a comment.

CSS in React isn't styling

My CSS doesn't work with my React project, it only changes body (I changed the background color from white to black), the rest from .info isn't working at all. What am I doing wrong?
import React from 'react';
import styled from 'styled-components';
import styles from 'assets/css/CSS.module.css';
const Offer = () => (
<div>
<div className={'info'}>
<h1 className={'info__title'}>Pick a pricing plan</h1>
<p className={'info__description'}>
We did our best to meet your expectations.
Please feel free to pick the right plan for your needs.
Remember that in any moment you can switch your pricing plan.
</p>
</div>
<div className={'container'}>
<div className={'box'}>
<h2 className={'box__title'}>Basic</h2>
<p className={"box__description"}>
Everything you need. For a reasonable price.
</p>
<p className={"box__price"}>$29</p>
<button className={"box__button"}>choose</button>
</div>
<div className={"box box--featured"}>
<h2 className={"box__title"}>Pro</h2>
<p className={"box__description"}>
More than anyone can give – for less than anywhere else.
</p>
<p className={"box__price"}>$99</p>
<button className={"box__button"}>choose</button>
</div>
<div className={"box"}>
<h2 className={"box__title"}>VIP</h2>
<p className={"box__description"}>
Ok, we get it. You’re the boss now. Just tell us what you need.
</p>
<p className={"box__price"}>$429</p>
<button className={"box__button"}>choose</button>
</div>
</div>
</div>
);
const HomePage = () => (
<>
<div>
<Offer/>
</div>
</>
);
export default HomePage;
$dark: #171717;
$light: #ffffff;
$font-stack: 'Fira Code', sans-serif;
html {
box-sizing: border-box;
}
*, *::before, *::after {
box-sizing: inherit;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
body {
font-family: $font-stack;
background-color: $dark;
color: $light;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
padding: 50px 0 0;
}
.info {
text-align: center;
max-width: 700px;
margin-bottom: 60px;
&__title {
font-size: 45px;
}
&__description {
font-size: 18px;
}
}
.container {
display: grid;
max-width: 1000px;
align-items: center;
#media (min-width: 800px) {
grid-template-columns: repeat(3, 1fr);
}
}
.box {
min-height: 500px;
border: 5px solid $light;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
padding: 0 15%;
position: relative;
&:first-of-type {
right: -5px;
}
&:last-of-type {
left: -5px;
}
&__title,
&__price {
font-size: 45px;
font-weight: bold;
}
&__title {
margin: 0 0 20px;
}
&__price {
margin: 30px 0;
}
&__description {
font-size: 14px;
}
&__button {
background-color: $light;
padding: 8px 25px;
font-family: $font-stack;
font-weight: bold;
border: none;
}
&--featured {
background-color: $light;
color: $dark;
min-height: 550px;
box-shadow:
-20px 0 25px -15px rgba(255,255,255, .3),
20px 0 25px -15px rgba(255,255,255, .3);
&::before {
width: 95%;
height: 97%;
content: '';
position: absolute;
border: 5px solid $dark;
}
&::after {
top: 1.5%;
width: 40%;
min-width: 45px;
height: 30px;
content: 'most popular';
font-size: 12px;
display: flex;
justify-content: center;
align-items: center;
color: $light;
background-color: $dark;
position: absolute;
}
.box__title,
.box__price {
font-size: 60px;
}
.box__description {
font-size: 16px;
}
.box__button {
position: relative;
z-index: 10;
background-color: $dark;
color: $light;
font-size: 20px;
padding: 12px 28px;
}
}
}
I added the correct code, before that i started writing something else, but that doesnt matter now. details, details, details , details - just wrote this so i could edit.
I've changed css. to scss, imported scss. and installed sass, but the only thing that change is the body background to black
Use a relative path. Assuming HomePage.js is in components, the import should be import '../assets/css/CSS.module.css'
There are several problems in your original post.
1) jsx className syntax
Your JSX should look like this:
const Offer = () => (
<div className={'info'}>text</div>
...
See codeburst.io/styling-in-react.
2) Specify the correct import
Your path / filename for the stylesheet should be something like:
import '../../assets/css/CSS.module.css';
3) Add Sass to your project
Node-sass is a library that provides binding for Node. js to LibSass, the C version of the popular stylesheet preprocessor, Sass. It allows you to natively compile . scss files to css
Here you can read more about node-sass.
Once you fixed your path, you need to make sure that sass is correctly interpreted. To make your css (sass syntax) work you need to do two things as css is not scss:
1) Rename your .css file to .scss (yarn will show an error then)
2) Run npm install node-sass (to install sass)
npm install node-sass and add it to your project by adding --save to the command.

Header extends over scrollbar when width=100%

My problem is with the width of a sticky header. It is extending horizontally over the vertical scrollbar on the right. So if the thumb of the scrollbar is at the top, and under the header, then you can't grab and drag it. Curiously the thumb appears to be on top of the header but if you try to grab and drag it, you will be selecting text rather than moving the scroll position.
Is there a way to fix this header width so that it's wide enough to cover the scrolling text but not so wide that it covers the scrollbar, or a way to put the scrollbar on top of the header?
https://codesandbox.io/s/fragrant-cookies-g9w4c
.App {
font-family: sans-serif;
text-align: center;
}
::-webkit-scrollbar {
width: 40px;
position: fixed;
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
/* Track */
::-webkit-scrollbar-track {
box-shadow: inset 0 0 5px grey;
border-radius: 18px;
}
/* Handle */
::-webkit-scrollbar-thumb {
background: red;
border-radius: 18px;
}
/* Handle on hover */
::-webkit-scrollbar-thumb:hover {
background: #b30000;
}
.sticky-heading {
background-color: aqua;
font-weight: bold;
font-size: 22px;
padding-top: 10px;
width: 100%;
position: fixed;
}
.list {
overflow-y: scroll;
-webkit-overflow-scrolling: touch;
padding: 20px;
position: fixed;
background: #fff;
height: 100vh;
width: -webkit-fill-available;
overflow-x: hidden;
}
import React from "react";
import ReactDOM from "react-dom";
import "./styles.css";
function App() {
return (
<div className="App">
<div className="list">
<div>
<div>
<div className="sticky-heading">
This should not cover the scrollbar
</div>
<div>
{Array.from({ length: 300 }, () => {
return (
<div>
this must be covered by the heading when scrolling
<br />
</div>
);
})}
</div>
</div>
</div>
</div>
</div>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
::-webkit-scrollbar {
width: 40px;
}
Given width of scrollbar is 40px & scrollbar present at right side of page , so add right:40px in:
.sticky-heading {
right: 40px; //or 30px whatever you want but more than scrollbar width
}
You can try to use this position: absolute; instead of position: fixed;
.sticky-heading {
background-color: aqua;
font-weight: bold;
font-size: 22px;
padding-top: 10px;
width: 100%;
position: absolute;
}
Is this what you want?

How to create a Hero Image with form beside it and make full-width?

I want to know how to develop a hero section and put booking form beside each and make it scale on all screen sizes.
This how I want the hero section to look on the page. Trying to find out different examples and ideas.
Design Concept:
This what it looks in the browser:
Hero Component
import React, { Component } from 'react';
import '../sass/main.scss';
import { Container, Row, Col} from 'react-bootstrap';
import FindSpaceFormComponment from '../layouts/findspaceform'; // image is defined but never used...
import Hero from "../../src/images/1421x1126.png";
const HeroStyle = {
width: "1421px",
height: "100vh",
backgroundImage: `url(${Hero})`
};
class App extends Component {
render() {
return (
<div>
<Container fluid={true}>
<Row>
<Col md="2" lg="2" xl="2" mb="2">
<div className="OnTop">
<FindSpaceFormComponment />
</div>
</Col>
<Col md="6" lg="6" xl="6" mb="6">
<div className="ImgBg VidBg" style={ HeroStyle }>
</div>
</Col>
</Row>
</Container>
</div>
);
}
}
export default App;
Hero Component CSS
.ImgBg {
width: 100%;
position: relative;
z-index: 0;
top: -96px;
bottom: 0;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
Booking Component
import React, { Component } from 'react';
import '../sass/main.scss';
class App extends Component {
render() {
return (
<div className="FindSpaceForm">
<h1 className="MainTitle">Find a Place To Get Together</h1>
<form onSubmit="">
<div className="FormChild">
<label>Where</label>
<input placeholder="Anywhere" type="text" value="" onChange="" />
</div>
<div className="FormChild">
<div className="FlexInline PFM">
<label>Book-In</label>
<select className="Idjefm329 style3w948">
<option value="grapefruit">Grapefruit</option>
<option value="lime">Lime</option>
<option value="coconut">Coconut</option>
<option value="mango">Mango</option>
</select>
</div>
<div className="FlexInline">
<label>Book-Out</label>
<select className="style3w948">
<option value="grapefruit">Grapefruit</option>
<option value="lime">Lime</option>
<option value="coconut">Coconut</option>
<option value="mango">Mango</option>
</select>
</div>
</div>
<div className="FormChild">
<label>Attendees</label>
<select className="style3w948">
<option value="grapefruit">Grapefruit</option>
<option value="lime">Lime</option>
<option value="coconut">Coconut</option>
<option value="mango">Mango</option>
</select>
</div>
<div className="FormChild">
<button className="book-now" type="submit" value="Submit" >Submit</button>
</div>
</form>
</div>
);
}
}
export default App;
Booking Component CSS
.OnTop {
position: absolute;
margin-left: 3em;
margin-top: 7em;
margin-bottom: 7em;
width: 191vh;
z-index: 2;
}
.OnTop .MainTitle {
font-size: 4.75rem;
width: 474px;
margin-bottom: 30px;
}
.OnTop .FindSpaceForm {
background: black;
padding: .9em 1em;
width: 100%;
height: 100%;
}
.OnTop .FindSpaceForm form .FormChild {
padding-bottom: 1.3em;
width: 100%;
}
.OnTop .FindSpaceForm form .FormChild .book-now {
position: absolute;
right: 0;
height: calc(100% + 1px);
width: 130px;
}
.OnTop .FindSpaceForm form label {
display: block;
font-size: 1.25em;
color: white;
padding-bottom: 1.2em;
}
.OnTop .FindSpaceForm form input, .OnTop .FindSpaceForm form button, .OnTop .FindSpaceForm form select, .OnTop .FindSpaceForm form option {
height: 73px;
width: 100%;
padding: 1em;
border: none;
margin-bottom: 1em;
}
That kind of layout will definitely not work for all screen sizes based on your request so we may ask. Is this really a CSS/HTML question or a design issue? For design, here's how I'd go about designing that layout mobile and desktop:
So the simple answer to your question is use CSS media queries and I wouldn't tag this as a React question since the React part of it mostly negligible. It's a layout problem.
I also went ahead to create a quick code demo of how you might achieve this with HTML and CSS here on codepen
*{box-sizing: border-box}
h2{margin: 10px 0}
a{text-decoration: none; color: #776}
.hero{
position: relative;
height: 500px;
margin-bottom: 240px;
header{
display: flex;
height: 70px;
align-items: center;
justify-content: space-between;
position: relative;
padding: 10px 20px;
background: none;
}
.hamburger{
-webkit-appearance: none;
position: relative;
display: block;
width: 40px;
height: auto;
background: none;
border: 0;
border-top: solid medium #776;
outline: none;
&::before, &::after{
content: '';
position: absolute;
left: 0;
display: block;
width: 40px;
border-top: solid medium #776;
}
&::before{
top: -12px;
}
&::after{
bottom: -6px;
}
#media(min-width: 620px) {
display: none;
}
}
nav{
display: none;
margin: 10px 0;
a{ margin-left: 15px; display: inline-block; }
#media(min-width: 620px) {
display: block;
}
}
.backdrop{
position: absolute;
top: 0;
z-index: -1;
width: 100%;
height: 100%;
background: #ddd;
#media (min-width: 720px) {
left: 20%;
}
}
}
.content{
position: relative;
margin: 40px auto;
padding: 0 20px;
text-align: center;
h1{margin: 30px 0;}
#media(min-width: 720px) {
text-align: right;
h1{
margin: 50px 0;
font-size: 50px;
}
}
}
.btn{
padding: 15px 40px;
background: #06a;
border: 0;
border-radius: 2px;
color: #ddd;
}
.form{
width: 90%;
max-width: 400px;
height: 400px;
margin: 40px auto;
background: #089;
#media(min-width: 720px) {
position: absolute;
top: 100px;
left: 40px;
}
}
<div class="hero">
<header>
<h2>Logo</h2>
<button class="hamburger"></button>
<nav>
Menu One
Menu Two
Menu Three
</nav>
</header>
<div class="content">
<h1>Some catchy title here</h1>
<button class="btn">Call to action</button>
<form class="form">
</form>
</div>
<div class="backdrop"></div>
</div>
<p>Bottom content</p>