![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
@asphalt-react/appbar
Advanced tools
Appbar component is the main navigation bar for the whole application. Use this component at the root of your application as the top navigation bar. It contains a list of links that can either take the user to another page or to another section on the same page. Appbar is responsive and adapts to small, medium & large screens. You can also create a custom Appbar through a family of unit components exported by Appbar.
import { Appbar, Nav, NavItem, NavLink } from "@asphalt-react/appbar"
function App () {
return (
<Appbar>
<Nav>
<NavItem active>
<NavLink asProps={{ href: "/" }}>Home</NavLink>
</NavItem>
<NavItem>
<NavLink asProps={{ href: "/Dashboard" }}>Dashboard</NavLink>
</NavItem>
</Nav>
</Appbar>
);
}
export default App;
Appbar has 3 sections:
head
prop.tail
prop.The styles required for the Appbar to stick to the top of the screen needs to be added while implementation.
Appbar exports a family of unit components to create the nav items:
Using these components, you can compose a variety of nav items.
Appbar adapts to smaller screens (below 600px). The Appbar renders at the top of its container with the head and tail section visible. The body section is hidden under a hamburger button that appears in the head section.
Activating the hamburger button shows the hidden sections in a container (or drawer) that covers the complete screen. The hamburger button is replaced by a cross button to close the drawer. Appbar also exposes a close()
function that to close the drawer. It can be useful if you want to close the drawer on selecting a nav item. For example:
import { Appbar, Nav, NavItem, NavLink } from "@asphalt-react/appbar"
function App () {
const close = () => Appbar.close
return (
<Appbar>
<Nav>
<NavItem>
<NavLink onClick={close} asProps={{ href: "example.com" }}>Dashboard</NavLink>
</NavItem>
</Nav>
</Appbar>
)
}
Appbar exports layout unit components using which you can create a custom implementation of Appbar:
You would need to add the responsive styles as they are not screen responsive by default. These layout components do not respond to different screen sizes. You can wrap them in containers with media queries for the custom Appbar to adapt to screen sizes. For example:
@media only screen and (max-width: 600px) {
.container {
/* some styles */
}
.content {
/* some styles */
}
}
const CustomAppbar = () => {
return (
<div className="container">
<BaseAppbar>
<div className="content">
<AppbarBody>
// NavItems
</AppbarBody>
</div>
</BaseAppbar>
</div>
)
}
Appbar exports a useAppbar
hook to help you create custom functionality.
React hook to implement the ability to open/close the Appbar in smaller screens. Use this hook when you are implementing your custom Appbar using the unit layout components. Let's look at the usage:
import { Appbar, useAppbar } from "@asphalt-react/appbar"
const CustomAppbar = () => {
const { visible, open, close } = useAppbar({ defaultOpen: true })
return (
<Appbar>
<div className={visible ? "show" : "hide"}>
{visible ? (
<Button onClick={close}>close</Button>
) : (
<Button onClick={open}>open</Button>
)}
</div>
</Appbar>
)
}
visible
: A stateful boolean value to control the (open/close) state.open
: A function to open the Appbar.close
: A function to close the Appbar.useAppbar
accepts the defaultVisible
prop as the argument.
React node to render in the Appbar content.
type | required | default |
---|---|---|
node | false | N/A |
Content to display in the Appbar head.
type | required | default |
---|---|---|
node | false | null |
Content to display in the Appbar tail.
type | required | default |
---|---|---|
node | false | null |
"aria-label" for the button to close Appbar in smaller screens.
type | required | default |
---|---|---|
string | false | "close appbar navigation" |
"aria-label" for the button to open Appbar in smaller screens.
type | required | default |
---|---|---|
string | false | "open appbar navigation" |
Appbar shows the body section in the initial state.
type | required | default |
---|---|---|
bool | false | false |
React nodes to render in the Nav content.
type | required | default |
---|---|---|
node | true | N/A |
Using NavItem component, links can be added to the Appbar. By default, it renders an <a>
tag but you can pass your custom element or React component using as
prop. All the props related to the link should be passed in asProps
element.
Content for a nav item.
type | required | default |
---|---|---|
node | true | N/A |
React node to render the caption of the nav item.
type | required | default |
---|---|---|
node | false | N/A |
Icon for the NavItem. Accepts SVG.
Icon to enhance the nav item's caption. Accepts SVG.
type | required | default |
---|---|---|
node | false | N/A |
Accepts elements for custom actions in a NavItem.
React node to render action elements for a nav item.
type | required | default |
---|---|---|
node | false | N/A |
Allow events to propagate to the parent element.
type | required | default |
---|---|---|
bool | false | false |
Renders the link element for a NavItem.
React node to render link content.
type | required | default |
---|---|---|
node | false | N/A |
Html element/React component to replace the default element. Using this prop, you can use your router's link element, such as "react-router-dom"'s Link element.
type | required | default |
---|---|---|
elementType | false | "a" |
Pass the props such as "href", "id" for the custom link element passed in as
prop.
type | required | default |
---|---|---|
object | false | {} |
Marks the nav link as active.
type | required | default |
---|---|---|
bool | false | false |
An active style. Adds an indicator to accent the active nav link.
type | required | default |
---|---|---|
bool | false | false |
A subtle active style. Highlights the surface of the nav item.
type | required | default |
---|---|---|
bool | false | false |
An icon only nav link.
type | required | default |
---|---|---|
bool | false | false |
Adds padding.
type | required | default |
---|---|---|
bool | false | true |
The base container unit component.
Container for the BaseAppbar content.
type | required | default |
---|---|---|
node | true | N/A |
Adds padding.
type | required | default |
---|---|---|
bool | false | true |
The unit component for rendering the head elements.
Container for the AppbarHead content.
type | required | default |
---|---|---|
node | false | N/A |
Adds padding.
type | required | default |
---|---|---|
bool | false | true |
The unit component to render the main content.
Container for the AppbarBody content.
type | required | default |
---|---|---|
node | true | N/A |
React node to render content in the tail section.
Container for the AppbarTail content.
type | required | default |
---|---|---|
node | true | N/A |
Adds padding.
type | required | default |
---|---|---|
bool | false | true |
FAQs
Appbar
The npm package @asphalt-react/appbar receives a total of 5 weekly downloads. As such, @asphalt-react/appbar popularity was classified as not popular.
We found that @asphalt-react/appbar demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.