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.
| Name | Type | Description |
|---|---|---|
parent | HTMLElement | HTML element that is going to be the parent of the component |
props | TComponents. |
- Source
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.
- string
- Source
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:
Header1Header2Header3BodyDescriptionErrorWarningSuccessInformation
- string
- Source
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).
- Overrides
- Source
- Type:
- TComponents.
TextProps
markup() → {string}
Returns the markup for the text component.
- Overrides
- Source
HTML markup for the text component.
- Type:
- string
onRender() → {void}
Renders the text component and applies the styles and properties.
- Overrides
- Source
Throws error code ErrorCode.FailedToRunOnRender when runtime error happens.
- Type
- Error
- Type:
- void
(static) loadCssClassFromString(css) → {void}
Add css properties to the component
| Name | Type | Description |
|---|---|---|
css | string | The css string to be loaded into style tag |
- Source
- Type:
- void
TComponents.Text.loadCssClassFromString(`
.tc-text {
height: inherit;
}`
);