CodeInput
CodeInput
component allows users to input strings.Basic usage
language
prop.tsxCopied1<CodeInput2label="Write some code"3language="javascript"4defaultValue='console.log("Hello world!");'5/>
- sql
- mysql
- pgsql
- json
- javascript
- jsx
- typescript
- tsx
- yaml
Customization
tsxCopied1<CodeInput2label="Write some code"3language="javascript"4theme="dark"5lineNumbers6foldGutter7defaultValue={DEFAULT_CODE}8/>
Component state
defaultValue
prop to set the initial value. You can also access the code input
contents using the value
field on the component state.tsxCopied1<CodeInput2id={componentState.id}3label="Write some code"4language="javascript"5defaultValue='console.log("Hello world!");'6/>7<Code language="javascript">{componentState.value || ""}</Code>
Component API
The input's disabled state on initial render
The input value on initial render
Description displayed below the input.
Disables the input. Prefer to use defaultDisabled and component state.
Error text displayed below the input.
Whether to enable code folding.
The ID referenced by the global component state
Label displayed above the input.
The language that the code input should be configured with.
Whether to show line numbers.
Callback when input changes when using as a controlled component. Prefer using the global component state.
Hint text displayed when the input is empty.
Adds red asterisk on the right side of label and sets required on input element
Theme of the code input.
A single function or an array of functions that validate the input value.
The value of the input when using as a controlled component. Prefer using defaultValue and the global component state.
State API
Whether the code input is disabled
Sets the disabled value of the code input. If the disabled
value is not provided, the code input will be disabled
Sets the value of the code input
The string currently in the code input