PasswordInput is used for entering sensitive data, like passwords, API keys and so on. It works the same way as TextInput, except input value is masked and replaced with asterisks ("*").
import {PasswordInput} from '@inkjs/ui';<PasswordInput placeholder="Enter password..." onSubmit={password => { // `password` contains user input }}/>;
StatusMessage can also be used to indicate a status, but when longer explanation of such status is required.
import {StatusMessage} from '@inkjs/ui';<StatusMessage variant="success"> New version is deployed to production</StatusMessage><StatusMessage variant="error"> Failed to deploy a new version of this app</StatusMessage><StatusMessage variant="warning"> Health checks aren't configured</StatusMessage><StatusMessage variant="info"> This version is already deployed</StatusMessage>
Alert is used to focus user's attention to important messages.
import {Alert} from '@inkjs/ui';<Alert variant="success"> A new version of this CLI is available</Alert><Alert variant="error"> Your license is expired</Alert><Alert variant="warning"> Current version of this CLI has been deprecated</Alert><Alert variant="info"> API won't be available tomorrow night</Alert>
All component have their styles defined in a theme, which is accessible to components via React context. Ink UI ships with a default theme and it can be customized or replaced with a different theme altogether.
Let's get a quick look on how to customize a Spinner's component theme. Here's how it looks by default:
First, look up component's default theme, which will give an overview which parts does this component consist of. Documentation of each component includes a link to component's theme.ts file on top. In the case of Spinner, it's source/components/spinner/theme.ts.
This component theme hints that Spinner has 3 parts: container, frame and a label. So to customize the color of the spinner itself, we'd want to change the color prop returned from the frame function.
To customize the default theme, use extendTheme function and make that custom theme available to children components via ThemeProvider.
Since each field in styles object is a function, it can return different styles based on the props that were passed in or a state of a component.
Component themes can also include configuration for rendering a component in a config object, that's not related to styling. For example, UnorderedList specifies a marker, which is a character that's rendered before each list item.
Components shipped in Ink UI automatically read the necessary styles and configuration from a theme. However, if you're adding a new custom component and a theme for it, use useComponentTheme hook to access it.