Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Zod bridge - passing props #1321

Merged
merged 5 commits into from
May 24, 2024
Merged

Improve Zod bridge - passing props #1321

merged 5 commits into from
May 24, 2024

Conversation

piotrpospiech
Copy link
Collaborator

@piotrpospiech piotrpospiech commented Apr 20, 2024

  • Extended Zod with custom ZodType function to pass custom props to the field
  • It supports passing props objects or uniforms component
  • It's based on the uniforms extension for the SimpleSchema2Bridge, but it doesn't support passing string (I tested it with SimpleSchema, and it doesn't work, either. It needs further investigation)
  • It's possible to add a custom label now via props (mentioned in the Improve Zod integration #1210)

Further work:

Support custom labels for error messages (#1320)

Example:

import z from "zod";
import { DateField } from "uniforms-semantic";
import { ZodBridge } from "uniforms-bridge-zod";

const schema = z.object({
  date: z.string().uniforms(DateField),
  number: z.string().uniforms({ component: NumField, disabled: true }),
  username: z.string().min(4).uniforms({ label: "Custom label (username)" }),
  password: z.string().uniforms({ type: "password" }),
});

const bridge = new ZodBridge({ schema });
image

@piotrpospiech piotrpospiech added this to the v4.0 milestone Apr 20, 2024
@piotrpospiech piotrpospiech self-assigned this Apr 20, 2024
@github-actions github-actions bot added Area: Bridge Affects some of the bridge packages Bridge: Zod Affects the uniforms-bridge-zod package labels Apr 20, 2024
Copy link

codecov bot commented May 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.57%. Comparing base (4b3f109) to head (da8fd1d).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1321      +/-   ##
==========================================
+ Coverage   94.55%   94.57%   +0.01%     
==========================================
  Files         231      231              
  Lines        3823     3831       +8     
  Branches     1030     1031       +1     
==========================================
+ Hits         3615     3623       +8     
  Misses         82       82              
  Partials      126      126              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@piotrpospiech piotrpospiech merged commit 75dbb94 into master May 24, 2024
7 checks passed
@piotrpospiech piotrpospiech deleted the zod-props branch May 24, 2024 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Bridge Affects some of the bridge packages Bridge: Zod Affects the uniforms-bridge-zod package
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants