Wraps html text with some preset style options in a configurable tag container. When editable is true, the text becomes editable on focus, with accessibility and onChange support. Optionally, a hidden input can store the value for form submission, and a button can copy content to the clipboard inline.

Parameters:
NameTypeDescription
propsobject

Component props.

Properties
NameTypeDescription
asHtmlboolean

Whether or not to accept HTML in the content (ignored when editable).

childrenJSX.Element

React element children (ignored when editable).

colorstring

The text color.

contentstring | number

The text content.

copyButtonAttributesobject

Custom attributes for the copy button.

copyButtonClassesstring | Array | object

Custom classes for the copy button.

customAttributesobject

Custom attributes for the component.

customClassesstring | Array | object

Custom classes for the component.

editableboolean

Whether the text is editable on focus (default false).

idstring

Optional id attribute when editable.

namestring

Optional name attribute when editable.

onBlurfunction

Handler for blur events when editable (default empty function).

onChangefunction

Handler for text changes when editable.

onCopyfunction

Handler for copy events when showCopyButton is true (default empty function).

onFocusfunction

Handler for focus events when editable (default empty function).

placeholderstring

Placeholder text when editable and empty (default empty string).

showCopyButtonboolean

Whether to show a button to copy the content to the clipboard (default false).

sizestring

The font size for the text.

spacingstring | number | Array | object

The spacing for the component.

tagNamestring

The tag used for the container element.

truncateboolean

Whether to truncate the text (default false).

useHiddenInputboolean

Whether to include a hidden input for form submission (default false).

weightstring

The font weight for the text.

refobject | null

Ref to the component.

Since
  • 1.1.15
Returns:

The text component.

Type: 
JSX.Element
Example
// With copy button inline, non-editable
<Text content="Copy Me" showCopyButton />

// Controlled usage with copy button inline
const [text, setText] = useState("Hello world");
<Text content={text} editable onChange={setText} showCopyButton />

// Self-managed form usage with copy button inline
<form>
  <Text content="Hello world" editable useHiddenInput name="text-field" id="text-1" showCopyButton />
  <button type="submit">Submit</button>
</form>