npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@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, or auto 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.