Skip to content

nss_libs - NssTextBox

A styled text display component with responsive sizing and a three-part visual structure (before-cap, text, after-cap). NUI

Getting Started

NssTextBox renders text inside a decorative three-part container. Load it via NssUiApi or import directly. The component requires NssResponsive to be initialized — it will warn via window.alert if missing.

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

const nss_ui_api = new NssUiApi('my_resource');
nss_ui_api.load([NssUiApi.NssResponsive, NssUiApi.NssTextBox]).then((components) => {
    new components.NssResponsive();

    const text_box = new components.NssTextBox(document.getElementById('container'));
    text_box.setText('Hello World').show();
});

Constructor

new NssTextBox(target_el)

Creates a new text box instance. The DOM is created lazily on the first show() call.

Parameters

  • target_el : HTMLElement — The parent element the text box will be appended to.

Example

js
const text_box = new NssTextBox(document.getElementById('my-container'));

Methods

show()

Creates the DOM structure (if not yet created) and makes the text box visible.

Syntax

js
text_box.show()

Parameters

None.

Return Value

Returns NssTextBox — the instance for chaining.

Example

js
text_box.setText('Welcome back').show();

hide()

Hides the text box by removing the visibility CSS class.

Syntax

js
text_box.hide()

Parameters

None.

Return Value

Returns NssTextBox — the instance for chaining.

Example

js
text_box.hide();

removeDom()

Removes the text box DOM element from the document and clears internal references.

Syntax

js
text_box.removeDom()

Parameters

None.

Return Value

Returns undefined.

Example

js
text_box.hide();
text_box.removeDom();

setText(value)

Sets the text content displayed in the text box.

Syntax

js
text_box.setText(value)

Parameters

  • value : string — The text to display.

Return Value

Returns NssTextBox — the instance for chaining.

Example

js
text_box.setText('Press E to interact').show();

getText()

Returns the current text content.

Syntax

js
text_box.getText()

Parameters

None.

Return Value

Returns string — the current text value.

Example

js
const current_text = text_box.getText();

setNoWrap()

Prevents the text from wrapping to a new line.

Syntax

js
text_box.setNoWrap()

Parameters

None.

Return Value

Returns NssTextBox — the instance for chaining.

Example

js
text_box.setText('Single line only').setNoWrap().show();

setWrap()

Allows the text to wrap (default behavior).

Syntax

js
text_box.setWrap()

Parameters

None.

Return Value

Returns NssTextBox — the instance for chaining.

Example

js
text_box.setWrap();

setTextSizeSmall()

Sets the text size to small (0.8rem).

Syntax

js
text_box.setTextSizeSmall()

Parameters

None.

Return Value

Returns NssTextBox — the instance for chaining.

Example

js
text_box.setText('Fine print').setTextSizeSmall().show();

setTextSizeDefault()

Resets the text size to default (1rem).

Syntax

js
text_box.setTextSizeDefault()

Parameters

None.

Return Value

Returns NssTextBox — the instance for chaining.

Example

js
text_box.setTextSizeDefault();

setTextSizeMedium()

Sets the text size to medium (1.2rem).

Syntax

js
text_box.setTextSizeMedium()

Parameters

None.

Return Value

Returns NssTextBox — the instance for chaining.

Example

js
text_box.setText('Important notice').setTextSizeMedium().show();

setTextSizeLarge()

Sets the text size to large (1.5rem).

Syntax

js
text_box.setTextSizeLarge()

Parameters

None.

Return Value

Returns NssTextBox — the instance for chaining.

Example

js
text_box.setText('Headline').setTextSizeLarge().show();

Events / Callbacks

None. NssTextBox is a pure display component without user interaction callbacks.

CSS

Classes

ClassDescription
.nss-text-box__containerRoot grid container.
.nss-text-box__container--visibleApplied when show() is called.
.nss-text-box__container--smallSmall text variant (0.8rem).
.nss-text-box__container--mediumMedium text variant (1.2rem).
.nss-text-box__container--largeLarge text variant (1.5rem).
.nss-text-box__container--no-wrapPrevents text wrapping.
.nss-text-box__text-beforeLeft decorative cap.
.nss-text-box__textCenter text area with background image.
.nss-text-box__text-afterRight decorative cap.

Custom Properties

PropertyDefaultDescription
--font-size1remBase font size, overridden by size modifiers.
--padding-tbvar(--5rpx)Vertical padding, scales with size modifiers.

Dependencies

  • NssResponsive — must be initialized before using NssTextBox. Will alert if missing.
  • NssUiComponentInterfaceNssUiComponent — base class chain.

Things to Know

  • The DOM is created lazily on the first show() call. Calling setText() before show() stores the value and applies it when the DOM is created.
  • After removeDom(), calling show() again will re-create the DOM structure.
  • All setter methods can be called before or after show() — state is applied immediately if DOM exists, or queued for the next show().

NIGHTSHIFT STUDIO Documentation