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

form-helper-chrome

v1.0.3

Published

A React component for form error handling using Chrome's Built-in AI to generate helpful messages for form errors.

Downloads

242

Readme

Form Helper Chrome

npm npm license

form-helper-chrome is an npm package that provides a React component for form error handling using Chrome's Built-in AI. This package leverages AI to generate helpful messages for form errors, enhancing user experience.

Installation

To install the package, use npm:

npm install form-helper-chrome

Usage

To use the FormHelperChrome component and createPrompt function, import them into your React application:

import React from 'react';
import { FormHelperChrome, createPrompt } from 'form-helper-chrome';

const App = () => {
  const formGuideHtml = "<p>Your form guide here</p>";
  const error = {
    name: ['fieldName'],
    errors: ['This field is required'],
    value: '',
    touched: true
  };

  // Create a prompt using the createPrompt function
  const prompt = createPrompt(error, formGuideHtml);

  return (
    <FormHelperChrome
      prompt={prompt}
      fontSize="14px"
      isDarkMode={false}
      plain={false}
    />
  );
};

export default App;

demo

Custom Prompt

If you prefer to create a custom prompt, you can construct it manually as shown below:

const customPrompt = `
  # Custom Form Guide:
  \`\`\`
  ${formGuideHtml}
  \`\`\`

  # Custom Error Description:
  Field: \`${error.name.join(".")}\`
  Value: \`${error.value}\`
  Error: \`${error.errors.join(", ")}\`
  
  Please provide a response in the following format:
  ${outputFormat}
`;

You can then pass this customPrompt to the FormHelperChrome component:

Props

FormHelperChrome

| Prop Name | Type | Default Value | Required | Description | |---------------|----------|---------------------|----------|-----------------------------------------------------------------------------| | prompt | string | "" | Yes | The prompt string to be sent to the AI for generating a response. | | fontSize | string | "16px" | No | Font size for the rendered markdown content. | | isDarkMode | boolean | false | No | Enables dark mode styling if set to true. | | plain | boolean | false | No | If true, renders only the markdown content without the card component. |

createPrompt

| Parameter | Type | Description | |-----------------|------------|-----------------------------------------------------------------------------| | error | object | An object containing error details for the form field. It includes: | | | | - name: An array of strings representing the field name(s). | | | | - errors: An array of error messages related to the field. | | | | - value: The current value of the field. | | | | - touched: A boolean indicating whether the field has been interacted with.| | formGuideHtml | string | HTML content for the form guide. | | outputFormat | string | Format for the AI-generated response. Defaults to DEFAULT_OUTPUT_FORMAT. |

Prerequisites

This package utilizes Chrome's Built-in AI APIs, which require specific browser settings and access permissions. Please follow the steps below to ensure proper setup:

  1. Join the Early Preview Program: To experiment with Chrome's Built-in AI APIs, you must join the early preview program. Upon joining, you will receive access to the setup guide necessary for configuring your browser.

  2. Set Up Chrome Canary or Dev Version: The AI features are available in the Chrome Canary or Dev versions. Ensure you have the appropriate version installed.

  3. Enable Required Flags: Follow the instructions provided in the setup guide to enable the necessary flags in your Chrome browser to access the AI APIs.

For an overview of Chrome's Built-in AI APIs, refer to the official introduction.

License

This project is licensed under the MIT License.