Skip to content

NssButtons

A styled button component with colors, sizes, glow effects, and click callbacks. NUI

Getting Started

NssButtons is a factory that creates NssButton instances. Each button supports chained configuration for colors, sizes, glow effects, and click handling.

js
import {NssUiApi} from "nui://nss_libs/ui/NssUiApi.js";

nss_ui_api.load([NssUiApi.NssButtons]).then((components) => {
    const buttons = new components.NssButtons();
    const btn = buttons.create('Click me');

    btn.setGold().setGlowGold().onClick(() => {
        console.log('Button clicked');
    }).appendTo(document.getElementById('button-container'));
});

Constructor

new NssButtons()

Creates a button factory instance.

js
const buttons = new NssButtons();

Methods

.create(label)

Creates a new NssButton instance with the given label.

ParamTypeDefaultDescription
labelstringThe button text. Supports HTML

Returns NssButton — a new button instance.

js
const save_btn = buttons.create('Save');
const cancel_btn = buttons.create('Cancel');

NssButton Methods

All NssButton methods return this for chaining unless noted otherwise.

.onClick(callback)

Registers a click handler.

ParamTypeDefaultDescription
callbackNssPadLock~onClickCallbackCalled with the NssButton instance when clicked

Returns NssButton — chainable.

js
btn.onClick((button) => {
    button.setDisabled();
    nss_client.post('submit');
});

.appendTo(target_el)

Appends the button wrapper to a DOM element.

ParamTypeDefaultDescription
target_elHTMLElementThe parent element

Returns NssButton — chainable.

js
btn.appendTo(document.getElementById('footer'));

.setLabel(label)

Changes the button label. Supports HTML.

ParamTypeDefaultDescription
labelstringThe new label text

Returns NssButton — chainable.

js
btn.setLabel('Saving...');

.getEl()

Returns the inner <button> element.

Returns HTMLButtonElement — the button element.

js
btn.getEl().focus();

.getWrapperEl()

Returns the outer <div> wrapper element. Use this when adding the button as a child of another element.

Returns HTMLDivElement — the wrapper element.

js
container_el.appendChild(btn.getWrapperEl());

Color Methods

Set the button color. Only one color can be active at a time.

MethodDescription
setWhite()White background
setGrey()Grey background
setDanger()Red background
setGold()Gold background
setSuccess()Green background
js
const confirm_btn = buttons.create('Confirm').setSuccess();
const delete_btn = buttons.create('Delete').setDanger();

Size Methods

Set the button size.

MethodFont Size
setSizeVerySmall()0.5rem
setSizeSmall()0.8rem
setSizeNormal()1rem (default)
setSizeLarge()1.25rem
js
btn.setSizeLarge();

Glow Methods

Add animated glow effects to the button.

MethodDescription
enableGlowing()Enables the glow animation
disableGlowing()Disables the glow animation
setGlowGreen()Green glow color
setGlowDanger()Red glow color
setGlowGold()Gold glow color
js
btn.setSuccess().setGlowGreen();
btn.setDanger().setGlowDanger();

State Methods

MethodDescription
setDisabled()Disables the button (no clicks, dimmed)
setEnabled()Enables the button
isDisabled()Returns boolean
setBorderless()Removes inner padding (icon-only style)
unsetBorderless()Restores padding
setIcon()Switches to icon-only mode (reduced padding, no min-width)
unsetIcon()Switches back to text mode
js
btn.setDisabled();
// After async operation:
btn.setEnabled();

Events / Callbacks

  • Click — registered via onClick(callback). Audio: NssAudio.playSfxNext() on click (suppressed when disabled).
  • Hover — plays NssAudio.playSfxUpDown() automatically.

CSS

Classes

ClassDescription
.nss-btnBase button element
.nss-btn__wrapperInline-block wrapper
.nss-btn--white / --grey / --danger / --success / --goldColor variants
.nss-btn--very-small / --small / --largeSize variants
.nss-btn--iconIcon-only mode
.nss-btn--borderlessNo padding
.nss-btn--glowGlow base class
.nss-btn--glow-green / --glow-danger / --glow-goldGlow color variants

Custom Properties

PropertyDefaultDescription
--padding-tbcalc(var(--1rpx) * 12)Vertical padding
--padding-lrcalc(var(--1rpx) * 25)Horizontal padding
--min-widthvar(--100rpx)Minimum button width
--font-size1remFont size
--colorrgba(255,255,255,0.8)Text color
--hover-colorrgba(255,255,255,1)Text color on hover
--img-urlurl(./img/btn_bg.png)Background image

Animations

KeyframeDescription
glowingAnimated gradient glow effect (15s infinite loop)

Dependencies

  • NssUiComponent — base class (initializes NssResponsive).
  • NssAudio — hover and click sound effects.

Things to Know

WARNING

NssButtons is the factory, NssButton is the individual button instance. You never instantiate NssButton directly.

  • Hover audio (playSfxUpDown) plays automatically — no opt-out. Click audio (playSfxNext) is suppressed when the button is disabled.
  • Use getWrapperEl() (not getEl()) when appending a button to a container — the wrapper provides correct inline-block layout.

NIGHTSHIFT STUDIO Documentation