Skip to content

Commit

Permalink
fix(docs): updated samples to use typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
robertLichtnow committed Nov 3, 2021
1 parent f240199 commit 5321085
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 46 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
dist
coverage
coverage
.vscode
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,21 @@ $ yarn add zod-formik-adapter

## Usage

```JSX
const { z } = require('zod');
const { Formik } = require('formik');
const { toFormikValidationSchema } = require('zod-formik-adapter');

```TSX
import { z } from 'zod';
import { Formik } from 'formik';
import { toFormikValidationSchema } from 'zod-formik-adapter';

const Schema = z.object({
name: z.string(),
age: z.number(),
});

function Component = () => (
const Component = () => (
<Formik
validationSchema={toFormikValidationSchema(Schema)}
>
{...}
</Formik>
)

);
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
"peerDependencies": {
"formik": "^2.2.9",
"react": "^17.0.2",
"zod": "^3.7.2"
"zod": "~3.7.2"
}
}
33 changes: 0 additions & 33 deletions samples/index.jsx

This file was deleted.

32 changes: 32 additions & 0 deletions samples/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react';
import { Formik } from 'formik';
import { z } from 'zod';
import { toFormikValidationSchema } from 'zod-formik-adapter';

const Schema = z.object({
name: z.string(),
age: z.number(),
});

const initialValues = {
name: "",
age: 1,
}

export const SampleForm = () => (
<Formik
initialValues={initialValues}
validationSchema={toFormikValidationSchema(Schema)}
onSubmit={console.log}
>
{({ errors, values, handleChange }) => (
<form>
<input value={values.name} onChange={handleChange("name")} />
<span>{errors.name}</span>

<input value={values.age} onChange={handleChange("age")} />
<span>{errors.age}</span>
</form>
)}
</Formik>
);
8 changes: 7 additions & 1 deletion samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
"dependencies": {
"formik": "^2.2.9",
"react": "^17.0.2",
"zod-formik-adapter": "file:../"
"react-dom": "^17.0.2",
"zod": "~3.7.2",
"zod-formik-adapter": "^1.0.1"
},
"devDependencies": {
"@types/react-dom": "^17.0.11",
"typescript": "^4.4.4"
}
}
11 changes: 11 additions & 0 deletions samples/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"jsx": "react",
"target": "es5",
"module": "commonjs",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}
64 changes: 62 additions & 2 deletions samples/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,37 @@
# yarn lockfile v1


"@types/prop-types@*":
version "15.7.4"
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.4.tgz#fcf7205c25dff795ee79af1e30da2c9790808f11"
integrity sha512-rZ5drC/jWjrArrS8BR6SIr4cWpW09RNTYt9AMZo3Jwwif+iacXAqgVjm0B0Bv/S1jhDXKHqRVNCbACkJ89RAnQ==

"@types/react-dom@^17.0.11":
version "17.0.11"
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-17.0.11.tgz#e1eadc3c5e86bdb5f7684e00274ae228e7bcc466"
integrity sha512-f96K3k+24RaLGVu/Y2Ng3e1EbZ8/cVJvypZWd7cy0ofCBaf2lcM46xNhycMZ2xGwbBjRql7hOlZ+e2WlJ5MH3Q==
dependencies:
"@types/react" "*"

"@types/react@*":
version "17.0.34"
resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.34.tgz#797b66d359b692e3f19991b6b07e4b0c706c0102"
integrity sha512-46FEGrMjc2+8XhHXILr+3+/sTe3OfzSPU9YGKILLrUYbQ1CLQC9Daqo1KzENGXAWwrFwiY0l4ZbF20gRvgpWTg==
dependencies:
"@types/prop-types" "*"
"@types/scheduler" "*"
csstype "^3.0.2"

"@types/scheduler@*":
version "0.16.2"
resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.2.tgz#1a62f89525723dde24ba1b01b092bf5df8ad4d39"
integrity sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==

csstype@^3.0.2:
version "3.0.9"
resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.0.9.tgz#6410af31b26bd0520933d02cbc64fce9ce3fbf0b"
integrity sha512-rpw6JPxK6Rfg1zLOYCSwle2GFOOsnjmDYDaBwEcwoOg4qlsIVCN789VkBZDJAGi4T07gI4YSutR43t9Zz4Lzuw==

deepmerge@^2.1.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-2.2.1.tgz#5d3ff22a01c00f645405a2fbc17d0778a1801170"
Expand Down Expand Up @@ -54,6 +85,15 @@ object-assign@^4.1.1:
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=

react-dom@^17.0.2:
version "17.0.2"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-17.0.2.tgz#ecffb6845e3ad8dbfcdc498f0d0a939736502c23"
integrity sha512-s4h96KtLDUQlsENhMn1ar8t2bEa+q/YAtj8pPPdIjPDGBDIVNsrD9aXNWqspUe6AzKCIG0C1HZZLqLV7qpOBGA==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
scheduler "^0.20.2"

react-fast-compare@^2.0.1:
version "2.0.4"
resolved "https://registry.yarnpkg.com/react-fast-compare/-/react-fast-compare-2.0.4.tgz#e84b4d455b0fec113e0402c329352715196f81f9"
Expand All @@ -72,6 +112,14 @@ react@^17.0.2:
loose-envify "^1.1.0"
object-assign "^4.1.1"

scheduler@^0.20.2:
version "0.20.2"
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.20.2.tgz#4baee39436e34aa93b4874bddcbf0fe8b8b50e91"
integrity sha512-2eWfGgAqqWFGqtdMmcL5zCMK1U8KlXv8SQFGglL3CEtd0aDVDWgeF/YoCmvln55m5zSk3J/20hTaSBeSObsQDQ==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"

tiny-warning@^1.0.2:
version "1.0.3"
resolved "https://registry.yarnpkg.com/tiny-warning/-/tiny-warning-1.0.3.tgz#94a30db453df4c643d0fd566060d60a875d84754"
Expand All @@ -82,5 +130,17 @@ tslib@^1.10.0:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==

"zod-formik-adapter@file:..":
version "1.0.0"
typescript@^4.4.4:
version "4.4.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.4.tgz#2cd01a1a1f160704d3101fd5a58ff0f9fcb8030c"
integrity sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA==

zod-formik-adapter@~1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/zod-formik-adapter/-/zod-formik-adapter-1.0.1.tgz#6b12fe20ae17cd005aec73dc10de3381a347a92a"
integrity sha512-TzX7/kpibeb6BCh0wLIM/tCX4nKbWJCfJRr6AmhP0CZEjFY8hBfVX6Y6Ir6UTkhNcCjj8cy28jQlrLmEwDefjw==

zod@~3.7.2:
version "3.7.3"
resolved "https://registry.yarnpkg.com/zod/-/zod-3.7.3.tgz#83363e528de4538429f0b5828a5a0ad6198b70e1"
integrity sha512-g2vA55KUfAkQPNPg0Ikj1Qy9THLUBHlnh2ZRXJc0eUaue81Sm0J4w1daRcuzdgapxn+J71kbxg0lBqMJJZSK5g==

0 comments on commit 5321085

Please sign in to comment.