form_props 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4679a4eb6f011a9769e059c9516dcdba626c5fc19082858c2da895ce564b7832
4
- data.tar.gz: ab7a23b584b3f0c82f4d73c06b9f10af13e758448ee9c14f606e50d9d7d4701c
3
+ metadata.gz: 6afc4d5cd3b6527eda75e36d715a828d50fb91f7cd35015840cfda0fd3bd1757
4
+ data.tar.gz: 112580b30cc0ee20c4bb7903bf2b710c07452e9584753306badd4b091965f367
5
5
  SHA512:
6
- metadata.gz: d9647979c20fec9abc688d4dcdfcc827627b057c7d6a0bc72359e067419358ab95baa656e9bf0445afb9e2467aa4846eae200616da1e5aedf4ed554b1253855c
7
- data.tar.gz: fdb9166102654f8e5e4df47ed2a979ce036422b581c8525b586a1d0590a0646c3de7247887785f39488187e0398a9a4645f09ca643a80ef8c800fb1ea19007a7
6
+ metadata.gz: f96bd0cf7459cf432c86d4e0b660a061b0787d294ce154ed18af9c6a44feebc5ee8451525bc9e9304823c1b16ff41be0a10423e0e30e47435b5b94e3eae6e1de
7
+ data.tar.gz: f15f59d1ce001e8f4208d1e9081feb01967964cd6e8b2be7633ac97166ef17aaf8a4df2b2a0333b113ba7438858a2ffa0913d7bc5cfaa5dfc9a83906718f38b2
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # Form Props
2
2
 
3
- FormProps is a Rails form builder that outputs input attributes (in JSON) instead of
4
- tags. Now you can enjoy the conviences of Rails helpers in other view libraries like
5
- React, and React Native.
3
+ ![Build Status](https://github.com/thoughtbot/form_props/actions/workflows/build.yml/badge.svg?branch=main)
4
+
5
+ FormProps is a Rails form builder that outputs HTML props instead of tags. Now
6
+ you can enjoy the power and convenience of Rails helpers in React!
6
7
 
7
8
  By separting attributes from tags, FormProps can offer greater flexbility than normal
8
9
  Rails form builders; allowing designers to stay longer in HTML land and more easily
@@ -24,7 +25,7 @@ gem "form_props"
24
25
  and `bundle install`
25
26
 
26
27
  ## Usage
27
- `form_props` is designed to be used in a [PropsTemplate] template (it can work with
28
+ `form_props` is designed to be used in a [PropsTemplate] template (it can work with
28
29
  [jbuilder](#jbuilder)). For example in your `new.json.props`:
29
30
 
30
31
  ```ruby
@@ -44,7 +45,7 @@ would output
44
45
  props: {
45
46
  id: "create-post",
46
47
  action: "/posts/123",
47
- accept-charset: "UTF-8",
48
+ acceptCharset: "UTF-8",
48
49
  method: "post"
49
50
  },
50
51
  extras: {
@@ -52,23 +53,23 @@ would output
52
53
  name: "_method",
53
54
  type: "hidden",
54
55
  defaultValue: "patch",
55
- autocomplete: "off"
56
+ autoComplete: "off"
56
57
  },
57
58
  utf8: {
58
59
  name: "utf8",
59
60
  type: "hidden",
60
61
  defaultValue: "\u0026#x2713;",
61
- autocomplete: "off"
62
+ autoComplete: "off"
62
63
  }
63
64
  csrf: {
64
65
  name: "utf8",
65
66
  type: "authenticity_token",
66
67
  defaultValue: "SomeTOken!23$",
67
- autocomplete: "off"
68
+ autoComplete: "off"
68
69
  }
69
70
  },
70
71
  inputs: {
71
- name: {type: "text", defaultValue: "hello"},
72
+ title: {name: "post[title]", id: "post_title", type: "text", defaultValue: "hello"},
72
73
  submit: {type: "submit", value: "Update a Post"}
73
74
  }
74
75
  }
@@ -82,12 +83,11 @@ import React from 'react'
82
83
 
83
84
  export default ({props, inputs, extras}) => {
84
85
  <form {...props}>
85
- {Object.values(extras).map((hiddenProps) => (<input {...hiddenProps} type="hidden"/>))}
86
-
87
- <input {...inputs.name} type="text"/>
88
- <label for={inputs.name.id}>Your Name</label>
86
+ {Object.values(extras).map((hiddenProps) => (<input {...hiddenProps} key={hiddenProps.name}/>))}
89
87
 
90
- <input {...inputs.submit} type="submit"/>
88
+ <input {...inputs.title} />
89
+ <label for={inputs.title.id}>Your Name</label>
90
+ <button {...inputs.submit}>{inputs.submit.text}</button>
91
91
  </form>
92
92
  }
93
93
  ```
@@ -190,7 +190,7 @@ By default, the `controlled` option is `false`.
190
190
 
191
191
  ###
192
192
 
193
- `props` Attributes that you can splat direclty into your `<form>` element.
193
+ `props` Attributes that you can splat directly into your `<form>` element.
194
194
 
195
195
 
196
196
  `extras` contain hidden input attributes that are created by form_props
@@ -647,7 +647,7 @@ available.
647
647
 
648
648
  ## jbuilder
649
649
 
650
- form_props can work with jbuilder, but needs an extra call in the beginning of
650
+ form_props can work with jbuilder, but needs an extra call in the beginning of
651
651
  your template to `FormProps.set` to inject `json`. For example.
652
652
 
653
653
  ```ruby
@@ -40,6 +40,7 @@ module FormProps
40
40
  end
41
41
 
42
42
  html_options = html_options_for_form_with(url, model, **options)
43
+ html_options["acceptCharset"] ||= html_options.delete("accept-charset")
43
44
 
44
45
  json.extras do
45
46
  extra_props_for_form(json, html_options)
@@ -62,7 +63,7 @@ module FormProps
62
63
  json.name request_forgery_protection_token.to_s
63
64
  json.type "hidden"
64
65
  json.default_value token
65
- json.autocomplete "off"
66
+ json.auto_complete "off"
66
67
  end
67
68
  end
68
69
  end
@@ -72,7 +73,7 @@ module FormProps
72
73
  json.name "_method"
73
74
  json.type "hidden"
74
75
  json.default_value method.to_s
75
- json.autocomplete "off"
76
+ json.auto_complete "off"
76
77
  end
77
78
  end
78
79
 
@@ -81,7 +82,7 @@ module FormProps
81
82
  json.name "utf8"
82
83
  json.type "hidden"
83
84
  json.default_value "&#x2713;"
84
- json.autocomplete "off"
85
+ json.auto_complete "off"
85
86
  end
86
87
  end
87
88
 
@@ -132,7 +132,7 @@ module FormProps
132
132
  def submit(value = nil, options = {})
133
133
  value, options = nil, value if value.is_a?(Hash)
134
134
  value ||= submit_default_value
135
- options = {name: "commit", value: value}.update(options)
135
+ options = {name: "commit", text: value}.update(options)
136
136
 
137
137
  Inputs::Submit.new(@template, options).render
138
138
  end
@@ -4,7 +4,7 @@ module FormProps
4
4
  module Inputs
5
5
  class HiddenField < TextField
6
6
  def render
7
- @options[:autocomplete] = "off"
7
+ @options[:auto_complete] = "off"
8
8
  super
9
9
  end
10
10
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FormProps
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.3"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: form_props
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johny Ho
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-30 00:00:00.000000000 Z
11
+ date: 2023-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: 7.0.0
41
41
  - !ruby/object:Gem::Dependency
42
- name: props_tempate
42
+ name: props_template
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="