semantic-ui-react Content goes under the menu when it's stackable - css

I have a main component
return (
<>
<NavBar />
<Container style={{marginTop: '7em'}}>
<List>
{accounts.map(account => (
<List.Item key={account.id}>
{account.id}
</List.Item>
))}
</List>
</Container>
</>
);
That contains a NavBar
import React from 'react';
import { Container, Icon, Menu } from 'semantic-ui-react';
export default function NavBar() {
return (
<Menu inverted fixed='top' stackable>
<Container>
<Menu.Item header>
<Icon name='chess pawn' size='large' />
Menu 1
</Menu.Item>
<Menu.Item name='Menu 2' />
<Menu.Item name='Menu 3' />
<Menu.Item name='Menu 4' />
<Menu.Item name='Menu 5' />
</Container>
</Menu>
)
}
This looks alright on desktop
but on mobile resolutions when the Menu stacks and some content goes behind it.
Is there any elegant way to address this issue?

In semantic-ui, when using fixed='top' on Menu, it is taken out of the flow of document due to position: fixed, which allows other content to go under it.
It is also the reason why a higher marginTop was needed on the content container to create some space on top.
Instead of fixed='top', try use a custom class (or inline style) for NavBar to apply position: sticky on it, so it is placed considering the flow but still stays in view as the window scrolls.
More about position: sticky
Live demo of the minimized example: stackblitz
Example:
.custom-nav {
position: sticky;
top: 0;
}
Add the className to NavBar:
import React from 'react';
import { Container, Icon, Menu } from 'semantic-ui-react';
export default function NavBar() {
return (
<Menu inverted stackable className="custom-nav">
<Container>
<Menu.Item header>
<Icon name='chess pawn' size='large' />
Menu 1
</Menu.Item>
<Menu.Item name='Menu 2' />
<Menu.Item name='Menu 3' />
<Menu.Item name='Menu 4' />
<Menu.Item name='Menu 5' />
</Container>
</Menu>
)
}
Alternatively, perhaps a sticky component by semantic-ui can be used to wrap NavBar for the same result, although it seems that it would result in an additional wrapper in the structure.
Hope this will help.

Related

how to antd menu horizontal mode

const Navigation =()=>{
return (
<>
<Menu mode={"horizontal"} style={{
display: 'flex',
justifyContent: 'space-around'}} theme={"light"}>
<Menu.Item key={"home"} >
홈
</Menu.Item>
<Menu.Item key={"message"}>
쪽지
</Menu.Item>
<Menu.Item key={"post"}>
게시판
</Menu.Item>
<Menu.Item key={"homepage"}>
홈페이지
</Menu.Item>
</Menu>
</>
)}
I use react js and antd.
I want to give the items Menu.Item justify-content as space-around. But it doesn't work like the picture. What should I do?
Menu.Item should be spaced evenly, but it doesn't.
you can just set the width of each Menu.Item to 25% and remove the styles from Menu.
but changing this is not a good idea i think, as it will break some menu behavior of antd. maybe leading to some unexpected behaviour.
const Navigation =()=>{
return (
<>
<Menu mode={"horizontal"} theme={"light"}>
<Menu.Item key={"home"} style={{ width: '25%' }}>
홈
</Menu.Item>
<Menu.Item key={"message"} style={{ width: '25%' }}>
쪽지
</Menu.Item>
<Menu.Item key={"post"} style={{ width: '25%' }}>
게시판
</Menu.Item>
<Menu.Item key={"homepage"} style={{ width: '25%' }}>
홈페이지
</Menu.Item>
</Menu>
</>
)}

div wrap for antd component

