Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@thoughtbot/candy_wrapper

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thoughtbot/candy_wrapper

Use rails forms with popular react UI libraries

  • 0.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

candy_wrapper

candy_wrappers are lightweight wrapper components around popular UI libraries made to work with form_props. Easily use the power of Rails forms with any supported React UI library.

Caution

This project is in its early phases of development. Its interface, behavior, and name are likely to change drastically before a major version release.

Component status

Each component are meant to be copied from this repo to your own project and customized to your liking. There are no CLI tools to help. just copy and paste from github.

form_props helperComponentVanilla ReactReact Aria?
f.text_fieldCheckbox:heavy_check_mark::white_large_square::white_large_square:
f.collection_check_boxesCollectionCheckboxes:heavy_check_mark::white_large_square::white_large_square:
f.collection_radio_buttonsCollectionRadioButtons:heavy_check_mark::white_large_square::white_large_square:
f.color_fieldColorField:heavy_check_mark::white_large_square::white_large_square:
f.date_fieldDateField:heavy_check_mark::white_large_square::white_large_square:
f.datetime_local_fieldDateTimeLocalField:heavy_check_mark::white_large_square::white_large_square:
f.email_fieldEmailField:heavy_check_mark::white_large_square::white_large_square:
FieldError:heavy_check_mark::white_large_square::white_large_square:
f.month_fieldMonthField:heavy_check_mark::white_large_square::white_large_square:
f.number_fieldNumberField:heavy_check_mark::white_large_square::white_large_square:
f.password_fieldPasswordField:heavy_check_mark::white_large_square::white_large_square:
f.range_fieldRangeField:heavy_check_mark::white_large_square::white_large_square:
f.search_fieldSearchField:heavy_check_mark::white_large_square::white_large_square:
f.selectSelect:heavy_check_mark::white_large_square::white_large_square:
f.tel_fieldTelField:heavy_check_mark::white_large_square::white_large_square:
f.file_fieldFileField:heavy_check_mark::white_large_square::white_large_square:
f.text_fieldTextField:heavy_check_mark::white_large_square::white_large_square:
f.time_fieldTimeField:heavy_check_mark::white_large_square::white_large_square:
f.url_fieldUrlField:heavy_check_mark::white_large_square::white_large_square:
f.text_areaTextArea:heavy_check_mark::white_large_square::white_large_square:
f.grouped_collection_selectSelect:heavy_check_mark::white_large_square::white_large_square:
f.weekday_selectSelect:heavy_check_mark::white_large_square::white_large_square:
f.time_zone_selectSelect:heavy_check_mark::white_large_square::white_large_square:
f.submitSubmitButton:heavy_check_mark::white_large_square::white_large_square:

Installation

There's nothing to install, but if you need types:

npm install -D candy_wrapper

Then go to the wrapper directory in this repo and copy the wrappers for the UI library of your choice into your project.

Usage

Once you've copied the components to your project. Use form_props to build your form:

json.newPostForm do
  form_props(@post) do |f|
    f.text_field :title
    f.submit
  end
end

This would create a payload that looks something this:

{
  someForm: {
    props: {
      id: "create-post",
      action: "/posts/123",
      acceptCharset: "UTF-8",
      method: "post"
    },
    extras: {
      method: {
        name: "_method",
        type: "hidden",
        defaultValue: "patch",
        autoComplete: "off"
      },
      utf8: {
        name: "utf8",
        type: "hidden",
        defaultValue: "\u0026#x2713;",
        autoComplete: "off"
      }
      csrf: {
        name: "utf8",
        type: "authenticity_token",
        defaultValue: "SomeTOken!23$",
        autoComplete: "off"
      }
    },
    inputs: {
      title: {name: "post[title]", id: "post_title", type: "text", defaultValue: "hello"},
      submit: {type: "submit", value: "Update a Post"}
    }
  }
}

Take the payload and pass it to the wrapper:

import {Form, TextField, SubmitButton} from './copied_components'

const {form, extras, inputs} = newPostForm

<Form {...form} extras={extras}>
  <TextField {...inputs.title} label="Post title" />
  <SubmitButton {...inputs.submit} />
</Form>

Server errors

Each wrapper comes with inline support for server errors which renders a FieldError underneath the input.

import {Form, TextField} from './copied_components'

const validationErrors = {
  full_title: "Invalid length"
}

const {form, extras, inputs} = newPostForm

<Form {...form} extras={extras}>
  <TextField {...inputs.title} label="Post title" errorKey="full_title" />
  <SubmitButton {...inputs.submit} />
</Form>

Contributors

Thank you, contributors!

FAQs

Package last updated on 02 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc