enter image description here
How can i fix this problem. I don't know i try search this problem in google but i don't find solution. And it's very important for me. I try put children like props but it's not working please help me
my sidebar component.
import React, { Children, useState } from "react";
import {
ProSidebar,
Menu,
MenuItem,
SidebarHeader,
SidebarContent,
} from "react-pro-sidebar";
import { FaList, FaRegHeart, FaTh } from "react-icons/fa";
import { FiHome, FiArrowLeftCircle, FiArrowRightCircle } from "react-icons/fi";
import { RiPencilLine } from "react-icons/ri";
import { BiCog } from "react-icons/bi";
import "react-pro-sidebar/dist/css/styles.css";
import "./Header.css";
import { Link } from "react-router-dom";
import {pathEdebiyat, pathChemistry, pathEnglish, pathGeography, pathMath, pathPhysics } from "../../Router";
const Header = ({children}) => {
const [menuCollapse, setMenuCollapse] = useState(false);
const menuIconClick = () => {
menuCollapse ? setMenuCollapse(false) : setMenuCollapse(true);
};
return (
<>
<div id="header">
{/* collapsed props to change menu size using menucollapse state */}
<ProSidebar collapsed={menuCollapse}>
<SidebarHeader>
<div className="logotext">
<p>{menuCollapse ? "Logo" : "Big Logo"}</p>
</div>
<div className="closemenu" onClick={menuIconClick}>
{menuCollapse ? <FiArrowRightCircle /> : <FiArrowLeftCircle />}
</div>
</SidebarHeader>
<SidebarContent>
<Menu iconShape="square">
<MenuItem active={window.location.pathname === pathEdebiyat} icon={<FiHome />}>
Edebiyat
<Link to={pathEdebiyat}/>
</MenuItem>
<MenuItem icon={<FaList />} active={window.location.pathname === pathMath}>Matematika <Link to={pathMath}/></MenuItem>
<MenuItem icon={<FaRegHeart />}>Turkmen dili</MenuItem>
<MenuItem icon={<RiPencilLine />}>Himiya</MenuItem>
<MenuItem icon={<BiCog />}>Rus DIli</MenuItem>
</Menu>
</SidebarContent>
</ProSidebar>
<main>{children}</main>
</div>
</>
);
};
export default Header;
sidebar styles. I try to use overflow but it isn't help me. And i don't know how i can solve this
#header {
position: absolute;
width: 220px;
}
#header .pro-sidebar {
height: 100vh;
}
#header .closemenu {
color: #000;
position: absolute;
right: 0;
z-index: 9999;
line-height: 20px;
border-radius: 50%;
font-weight: bold;
font-size: 22px;
top: 35px;
cursor: pointer;
}
#header .pro-sidebar {
width: 100%;
min-width: 100%;
}
#header .pro-sidebar.collapsed {
width: 80px;
min-width: 80px;
}
#header .pro-sidebar-inner {
background-color: white;
box-shadow: 0.5px 0.866px 2px 0px rgba(0, 0, 0, 0.15);
}
#header .pro-sidebar-inner .pro-sidebar-layout {
overflow-y: hidden;
}
#header .pro-sidebar-inner .pro-sidebar-layout .logotext p {
font-size: 20px;
padding: 0 20px;
color: #000;
font-weight: bold;
}
#header .pro-sidebar-inner .pro-sidebar-layout ul {
padding: 0 5px;
}
#header .pro-sidebar-inner .pro-sidebar-layout ul .pro-inner-item {
color: #000;
margin: 10px 0px;
font-weight: bold;
}
#header .pro-sidebar-inner .pro-sidebar-layout ul .pro-inner-item .pro-icon-wrapper {
background-color: #fbf4cd;
color: #000;
border-radius: 3px;
}
#header .pro-sidebar-inner .pro-sidebar-layout ul .pro-inner-item .pro-icon-wrapper .pro-item-content {
color: #000;
}
#header .pro-sidebar-inner .pro-sidebar-layout .active {
background-image: linear-gradient(0deg, #fece00 0%, #ffe172 100%);
}
#header .logo {
padding: 20px;
}
main {
width: 100%;
padding: 20px;
}
#media only screen and (max-width: 720px) {
html {
overflow: hidden;
}
}
my router component. Router.jsx
import React from "react";
import { BrowserRouter, Route, Routes } from "react-router-dom";
import Chemistry from "./components/Chemistry";
import Edebiyat from "./components/Edebiyat";
import English from "./components/English";
import Geography from "./components/Geography";
import Header from "./components/Header/Header";
import Math from "./components/Math";
import Physics from "./components/Physics";
export const pathMath = "/Math";
export const pathPhysics = "/Physics";
export const pathEnglish = "/English";
export const pathGeography = "/Geography";
export const pathChemistry = "/Chemistry";
export const initialPage = "/";
export const pathEdebiyat = "/Edebiyat";
export default function Router() {
return (
<BrowserRouter>
<Routes>
<Route path={pathEdebiyat} element={<Edebiyat />} />
<Route path={pathMath} element={<Math />} />
<Route path={pathChemistry} element={<Chemistry />} />
<Route path={pathPhysics} element={<Physics />} />
<Route path={pathEnglish} element={<English />} />
<Route path={pathGeography} element={<Geography />} />
</Routes>
</BrowserRouter>
);
}
Related
I have a react component called TeamBanner like so
import styles from "./teamBanner.module.css";
import { useNavigate } from "react-router-dom";
import { TeamBannerProps } from "../ProjectTypes.types";
export const TeamBanner = ({
team,
onBannerClick,
showName,
}: TeamBannerProps) => {
let navigate = useNavigate();
const handleOnClick = () => {
navigate(`/${team}`);
onBannerClick();
};
return (
<div
className={`${styles.container} flex theme-light ${
showName ? "" : styles["no-name"]
}`}
title={team}
onClick={handleOnClick}
>
<div>
<img
src={require(`../logos/${team}.svg`)}
alt="logo"
className={`${styles.logo} ${showName ? "" : styles["only-logo"]}`}
/>
</div>
{showName ? team : ""}
</div>
);
};
The teamBanner.module.css file is like so
.container {
margin: 0.25em;
align-items: center;
cursor: pointer;
top: 0;
z-index: 2;
background-color: hsl(var(--color-background));
padding: 0.1em 0.25em;
border-radius: 0.5em;
box-shadow: 0.05rem 0.05rem 0.2rem rgb(0 0 0 / 50%);
font-family: var(--ff-serif);
font-size: var(--fs-200);
}
.logo {
display: inline-block;
vertical-align: middle;
width: 3vmax;
height: 3vmax;
}
.container:hover {
outline: 0.15em solid hsl(240, 90%, 67%);
}
.no-name {
border-radius: 0.25em;
}
.only-logo {
width: 5vmax;
height: 5vmax;
}
I am using it to create a list of team of a page & this works just fine.
However, I want to use it in another place also. In the place, the to now want the .container:hover effect & I want the font properties of the .contaner and width & height properties of the .logo changed.
How can I accomplish this? only changing these items of the module.css? Can any one help? Thanks
Im crating a navbar for a cite and currently formatting the page Im pretty new to react so im trying to start with the basics. I am stuck on how to center my NavBarLinks, I have used text-center and position to make the links be in the center of the navbar but if I make the web browser smaller it wont stay in the center. My question is what is the right to center items in react.
import React, { useState } from "react";
import {
NavbarContainer,
TopContainer,
BottomContainer,
NavbarExtendedContainer,
NavbarInnerContainer,
NavbarLinkContainer,
NavbarLink,
Logo,
OpenLinksButton,
NavbarLinkExtended,
} from "../styles/Navbar.style";
import LogoImg from "../assets/logo.png";
function Navbar() {
const [extendNavbar, setExtendNavbar] = useState(false);
return (
<NavbarContainer extendNavbar={extendNavbar}>
<NavbarInnerContainer>
<TopContainer>
<NavbarLinkContainer>
<OpenLinksButton
onClick={() => {
setExtendNavbar((curr) => !curr);
}}
>
{extendNavbar ? <>✕</> : <> ≡</>}
</OpenLinksButton>
<Logo src={LogoImg}></Logo>
</NavbarLinkContainer>
</TopContainer>
<BottomContainer>
<NavbarLinkContainer>
<NavbarLink to="/"> Home</NavbarLink>
<NavbarLink to="/products"> Products</NavbarLink>
<NavbarLink to="/contact"> Contact Us</NavbarLink>
<NavbarLink to="/about"> About Us</NavbarLink>
</NavbarLinkContainer>
</BottomContainer>
</NavbarInnerContainer>
{extendNavbar && (
<NavbarExtendedContainer>
<NavbarLinkExtended to="/"> Home</NavbarLinkExtended>
<NavbarLinkExtended to="/products"> Products</NavbarLinkExtended>
<NavbarLinkExtended to="/contact"> Contact Us</NavbarLinkExtended>
<NavbarLinkExtended to="/about"> About Us</NavbarLinkExtended>
</NavbarExtendedContainer>
)}
</NavbarContainer>
);
}
export default Navbar;
Style page
import styled from "styled-components";
import { Link } from "react-router-dom";
export const NavbarContainer = styled.nav`
width: 100%;
background-color: black;
#media (min-width: 700px) {
height: 80px;
}
`;
export const TopContainer = styled.div`
padding-left: 5%;
`;
export const BottomContainer = styled.div`
padding-right: 50px;
background-color:salmon;
`;
export const NavbarInnerContainer = styled.div`
width: 100%;
height: 80px;
`;
export const NavbarLinkContainer = styled.div`
display: flex;
`;
export const NavbarLink = styled(Link)`
color: white;
font-size: x-large;
font-family: Arial, Helvetica, sans-serif;
position: relative;
left: 43%;
top:10%;
text-decoration: none;
margin: 10px;
height: 30px;
text-align: center;
#media (max-width: 700px) {
display: none;
}
`;
export const NavbarLinkExtended = styled(Link)`
color: white;
font-size: x-large;
font-family: Arial, Helvetica, sans-serif;
text-decoration: none;
margin: 10px;
`;
export const Logo = styled.img`
#media (min-width: 700px) {
margin: auto;
}
margin: 10px;
max-width: 180px;
height: auto;
`;
I really wouldn't recommend using a whole different page for css instead just add your code to index.css, from there you can access your css from any component in your react app.
And to center the NavbarLink you can use flexbox.
Create some css code in index.css:
.navbar__link {
width: 100%
display: flex;
justify-content: center;
}
And add that class in your component element:
<NavbarLinkContainer className='navbar__link'>
<NavbarLink to="/"> Home</NavbarLink>
<NavbarLink to="/products"> Products</NavbarLink>
<NavbarLink to="/contact"> Contact Us</NavbarLink>
<NavbarLink to="/about"> About Us</NavbarLink>
</NavbarLinkContainer>
As stated I have tried adding margin-bottom to the css file tha the App consumes and I have tried adding it to the inline app called pagination, but it's not working. How do I get the offset?
Here's my app component. I believe the problem stems somewhere along the bottom of the render() method.
import React, { Component } from 'react';
import styles from './App.module.css';
import { Card } from 'react-bootstrap';
import dateFormat from 'dateformat';
import 'bootstrap/dist/css/bootstrap.min.css'
class App extends Component {
state = {
results: null,
total: null,
total_pages: null,
per_page: null,
current_page: 1
}
componentDidMount() {
this.makeHttpRequestWithPage(1);
}
makeHttpRequestWithPage = async pageNumber => {
const response = await fetch(`http://127.0.0.1:8000/cfdilist/?page=${pageNumber}`, {
method: 'GET',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
});
const data = await response.json();
this.setState({
results: data.results,
total: data.total,
total_pages: data.total_pages,
per_page: data.page_size,
current_page: data.page
});
}
render() {
console.dir(this.state.results)
let results, renderPageNumbers;
if (this.state.results !== null) {
results = this.state.results.map(result => (
<Card>
<Card.Title>entry: {result.id}</Card.Title>
<Card.Text><b>Name:</b> {result.issuer_name}</Card.Text>
<Card.Text><b>Date:</b> {dateFormat(result.date_issued, "mmmm dS, yyyy")}</Card.Text>
<Card.Text><b>RFC:</b> {result.issuer_rfc}</Card.Text>
<Card.Text><b>Amount:</b> {result.total_amount}$</Card.Text>
<Card.Text><b>cfdi XML:</b></Card.Text>
<textarea>{result.cfdi_xml}</textarea>
</Card>
));
}
const pageNumbers = [];
if (this.state.total !== null) {
for (let i = 1; i <= this.state.total_pages; i++) {
pageNumbers.push(i);
}
renderPageNumbers = pageNumbers.map(number => {
let classes = this.state.current_page === number ? styles.active : '';
if (number === 1 || number === this.state.total || (number >= this.state.current_page - 2 && number <= this.state.current_page + 2)) {
return (
<span key={number} className={classes} onClick={() => this.makeHttpRequestWithPage(number)}>{number}</span>
);
}
});
}
return (
<div className={styles.app}>
<div className={styles.header}>
<h1>CFDI Page</h1>
</div>
{results}
<div className={styles.pagination}>
<span onClick={() => this.makeHttpRequestWithPage(1)}>«</span>
{renderPageNumbers}
<span onClick={() => this.makeHttpRequestWithPage(1)}>»</span>
</div>
</div>
);
}
}
export default App;
And here's my App.module.css
.app {
width: 70%;
margin: 0 auto;
margin-bottom: 50px auto;
}
.Header {
width: 70%;
text-align: center;
margin: 0 auto;
margin-bottom: 50px;
}
.pagination {
margin-top: 25px;
margin-bottom: 40px;
}
.pagination span {
cursor: pointer;
color: black;
float: left;
padding: 8px 16px;
text-decoration: none;
transition: background-color .3s;
border: 1px solid #ddd;
}
.pagination span.active {
background-color: #0099FF;
color: white;
border: 1px solid #0099FF;
}
There is an error in your css:
.app {
width: 70%;
margin: 0 auto;
margin-bottom: 50px auto;
}
Should be:
.app {
width: 70%;
margin: 0 auto;
margin-bottom: 50px; <-remove auto
}
Is your class being triggered if you inspect elements on your app?
EG: <div className="app">
Tried changing the default color of the placeholder of my react-virtualized-select element using both input::-webkit-input-placeholder as well as singleValue property but it doesn't work. I even tried wrapping the entire code in a custom theme where the primary color was blue but it didn't work too. I want it to change it to the color that is in the textfield placeholder.
import "react-select/dist/react-select.css";
import "react-virtualized/styles.css";
import "react-virtualized-select/styles.css";
import "material-components-web/dist/material-components-web.css";
import "./react-select.css";
import React from "react";
import ReactDOM from "react-dom";
import Select from "react-virtualized-select";
import TextField from "rmwc/TextField";
const colourStyles = {
singleValue: styles => ({ ...styles, color: "blue" })
};
const options = Array.from(new Array(10), (_, index) => ({
label: `Item ${index}`,
value: index
}));
class Foo extends React.Component {
constructor(props) {
super(props);
this.state = {
option: undefined
};
}
render() {
return (
<React.Fragment>
<Select
className={"mdc-react-select"}
value={this.state.option}
onChange={option => this.setState({ option })}
styles={colourStyles}
options={options}
inputRenderer={props => {
return (
<TextField
{...props}
fullwidth
ref={undefined}
inputRef={props.ref}
placeholder={"Farm"}
required
value={
props.value ||
(this.state.option ? this.state.option.label : undefined)
}
/>
);
}}
/>
<br />
<br />
<div>
<TextField
ref={undefined}
label={"Farm"}
value={this.state.option ? this.state.option.label : undefined}
style={{ width: "100%" }}
/>
</div>
</React.Fragment>
);
}
}
ReactDOM.render(<Foo />, document.getElementById("root"));
CSS:
body {
font-family: "Roboto";
}
.mdc-react-select .Select-placeholder,
.mdc-react-select .Select-value {
display: none;
}
.mdc-react-select .Select-control {
background-color: transparent;
border-color: none;
border-radius: 0;
border: none;
color: #333;
cursor: default;
display: table;
border-spacing: 0;
border-collapse: separate;
height: 36px;
outline: none;
overflow: hidden;
position: relative;
width: 100%;
box-shadow: none !important;
}
.mdc-react-select .Select-input {
opacity: 1 !important;
width: 100%;
}
.mdc-text-field .mdc-line-ripple{
background-color: rgb(23,87,170);
}
.mdc-floating-label .mdc-floating-label--float-above{
color: rgb(23,87,170) !important;
}
.mdc-text-field--focused:not(.mdc-text-field--disabled) .mdc-floating-label{
color:rgb(23,87,170) !important;
}
/* .mdc-text-field--invalid:not(.mdc-text-field--disabled):not(.mdc-text-field--outlined):not(.mdc-text-field--textarea) .mdc-text-field__input:hover{
color:rgb(23,87,170) !important;
} */
/* input::-webkit-input-placeholder {
color: #999;
} */
Try this:
.mdc-react-select .Select-input {
color: red;
}
.mdc-react-select .Select-placeholder {
color: red;
}
IconButton in #material-ui/core/IconButton is showing a weird elliptical background when I hover the cursor over it.
I thought it is a mistake by me, so I just copied the code from material-ui website, but the problem remains.
However, when I created new react project, and created an icon button in it, the background was the usual circle.
I'm new to react and can't figure out what is going on, I'm using icon button without any explicit styling,
App.js
import React, { Component } from 'react';
import './App.css';
import { IconButton } from '#material-ui/core';
import WorkIcon from '#material-ui/icons/Work';
import CssBaseline from '#material-ui/core/CssBaseline';
class App extends Component {
render() {
return (
<div>
<CssBaseline />
<IconButton>
<WorkIcon />
</IconButton>
</div>
);
}
}
export default App;
App.css
.App {
text-align: center;
}
.App-logo {
animation: App-logo-spin infinite 20s linear;
height: 80px;
}
.App-header {
background-color: #222;
height: 150px;
padding: 20px;
color: white;
}
.App-title {
font-size: 1.5em;
}
.App-intro {
font-size: large;
}
#keyframes App-logo-spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
.MuiCardContent-root-29 {
display: inline-block;
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
width: 500px;
height: 300px;
margin: auto;
background-color: #f3f3f3;
}
.login {
margin-top: 50px;
margin-left: 50px;
}
.form-group {
margin-bottom: 35px;
}
index.js
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from "react-redux";
import './index.css';
import App from './App';
import store from "./store/index";
import registerServiceWorker from './registerServiceWorker';
ReactDOM.render(<Provider store={store}>
<App />
</Provider>, document.getElementById('root'));
registerServiceWorker();
index.css
body {
background-color : #484848;
margin: 0;
padding: 0;
}
h1 {
color : #000000;
text-align : center;
font-family: "SIMPSON";
}
form {
width: 300px;
margin: 50px auto;
}
button {
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
cursor: pointer;
width: 100%;
opacity: 0.9;
width: 100px;
}
.tableHeader {
background-color: green !important;
}
.header {
color: green;
font-weight: bold;
}
.edit {
height: 30px;
cursor: pointer;
}
.delete {
height: 20px;
cursor: pointer;
padding-left: 10px;
}
This problem persists in my whole project wherever I use icon buttons, and not just with this file only. And when I use this same file in a new project it works as expected: No elliptical backgrounds.
EDIT:
The accepted answer works well. In my also case I tried setting the width in button of index.css to auto and it fixed the error too.
This is what I did to remove the elliptical shape:
<IconButton style={{borderRadius: 0}}>
<DeleteIcon/>
</IconButton>
Now, it will be a rectangular shape when hovered.
I don't know why the above two solutions didn't work for me. So I added margin and width to the parent element and padding-right to the child element in App.css.
//For the buttons on top
button.MuiButtonBase-root {
margin: 10px;
width: 50px;
}
button.MuiButtonBase-root span span {
padding-right: 50px;
}
//For the checkboxes
span.MuiButtonBase-root {
margin-left: 10px;
width: 45px;
}
span.MuiButtonBase-root span {
padding-right: 10px;
}
The problem is the button CSS in your index.css. It is setting the width of all buttons to 100px. IconButton is implemented via a button tag around the icon.
Fixing the look of IconButton is easy -- just remove that button CSS. The more tedious part is that presumably you want that button styling on all your other buttons.
One way to handle this is to change the following in index.css:
button {
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
cursor: pointer;
width: 100%;
opacity: 0.9;
width: 100px;
}
to be a CSS class rather than targeting all buttons:
.standard-button {
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
cursor: pointer;
width: 100%;
opacity: 0.9;
width: 100px;
}
and then change places where you are rendering button elements to use:
<button className="standard-button">
instead of just <button>.
This worked for me
<IconButton style={{height:"45px",marginTop:"20px"}}>
<DeleteIcon/>
</IconButton>
Hi you can override ripple root and child style to change border radius or background color.
const useStyles = makeStyles({
root: {
borderRadius: 0, // <---- icon button root style
'.MuiTouchRipple-ripple .MuiTouchRipple-child': { // <----this should change ripple style when clicked or touched
borderRadius: 0,
backgroundColor: 'red'
},
},
});
<IconButton className={classes.rippleRoot}>
<WorkIcon />
</IconButton>
OR MUI5 with sx props
<IconButton
sx={{
borderRadius: 0,
'.MuiTouchRipple-ripple .MuiTouchRipple-child': {
borderRadius: 0,
backgroundColor: 'red',
},
}}
>
<WorkIcon />
</IconButton>
use height and width with same value to have circular shade on hover-
<IconButton sx={{height:"40px",width:"40px"}}>
<WorkIcon />
</IconButton>