Hi i am having some trouble with Antd Space wrapping.
Sorry i'm an idiot with the css. Is there a css or style i can do to make it wrap to the next row?
This is within a <List.Item>
(Am ok to switch out the Space component to a normal div with appropriate css that can do the wrapping)
import { Card, Col, Row, Space } from 'antd';
<Space>
{ item.shares.reverse().map((share, i) => (
<SinglePost
share = {share}
height={300}
width={300}
/>
))}
</Space>
in SinglePost.js
return (
<Col span={8}>
<Card style={{ width: props.width, height: props.height }}
bordered={false}
>
<div className="approval-list-sub-box-holder-small">
<Player
playsInline
// src={currentData.content.video}
fluid={false}
height="100%"
width="100%"
>
. . .
</div>
</Card>
</Col>
)
This is the output currently but as you can see it might become too long on the width and becomes unviewable :(
Adding a wrap = true seems to work. For some reason i think i tried it just now but didn't.
Alternatively having a div with flex-wrap: wrap; also seem to work. i went with space for now.
<Space wrap = {true}>
{ item.shares.reverse().map((share, i) => (
<SinglePost
share = {share}
userId = {props.userId}
height={300}
width={300}
/>
))}
</Space>

How to make logo (image) responsive in React Ant design layout?

I'm using Ant design layout in my React App.
I have added header and sidebar, I have some issue on the logo, when I click the toggle, after that the logo is not responsive. How do I make it responsive?
Here is stazkblitz.
code
import React from 'react';
import ReactDOM from 'react-dom';
import 'antd/dist/antd.css';
import './index.css';
import { Layout, Menu } from 'antd';
import {
MenuUnfoldOutlined,
MenuFoldOutlined,
UserOutlined,
VideoCameraOutlined,
UploadOutlined,
} from '#ant-design/icons';
const { Header, Sider, Content } = Layout;
class SiderDemo extends React.Component {
state = {
collapsed: false,
};
toggle = () => {
this.setState({
collapsed: !this.state.collapsed,
});
};
render() {
return (
<Layout>
<Sider trigger={null} collapsible collapsed={this.state.collapsed}>
<div className="logo" />
<Menu theme="dark" mode="inline" defaultSelectedKeys={['1']}>
<Menu.Item key="1" icon={<UserOutlined />}>
nav 1
</Menu.Item>
<Menu.Item key="2" icon={<VideoCameraOutlined />}>
nav 2
</Menu.Item>
<Menu.Item key="3" icon={<UploadOutlined />}>
nav 3
</Menu.Item>
</Menu>
</Sider>
<Layout className="site-layout">
<Header className="site-layout-background" style={{ padding: 0 }}>
{React.createElement(this.state.collapsed ? MenuUnfoldOutlined : MenuFoldOutlined, {
className: 'trigger',
onClick: this.toggle,
})}
</Header>
<Content
className="site-layout-background"
style={{
margin: '24px 16px',
padding: 24,
minHeight: 280,
}}
>
Content
</Content>
</Layout>
</Layout>
);
}
}
ReactDOM.render(<SiderDemo />, document.getElementById('container'));
You can remove the <div> with background image (current implementation in the question) to show the logo.
And, use <img> with CSS to make it responsive.
CSS:
.logo {
width: 100%;
max-width: 169px;
height: 24px;
}
JSX:
<img
className="logo"
src="https://www.skysens.io/images/white-logo.png"
/>

React component won't align with react-bootstrap navbar

I'm trying to align and size a react component under a Navbar using react-bootstrap v0.33.1. I want the map to have the full width of the Navbar component and be centrally aligned beneath it. However, no matter how I place the component, it will do one of the following:
If I use the <Grid> and <Col> component to wrap the <Map> component, then the map is too far to the right.
export default function Map() {
return (
<Grid>
<Col md={12}>
<MapContainer />
</Col>
</Grid>
);
}
If I remove <Grid> and then I end up with the` component being the full width of my device screen.
export default function Map() {
return (
<MapContainer />
);
}
Here are the other components:
function MapContainer(props) {
const mapStyles = {
width: '100%',
height:'500px'
};
return (
<div>
<Map
google={props.google}
zoom={10}
// style={{
// width: "300px"
// }}
style={mapStyles}
initialCenter={{
lat: 47.6128856,
lng: -122.3631801
}}
/>
</div>
)
}
function App() {
return (
<div className="App container">
<Navbar fluid collapseOnSelect>
<Navbar.Header>
<Navbar.Brand>
<Link to="/">Skatespots</Link>
</Navbar.Brand>
<Navbar.Toggle />
</Navbar.Header>
<Navbar.Collapse>
<Nav pullRight>
{ isAuthenticated
? <NavItem onClick={handleLogout}>Logout</NavItem>
: <>
<LinkContainer to="/signup">
<NavItem>Signup</NavItem>
</LinkContainer>
<LinkContainer to="/login">
<NavItem>Login</NavItem>
</LinkContainer>
</>
}
</Nav>
</Navbar.Collapse>
</Navbar>
<AppContext.Provider value={{isAuthenticated, userHasAuthenticated}}>
<Routes />
</AppContext.Provider>
</div>
);
.App {
margin-top: 15px;
}
.App .navbar-brand {
font-weight: bold;
}
I do not know what the issue is and this simple issue is being such a pain. using a negative margin value seems like it'd be the wrong way to fix scenario 1 and using a fixed width with px seems like it wouldn't be dynamic for different screen sizes for scenario 2. Thanks.

cards in ant design for are floating over fixed nav bar

I made a single page app in react using ant design. I made the navbar on top fixed, now when scrolling the cards in the content are floating over the navbar.
Top menu/navbar code
import React,{Component} from 'react'
import {Layout, Menu, Row, Col, Icon} from 'antd'
import Logo from './Glogo.png'
const {Header}=Layout
const SubMenu = Menu.SubMenu;
const MenuItemGroup = Menu.ItemGroup;
export default class TopMenu extends Component{
render(){
return(
<Header style={{position: 'fixed', width: '100%' }}>
<img src={Logo} style={{height:"40px", width:"140px",
float:"left", marginTop:"10px"}}alt="Logo"/>
<Menu
theme="dark"
mode="horizontal"
style={{ lineHeight: '64px' }}
>
</Menu>
</Header>
)
}
}
In header i declared the position as fixed.
Content code:
import React, {Component} from 'react';
import {Layout, Card, Row, Col, List} from 'antd';
const {Content} = Layout;
class Dashboard extends Component{
constructor(props){
super();
this.state={
session_id:[
{
event:"underline",
timestamp:"10:30",
observation:["magnetic effect","flemings right hand rule","magnetic effect","flemings right hand rule","magnetic effect","flemings right hand rule","magnetic effect","flemings right hand rule","magnetic effect","flemings right hand rule"],
suggestions:["take a look at this concept", " watch this video"]
},
{
event:"underline",
time:"10:30",
observation:["magnetic effect","flemings right hand rule"],
suggestions:["take a look at this concept", " watch this video"]
},
{
event:"underline",
time:"10:30",
observation:["magnetic effect","flemings right hand rule"],
suggestions:["take a look at this concept", " watch this video"]
},
]
}
}
render(){
return(
<Content style={{ padding: '0 50px', marginTop: 64, minHeight: "calc(100vh - 128px)" }}>
<div style={{ background: '#fff', padding: 24, minHeight: 500, marginBottom:"30px" }}>
{this.state.session_id.map((val, i)=>
<Card key={i}hoverable style={{margin:"15px", boxShadow:"0 0 10px gray "}}>
<Row gutter={16}>
<Col xs={24} sm={24} md={8} lg={8} >
<Card title="Event" hoverable bordered={false}>
Name: {val.event}<br/>Time: {val.time}
</Card>
</Col>
<Col xs={24} sm={24} md={8} lg={8} >
<Card title="Observation" hoverable bordered={false}>
<List
size="small"
bordered
dataSource={val.observation}
renderItem={item => (<List.Item>{item}</List.Item>)}
/>
</Card>
</Col>
<Col xs={24} sm={24} md={8} lg={8} >
<Card title="Suggestions" hoverable bordered={false}>
<List
size="small"
bordered
dataSource={val.suggestions}
renderItem={item => (<List.Item>{item}</List.Item>)}
/>
</Card>
</Col>
</Row>
</Card>)}
</div>
</Content>
)
}
}
export default Dashboard;
The cards in the content are floating over the fixed header while the content itself is below the header.
I want the navbar to be on top of everthing else. What can i do.
May z-index will help you in your case.
<Header style={{position: 'fixed', width: '100%', zIndex: 100}}>

Resources