React-leaflet when i introduce a drop down menu at top, its hidden behind the map when i drop it down. Any help will be appreciated. Below is a screen shoot of how its rendering on my front
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import { Map, TileLayer, Marker, Popup } from 'react-leaflet';
import 'leaflet/dist/leaflet.css'
const position = [-0.29008, 3.81987]
class App extends Component {
render() {
return (
<div>
<div className='form-row'>
<div className='form-group col-md-12'>
<Select
placeholder='Search a single Fleet'
options={[{ value: 'clear', label: 'Clear Search' }, ...options]}
key={'show'}
onChange={(e) => {
if (e.value === 'clear') setTheVehicle(undefined)
else setTheVehicle(e.value)
}}
/>
</div>
</div>
<Map center={position} zoom={13}>
<TileLayer
url='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'
attribution='© OpenStreetMap contributors'
/>
<Marker position={this.state.center}>
<Popup>
A pretty CSS3 popup. <br /> Easily customizable.
</Popup>
</Marker>
</Map>
</div>
);
}
}
const rootElement = document.getElementById('root');
ReactDOM.render(<App />, rootElement);
Rather little lazy answer but took me ages :
Check new style on first <div>
<div className='form-row' style={{position: 'relative', z-index: 999}}>
<div className='form-group col-md-12'>
<Select
placeholder='Search a single Fleet'
options={[{ value: 'clear', label: 'Clear Search' }, ...options]}
key={'show'}
onChange={(e) => {
if (e.value === 'clear') setTheVehicle(undefined)
else setTheVehicle(e.value)
}}
/>
</div>
</div>
Related
I have a simple div which uses react-tooltip
Inside the tooltip I am trying to render kendo progress bar but it doesn't seem to be working, the bar is shown but the progress is not shown
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import ReactDOMServer from 'react-dom/server';
import 'react-tooltip/dist/react-tooltip.css'
import { Tooltip as ReactTooltip } from 'react-tooltip'
import { ProgressBar } from '#progress/kendo-react-progressbars';
const App = () => {
const TooltipContentTemplate = () => {
return <div>
<ProgressBar value={20} labelVisible={false}/>
</div>
};
return (
<div className="container">
<div className="row mb-4" id="1"
data-tooltip-html={ReactDOMServer.renderToString(<TooltipContentTemplate></TooltipContentTemplate>)}>
Hello World
</div>
<ReactTooltip style={{zIndex:"10", backgroundColor:"black",color:"black",width:"200px",height:"300px",border:'1px solid black'}} anchorId="1"/>
<div>
<ProgressBar value={20} labelVisible={false}/>
</div>
</div>
);
};
ReactDOM.render(
<App />,
document.querySelector('my-app')
);
Without hover on Hello World
On hover
I am trying with above code
This seems to be an issue related to the usage of ReactDOMServer.renderToString(), not sure what though.
You can try putting the tooltip content inside the tooltip component directly, instead of using data-tooltip-html on the anchor.
Your code updated:
import * as React from "react";
import * as ReactDOM from "react-dom";
import "react-tooltip/dist/react-tooltip.css";
import { Tooltip as ReactTooltip } from "react-tooltip";
import { ProgressBar } from "#progress/kendo-react-progressbars";
const App = () => {
const TooltipContentTemplate = () => {
return (
<div>
<ProgressBar value={20} labelVisible={false} />
</div>
);
};
return (
<div className="container">
<div className="row mb-4" id="1">
Hello World
</div>
<ReactTooltip
style={{
zIndex: "10",
backgroundColor: "black",
color: "black",
width: "200px",
height: "300px",
border: "1px solid black"
}}
anchorId="1"
>
{/* tooltip content here */}
<TooltipContentTemplate></TooltipContentTemplate>
</ReactTooltip>
<div>
<ProgressBar value={20} labelVisible={false} />
</div>
</div>
);
};
ReactDOM.render(<App />, document.querySelector("my-app"));
I have a video on my site that I want to be paused when I scroll it and play only when its visible. I have tried some solutions from internet but things are not working out.
This is my current code. I have tried out a solution from stackoverflow which shows me observe error. I would be glad if someone helps me out on this. Thank you.
Player.js
import { Box, Container } from "#mui/system";
import React, { useEffect, useRef, useState } from "react";
import ReactPlayer from "react-player";
import styled from "styled-components";
import videosample from "./homepagevideo.mp4";
const ResponsiveStyledPlayer = () => {
const Player = ({ className }) => (
<ReactPlayer
url={videosample}
className={className}
playing={true}
autoplay={true}
width="100%"
height="100%"
controls={false}
muted
loop={true}]
/>
);
const AbsolutelyPositionedPlayer = styled(Player)`
position: absolute;
top: 0;
left: 0;
`;
const RelativePositionWrapper = styled.div`
position: relative;
padding-top: 56.25%;
`;
return (
<Box>
<Container>
<RelativePositionWrapper>
<AbsolutelyPositionedPlayer />
</RelativePositionWrapper>
</Container>
</Box>
)
};
export default ResponsiveStyledPlayer;
you can you Waypoint for your requirement. I have made one demo for you, you can refer to that. Link Demo
import React, { useState } from 'react';
import ReactPlayer from 'react-player/youtube';
import { Waypoint } from 'react-waypoint';
import './style.css';
export default function App() {
let [shouldPlay, updatePlayState] = useState(false);
let handleEnterViewport = function () {
updatePlayState(true);
};
let handleExitViewport = function () {
updatePlayState(false);
};
return (
<div>
<Waypoint onEnter={handleEnterViewport} onLeave={handleExitViewport}>
<div>
<ReactPlayer
playing={shouldPlay}
url="https://www.youtube.com/watch?v=ysz5S6PUM-U"
/>
</div>
</Waypoint>
<h1>hii</h1>
<br />
<h1>hii</h1>
<br />
<h1>hii</h1>
<br />
<h1>hii</h1>
<br />
<h1>hii</h1>
<br />
<h1>hii</h1>
<br />
<h1>hii</h1>
<br />
<h1>hii</h1>
<br />
<h1>hii</h1>
<br />
</div>
);
}
I'm facing with a problem that I can't get my current location by react-leaflet v4.0.1 and react v18.2.0 when the project has been deployed on IIS.
I Just can get the current location when node js is running on localhost/register but not on domain example.com/register.
maybe its CROS origin problem but I dont know how to handle it by domain
name.
it workes well:
but it has problem with domain:
in Map.js
import React, { useEffect, useState } from 'react'
import { MapContainer, TileLayer, Marker, Popup, useMap } from 'react-leaflet'
import 'leaflet/dist/leaflet.css'
import L from 'leaflet'
import icon from './constants'
export default function App() {
function LocationMarker() {
const [position, setPosition] = useState(null)
const [bbox, setBbox] = useState([])
const map = useMap()
useEffect(() => {
map.locate().on('locationfound', function (e) {
setPosition(e.latlng)
map.flyTo(e.latlng, map.getZoom())
setBbox(e.bounds.toBBoxString().split(','))
})
}, [map])
return position === null ? null : (
<Marker position={position} icon={icon}>
<Popup>
You are here. <br />
Map bbox: <br />
<b>Southwest lng</b>: {bbox[0]} <br />
<b>Southwest lat</b>: {bbox[1]} <br />
<b>Northeast lng</b>: {bbox[2]} <br />
<b>Northeast lat</b>: {bbox[3]}
</Popup>
</Marker>
)
}
return (
<MapContainer
center={[35.1951, 51.6068]}
zoom={13}
scrollWheelZoom
style={{ height: '50vh' }}
>
<div style={{ height: '50vh' }}>
<TileLayer
attribution='© OpenStreetMap contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
<LocationMarker />
</div>
</MapContainer>
)
}
Hi i can't figure out how to set up the onclick function for the action below for Antd Card. Could someone help me pls? thanks.
const expand = () =>{
console.log("expand")
}
const IconText = ({ icon, text, cb }) => (
<Space>
<div onClick={e => cb}>
{React.createElement(icon)}
{text}
</div>
</Space>
);
<Card style={{ width: props.width, height: props.height }}
actions={[
<IconText icon={ExpandOutlined} text="Expand" key="list-vertical-star-o" cb={()=>expand}/>,
<IconText icon={MessageOutlined} text="Comments" key="list-vertical-like-o" />,
]}
>
https://ant.design/components/card/
see the callbacks ( Working codesandbox)
cb = {
() => {
expand("Comments");
}
}
also while binding:
<div onClick={e=> cb}>
import React from "react";
import ReactDOM from "react-dom";
import "antd/dist/antd.css";
import "./index.css";
import { Card, Avatar, Space } from "antd";
import {
EditOutlined,
EllipsisOutlined,
SettingOutlined
} from "#ant-design/icons";
const { Meta } = Card;
const IconText = ({ icon, text, cb }) => (
<Space>
<div onClick={cb}>
{/*React.createElement(icon)*/}
{text}
</div>
</Space>
);
const expand = (text) => {
console.log("expand", text);
};
ReactDOM.render(
<Card
style={{ width: 300 }}
cover={
<img
alt="example"
src="https://gw.alipayobjects.com/zos/rmsportal/JiqGstEfoWAOHiTxclqi.png"
/>
}
actions={[
<IconText
text="Expand"
key="list-vertical-star-o"
cb={() => {
expand("Comments");
}}
/>,
<IconText text="Comments" key="list-vertical-like-o" />,
<SettingOutlined key="setting" />,
<EditOutlined key="edit" />,
<EllipsisOutlined key="ellipsis" />
]}
>
<Meta
avatar={
<Avatar src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png" />
}
title="Card title"
description="This is the description"
/>
</Card>,
document.getElementById("container")
);
I have a component of "Drawer", I am opening and closing this drawer with component state and passing this state down to the Drawer Component and Also passing a callback function that can help me to close the drawer,
Now the issue is that when ever I am trying to open that drawer, the whole ui is disappearing. Need help
here is the code
import IconButton from '#material-ui/core/IconButton';
import MenuIcon from '#material-ui/icons/Menu';
import Drawer from '../Drawer';
import Header from '../Header';
export default class LandingPage extends Component {
constructor() {
super();
this.state = {
openDrawer: false,
};
}
handleDrawer = (state) => {
this.setState({
openDrawer: state,
});
};
render() {
return (
<div className='landing-page-container'>
<div className='menu-btn'>
<IconButton
edge='start'
color='inherit'
aria-label='menu'
onClick={() => this.handleDrawer(true)}
>
<MenuIcon />
</IconButton>
</div>
<Drawer
handleDrawer={this.handleDrawer}
openDrawer={this.state.openDrawer}
/>
</div>
);
}
}
Here is Drawer
import React, { Component } from 'react';
import {
Drawer,
IconButton,
Divider,
List,
ListItem,
ListItemIcon,
Button,
ListItemText,
makeStyles,
} from '#material-ui/core';
import { withStyles } from '#material-ui/core/styles';
import {
ChevronLeft,
NoteAdd,
Person,
PersonAdd,
AttachMoney,
Build,
Settings,
} from '#material-ui/icons';
const styles = makeStyles((theme) => ({
root: {
display: 'flex',
},
drawerPaper: {
backgroundColor: theme.primary,
},
}));
export class DrawerMenu extends Component {
render() {
const { classes, openDrawer, handleDrawer } = this.props;
return (
<div className='drawer-container'>
<Drawer
variant='persistent'
anchor='left'
open={false}
classes={{
paper: classes.drawerPaper,
}}
backgroundColor='primary'
>
<div className='logo-icon'>
<div className='logo'>Logo</div>
<div className='collapse-icon'>
<IconButton onClick={() => handleDrawer(false)}>
<ChevronLeft />
</IconButton>
</div>
</div>
<Divider />
<div className='drawer-menu-container'>
<div className='drawer-menu'>
<List>
{[
'Booking',
'Positions',
'User Management',
'Trading',
'Instruments',
].map((text, index) => (
<ListItem button key={text}>
<ListItemIcon>
{index === 0 && <NoteAdd />}
{index === 1 && <Person />}
{index === 2 && <PersonAdd />}
{index === 3 && <AttachMoney />}
{index === 4 && <Build />}
</ListItemIcon>
<ListItemText primary={text} />
</ListItem>
))}
</List>
<Divider />
</div>
<div className='drawer-action-button'>
<div className='setting-logout'>
<div className='setting'>
<Settings />
</div>
<div className='logout'>
<Button variant='contained' color='primary'>
Logout
</Button>
</div>
</div>
</div>
</div>
</Drawer>
</div>
);
}
}
export default withStyles(styles, { withTheme: true })(DrawerMenu);
Your problem could be related to the fact that your Drawer is not on a Fragment. Try to modify your Drawer component code like:
import React, { Component, Fragment } from 'react'; //<-- import Fragment
...
export class DrawerMenu extends Component {
render() {
<div className='drawer-container'>
<Fragment>
<Drawer
variant='persistent'
anchor='left'
open={false}
classes={{
paper: classes.drawerPaper,
}}
backgroundColor='primary'
>
...
</Drawer>
</Fragment>
</div>
};
}
This should solve your problem.