How to build a side toggle menu respond to header menu in React - reactjs

All:
Im pretty new to React, I wonder how can I implement a Header Menu + Side Menu component layout in React?
It should be something like:
Click the orange header menu item, according side menu(the dark grey part on the left, there is no the dark grey part shown initial, only show when click according item in the header menu) will show up, click same item again, it will slide left to toggle. And the content area will auto scale.
Any help about how to implement this will be appreciated, it does not have to be a total solution, somethign like how to click and side menu toggle slide out or how scale the right side when left side menu slide out, or something like that.
Thanks

Theres too much in this question to give a full answer. So I'm just going to give a simple layout design with no code. You should be able to write the code yourself with this setup as it should be very straight forward.
you need a main component that renders the Header, Sidebar and Content of the page.
the header main component needs to handle an open or closed state based on the header clicks. so header item onClick(this.props.onClick). the props.onClick is passed to the header component and the main component needs to capture that and set a state.
this.setState({sidebarOpen: !this.state.sidebarOpen}); this will sumulate a toggle effect on the state for the click. now when you render just set a className based on that state.
let sidebarClassname = this.state.sidebarOpen ? 'sidebar open' : 'sidebar';
let contentClassname = this.state.sidebarOpen ? 'content open' : 'content';
and pass that through on the render to your component.
<Sidebar className={sidebarClassname}
<Content className={contentClassname}
from here you should have the components rendering and the sidebar should be getting an active class when you click on the header. then you just need to style it
the layout itself should be fairly simple.
css
.header {
position: absolute;
top: 0;
left: 0;
right: 0;
height: 60px;
}
.sidebar {
position: absolute;
top: 60px;
left: -300px;
height: 100%;
width: 300px;
transition: left .3s ease-in-out;
}
.content {
position: absolute;
top: 60px;
left: 0;
right: 0;
height: 100%;
transition: left .3s ease-in-out;
}
that should be pretty straight forward. you need to position the sidebar out of the page and the content needs to fill the page
the cool part here is when you get an active class (i.e open) you should be able to adjust the left position to create the slide in effect (because we added the css transition on the left property.
.sidebar.open {
left: 0;
}
.content.open {
left: 300px;
}
Sample Fiddle

Related

Can't absolute position an image in Swiper.js

I am trying to position an image inside a Swiper slider, and I need it to overflow the Swiper Container which has an overflow of hidden and display it on the bottom of another container. I am wondering is this possible to achieve?
see actual design
I have tried setting the Swiper Container to:
overflow: hidden;
and the .swiper-slide to:
.swiper-slide {
opacity: 0;
visibility: hidden;
transition: opacity 200ms ease-in-out, visibility 200ms ease-in-out;
}
so when the next slide come into play I trigger it back with:
.swiper-slide-active {
opacity: 1;
visibility: visible;
}
sadly this method makes the scroll bar appear on the bottom of the page...
see screenshot example here
also I made a Codesandbox to keep the things simple see codesandbox example

How to add scroll in the framer-motion expandable card example?

click one of the card
the card expands and pops up
tried to scroll but only scrolling the background page while I wanted to scroll down to view more text
I already tried overflow:hidden which doesn't scroll ( and the scroll bar is ugly)
How can I solve this ? thank you very much !
https://codesandbox.io/s/framer-motion-animatesharedlayout-app-store-demo-i1kct?from-embed
It looks like a few things are preventing the scroll:
height: auto sizes the container to fit the content.
overflow: hidden instead of scroll.
pointer-events: none prevents the element from getting the scroll events.
Changing this block in styles.css:
.open .card-content {
height: auto;
max-width: 700px;
overflow: hidden;
pointer-events: none;
}
to this:
.open .card-content {
max-width: 700px;
overflow-y: scroll;
}
seems to work.

How to customize a ui-grid table?

I am trying to customize the grid menu for angular ui grid
By default the menu icon appears in the top right corner of the table. But i want to show it on the top left corner of the table. How can i configure this?
Also I want to change the default icon to a customized one.
This is not something supported by the API, so you will have to do it by changing some of the CSS:
.ui-grid-menu-button {
left: -21px;
width: 20px;
}
.ui-grid-menu-button .ui-grid-menu{
left: -11px;
top: 27px;
}
To change the icon you will have to edit:
.ui-grid-icon-menu:before {
content:'\c363';
}
to whatever you want.

angular-google-map-container flows off screen with Ionic and Angular

I'm building a SPA with Ionic and Angular. My map shows up just fine when it takes up the full screen (i.e., ion header + map only) but in one of my screens, I'm trying to show the ion header + a form + the map so that the map would only occupy ~50% (~325px) of the screen. My issue is that, for this screen, the map still takes on the full screen height (~625px) so that ~50% of the map exists off-screen.
My current structure looks as follows:
ionic nav bar
formContainer div (height determined by contents) wraps the form
mapContainer div (height set to fill the rest of the visible screen via flex box) wraps the map
I think that my issue is caused by this css styling:
.angular-google-map {
height: 100%;
}
.angular-google-map-container {
position: absolute;
height: 100%;
width: 100%;
}
My hypothesis is that the height gets set to 100% (~625px) before the mapContainer div can determine its height (~325px). Has anyone had any luck wrapping a map so that its height only takes up the visible div?
Try to set top and left. Also remember that ionic adds a new scroll class to your content
.map-container .scroll{
height: 100%;
}
.angular-google-map-container {
height: 100%;
width: 100%;
position: absolute;
top: 0;
left: 0;
}

Adding things above and below bootstrap fixed navbar

I am trying to add a banner above my fixed-top navbar. I have looked around and understand some basic concepts on how to do this but my example is a little more complex and I am getting a little lost.
User can add a custom banner to the top of my page. If this happens I need to push everything (including the fixed navbar) down the height of the banner (say 20 px).
I have created a class that I can apply to the nav element:
.top-banner-nav {
top: 20px;
}
Navbar:
<nav class="navbar navbar-default navbar-fixed-top" ng-class="{'top-banner-nav': banner == true}">
That works great to push the static navbar down 20px if there is a banner. However I have to problems.
When you have a static navbar like this you have to add a top padding to the body to push the body content below the banner. Now all of the sudden I would need to push the body content down 70px. Not sure if there is a good way to make this happen dynamically.
I have another static navbar directly underneath the very top navbar. When I move the very top navbar down 20px I need to move this other navbar down 20px as well. Unfortunately this lower nav is fixed as well with top: 50px to place it right below the upper navbar.
I have a plunker here that demonstrates the problem. And I am not really sure where to go from here. Might have to mess with things in javascript, but I would like to try and avoid that is at all possible to avoid things jumping around on page load.
http://plnkr.co/edit/DYYMz1?p=preview
I looked at your plunker. I made some changes to your CSS and HTML to accomplish what you are looking for. The change I made to the HTML was the body tag. The new tag looks like this:
<body ng-controller="MainController" ng-class="{'bodyModified': banner == true}">
The new CSS file looks like this:
body {
padding-top: 50px; Need this to move down body under fixed header
}
.bodyModified {
padding-top: 20px;
}
.settings-nav {
position: relative;
right: 0;
left: 0;
background-color: #E2E2E2;
z-index: 1029;
top:0px;
}
.settings-content {
padding-top: 70px;
}
.top-banner-nav {
position: relative;
margin: 0;
height: 20px;
}
.top-banner {
position: fixed;
right: 0;
left: 0;
top:0;
margin-bottom: 0px;
background-color: #FFFF00;
}
You can also use javascript and jQuery to accomplish this as well. Hope that helps. Let me know how it goes.
Here is a plunker demonstrating the changes
http://plnkr.co/edit/39LhQA2gdMremnTOGXe4?p=preview
you can try jquery solution for this.for example if you are using top-nav-fixed-banner class you can code something like this.
function fixBannerHeight(){
var bannerHeight = $(".top-banner-div").height();
$(".top-nav-fixed-banner").each(function(e){
var height = $(this).height();
bannerHeight = bannerHeight + height;
})
$('.top-banner-div').css({"height":bannerHeight+"px"});
}
call fixBannerHeight() when you are adding dynamically banner.
Hope this helps.

Resources