@slinks/ui
v1.0.13
Published
A javascript library for rendering Blink UI components for Sei.
Downloads
14
Readme
@slinks/ui
The SlinkCard
component is a customizable React component to render Sei Action links in a standardized user interface. It renders a form based on a set of input actions and parameters returned from a Sei Actions spec compliant API. It also supports posting the form data to a specified endpoint and includes error tracking for user inputs and failed requests. Typescript types for Sei action objects can be found in the @slinks/actions
package.
To learn more about Actions and Slinks, visit the Slinks documentation.
Features
- Dynamic Form Rendering: Renders form elements like text inputs, textareas, checkboxes, radios, and selects based on the action configuration.
- Validation: Each form input is validated based on its provided regex pattern, and errors are shown to the user if the input is invalid.
- Action Execution: Sends a POST request to the specified endpoint using form values.
- Error Handling: Tracks and displays errors during form submission. If a request fails, the action button turns red to indicate the failure.
- Theming Support: Fully customizable via Mantine’s v7 theming system, allowing users to apply their own color schemes and theme preferences.
- Loading State: Shows a loading state on the action button while the form submission is in progress.
Installation
To use this component, ensure you have the following dependencies installed in your project:
[Installation command here, e.g., yarn add @mantine/core @mantine/hooks @tabler/icons-react @slinks/actions]
Usage
import { SlinkCard } from '@slinks/ui';
const YourComponent = () => {
const action = {
title: 'Submit a Slink',
description: 'Submit a Slink to the SEI network.',
icon: 'https://example.com/icon.png',
links: {
actions: [
{
label: 'Submit',
parameters: [
{
name: 'title',
label: 'Title',
type: 'text',
required: true,
},
{
name: 'description',
label: 'Description',
type: 'textarea',
required: true,
},
{
name: 'category',
label: 'Category',
type: 'select',
required: true,
options: [
{ value: '1', label: 'Category 1' },
{ value: '2', label: 'Category 2' },
],
},
],
},
],
},
};
const senderAddress = '0x...';
const endpointPath = 'https://example.com/submit';
return (
<SlinkCard
action={action}
senderAddress={senderAddress}
endpointPath={endpointPath}
/>
);
};
Props
action
*
- Type:
GetSeiActionResponse
- Description: This is the action object returned from an API request, containing the form fields, links, and other necessary data used to generate the interactive form within the component.
senderAddress
*
- Type:
string
- Description: The sender's address (either an EVM or Cosmos address). This represents the user who is submitting the form through the component.
endpointPath
*
- Type:
string
- Description: The URL endpoint to which the form data is submitted. This path is used for handling the submission of user input.
theme
(optional)
- Type:
MantineTheme
- Description: Optional custom theme object based on Mantine's theming system. You can define your custom primary colors, fonts, and styles.
colorScheme
(optional)
- Type:
MantineColorScheme
- Description: Optional color scheme for the component, allowing for
light
,dark
, orauto
modes to adjust the styling dynamically.
Action Object (GetSeiActionResponse
)
The action
prop represents the action configuration used to generate the form. This includes:
title
: The form's title.description
: The description of the action.icon
: The URL of an icon that is displayed at the top of the form.links.actions
: The array of action configurations, which define the form fields and submission logic.
Each action in the links.actions
array contains:
label
: The label of the action (e.g., "Submit").parameters
: An array of form input configurations. Each parameter includes:name
: The name of the input.label
: The label displayed for the input.type
: The type of input (e.g.,text
,email
,checkbox
, etc.).required
: Boolean indicating if the input is mandatory.pattern
: (Optional) A regex pattern for input validation.patternDescription
: (Optional) A custom error message for validation failure.
import { GetSeiActionResponse } from '@slinks/actions';
const action: GetSeiActionResponse = {
title: 'Submit a Slink',
description: 'Submit a Slink to the SEI network.',
icon: 'https://example.com/icon.png',
links: {
actions: [
{
label: 'Submit',
parameters: [
{
name: 'title',
label: 'Title',
type: 'text',
required: true,
},
{
name: 'description',
label: 'Description',
type: 'textarea',
required: true,
},
{
name: 'category',
label: 'Category',
type: 'select',
required: true,
options: [
{ value: '1', label: 'Category 1' },
{ value: '2', label: 'Category 2' },
],
},
],
},
],
},
}
Customizing Themes
The component uses Mantine’s v7 theming system for styling. You can pass your own theme
or colorScheme
to the SlinkCard
component.
For detailed info on theming, see the Mantine documentation for theming and color schemes.
Error Handling
When the form submission encounters an error (e.g., network failure or invalid response), the postError
state is set, and the action button changes color to red, signaling to the user that an error has occurred. This state is reset any time the user changes an input value.