diff --git a/website/components/Playground.tsx b/website/components/Playground.tsx index 7e88adc0e..000329cc9 100644 --- a/website/components/Playground.tsx +++ b/website/components/Playground.tsx @@ -14,6 +14,10 @@ import styles from '../lib/styles'; import { themes } from '../lib/universal'; import { compress, parseQuery, updateQuery } from '../lib/utils'; +function replacer(key: string, value: any) { + return value === undefined ? 'undefined' : value; +} + export class Playground extends Component { static getDerivedStateFromError(error: Error) { return { error }; @@ -116,7 +120,12 @@ const PlaygroundModelDebug = () => {

-        {`const model = ${JSON.stringify(model, null, 2)};`}
+        
+          {`const model = ${JSON.stringify(model, replacer, 2)};`.replace(
+            /"undefined"/g,
+            'undefined',
+          )}
+        
       
); @@ -198,7 +207,7 @@ class PlaygroundProps extends Component { { + return model => { validator(model); if (validator.errors && validator.errors.length) { @@ -61,83 +61,84 @@ const presets = { 'Address (SimpleSchema)': preset` new SimpleSchema2Bridge({ schema: new SimpleSchema({ - city: { - type: String, - optional: true, - max: 50, - }, - state: String, - street: { type: String, max: 100 }, - zip: { - type: String, - regEx: /^[0-9]{5}$/, - }, - }) + city: { + type: String, + optional: true, + max: 50, + }, + state: String, + street: { type: String, max: 100 }, + zip: { + type: String, + regEx: /^[0-9]{5}$/, + }, + }), }) `, 'Address (Zod)': preset` new ZodBridge({ schema: z.object({ - city: z.string().max(50).optional(), - state: z.string(), - street: z.string().max(100), - zip: z.string().regex(/^[0-9]{5}$/), - }) + city: z.string().max(50).optional(), + state: z.string(), + street: z.string().max(100), + zip: z.string().regex(/^[0-9]{5}$/), + }), }) `, 'All Fields (SimpleSchema)': preset` new SimpleSchema2Bridge({ schema: new SimpleSchema({ - text: { type: String }, - num: { type: Number }, - bool: { type: Boolean }, - nested: { type: Object }, - 'nested.text': { type: String }, - date: { type: Date }, - list: { type: Array }, - 'list.$': { - type: String, - uniforms: { label: 'List Text', placeholder: 'List Text Placeholder' }, - }, - select: { - type: String, - uniforms: { - options: [ - { label: 'Option A', value: 'a' }, - { label: 'Option B', value: 'b' }, - ], - }, + text: { type: String }, + num: { type: Number }, + bool: { type: Boolean }, + nested: { type: Object }, + 'nested.text': { type: String }, + date: { type: Date }, + list: { type: Array }, + 'list.$': { + type: String, + uniforms: { label: 'List Text', placeholder: 'List Text Placeholder' }, + }, + select: { + type: String, + uniforms: { + options: [ + { label: 'Option A', value: 'a' }, + { label: 'Option B', value: 'b' }, + ], }, - radio: { - type: String, - uniforms: { - checkboxes: true, - options: [ - { label: 'Option A', value: 'a' }, - { label: 'Option B', value: 'b' }, - ], - }, + }, + radio: { + type: String, + uniforms: { + checkboxes: true, + options: [ + { label: 'Option A', value: 'a' }, + { label: 'Option B', value: 'b' }, + ], }, - }) + }, + }), }) `, 'All Fields (Zod)': preset` new ZodBridge({ schema: z.object({ - text: z.string(), - num: z.number(), - bool: z.boolean(), - nested: z.object({ text: z.string() }), - date: z.date(), - // TODO: Custom label and placeholder. - list: z.array(z.string()), - select: z.enum(['a', 'b']), - // TODO: Enums with custom props. - radio: z.enum(['a', 'b']), - }) + text: z.string(), + num: z.number(), + bool: z.boolean(), + nested: z.object({ text: z.string() }), + date: z.date(), + list: z + .string() + .uniforms({ label: 'List Text', placeholder: 'List Text Placeholder' }) + .array(), + select: z.enum(['a', 'b']), + radio: z.enum(['a', 'b']).uniforms({ checkboxes: true }), + }), }) `, };