ng-simple-button

Introduction

ng-simple-button is a standalone, reusable and customizable component for Angular 18, 19 and 20.

It is designed to work with signals and Angular zoneless, providing a lightweight, flexible, and accessible simple button. It is also fully compatible with SSR, CSR and prerender.

Installation

If you want to install the latest version (currently 20):


    npm install ng-simple-button
  

Angular 19:


    npm install ng-simple-button@v19-lts
  

Angular 18:


    npm install ng-simple-button@v18-lts
  

Overview

Using ng-simple-button is easy:

  • Define the component’s functionality through the (onClick) output.
  • Configure its type, shape, hover behavior, and accessibility using inputs..
  • Style it with customizable CSS variables to match your design needs.

Here’s a basic usage example:


    import { Component, signal } from '@angular/core';
import { NgSimpleButton } from 'ng-simple-button';

@Component({
  selector: 'app',
  standalone: true,
  imports: [NgSimpleButton],
  template: `
    <ng-simple-button
      (onClick)="clickFunction()"
      type="solid"
      [square]="true"
      hover="shadow"
      ariaLabel="Custom aria label"
    >
      Simple button inner content
    </ng-simple-button>

    <p>Clicked {{ count() }} times</p>
  `,
})
export class App {
  count = signal<number>(1);

  clickFunction() {
    const current = this.count();
    this.count.set(current + 1);
  }
};
  

Functionality

As you can see in the example bellow, you can use the (onClick) output to assign the action you want the button to execute.

You can also access the native MouseEvent if you need to handle event data:


    <ng-simple-button (onClick)="handleClick($event)">
  Click me
</ng-simple-button>
  

    handleClick(event: MouseEvent) {
  console.log(event.clientX, event.clientY);
}
  

Inputs and Outputs

Here is a list of all input/ouput:

Action Output

OutputDescriptionDefault
onClick Emits a MouseEvent when the button is clicked. -

Style & Behavior Inputs

InputDescriptionDefault
type Defines the button’s visual style (solid, minimal, or outline). 'solid'
square Makes the button shape perfectly square instead of rounded. false
hover Sets the hover effect style (tone, scale, stroke, shadow, or none). 'tone'
direction Arranges the button’s inner content horizontally or vertically. (row / column). 'row'

Accessibility Inputs

InputDescriptionDefault
ariaLabel Provides an accessible label for assistive technologies. null
title Sets the native tooltip text shown on hover. null
tabIndex Controls the button’s tab order in keyboard navigation. 0
disabled Disables the button and prevents user interaction. false

Styling

You can easily customize the component’s appearance using the CSS variables listed below.


    ng-simple-button {
  --simple-button-bg: orange;
  --simple-button-hover-bg: red;
}
  

Layout & Spacing

VariableDescriptionDefault
--simple-button-width Defines the button width. fit-content
--simple-button-height Sets the button height. auto
--simple-button-radius Controls the corner roundness. 1.3rem
--simple-button-padding Sets the inner spacing. .5rem 1rem
--simple-button-gap Space between icon and label. .5rem
--simple-button-justify-content Horizontal alignment of content. center
--simple-button-align-items Vertical alignment of content. center

Style & Visuals

VariableDescriptionDefault
--simple-button-bg Background color of the button. white (solid) / transparent (outline, minimal)
--simple-button-color Main color. black (solid) / inherit (outline, minimal)
--simple-button-border Defines the border style. none (solid, minimal) / 2px solid currentColor (outline)
--simple-button-focus-ring Outline shown when focused. 2px solid currentColor
--simple-button-transition-duration Duration of hover/focus transitions. .3s

Hover Effects

VariableDescriptionDefault
--simple-button-hover-color Text color on hover. var(--simple-button-color, black)
--simple-button-hover-scale Scale effect applied on hover. 1.05 (scaleHover)
--simple-button-hover-shadow Box shadow applied on hover. 2px 2px 5px #525252 (shadowHover)
--simple-button-hover-bg Background color on hover. #949494 (toneHover)
--simple-button-hover-stroke Outline stroke on hover. 2px solid currentColor (strokeHover)

Styling considerations:

You can apply styles to a specific button type as follows:


    ng-simple-button[type="solid"] {
  --simple-button-bg: orange;
}
  

If you have multiple buttons and need different custom styles, you can also add a class to target them more precisely:


    ng-simple-button.myClass {
  --simple-button-outline: 2px solid orange;
}
  

Accessibility

You can configure the accessibility of the component using the accessibility inputs explained in the inputs/outputs section: Accessibility Inputs