TComponents. Text

new Text(parent, props)

Text component that displays various types of text (e.g., headers, body, description) with customizable styles. This class focuses on the specific properties of the Text component. Since it inherits from Accessor_A, all basic properties (e.g., height, width) are available but documented in the Accessor_A part.

Parameters:
NameTypeDescription
parentHTMLElement

HTML element that is going to be the parent of the component

propsTComponents.TextProps
Example
const text = new TComponents.Text(document.body, {
  position: 'absolute',
  zIndex: 1000,
  text: 'Hello',
  color: '#000',
});

// Render the component.
text.render();

Extends

Members

text :string

Sets the text content.

Type:
  • string
Example
const text = new TComponents.Text(document.body, {
  position: 'absolute',
  zIndex: 1000,
  text: 'Hello',
  color: '#000',
});

text.render();

// Set text value.
text.text = 'new Text';

textType :string

Sets the text type and adjusts corresponding styles. The supported text types are:

  • Header1
  • Header2
  • Header3
  • Body
  • Description
  • Error
  • Warning
  • Success
  • Information
Type:
  • string
Example
const text = new TComponents.Text(document.body, {
  position: 'absolute',
  zIndex: 1000,
  text: 'Hello',
  color: '#000',
});

text.render();

// Set text tyoe.
text.textType = 'Header1';

Methods

(protected) defaultProps() → {TComponents.TextProps}

Returns the default values of class properties (excluding parent properties).

Returns:
Type: 
TComponents.TextProps

markup() → {string}

Returns the markup for the text component.

Returns:

HTML markup for the text component.

Type: 
string

onRender() → {void}

Renders the text component and applies the styles and properties.

Throws:

Throws error code ErrorCode.FailedToRunOnRender when runtime error happens.

Type
Error
Returns:
Type: 
void

(static) loadCssClassFromString(css) → {void}

Add css properties to the component

Parameters:
NameTypeDescription
cssstring

The css string to be loaded into style tag

Returns:
Type: 
void
Example
TComponents.Text.loadCssClassFromString(`
  .tc-text {
    height: inherit;
   }`
);