{"id":20737982,"url":"https://github.com/stephencookdev/react-t-shirt-forms","last_synced_at":"2025-03-11T11:28:36.761Z","repository":{"id":34149908,"uuid":"166577349","full_name":"stephencookdev/react-t-shirt-forms","owner":"stephencookdev","description":null,"archived":false,"fork":false,"pushed_at":"2023-01-07T02:51:27.000Z","size":3057,"stargazers_count":0,"open_issues_count":27,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-19T05:33:48.889Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stephencookdev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-19T18:03:58.000Z","updated_at":"2019-07-12T08:48:14.000Z","dependencies_parsed_at":"2023-01-15T04:55:33.285Z","dependency_job_id":null,"html_url":"https://github.com/stephencookdev/react-t-shirt-forms","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephencookdev%2Freact-t-shirt-forms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephencookdev%2Freact-t-shirt-forms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephencookdev%2Freact-t-shirt-forms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephencookdev%2Freact-t-shirt-forms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stephencookdev","download_url":"https://codeload.github.com/stephencookdev/react-t-shirt-forms/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243024563,"owners_count":20223630,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T06:16:08.491Z","updated_at":"2025-03-11T11:28:36.726Z","avatar_url":"https://github.com/stephencookdev.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 👕 React T-Shirt Forms\n\nSometimes life calls for more than a t-shirt. But t-shirts are easy, and comfortable - a good default until you need more.\n\n## Another Form Library?\n\nMaking a form in React is hard. Needlessly hard, with a _lot_ of boilerplate - even when using any of the popular React form libraries.\n\nT-Shirt Forms is intended to make creating simple forms simple.\n\nIt is powerful enough to handle complex and irregular cases, but it is more heavily geared towards reducing the boilerplate around _regular_ forms.\n\nIf your app has lots of complex and irregular forms, then this library is probably not going to be the best solution. I would recommend looking at [Formik](https://github.com/jaredpalmer/formik) instead.\n\n## Installing\n\n```\nnpm install --save-dev react-t-shirt-forms\n```\n\nor\n\n```\nyarn add -D react-t-shirt-forms\n```\n\n## Usage\n\n### API\n\nSee the [API docs](./api).\n\n### Examples\n\nWe show some basic examples on this page.\n\nBut you can see some more common flows [in the examples](./examples).\n\n### Bare Bones Form\n\n```javascript\nimport TShirtForm from \"react-t-shirt-forms\";\n\n// by default no styling is included in your bundle\n// but you can pull in a basic CSS file if you like\nimport \"react-t-shirt-forms/dist/stylesheets/basic.min.css\";\n\nconst formSchema = {\n  name: {\n    type: \"string\",\n    label: \"Name\",\n    initialValue: \"Bruce Wayne\"\n  },\n  email: {\n    type: \"email\",\n    label: \"Email\"\n  }\n};\n\nconst onFormSubmit = async ({ formArgs }) =\u003e {\n  console.log(JSON.stringify(formArgs, null, 2));\n};\n\nconst App = () =\u003e (\n  \u003cTShirtForm schema={formSchema} handleSubmit={onFormSubmit} /\u003e\n);\n```\n\n### Validation\n\nT-Shirt Forms allows integration with any validation library, but comes with out of the box hooks for [yup](https://github.com/jquense/yup).\n\n```javascript\nimport * as yup from \"yup\";\nimport { addValidation, yupSupport } from \"react-t-shirt-forms\";\n\n// this tells T-Shirt Forms to use `yup` for any validations\n// it also adds default validations for common fields\naddValidation(yup, yupSupport);\n```\n\nNow you can use `yup` validations in your form schema:\n\n```javascript\nconst formSchema = {\n  name: {\n    type: \"string\",\n    label: \"Name\",\n    validation: yup()\n      .string()\n      .min(10)\n  }\n};\n```\n\n### Custom Fields\n\nIf you have a custom React component that you need to use for all password inputs, you can specify a global rule for this.\n\n```javascript\nimport { setSchemaDefaults } from \"react-t-shirt-forms\";\n\nconst MyCustomPasswordInput = ({ onChange, onBlur, value, label }) =\u003e (\n  \u003clabel\u003e\n    {label}\n    \u003cinput\n      type=\"password\"\n      value={value}\n      onChange={e =\u003e onChange(e.target.value)}\n      onBlur={e =\u003e onBlur(e)}\n    /\u003e\n  \u003c/label\u003e\n);\n\nsetSchemaDefaults({\n  type: {\n    password: {\n      component: MyCustomPasswordInput\n    }\n  }\n});\n```\n\nand now whenever you use a password input field\n\n```javascript\nconst formSchema = {\n  myPasswordField: {\n    type: \"password\",\n    label: \"My custom password field\"\n  }\n};\n```\n\nyou'll see that it's using your `MyCustomPasswordInput` component.\n\n## Bundle Size\n\nT-Shirt Forms makes an effort to be minimal and modular.\n\nHere's a look at its size, after tree-shaking, in different contexts:\n\n- bare bones (22.61 KB / **6.30 KB gzipped**)\n- with CSS stylings (30.89 KB / **9.11 KB gzipped**)\n- with yup validation (30.93 KB / **9.13 KB gzipped**)\n\n## Contributing\n\nContributors are welcome! 😊\n\nCheck out the [CONTRIBUTING.md](./CONTRIBUTING.md).\n\n## License\n\n[MIT](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstephencookdev%2Freact-t-shirt-forms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstephencookdev%2Freact-t-shirt-forms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstephencookdev%2Freact-t-shirt-forms/lists"}