I would like to render some header/title for time picker to indicate this is HH, MM and SS (Which is Hour, Minute, Sec) but unable to do.
I can achieve it by only renderExtraFooter which renders at the bottom of the picker but I need it on the top of the time picker. You can check the code below:
https://stackblitz.com/edit/react-j1kksn-ef4m56?file=index.js
Some of the users feels hard to find which is hour, minute and seconds. It would be better to have that option.
import React from "react";
import ReactDOM from "react-dom";
import "antd/dist/antd.css";
import "./index.css";
import { TimePicker } from "antd";
const onChangeTime = time => {
console.log(time);
};
ReactDOM.render(
<TimePicker
onChange={onChangeTime}
renderExtraFooter={() => (
<div className="timePickerHeader">
<p>HH</p>
<p>MM</p>
<p>SS</p>
</div>
)}
/>,
document.getElementById("container")
);
.timePickerHeader {
position: float;
}
.timePickerHeader p {
display: inline-block;
width: 33%;
}
Looks like there is no header option, but you can change the style to make the footers align with their respective column. Use a grid column layout.
Avoid using <p> and position:float and display:inline-block in favor of <div> with display:grid and display:flex.
renderExtraFooter={() => (
<div className="timePickerHeader">
<div>HH</div>
<div>MM</div>
<div>SS</div>
</div>
)}
.ant-picker-footer-extra {
padding-left: 7px;
}
.timePickerHeader {
display: grid;
grid-auto-flow: column;
}
.timePickerHeader div {
padding-left: 14px;
text-align: left;
}
Note: The CSS above can be simplified to the following, if you just want to center the text within each column.
.ant-picker-footer-extra {
padding: 0;
}
.timePickerHeader {
display: grid;
grid-auto-flow: column;
}
.timePickerHeader div {
text-align: center;
}
Related
I have created a product carousel with react, it has 10 products, but I only want a max of 4 products to display at any one time, I tried reducing the width but that didn't work. Also had a look at the documentation for the carousel but couldn't find a solution for this https://www.npmjs.com/package/pure-react-carousel#component-properties-props
This is the git repo for the carousel https://github.com/RMP1992/react-product-carousel
react Carousel component
import React from 'react';
import {data} from'../data/data';
import { CarouselProvider, Slider, Slide, ButtonBack, ButtonNext, Image } from 'pure-react-carousel';
import './Carousel.css';
import Card from './Card';
export default class extends React.Component {
render() {
return (
<CarouselProvider
naturalSlideWidth={100}
naturalSlideHeight={125}
currentSlide={4}
totalSlides={10}
visibleSlides={4}
>
<Slider>
{data.map(item =>(
item.carouselData.map(product => (
<Slide >
<Image><img src={product.productImageUrl}/></Image>
<p>{product.name}</p>
<p>£{product.price.formattedValue}</p>
</Slide>
))
))}
</Slider>
<ButtonBack>Back</ButtonBack>
<ButtonNext>Next</ButtonNext>
</CarouselProvider>
);
}
}
CSS
.image___xtQGH {
display: block;
}
.carousel__slide {
list-style-type: none;
padding-bottom: unset !important;
width: 306px !important;
border: black solid 1px;
margin: 0 10px !important;
}
.carousel__slider-tray {
display: flex;
flex-direction: row;
}
I see you haven't imported their css yet.
Add this line to your App component and delete all your custom css as well. I think everything will work just fine.
import "pure-react-carousel/dist/react-carousel.es.css";
You can use Array#filter method to take first n elements from array.
{data.filter((item, index) => index < 4).map(item =>(
item.carouselData.map(product => (
<Slide >
<Image><img src={product.productImageUrl}/></Image>
<p>{product.name}</p>
<p>£{product.price.formattedValue}</p>
</Slide>
))
))}
Also, you can use lodash take method
https://lodash.com/docs/4.17.15#take
I have an Button that I want to animate :after and ::before width onMouseOver from 0% to 50%,
and when onMouseLeave from 50% to 0
i'm using react-hooks but it's working only onMouseOver
what is my problem ?
my code in this link
https://codesandbox.io/s/cold-haze-t7b4c
You could animate things with the following using styled components. Although you could do the same with just the padding instead of using :before and :after.
File: Button.js
import styled from "styled-components";
const Button = styled.button`
display: flex;
line-height: 30px;
padding: 0;
&:before,
&:after {
display: block;
width: 0px;
content: "";
transition: all 250ms ease-in-out 0s;
}
&:hover {
&:before, &:after {
width: 50px;
}
}
`;
export default Button;
File: App.js
import React from "react";
import "./styles.css";
import Button from "./Button";
export default function App() {
return (
<div className="App">
<Button>Hover Me</Button>
</div>
);
}
Scrollbar and scrolling is disable in parent element (with "overflow-y" set to "scroll") inside the component in Router children , Why its behaving like this and how do i prevent it / make it work?
live demo here: https://codesandbox.io/s/priceless-johnson-1fkju
import React from "react";
import { Router } from "#reach/router";
import Chats from "./Chats";
import { TopBar, AndroidControls } from "../components/shared";
const Routing = () => {
return (
<div className="app-wrapper">
<TopBar />
{* <section className="content"> *} // So i tested this, the section element need to be outside of the router comp for it to work , why?
<Router>
<Chats path="/" />
</Router>
{/* </section> *}
<AndroidControls />
</div>
);
};
export default Routing;
The problem is with your CSS
Slightly modify you css
from this
.content {
width: 100%;
height: calc(100% - 22rem);
padding-bottom: 4.9rem;
background-color: #fff;
overflow-y: scroll;
}
to this
.content {
width: 100%;
height: 80vh; /*Changed the height value*/
padding-bottom: 4.9rem;
background-color: #fff;
overflow-y: auto; /*Changed to auto*/
}
CodeSandbox modified
I'm building a new project using reactJS, nodeJS, and react-bootstrap. When setting up my landing page. There is a gap in the margin on the right side of the page that won't go away, no matter what I try.
.I've tried including the meyer's reset css file in the index.html.
.I've tried setting margins, borders, and padding on the Body element to zero.
.I've tried setting my Container to width: 100%.
.I've tried resizing the background image.
.I've tried including the bootstrap 4 cdn in my index.html.
App.js
import React, { Component } from 'react';
import { BrowserRouter as Router, Route, Switch } from "react-router-dom";
import LandingPage from './components/landingpage';
import Header from './components/header';
import Footer from './components/footer';
import './App.css';
class App extends Component {
render() {
return (
<Router>
<Header/>
<Switch>
<Route exact path='/' component={LandingPage}/>
</Switch>
<Footer/>
</Router>
);
}
}
export default App;
App.css
/* {
box-sizing: border-box;
}*/
body {
background-image: url('./images/background.jpg');
background-repeat: no-repeat;
background-position: center center;
/*background-size: cover;*/
font-family: 'Courgette', cursive;
color: beige;
font-size: 28px;
text-align: center;
max-width: 100%;
margin: 0;
border: 0;
padding: 0;
}
.container {
margin: 0;
padding: 0;
width: 100%;
}
.courgette {
font-family: 'Courgette', cursive;
}
.lobster {
font-family: 'Lobster', cursive;
}
header.js
import React from "react";
import './header.css';
import { Container, Row, Col } from 'react-bootstrap';
import { Link } from "react-router-dom";
const Header = () => {
return(
<Container className='header'>
<Row>
<Col>
<Link href="#">
<img className='hamburgermenu' src={require('./../../images/navbaricon.png')} alt='Hamburger Menu Icon'/>
</Link>
</Col>
<Col>
<h1>MDNight</h1>
</Col>
<Col>
<p>Hello!</p>
</Col>
</Row>
</Container>
)
}
export default Header;
header.css
.header{
background-color: maroon;
margin: 0;
}
.hamburgermenu {
height: 80px;
width: auto;
}
The header is supposed to extend to the edge of the page, but it does not.
There is any margin gap in the application.
I have a WhiteBox react component which simply renders a white box with some styles.
I have a SmallBox react component which simply uses WhiteBox to render a more specific box.
I have a Content react component which renders three SmallBox boxes which does what it's supposed to do (renders three white boxes).
However when I tried to add a text as a props from the parent, the white box is aligned with some unexpected margin from top.
NOTE: when I simply put "This is a text" the css is okay, but when I send "this is a text" as props.text, the whitebox is rendered with extra margin from top.
I Use styled-components and react as I said.
I've tried to console.log the text, and everything seems to be okay. I also tried to switch the props.children or props.text and it does not work
-----------------White Box Component ----------------------
import styled from "styled-components";
const StyledBox = styled.div`
display: inline-block;
width: ${props => props.width}px;
height: ${props => props.height}px;
margin-right: ${props => props.marginRight}px;
margin-left: 100px;
background-color: white;
border-radius: 5px;
font-size: 13px;
font-weight: 700;
text-transform: uppercase;
color: #646777;
padding: 10px;
`;
const WhiteBox = props => {
return (
<StyledBox
width={props.width}
height={props.height}
marginRight={props.marginRight}
>
{props.text} // if I change this to simply "this is a text" it works well. somehow the props.text is causing problems.
</StyledBox>
);
};
export default WhiteBox;```
-----------------Small Box Component ----------------------
import React from "react";
import styled from "styled-components";
import WhiteBox from "../whitebox/white-box";
const SmallBox = props => {
return (
<WhiteBox width={320} height={130} marginRight={70} marginLeft={70} text={props.text}>
</WhiteBox>
);
};
export default SmallBox;
-----------------Content Component ----------------------
import React, { Component } from "react";
import SmallBox from "./smallbox/small-box";
import styled from "styled-components";
const StyledContent = styled.div`
position: absolute;
left: 320px;
top: 80px;
width: 100%;
height: 100%;
background-color: #f1f3f7;
`;
class Content extends Component {
render() {
return (
<>
<StyledContent>
<SmallBox text="this text is great" /> // causing problem
<SmallBox />
<SmallBox />
</StyledContent>
</>
);
}
}
export default Content;
The issue has to do with how many lines are rendered. The longer the text in the props, the more the lines rendered.
One solution would be to change the display property for WhiteBox:
const StyledBox = styled.div`
display: inline-flex;
....
`;
Another solution would be to override the default style vertical-align: baseline, simply add vertical-align: top;
const StyledBox = styled.div`
display: inline-block;
....
vertical-align: top;
`;