@@ -10,6 +10,7 @@ An input component to serve the common good.
1010* [ Installation] ( #installation )
1111* [ Usage] ( #usage )
1212* [ Styles] ( #styles )
13+ * [ FAQ] ( #FAQ )
1314* [ Examples] ( #examples )
1415
1516## Installation
@@ -69,6 +70,32 @@ A basic example may be;
6970}
7071```
7172
73+ ## FAQ
74+ (Mostly asked by myself, to myself)
75+
76+ * Why does this component even exist?
77+ Initially developing an application heavily dependent on HTML 'Input' elements,
78+ I was quickly overwhelmed with the vast options of options available on NPM.
79+ These options, whilst not opinionated, often didn't quite meet my requirements,
80+ which I felt really were 'core' and 'key' features of an input.
81+
82+ In working on this app, I developed my own (app specific) child component, made
83+ it rather hard to conveniently include in other projects. Work invested in copy
84+ / paste quickly became tedious (And the wrong way to manage things anyway).
85+
86+ Thus; react-component_input.js was born
87+
88+ * Goals of this Project
89+ The goal of this project is to provide a 'core'/'key' feature functional input
90+ component that performs nothing outside of that scope. These should also provide
91+ appropriate functionality that is exposed by React (Otherwise; what would be the
92+ point of making this a react component, right?)
93+
94+ Overall; this is one of the reasons styles are completely abstract from the
95+ project.
96+
97+ Yes.. Yes. It's not perfect.. :( See... [ Validation] ( #Validation )
98+
7299## Examples
73100
74101Inside an app:
@@ -107,4 +134,59 @@ class App extends Component {
107134}
108135
109136export default App ;
110- ```
137+ ```
138+
139+ ## Validation
140+ Oh gosh; how I wanted to/will eventually leave this out of the component. In its
141+ current state; this is an inbuilt and entirely custom to component feature.
142+ Validation, in it's pure form; isn't really built into HTML Inputs, nor should
143+ it ever be purely depended on for any form of 'backend' processing.
144+
145+ For now; the behavior was included to provide exposure to the validation
146+ error.
147+
148+ See; https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input
149+
150+ So.. for now, against my personal preference, and the project goals; it's
151+ included.
152+
153+ This is how it works;
154+
155+ Validation is a, or an array of, objects which contain a 'callback', and
156+ validation error message. This object is provided to the component via the
157+ 'validation' prop.
158+
159+ The callback functions are passed the value of the triggered input, as
160+ provided by the (React Event)[ https://reactjs.org/docs/handling-events.html ] .
161+ The return of the function, true or false, is used to determine the state of the
162+ component. If false; the validation error is rendered. If an array of validation
163+ is provided, and one fails - the component fails validation, however; only the
164+ failing validation object error message is shown.
165+
166+ An example validation object may be;
167+
168+ ``` js
169+ let validMinLength = (length = 0 ) => ({
170+ errorMessage:
171+ ' The length of your input must be more than ' + parseInt (length),
172+ callback : value => value .length >= parseInt (length)
173+ });
174+ ```
175+ and
176+ ``` js
177+ let validMinLength = (length = 0 ) => ({
178+ errorMessage:
179+ ' The length of your input must be more than ' + parseInt (length),
180+ callback : value => value .length >= parseInt (length)
181+ });
182+ ```
183+
184+ This is then passed to the component via the validation property.
185+ ``` jsx
186+ validation= {validMinLength (10 )}
187+ ```
188+
189+ As stated, as an array;
190+ ``` jsx
191+ validation= {[validMaxLength (32 ), validMinLength (10 )]}
192+ ```
0 commit comments