how can I resize the Components when window size change in my NavBar? - navbar

I'm new to ReactJs now learning the react-bootstrap and trying to learn the NavBar. I made a CodeSandbox.
I really like the design like this:
The NavBar is set to fixed="top" so it's always visible when user scroll.
When I change the size of the window the NavBar get higher I try setting css like:
.NavBar {
max-height: 80px;
}
But Buttons and all components jump around wrapping making NavBar larger and not very good looking.
how can I resize the Components when window size change?
I see many pages uses different NavBar layouts and switch between them when window is resized. Is that done using css or should I create another React Component another NavBar and replace NavBar depending on window size?

I see many pages uses different NavBar layouts and switch between them
when window is resized. Is that done using css or should I create
another React Component another NavBar and replace NavBar depending on
window size?
In React-bootstrap (or any Bootstrap library), this functionality is already provided for you. This is generally the job of Navbar.Toggle & Navbar.Collapse. Basically, this enables you to switch from the desktop view - wherein all the Nav Items are displayed on the header versus on the mobile view wherein majority of the Nav Items are inside a Dropdown which is toggleable via the Navbar.Toggle (Hamburger) Button.
So in short, my suggestion is to leverage the already available functionality of React-bootstrap regarding toggling between the desktop view and mobile view.
return (
<>
<Navbar
expand="xl"
bg="dark"
variant="dark"
fixed="top"
collapseOnSelect
>
<Container fluid>
<Navbar.Brand href="#home" className="img-container">
<img alt="" src={logo1} />
</Navbar.Brand>
<Navbar.Toggle
aria-controls="responsive-navbar-nav"
onClick={toggle}
/>
<Navbar.Collapse id="basic-navbar-nav">
<Col>
<Nav.Item>
<Form inline>
<FormControl
type="text"
placeholder="Search Title, event, date"
className="mr-sm-2 m-1"
size="lg"
/>
<Button className="m-1" variant="outline-info" size="lg">
Search
</Button>
</Form>
</Nav.Item>
</Col>
<Col md="auto">
<Button className="m-1" variant="primary" size="lg">
Articles
</Button>
<Button className="m-1" variant="primary" size="lg">
Timeline
</Button>
<Button className="m-1" variant="primary" size="lg">
About
</Button>
</Col>
</Navbar.Collapse>
</Container>
</Navbar>
</>
);
In retrospect, you should also be able to assess that on mobile, the screen is too small so forcing in the Nav Items to be shown right away will block majority of the viewport - potentially causing UI/UX issues.
If you opt to disregard that and absolutely must place all of these items in the header even on mobile, you can always use media queries.
Example is on your image which I recommend you resize on small devices:
#media (max-width: 991px) {
.navbar .navbar-brand {
max-width: 280px;
}
}
You can refer here to the Bootstrap break points: https://getbootstrap.com/docs/4.5/layout/overview/#containers
Refer here for React-bootstrap Navbar documentation: https://react-bootstrap.github.io/components/navbar/#navbars

Related

Change Mat-drawer State on Window Resize

I want the "Setting" drawer to respond to window resize like it does on this settings page.
Taking a look at their style elements, I can see a lot of mat-drawer css classes that (I presume) handle the drawer's state and events:
mat-drawer mat-drawer-side mat-drawer-open etc.
Is there documentation on these css classes on how they function? Are they even Material classes?
Trying this, I would ignorantly expect the side-nav to be open by default without using opened on mat-drawer but it does not work.
<mat-drawer-container
class="mat-drawer-container flex-auto sm:h-full mat-drawer-transition mat-drawer-container-has-open">
<mat-drawer #drawer class="mat-drawer sm:w-96 dark:bg-gray-900 mat-drawer-side mat-drawer-opened"
style="transform: none; visibility: visible;">
<p>Sidenav open</p>
</mat-drawer>
<button type="button" mat-button (click)="drawer.toggle()">
Toggle sidenav
</button>
</mat-drawer-container>
I would like to achieve this drawer functionality with a similar method like theirs without using Angular HostListener decorator like this.

How to link Button to another page in react JS?

Hi guys so I'm trying to use button in my react-bootstrap app and what that button do is everytime user click the button it will redirect the user to another page of the web-app. But for some reason it didn't work, can anyone help me please ? my router already work for other components such as header, footer, etc. But it didn't work for the Button.
Here's my code:
<Container fluid>
<Row className="Aboutus">
<Col sm={12} lg={6}>
<h1>About Us</h1>
<hr style={{border:'2px solid', color:'#10255A', width:'25.7%'}}></hr>
<p>The hotel itself possess a trendy design with attention to comfort,
quality and value based accommodation.
</p>
<button as={Link} to={"/Room"}>See Room</button>
</Col>
<Col sm={12} lg={6}>
<img src="#"></img>
</Col>
</Row>
</Container>
You would need to use bootstrap <Button> instead of native HTML <button> for that and change href instead of to:
<Button as={Link} href={"/Room"}>
See Room
</Button>;
Live Example:
You will need to open sandbox URL in another tab to see url change
Because you are using normal button, not Button in react-bootstrap.
Just update it
<Button as={Link} to={"/Room"}>See Room</Button>
Another option and just to take advantage of the native link component without using the Button component, is to use the bootstrap classes(which support styling a tags as a button):
<Link to="/Room" className="btn btn-primary">
See Room
</Link>

