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

radix-declarative-form-demo

v0.0.0-alpha.0

Published

Renders form elements as controlled components connected via redux-hook-form based using a single fields configuration.

Downloads

1

Readme

Radix Declarative Form

Renders form elements as controlled components connected via redux-hook-form based using a single fields configuration.

Basic Usage

Install:

npm i radix-declarative-form

In any React component:

import { useRDF, RDF } from 'radix-declarative-form';
import 'radix-declarative-form/rdf.css';

function Form() {
  const fields = [
    {
      name: 'hello',
      type: 'text,
      label: 'A simple, required field',
      placeholder: 'Write something here',
      options: {
        required: 'This field is required.',
      },
    }
  ]
  const onSubmit = async (formData, formState) => {
    console.log(formData) // => FormData ready for multipart submit
    console.log(formState) // => plain object (see typescript example below)
  }
  const form = useRDF(fields, onSubmit);

  return (<RDF form={form} />;
}

Using With Typescript

With typescript, you can create a type around your form data and pass to RDF via generics.

import { useRDF, RDF } from 'radix-declarative-form';
import type { RDFField } from 'radix-declarative-form';
import 'radix-declarative-form/rdf.css';

type Person = {
  firstName: string
  lastName: string
  employmentStatus: string
}

const fields: RDFField<Person>[] = [
  {
      name: 'firstName',
      type: 'text',
      label: 'First Name',
      options: {
        required: 'This field is required.',
      },
    },
    {
      name: 'lastName',
      type: 'text',
      label: 'Last Name',
      options: {
        required: 'This field is required.',
      },
    },
    {
      name: 'employmentStatus',
      type: 'select',
      label: 'Last Name',
      choices: [
        'Full time', 'part time', 'unemployed'
      ],
      default: 'Full time'
    },
];

function Form() {
  const handleSubmit = async function (formData: FormData, formState: Person){
    console.log(formData)
      // => FormData ready for multipart submit
    console.log(formState)
      // => object of Person type
  }
  const form = useRDF(fields, handleSubmit);

  return (<RDF<Person> form={form} />;
}

Currently Supported Types:

  • text
  • multiline
  • number
  • checkbox
  • select
  • radio
  • switch
  • media
  • list (BETA)
  • table (BETA)

CSS Variables with Defaults

Colors can be customized by setting these CSS variables in scope.


  --button-color-light: #222;
  --button-color-hover-light: #666;
  --button-text-light: #fff;
  --button-color-dark: #eee;
  --button-color-hover-dark: #fff;
  --button-text-dark: #222;

  --label-color-light: #555;
  --label-color-dark: #fff;

  --input-text-color-light: #333;
  --input-text-color-dark: #fff;
  --input-background-light: #fff;
  --input-background-dark: #333;
  --input-border-light: #888;
  --input-border-dark: #444;
  --input-focused-shadow-light: #888;
  --input-focused-shadow-dark: #999;
  --input-border-error-light: #ff7070;
  --input-border-error-dark: #ff7070;

  --checkbox-background-light: #fff;
  --checkbox-background-dark: #111;
  --checkbox-border-light: #888;
  --checkbox-border-dark: #bbb;
  --checkbox-check-light: #000;
  --checkbox-check-dark: #fff;

  --switch-on-background-light: rgb(55, 199, 55);
  --switch-on-background-dark: rgb(55, 199, 55);
  --switch-off-background-light: rgb(148, 148, 148);
  --switch-off-background-dark: rgb(125, 125, 125);

  --radio-select-indicator-light: #555;
  --radio-select-indicator-dark: #bbb;

  --select-placeholder-color-light: #777;
  --select-placeholder-color-dark: #777;
  --select-group-label-light: rgb(158, 158, 158);
  --select-group-label-dark: #aaa;
  --select-highlight-text-light: #222;
  --select-highlight-background-light: rgb(228, 228, 228);
  --select-highlight-text-dark: rgb(241, 241, 241);
  --select-highlight-background-dark: rgb(89, 89, 89);

  --select-item-disabled-light: #ddd;
  --select-item-disabled-dark: #555;

  --select-content-shadow-light: rgba(22, 23, 24, 0.35);
  --select-content-shadow-dark: rgba(190, 190, 190, 0.35);

  --media-target-background-light: #eee;
  --media-target-background-dark: rgb(86, 86, 86);
  --media-target-icon-color-light: rgb(207, 207, 207);
  --media-target-icon-color-dark: rgb(144, 144, 144);

  --link-color:  rgb(72, 202, 238);
  --error-message: #cc0000;