A react button that doubles down as a link.
$ npm install @moxy/next-button
This library is written in modern JavaScript and is published in both CommonJS and ES module transpiled variants. If you target older browsers please make sure to transpile accordingly.
Every website or app needs a button, so this is our bare-bones version of it. In addition, it doubles down as a NextLink if an href
prop is passed, maintaining the style of a button.
import React from 'react';
import NextButton from '@moxy/next-button';
const MyPage = (props) => (
<div className="container">
<NextButton>Button 1</NextButton>
<NextButton href="/about">Button 2</NextButton>
</div>
);
export default MyPage;
Import the stylesheet in the project's entry JavaScript file:
import '@moxy/next-button/dist/index.css';
Besides the following supported props by the NextButton
component, additional props are spread.
Type: node
| Required: true
What to render inside the component.
Type: func
| Required: false
The onClick event handler.
Type: string
| Required: false
If this prop is passed, a NextLink will be rendered, maintaining the style of a button. Check out its API to check available props.
Type: string
| Required: false
A className to apply to the component wrapper.
$ npm test
$ npm test -- --watch # during development
A demo Next.js project is available in the /demo
folder so you can try this component out.
First, build the next-button
project with:
$ npm run build
To run the demo, do the following inside the demo's folder:
$ npm i
$ npm run dev
Note: Everytime a change is made to the package a rebuild is required to reflect those changes on the demo.
There is an ongoing next.js issue about the loading order of modules and global CSS in development mode. This has been fixed in v9.3.6-canary.0, so you can either update next.js
to a version higher than v9.3.5
, or simply increase the CSS specificity when overriding component's classes, as we did in the demo
, e.g. having the page or section CSS wrap the component's one.
Released under the MIT License.