Handling overflowing components with semantic ui react

I am building a web app using next.js with react and semantic-ui-react for the styling, and I am trying to build a basic layout comprising of a fixed sidebar for navigation and the page content next to it. Initially I was trying to use the Sidebar component but could not get this to work. A user online suggested it's more for mobile usage, so I changed to using a Menu component with the vertical and fixed properties.
I now have a fixed menu but the main page content does not start beside it -- instead it starts behind the menu. The content is inside a container which has an auto margin working from the edge of the document/page, behind the menu.
Things I have tried:
Using dev-tools and adding padding-left to the content container fixes the issue but if I resize the page the issue returns -- it's not adaptive/responsive.
Using a grid -- I have added a grid to the components but it has made no difference.
Relevant code:
_app.js
<div>
<Head>
<title>Thoughts!</title>
</Head>
<Grid>
<Grid.Row>
<Grid.Column>
<FixedMenuLayout></FixedMenuLayout>
</Grid.Column>
<Grid.Column>
<Component {...props} />
</Grid.Column>
</Grid.Row>
</Grid>
</div>
FixedMenu.js
<Menu fixed='left' inverted vertical>
<Container>
<Menu.Item as='a' header>
<Image size='mini' src='/logo.png' style={{ marginRight: '1.5em' }} />
Project Name
</Menu.Item>
<Menu.Item as='a'>Home</Menu.Item>
<Dropdown item simple text='Dropdown'>
<Dropdown.Menu>
<Dropdown.Item>List Item</Dropdown.Item>
<Dropdown.Item>List Item</Dropdown.Item>
<Dropdown.Divider />
<Dropdown.Header>Header Item</Dropdown.Header>
<Dropdown.Item>
<i className='dropdown icon' />
<span className='text'>Submenu</span>
<Dropdown.Menu>
<Dropdown.Item>List Item</Dropdown.Item>
<Dropdown.Item>List Item</Dropdown.Item>
</Dropdown.Menu>
</Dropdown.Item>
<Dropdown.Item>List Item</Dropdown.Item>
</Dropdown.Menu>
</Dropdown>
</Container>
</Menu>
How can I get the content to be next to the sidebar? (I.e. the page starts on the right of the sidebar, like it's own frame.)
As an aside I would also like to be able to have the sidebar fixed, open by default but collapsible with the content taking full-width.

fxHide.gt-sm Not working

I have the following div and it shows a login button on a nav bar, but if the screen is small I want to hide this button. For some reason when I add the fxHide.gt-sm=true it doesn't hide when I make the screen smaller. How can I fix this?
<div fxHide.gt-sm="true">
<ng-template #login>
<button
mat-icon-button
[routerLink]="['/auth']"
[style.width]="'auto'"
[style.overflow]="'visible'"
matTooltip="Login or Register"
class="topbar-button-right">
<span>Login</span>
<mat-icon>exit_to_app</mat-icon>
</button>
</ng-template>
</div>
What you want:
Default behavior: shown
If lt-md (less than medium screen) => hide
With your current implementation you have:
Default behavior: shown
If gt-sm (greater than small screen) => hide
Now, what you want translates into:
<div fxShow fxHide.lt-md>
You could invert the logic into
<div fxHide fxShow.gt-sm>
That should do it.
fxHide.gt-sm means hide it when it's greater than small. Change it to fxShow.gt-sm if you only want it visible on larger screen.
Faced the same thing but after importing FlexLayoutModule it worked.
If the OP is having issues making the fxHide command work at all, this question may be a duplicate of Angular Material FlexLayout fxHide does not hide
You must ensure that FlexLayout is imported in all modules that wish to use it:
https://stackoverflow.com/a/62672981/4440629

Dropdown Menu/Search Bar bootstrap

Just two small problems, working on a school assignment to recreate a generic website, using bootstrap.
A) I've been hiding a search input field/submit button in the horizontal navbar when screen is < 820px and incorporating another dropdown list named "search" with a input field in the drop down which is fine.
But I'm trying to hide this Search dropdown until screen is < 820px and targeting this list with a class and display: none but it's still displaying. Is there anyway you can do this?
<li class="dropdown searchDropDown">
Search<span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>
<input type="text" class="form-control searchBox" placeholder="Search">
<button type="submit" class="btn btn-default">Submit</button>
</li>
</ul>
</li>
my .searchDropDown {display:none} and have a media query for max-width 820px display: block
But the problem is it isn't hiding this list class at full page size.
B) when i click the search dropdown and try click into the search input field but it loses focus and rolls back up.
B) your click is propagating to the above li that has a click event attached to it, you could add a function like this (jQuery)
$('.searchBox').click(function(e){
e.stopPropagation();
});
if that doesn't work, make sure that you're actually clicking the input and not another element.
I'll get back to A in a minute
For question A use
#media screen and (min-width: 820px) {
.searchDropDown {
display: none!important;
}
}
Also, remember to close your img and input tags