@react-foundry/form 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (C) 2019-2025 Crown Copyright
4
+ Copyright (C) 2019-2026 Daniel A.C. Martin
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
7
+ this software and associated documentation files (the "Software"), to deal in
8
+ the Software without restriction, including without limitation the rights to
9
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10
+ of the Software, and to permit persons to whom the Software is furnished to do
11
+ so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,102 @@
1
+ React Foundry - Form
2
+ ====================
3
+
4
+ A component to collect information from the user.
5
+
6
+
7
+ Using this package
8
+ ------------------
9
+
10
+ First install the package into your project:
11
+
12
+ ```shell
13
+ npm install -S @react-foundry/form
14
+ ```
15
+
16
+ Then use it in your code as follows:
17
+
18
+ ```js
19
+ import React, { createElement as h } from 'react';
20
+ import Form from '@react-foundry/form';
21
+
22
+ export const MyComponent = props => (
23
+ <Form action="/result" method="get">
24
+ <Form.TextInput
25
+ name="fullName"
26
+ label={<h2>What is your name?</h2>}
27
+ hint="Write your firstname followed by your surname"
28
+ validators={[
29
+ required()
30
+ ]}
31
+ />
32
+ <Form.Radios
33
+ name="sex"
34
+ label={<h2>Sex?</h2>}
35
+ options={[
36
+ { value: 'male', label: 'Male' },
37
+ { value: 'female', label: 'Female' },
38
+ { value: 'no', label: 'No thanks, we\'re British' }
39
+ ]}
40
+ validators={[
41
+ required('Provide your sex')
42
+ ]}
43
+ />
44
+ <Form.DateInput
45
+ name="dob"
46
+ prettyName="date of birth"
47
+ label={<h2>What is your date of birth?</h2>}
48
+ validators={[
49
+ required('Provide your date of birth'),
50
+ past(),
51
+ after('1900-01-01')()
52
+ ]}
53
+ />
54
+ <Form.Radios
55
+ name="married"
56
+ label={<h2>Are you married?</h2>}
57
+ options={[
58
+ { value: 'Y', label: 'Yes' },
59
+ { value: 'N', label: 'No' }
60
+ ]}
61
+ validators={[
62
+ required('Provide your marital status')
63
+ ]}
64
+ />
65
+ <Form.Submit value="Submit" />
66
+ </Form>
67
+ );
68
+
69
+ export default MyComponent;
70
+ ```
71
+
72
+
73
+ Working on this package
74
+ -----------------------
75
+
76
+ Before working on this package you must install its dependencies using
77
+ the following command:
78
+
79
+ ```shell
80
+ pnpm install
81
+ ```
82
+
83
+
84
+ ### Testing
85
+
86
+ ```shell
87
+ npm test
88
+ ```
89
+
90
+
91
+ ### Building
92
+
93
+ ```shell
94
+ npm run build
95
+ ```
96
+
97
+
98
+ ### Clean-up
99
+
100
+ ```shell
101
+ npm run clean
102
+ ```
File without changes
package/dist/Form.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ import type { ComponentProps, ComponentType, FC } from 'react';
2
+ import WTForm from '@react-foundry/forms';
3
+ import '../assets/Form.scss';
4
+ export type FormProps = ComponentProps<typeof WTForm>;
5
+ type TForm = ComponentType<FormProps> & {
6
+ Checkboxes: ComponentType<any>;
7
+ DateInput: ComponentType<any>;
8
+ Fork: ComponentType<any>;
9
+ Input: ComponentType<any>;
10
+ Page: ComponentType<any>;
11
+ Radios: ComponentType<any>;
12
+ Select: ComponentType<any>;
13
+ Submit: ComponentType<any>;
14
+ Textarea: ComponentType<any>;
15
+ TextInput: ComponentType<any>;
16
+ };
17
+ export declare const FormComponent: FC<FormProps>;
18
+ export declare const Form: TForm;
19
+ export default Form;
20
+ export { after, before, date, email, exactLength, future, integer, maximum, maxLength, maxWords, minimum, minLength, minWords, numeric, past, range, required, url, validator, withControl, withForm, withField } from '@react-foundry/forms';
21
+ export type { RawField } from '@react-foundry/forms';
package/dist/Form.js ADDED
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.withField = exports.withForm = exports.withControl = exports.validator = exports.url = exports.required = exports.range = exports.past = exports.numeric = exports.minWords = exports.minLength = exports.minimum = exports.maxWords = exports.maxLength = exports.maximum = exports.integer = exports.future = exports.exactLength = exports.email = exports.date = exports.before = exports.after = exports.Form = exports.FormComponent = void 0;
37
+ const react_1 = require("react");
38
+ const forms_1 = __importStar(require("@react-foundry/forms"));
39
+ const controls_1 = require("./controls");
40
+ const fields_1 = require("./fields");
41
+ require("../assets/Form.scss");
42
+ const FormComponent = ({ classBlock, ...props }) => (0, react_1.createElement)(forms_1.default, {
43
+ ...props,
44
+ classBlock: classBlock || 'react-foundry-form'
45
+ });
46
+ exports.FormComponent = FormComponent;
47
+ exports.Form = Object.assign(exports.FormComponent, {
48
+ Checkboxes: fields_1.Checkboxes,
49
+ DateInput: fields_1.DateInput,
50
+ Fork: forms_1.Fork,
51
+ Input: fields_1.Input,
52
+ Page: forms_1.Page,
53
+ Radios: fields_1.Radios,
54
+ Select: fields_1.Select,
55
+ Submit: controls_1.Submit,
56
+ Textarea: fields_1.Textarea,
57
+ TextInput: fields_1.TextInput
58
+ });
59
+ exports.default = exports.Form;
60
+ var forms_2 = require("@react-foundry/forms");
61
+ Object.defineProperty(exports, "after", { enumerable: true, get: function () { return forms_2.after; } });
62
+ Object.defineProperty(exports, "before", { enumerable: true, get: function () { return forms_2.before; } });
63
+ Object.defineProperty(exports, "date", { enumerable: true, get: function () { return forms_2.date; } });
64
+ Object.defineProperty(exports, "email", { enumerable: true, get: function () { return forms_2.email; } });
65
+ Object.defineProperty(exports, "exactLength", { enumerable: true, get: function () { return forms_2.exactLength; } });
66
+ Object.defineProperty(exports, "future", { enumerable: true, get: function () { return forms_2.future; } });
67
+ Object.defineProperty(exports, "integer", { enumerable: true, get: function () { return forms_2.integer; } });
68
+ Object.defineProperty(exports, "maximum", { enumerable: true, get: function () { return forms_2.maximum; } });
69
+ Object.defineProperty(exports, "maxLength", { enumerable: true, get: function () { return forms_2.maxLength; } });
70
+ Object.defineProperty(exports, "maxWords", { enumerable: true, get: function () { return forms_2.maxWords; } });
71
+ Object.defineProperty(exports, "minimum", { enumerable: true, get: function () { return forms_2.minimum; } });
72
+ Object.defineProperty(exports, "minLength", { enumerable: true, get: function () { return forms_2.minLength; } });
73
+ Object.defineProperty(exports, "minWords", { enumerable: true, get: function () { return forms_2.minWords; } });
74
+ Object.defineProperty(exports, "numeric", { enumerable: true, get: function () { return forms_2.numeric; } });
75
+ Object.defineProperty(exports, "past", { enumerable: true, get: function () { return forms_2.past; } });
76
+ Object.defineProperty(exports, "range", { enumerable: true, get: function () { return forms_2.range; } });
77
+ Object.defineProperty(exports, "required", { enumerable: true, get: function () { return forms_2.required; } });
78
+ Object.defineProperty(exports, "url", { enumerable: true, get: function () { return forms_2.url; } });
79
+ Object.defineProperty(exports, "validator", { enumerable: true, get: function () { return forms_2.validator; } });
80
+ Object.defineProperty(exports, "withControl", { enumerable: true, get: function () { return forms_2.withControl; } });
81
+ Object.defineProperty(exports, "withForm", { enumerable: true, get: function () { return forms_2.withForm; } });
82
+ Object.defineProperty(exports, "withField", { enumerable: true, get: function () { return forms_2.withField; } });
package/dist/Form.mjs ADDED
@@ -0,0 +1,23 @@
1
+ import { createElement as h } from 'react';
2
+ import WTForm, { Fork, Page } from '@react-foundry/forms';
3
+ import { Submit } from './controls';
4
+ import { Checkboxes, DateInput, Input, Radios, Select, Textarea, TextInput } from './fields';
5
+ import '../assets/Form.scss';
6
+ export const FormComponent = ({ classBlock, ...props }) => h(WTForm, {
7
+ ...props,
8
+ classBlock: classBlock || 'react-foundry-form'
9
+ });
10
+ export const Form = Object.assign(FormComponent, {
11
+ Checkboxes,
12
+ DateInput,
13
+ Fork,
14
+ Input,
15
+ Page,
16
+ Radios,
17
+ Select,
18
+ Submit,
19
+ Textarea,
20
+ TextInput
21
+ });
22
+ export default Form;
23
+ export { after, before, date, email, exactLength, future, integer, maximum, maxLength, maxWords, minimum, minLength, minWords, numeric, past, range, required, url, validator, withControl, withForm, withField } from '@react-foundry/forms';
@@ -0,0 +1,5 @@
1
+ import type { ButtonHTMLAttributes, ComponentType } from 'react';
2
+ import type { ControlProps } from '@react-foundry/forms';
3
+ type SubmitButtonProps = ButtonHTMLAttributes<HTMLButtonElement>;
4
+ export declare const Submit: ComponentType<SubmitButtonProps & ControlProps>;
5
+ export {};
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Submit = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const forms_1 = require("@react-foundry/forms");
6
+ const SubmitButton = ({ children, ...props }) => ((0, jsx_runtime_1.jsx)("button", { ...props, type: "submit", children: children }));
7
+ SubmitButton.displayName = 'Submit';
8
+ exports.Submit = (0, forms_1.withControl)(SubmitButton);
@@ -0,0 +1,5 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { withControl } from '@react-foundry/forms';
3
+ const SubmitButton = ({ children, ...props }) => (_jsx("button", { ...props, type: "submit", children: children }));
4
+ SubmitButton.displayName = 'Submit';
5
+ export const Submit = withControl(SubmitButton);
@@ -0,0 +1,13 @@
1
+ import type { ComponentType, InputHTMLAttributes, SelectHTMLAttributes, TextareaHTMLAttributes } from 'react';
2
+ import type { FieldProps } from '@react-foundry/forms';
3
+ type InputProps = InputHTMLAttributes<HTMLInputElement>;
4
+ type SelectProps = SelectHTMLAttributes<HTMLSelectElement> & {
5
+ options: any[];
6
+ };
7
+ type TextareaProps = TextareaHTMLAttributes<HTMLTextAreaElement>;
8
+ export declare const Input: ComponentType<InputProps & FieldProps>;
9
+ export declare const TextInput: ComponentType<InputProps & FieldProps>;
10
+ export declare const DateInput: ComponentType<InputProps & FieldProps>;
11
+ export declare const Select: ComponentType<SelectProps & FieldProps>;
12
+ export declare const Textarea: ComponentType<TextareaProps & FieldProps>;
13
+ export { Select as Checkboxes, Select as Radios };
package/dist/fields.js ADDED
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Radios = exports.Checkboxes = exports.Textarea = exports.Select = exports.DateInput = exports.TextInput = exports.Input = void 0;
4
+ const react_1 = require("react");
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const forms_1 = require("@react-foundry/forms");
7
+ const _Input = ({ ...props }) => ((0, jsx_runtime_1.jsx)("input", { ...props }));
8
+ const _TextInput = ({ ...props }) => ((0, jsx_runtime_1.jsx)("input", { type: "text", ...props }));
9
+ const _DateInput = ({ ...props }) => ((0, jsx_runtime_1.jsx)("input", { type: "date", ...props }));
10
+ const _Select = ({ options, ...props }) => ((0, jsx_runtime_1.jsx)("select", { ...props, children: options.map(({ label, selected, ...attrs }, i) => ((0, react_1.createElement)("option", { ...attrs, key: i }, label))) }));
11
+ const _Textarea = ({ ...props }) => ((0, jsx_runtime_1.jsx)("textarea", { ...props }));
12
+ _Input.displayName = 'Input';
13
+ _TextInput.displayName = 'TextInput';
14
+ _DateInput.displayName = 'DateInput';
15
+ _Select.displayName = 'Select';
16
+ _Textarea.displayName = 'Textarea';
17
+ exports.Input = (0, forms_1.withForm)(_Input);
18
+ exports.TextInput = (0, forms_1.withForm)(_TextInput);
19
+ exports.DateInput = (0, forms_1.withForm)(_DateInput);
20
+ exports.Select = (0, forms_1.withForm)(_Select);
21
+ exports.Checkboxes = exports.Select;
22
+ exports.Radios = exports.Select;
23
+ exports.Textarea = (0, forms_1.withForm)(_Textarea);
@@ -0,0 +1,19 @@
1
+ import { createElement as _createElement } from "react";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { withForm } from '@react-foundry/forms';
4
+ const _Input = ({ ...props }) => (_jsx("input", { ...props }));
5
+ const _TextInput = ({ ...props }) => (_jsx("input", { type: "text", ...props }));
6
+ const _DateInput = ({ ...props }) => (_jsx("input", { type: "date", ...props }));
7
+ const _Select = ({ options, ...props }) => (_jsx("select", { ...props, children: options.map(({ label, selected, ...attrs }, i) => (_createElement("option", { ...attrs, key: i }, label))) }));
8
+ const _Textarea = ({ ...props }) => (_jsx("textarea", { ...props }));
9
+ _Input.displayName = 'Input';
10
+ _TextInput.displayName = 'TextInput';
11
+ _DateInput.displayName = 'DateInput';
12
+ _Select.displayName = 'Select';
13
+ _Textarea.displayName = 'Textarea';
14
+ export const Input = withForm(_Input);
15
+ export const TextInput = withForm(_TextInput);
16
+ export const DateInput = withForm(_DateInput);
17
+ export const Select = withForm(_Select);
18
+ export const Textarea = withForm(_Textarea);
19
+ export { Select as Checkboxes, Select as Radios };
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@react-foundry/form",
3
+ "version": "0.1.0",
4
+ "description": "A component to collect information from the user.",
5
+ "main": "dist/Form.js",
6
+ "sass": "assets/Form.scss",
7
+ "exports": {
8
+ ".": {
9
+ "sass": "./assets/Form.scss",
10
+ "types": "./dist/Form.d.ts",
11
+ "import": "./dist/Form.mjs",
12
+ "require": "./dist/Form.js",
13
+ "default": "./dist/Form.mjs"
14
+ }
15
+ },
16
+ "files": [
17
+ "/assets",
18
+ "/dist"
19
+ ],
20
+ "author": "Daniel A.C. Martin <npm@daniel-martin.co.uk> (http://daniel-martin.co.uk/)",
21
+ "license": "MIT",
22
+ "keywords": [
23
+ "react-components"
24
+ ],
25
+ "dependencies": {
26
+ "@react-foundry/forms": "^0.1.0"
27
+ },
28
+ "peerDependencies": {
29
+ "@react-foundry/docs-components": "^0.1.0",
30
+ "@storybook/addon-docs": "^9.1.17",
31
+ "react": "^19.2.3"
32
+ },
33
+ "peerDependenciesMeta": {
34
+ "@react-foundry/docs-components": {
35
+ "optional": true
36
+ },
37
+ "@storybook/addon-docs": {
38
+ "optional": true
39
+ }
40
+ },
41
+ "devDependencies": {
42
+ "@types/react": "19.2.9",
43
+ "jest": "30.2.0",
44
+ "jest-environment-jsdom": "30.2.0",
45
+ "ts-jest": "29.4.6",
46
+ "typescript": "5.9.3",
47
+ "@react-foundry/component-test-helpers": "0.1.0"
48
+ },
49
+ "scripts": {
50
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest",
51
+ "build": "npm run build:esm && npm run build:cjs",
52
+ "build:esm": "tsc -m es2022 && find dist -name '*.js' -exec sh -c 'mv \"$0\" \"${0%.js}.mjs\"' {} \\;",
53
+ "build:cjs": "tsc",
54
+ "clean": "rm -rf dist tsconfig.tsbuildinfo"
55
+ },
56
+ "module": "dist/Form.mjs",
57
+ "typings": "dist/Form.d.ts"
58
+ }