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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPZYQAumujy5kXaOKurr6zgTP2krHrFVXi2kj8seRYrlvq2GssUjReh5MiVpQbLFQNy9HsmcasqpBNVsXytWTw0ZDjA=

Form

import { Form, ObjectForm } from '@dxos/react-ui-form';
Terminal window
npm install @dxos/react-ui-form

Form builds a form from an Effect schema.

  • Each property becomes a field of the right kind.
  • The property’s title annotation becomes the field’s label.
  • The schema’s checks become the form’s validation.

When you change the schema, the form follows.

Add the package’s strings from @dxos/react-ui-form/translations to the resourceExtensions of Theme.Provider.

Part What it is
Form.Root The root, which takes the schema and the values or defaultValues. onSave gets the checked values
Form.Viewport The form’s container. With scroll it fills its parent and scrolls
Form.Content The form element
Form.Fields A field for each property of the schema, or of the properties in include
Form.Field One row, bound to the form at path or holding controls of your own
Form.FieldSet A labeled group of fields, which can fold
Form.Layout The schema’s fields laid out by a template
Form.Actions The Save and Cancel buttons
Form.Submit A submit button alone, with a label and icon of your own
Form.ErrorText The text of a field’s error

ObjectForm is a Form over an ECHO object. It writes each change to the object as the user makes it.

The type of each property decides the kind of field it gets.

Example (Describing a contact)

import * as
import Schema
Schema
from 'effect/Schema';
import {
import Format
Format
} from '@dxos/echo';
const
const ContactSchema: Schema.Struct<{
readonly name: Schema.String;
readonly email: Schema.optional<Schema.String>;
readonly role: Schema.Literals<readonly ["viewer", "editor", "admin"]>;
readonly notes: Schema.optional<Schema.String>;
}>
ContactSchema
=
import Schema
Schema
.
function Struct<{
readonly name: Schema.String;
readonly email: Schema.optional<Schema.String>;
readonly role: Schema.Literals<readonly ["viewer", "editor", "admin"]>;
readonly notes: Schema.optional<Schema.String>;
}>(fields: {
readonly name: Schema.String;
readonly email: Schema.optional<Schema.String>;
readonly role: Schema.Literals<readonly ["viewer", "editor", "admin"]>;
readonly notes: Schema.optional<Schema.String>;
}): Schema.Struct<{
readonly name: Schema.String;
readonly email: Schema.optional<Schema.String>;
readonly role: Schema.Literals<readonly ["viewer", "editor", "admin"]>;
readonly notes: Schema.optional<Schema.String>;
}>

Defines a struct schema from a map of field schemas.

Details

Each field value is a schema. Use

optionalKey

or

optional

to mark fields as optional, and

mutableKey

to mark them as mutable. Field definitions are discovered from own enumerable string and symbol properties of fields. Non-enumerable and inherited definitions are ignored.

The resulting schema's Type is a readonly object type with the fields' decoded types. The Encoded form mirrors the field schemas' encoded types. Declared fields on the input may be non-enumerable or inherited and are copied to own properties in the output. The __proto__ field is accepted only when it is an own property. Parsing does not guarantee that output keys retain their input order.

Example (Defining a basic struct)

import { Schema } from "effect"
const Person = Schema.Struct({
name: Schema.String,
age: Schema.Number,
email: Schema.optionalKey(Schema.String)
})
// { readonly name: string; readonly age: number; readonly email?: string }
type Person = typeof Person.Type
Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 }) // => { name: "Alice", age: 30 }

@stability ― stable

@category ― constructors

@since ― 3.10.0

Struct
({
name: Schema.String
name
:
import Schema
Schema
.
const String: Schema.String

Type-level representation of

String

.

Schema for string values. Validates that the input is typeof "string".

@stability ― stable

@category ― models

@since ― 4.0.0

@stability ― stable

@category ― schemas

@since ― 4.0.0

String
.
Pipeable.pipe<Schema.String, Schema.String>(this: Schema.String, ab: (_: Schema.String) => Schema.String): Schema.String (+21 overloads)
pipe
(
import Schema
Schema
.
function check<Schema.String>(checks_0: Check<string>, ...checks: Check<string>[]): (self: Schema.String) => Schema.String

Attaches one or more filter checks to a schema without changing the TypeScript type.

Example (Adding checks to a schema)

import { Schema } from "effect"
const AgeSchema = Schema.Finite.pipe(
Schema.check(Schema.isGreaterThanOrEqualTo(0), Schema.isLessThanOrEqualTo(120))
)
Schema.is(AgeSchema)(42) // => true
Schema.is(AgeSchema)(121) // => false

@stability ― stable

@category ― filtering

@since ― 4.0.0

check
(
import Schema
Schema
.
function isMinLength(minLength: number, annotations?: Schema.Annotations.Filter): Filter<{
readonly length: number;
}>

Validates that a value has at least the specified length. Works with strings and arrays.

Details

JSON Schema:

The bound must be finite; it is rounded down and clamped to zero. For arrays, this check corresponds to minItems. JavaScript counts UTF-16 code units while JSON Schema counts Unicode code points, so strings use minLength: Math.ceil(minLength / 2), the tightest lower bound that cannot reject a string accepted by this check.

Arbitrary:

During arbitrary generation, this applies a minLength constraint to ensure generated strings or arrays have at least the required length.

Example (Checking minimum length)

import { Schema } from "effect"
const NonEmptyStringSchema = Schema.String.check(Schema.isMinLength(1))
const NonEmptyArraySchema = Schema.Array(Schema.Number).check(Schema.isMinLength(1))
Schema.is(NonEmptyStringSchema)("a") // => true
Schema.is(NonEmptyArraySchema)([1]) // => true

@stability ― stable

@category ― validation

@since ― 4.0.0

isMinLength
(1))).
BottomWithoutNew<string, string, never, never, String, String, string, string, readonly [], string, "readonly", "required", "no-default", "readonly", "required">.annotate(annotations: Schema.Annotations.Bottom<string, readonly []>): Schema.String
annotate
({
Annotations.Augment.title?: string | undefined
title
: 'Name',
}),
email: Schema.optional<Schema.String>
email
:
import Schema
Schema
.
const optional: optionalLambda
<Schema.String>(self: Schema.String) => Schema.optional<Schema.String>

Type-level representation returned by

optional

.

Marks a struct field as optional, allowing the key to be absent or undefined.

Details

The resulting property may be absent or explicitly set to undefined. Equivalent to optionalKey(UndefinedOr(S)).

Use

optionalKey

instead if you want exact optional semantics (absent only, not undefined).

Example (Defining an optional field accepting undefined)

import { Schema } from "effect"
const schema = Schema.Struct({
name: Schema.String,
age: Schema.optional(Schema.Number)
})
// { readonly name: string; readonly age?: number | undefined }
type Person = typeof schema.Type

@stability ― stable

@category ― models

@since ― 3.10.0

@stability ― stable

@category ― combinators

@since ― 3.10.0

optional
(
import Format
Format
.
const Email: Schema.String

Email address (RFC 5321). The local part also allows an apostrophe, which real mail carries (o'day@corp.com). https://datatracker.ietf.org/doc/html/rfc5321#section-4.1.2

Email
.
BottomWithoutNew<string, string, never, never, String, String, string, string, readonly [], string, "readonly", "required", "no-default", "readonly", "required">.annotate(annotations: Schema.Annotations.Bottom<string, readonly []>): Schema.String
annotate
({
Annotations.Augment.title?: string | undefined
title
: 'Email' })),
role: Schema.Literals<readonly ["viewer", "editor", "admin"]>
role
:
import Schema
Schema
.
function Literals<readonly ["viewer", "editor", "admin"]>(literals: readonly ["viewer", "editor", "admin"]): Schema.Literals<readonly ["viewer", "editor", "admin"]>

Creates a union schema from a fixed-length tuple of literal values.

Gotchas

Use an inline tuple or as const to preserve positions for mapMembers and transform. Widened arrays and open-ended tuples are unsupported.

Example (Defining status codes)

import { Schema } from "effect"
const schema = Schema.Literals(["active", "inactive", "pending"])
Schema.decodeSync(schema)("active") // => "active"

@see ― Literal for a schema that represents a single literal.

@stability ― stable

@category ― constructors

@since ― 4.0.0

Literals
(['viewer', 'editor', 'admin']).
BottomWithoutNew<"viewer" | "editor" | "admin", "viewer" | "editor" | "admin", never, never, Union<Literal>, Literals<readonly ["viewer", "editor", "admin"]>, ... 8 more ..., "required">.annotate(annotations: Schema.Annotations.Bottom<"viewer" | "editor" | "admin", readonly []>): Schema.Literals<readonly ["viewer", "editor", "admin"]>
annotate
({
Annotations.Augment.title?: string | undefined
title
: 'Role',
}),
notes: Schema.optional<Schema.String>
notes
:
import Schema
Schema
.
const optional: optionalLambda
<Schema.String>(self: Schema.String) => Schema.optional<Schema.String>

Type-level representation returned by

optional

.

Marks a struct field as optional, allowing the key to be absent or undefined.

Details

The resulting property may be absent or explicitly set to undefined. Equivalent to optionalKey(UndefinedOr(S)).

Use

optionalKey

instead if you want exact optional semantics (absent only, not undefined).

Example (Defining an optional field accepting undefined)

import { Schema } from "effect"
const schema = Schema.Struct({
name: Schema.String,
age: Schema.optional(Schema.Number)
})
// { readonly name: string; readonly age?: number | undefined }
type Person = typeof schema.Type

@stability ― stable

@category ― models

@since ― 3.10.0

@stability ― stable

@category ― combinators

@since ― 3.10.0

optional
(
import Format
Format
.
const Text: Schema.String

Multi-line text.

Text
.
BottomWithoutNew<string, string, never, never, String, String, string, string, readonly [], string, "readonly", "required", "no-default", "readonly", "required">.annotate(annotations: Schema.Annotations.Bottom<string, readonly []>): Schema.String
annotate
({
Annotations.Augment.title?: string | undefined
title
: 'Notes' })),
});
type
type Contact = {
readonly name: string;
readonly role: "viewer" | "editor" | "admin";
readonly email?: string | undefined;
readonly notes?: string | undefined;
}
Contact
=
import Schema
Schema
.
namespace Schema

Namespace of type-level helpers for

Schema

.

A typed view of a schema that tracks only the decoded (output) type T.

Details

Use Schema<T> as a constraint when you want to accept "any schema that decodes to T" and do not need to know or constrain the encoded representation, required services, or any other type parameters.

This is a structural interface — concrete schema values are produced by the constructors in this module (e.g.

Struct

,

String

,

Number

). When you also need the encoded type or service requirements, use

Codec

.

Example (Accepting any schema decoding to string)

import { Schema } from "effect"
const accept = (_schema: Schema.Schema<string>): void => {}
accept(Schema.String)
accept(Schema.NonEmptyString)

@stability ― stable

@since ― 3.10.0

@see ― Codec — also tracks Encoded, DecodingServices, EncodingServices

@see ― Schema.Type — extract the decoded type at the type level

@stability ― stable

@category ― models

@since ― 3.10.0

Schema
.
type Schema<out T>.Type<S> = S extends {
readonly Type: infer T;
} ? T : never

Extracts the decoded Type from a schema.

Example (Extracting the decoded type)

import { Schema } from "effect"
const Person = Schema.Struct({ name: Schema.String, age: Schema.Number })
type Person = Schema.Schema.Type<typeof Person>
// { readonly name: string; readonly age: number }

@category ― utility types

@since ― 3.10.0

Type
<typeof
const ContactSchema: Schema.Struct<{
readonly name: Schema.String;
readonly email: Schema.optional<Schema.String>;
readonly role: Schema.Literals<readonly ["viewer", "editor", "admin"]>;
readonly notes: Schema.optional<Schema.String>;
}>
ContactSchema
>;

Format.Email asks for an email field, the set of literals in role asks for a select, and Format.Text asks for a text area.

Form.Fields renders a field for each property, and Form.Actions adds Save and Cancel.

The form checks the values as the user works:

  • A field shows its error once the user leaves it.
  • Save is disabled while a field the user touched has an error.
  • Save checks every value against the schema, then calls onSave with the values.

Example (Rendering a form for a new contact)

import {
function useState<S>(initialState: S | (() => S)): [S, React.Dispatch<React.SetStateAction<S>>] (+1 overload)

Returns a stateful value, and a function to update it.

@version ― 16.8.0

@see ― https://react.dev/reference/react/useState

useState
} from 'react';
import {
const Form: {
Root: {
<T extends AnyProperties = AnyProperties>({ children, ...props }: FormRootProps<T>): React.JSX.Element;
displayName: string;
};
Viewport: React.ForwardRefExoticComponent<Omit<import("@dxos/react-ui-form").FormViewportProps, "className"> & {
classNames?: import("@dxos/ui-types").ClassNameValue;
} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>;
Content: React.ForwardRefExoticComponent<{
children?: React.ReactNode | undefined;
} & React.RefAttributes<HTMLDivElement>>;
... 6 more ...;
ErrorText: typeof FormErrorText;
}

The Form namespace of @dxos/react-ui-form, rendered with the Next namespace of @dxos/react-ui; Root is the shared one.

Form
} from '@dxos/react-ui-form';
import * as
import Typography
Typography
from '@dxos/react-ui/Typography';
/** A form for a new contact: its fields come from the schema, and Save validates the values before `onSave`. */
export const
const NewContact: () => React.JSX.Element

A form for a new contact: its fields come from the schema, and Save validates the values before onSave.

NewContact
= () => {
const [
const saved: {
readonly role: "viewer" | "editor" | "admin";
readonly name: string;
readonly email?: string | undefined;
readonly notes?: string | undefined;
} | undefined
saved
,
const setSaved: React.Dispatch<React.SetStateAction<{
readonly role: "viewer" | "editor" | "admin";
readonly name: string;
readonly email?: string | undefined;
readonly notes?: string | undefined;
} | undefined>>
setSaved
] =
useState<{
readonly role: "viewer" | "editor" | "admin";
readonly name: string;
readonly email?: string | undefined;
readonly notes?: string | undefined;
}>(): [{
readonly role: "viewer" | "editor" | "admin";
readonly name: string;
readonly email?: string | undefined;
readonly notes?: string | undefined;
} | undefined, React.Dispatch<React.SetStateAction<{
readonly role: "viewer" | "editor" | "admin";
readonly name: string;
readonly email?: string | undefined;
readonly notes?: string | undefined;
} | undefined>>] (+1 overload)

Returns a stateful value, and a function to update it.

@version ― 16.8.0

@see ― https://react.dev/reference/react/useState

useState
<
type Contact = {
readonly role: "viewer" | "editor" | "admin";
readonly name: string;
readonly email?: string | undefined;
readonly notes?: string | undefined;
}
Contact
>();
return (
<>
<
const Form: {
Root: {
<T extends AnyProperties = AnyProperties>({ children, ...props }: FormRootProps<T>): React.JSX.Element;
displayName: string;
};
Viewport: React.ForwardRefExoticComponent<Omit<import("@dxos/react-ui-form").FormViewportProps, "className"> & {
classNames?: import("@dxos/ui-types").ClassNameValue;
} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>;
Content: React.ForwardRefExoticComponent<{
children?: React.ReactNode | undefined;
} & React.RefAttributes<HTMLDivElement>>;
... 6 more ...;
ErrorText: typeof FormErrorText;
}

The Form namespace of @dxos/react-ui-form, rendered with the Next namespace of @dxos/react-ui; Root is the shared one.

Form
.
type Root: {
<T extends AnyProperties = AnyProperties>({ children, ...props }: FormRootProps<T>): React.JSX.Element;
displayName: string;
}
Root
schema?: Schema.Codec<{
readonly role: "viewer" | "editor" | "admin";
readonly name: string;
readonly email?: string | undefined;
readonly notes?: string | undefined;
}, any, never, never> | undefined

Effect schema (Type literal).

schema
={
const ContactSchema: Schema.Struct<{
readonly name: Schema.String;
readonly email: Schema.optional<Schema.String>;
readonly role: Schema.Literals<readonly ["viewer", "editor", "admin"]>;
readonly notes: Schema.optional<Schema.String>;
}>
ContactSchema
}
values?: Partial<{
readonly role: "viewer" | "editor" | "admin";
readonly name: string;
readonly email?: string | undefined;
readonly notes?: string | undefined;
}> | undefined

Source values. Fields the user is not editing reflect this value; in-progress edits (including intermediate invalid values) are held locally and never snap back until they are committed and the source catches up. Persist committed values from onValuesChanged/onSave. The form re-renders when a new value is passed, so to reflect external/remote mutations pass a reactive source (e.g. a useObject snapshot that changes on mutation) rather than a raw live object — a render-time read of an ECHO object does not itself subscribe to it.

values
={{
role?: "viewer" | "editor" | "admin" | undefined
role
: 'viewer' }}
onSave?: ((values: {
readonly role: "viewer" | "editor" | "admin";
readonly name: string;
readonly email?: string | undefined;
readonly notes?: string | undefined;
}, meta: FormUpdateMeta<{
readonly role: "viewer" | "editor" | "admin";
readonly name: string;
readonly email?: string | undefined;
readonly notes?: string | undefined;
}>) => void) | undefined

Called when the form is submitted and passes validation.

onSave
={(
values: {
readonly role: "viewer" | "editor" | "admin";
readonly name: string;
readonly email?: string | undefined;
readonly notes?: string | undefined;
}
values
) =>
const setSaved: (value: React.SetStateAction<{
readonly role: "viewer" | "editor" | "admin";
readonly name: string;
readonly email?: string | undefined;
readonly notes?: string | undefined;
} | undefined>) => void
setSaved
(
values: {
readonly role: "viewer" | "editor" | "admin";
readonly name: string;
readonly email?: string | undefined;
readonly notes?: string | undefined;
}
values
)}
>
<
const Form: {
Root: {
<T extends AnyProperties = AnyProperties>({ children, ...props }: FormRootProps<T>): React.JSX.Element;
displayName: string;
};
Viewport: React.ForwardRefExoticComponent<Omit<import("@dxos/react-ui-form").FormViewportProps, "className"> & {
classNames?: import("@dxos/ui-types").ClassNameValue;
} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>;
Content: React.ForwardRefExoticComponent<{
children?: React.ReactNode | undefined;
} & React.RefAttributes<HTMLDivElement>>;
... 6 more ...;
ErrorText: typeof FormErrorText;
}

The Form namespace of @dxos/react-ui-form, rendered with the Next namespace of @dxos/react-ui; Root is the shared one.

Form
.
type Content: React.ForwardRefExoticComponent<{
children?: React.ReactNode | undefined;
} & React.RefAttributes<HTMLDivElement>>
Content
>
<
const Form: {
Root: {
<T extends AnyProperties = AnyProperties>({ children, ...props }: FormRootProps<T>): React.JSX.Element;
displayName: string;
};
Viewport: React.ForwardRefExoticComponent<Omit<import("@dxos/react-ui-form").FormViewportProps, "className"> & {
classNames?: import("@dxos/ui-types").ClassNameValue;
} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>;
Content: React.ForwardRefExoticComponent<{
children?: React.ReactNode | undefined;
} & React.RefAttributes<HTMLDivElement>>;
... 6 more ...;
ErrorText: typeof FormErrorText;
}

The Form namespace of @dxos/react-ui-form, rendered with the Next namespace of @dxos/react-ui; Root is the shared one.

Form
.
type Fields: typeof FormFields
Fields
/>
<
const Form: {
Root: {
<T extends AnyProperties = AnyProperties>({ children, ...props }: FormRootProps<T>): React.JSX.Element;
displayName: string;
};
Viewport: React.ForwardRefExoticComponent<Omit<import("@dxos/react-ui-form").FormViewportProps, "className"> & {
classNames?: import("@dxos/ui-types").ClassNameValue;
} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>;
Content: React.ForwardRefExoticComponent<{
children?: React.ReactNode | undefined;
} & React.RefAttributes<HTMLDivElement>>;
... 6 more ...;
ErrorText: typeof FormErrorText;
}

The Form namespace of @dxos/react-ui-form, rendered with the Next namespace of @dxos/react-ui; Root is the shared one.

Form
.
type Actions: typeof FormActions
Actions
/>
</
const Form: {
Root: {
<T extends AnyProperties = AnyProperties>({ children, ...props }: FormRootProps<T>): React.JSX.Element;
displayName: string;
};
Viewport: React.ForwardRefExoticComponent<Omit<import("@dxos/react-ui-form").FormViewportProps, "className"> & {
classNames?: import("@dxos/ui-types").ClassNameValue;
} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>;
Content: React.ForwardRefExoticComponent<{
children?: React.ReactNode | undefined;
} & React.RefAttributes<HTMLDivElement>>;
... 6 more ...;
ErrorText: typeof FormErrorText;
}

The Form namespace of @dxos/react-ui-form, rendered with the Next namespace of @dxos/react-ui; Root is the shared one.

Form
.
type Content: React.ForwardRefExoticComponent<{
children?: React.ReactNode | undefined;
} & React.RefAttributes<HTMLDivElement>>
Content
>
</
const Form: {
Root: {
<T extends AnyProperties = AnyProperties>({ children, ...props }: FormRootProps<T>): React.JSX.Element;
displayName: string;
};
Viewport: React.ForwardRefExoticComponent<Omit<import("@dxos/react-ui-form").FormViewportProps, "className"> & {
classNames?: import("@dxos/ui-types").ClassNameValue;
} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>;
Content: React.ForwardRefExoticComponent<{
children?: React.ReactNode | undefined;
} & React.RefAttributes<HTMLDivElement>>;
... 6 more ...;
ErrorText: typeof FormErrorText;
}

The Form namespace of @dxos/react-ui-form, rendered with the Next namespace of @dxos/react-ui; Root is the shared one.

Form
.
type Root: {
<T extends AnyProperties = AnyProperties>({ children, ...props }: FormRootProps<T>): React.JSX.Element;
displayName: string;
}
Root
>
<
import Typography
Typography
.
const Text: React.ForwardRefExoticComponent<Omit<Typography.TextProps & {
asChild?: boolean;
}, "className"> & {
classNames?: import("@dxos/ui-types").ClassNameValue;
} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLParagraphElement>>
export Text

Text whose first line is centred in a block, so it lines up with a Block or control beside it however many lines it wraps to. Renders a <p>; asChild puts the metrics on a heading or other text element instead.

Text
tone?: Typography.TextTone | undefined

Emphasis below the default (DESIGN.md "Text emphasis"): description for secondary content, subdued for interface text.

tone
='muted'>
{
const saved: {
readonly role: "viewer" | "editor" | "admin";
readonly name: string;
readonly email?: string | undefined;
readonly notes?: string | undefined;
} | undefined
saved
? `Saved ${
const saved: {
readonly role: "viewer" | "editor" | "admin";
readonly name: string;
readonly email?: string | undefined;
readonly notes?: string | undefined;
}
saved
.
name: string
name
} as ${
const saved: {
readonly role: "viewer" | "editor" | "admin";
readonly name: string;
readonly email?: string | undefined;
readonly notes?: string | undefined;
}
saved
.
role: "viewer" | "editor" | "admin"
role
}` : 'Not saved yet'}
</
import Typography
Typography
.
const Text: React.ForwardRefExoticComponent<Omit<Typography.TextProps & {
asChild?: boolean;
}, "className"> & {
classNames?: import("@dxos/ui-types").ClassNameValue;
} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLParagraphElement>>
export Text

Text whose first line is centred in a block, so it lines up with a Block or control beside it however many lines it wraps to. Renders a <p>; asChild puts the metrics on a heading or other text element instead.

Text
>
</>
);
};

values starts role at viewer, and onSave keeps the checked values in state.

To show only some of the fields, list them in include. They keep the schema’s order. Pass sort to reorder them.

Example (Showing two of the fields)

import {
const Form: {
Root: {
<T extends AnyProperties = AnyProperties>({ children, ...props }: FormRootProps<T>): React.JSX.Element;
displayName: string;
};
Viewport: React.ForwardRefExoticComponent<Omit<import("@dxos/react-ui-form").FormViewportProps, "className"> & {
classNames?: import("@dxos/ui-types").ClassNameValue;
} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>;
Content: React.ForwardRefExoticComponent<{
children?: React.ReactNode | undefined;
} & React.RefAttributes<HTMLDivElement>>;
... 6 more ...;
ErrorText: typeof FormErrorText;
}

The Form namespace of @dxos/react-ui-form, rendered with the Next namespace of @dxos/react-ui; Root is the shared one.

Form
} from '@dxos/react-ui-form';
/** Only the fields a quick-add needs. */
export const
const QuickAdd: ({ onSave, }: {
onSave: (contact: Contact) => void;
}) => React.JSX.Element

Only the fields a quick-add needs.

QuickAdd
= ({
onSave: (contact: Contact) => void
onSave
,
}: {
onSave: (contact: Contact) => void
onSave
: (
contact: {
readonly role: "viewer" | "editor" | "admin";
readonly name: string;
readonly email?: string | undefined;
readonly notes?: string | undefined;
}
contact
:
type Contact = {
readonly role: "viewer" | "editor" | "admin";
readonly name: string;
readonly email?: string | undefined;
readonly notes?: string | undefined;
}
Contact
) => void;
}) => (
<
const Form: {
Root: {
<T extends AnyProperties = AnyProperties>({ children, ...props }: FormRootProps<T>): React.JSX.Element;
displayName: string;
};
Viewport: React.ForwardRefExoticComponent<Omit<import("@dxos/react-ui-form").FormViewportProps, "className"> & {
classNames?: import("@dxos/ui-types").ClassNameValue;
} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>;
Content: React.ForwardRefExoticComponent<{
children?: React.ReactNode | undefined;
} & React.RefAttributes<HTMLDivElement>>;
... 6 more ...;
ErrorText: typeof FormErrorText;
}

The Form namespace of @dxos/react-ui-form, rendered with the Next namespace of @dxos/react-ui; Root is the shared one.

Form
.
type Root: {
<T extends AnyProperties = AnyProperties>({ children, ...props }: FormRootProps<T>): React.JSX.Element;
displayName: string;
}
Root
schema?: Schema.Codec<{
readonly role: "viewer" | "editor" | "admin";
readonly name: string;
readonly email?: string | undefined;
readonly notes?: string | undefined;
}, any, never, never> | undefined

Effect schema (Type literal).

schema
={
const ContactSchema: Schema.Struct<{
readonly name: Schema.String;
readonly email: Schema.optional<Schema.String>;
readonly role: Schema.Literals<readonly ["viewer", "editor", "admin"]>;
readonly notes: Schema.optional<Schema.String>;
}>
ContactSchema
}
values?: Partial<{
readonly role: "viewer" | "editor" | "admin";
readonly name: string;
readonly email?: string | undefined;
readonly notes?: string | undefined;
}> | undefined

Source values. Fields the user is not editing reflect this value; in-progress edits (including intermediate invalid values) are held locally and never snap back until they are committed and the source catches up. Persist committed values from onValuesChanged/onSave. The form re-renders when a new value is passed, so to reflect external/remote mutations pass a reactive source (e.g. a useObject snapshot that changes on mutation) rather than a raw live object — a render-time read of an ECHO object does not itself subscribe to it.

values
={{
role?: "viewer" | "editor" | "admin" | undefined
role
: 'viewer' }}
onSave?: ((values: {
readonly role: "viewer" | "editor" | "admin";
readonly name: string;
readonly email?: string | undefined;
readonly notes?: string | undefined;
}, meta: FormUpdateMeta<{
readonly role: "viewer" | "editor" | "admin";
readonly name: string;
readonly email?: string | undefined;
readonly notes?: string | undefined;
}>) => void) | undefined

Called when the form is submitted and passes validation.

onSave
={
onSave: (contact: Contact) => void
onSave
}>
<
const Form: {
Root: {
<T extends AnyProperties = AnyProperties>({ children, ...props }: FormRootProps<T>): React.JSX.Element;
displayName: string;
};
Viewport: React.ForwardRefExoticComponent<Omit<import("@dxos/react-ui-form").FormViewportProps, "className"> & {
classNames?: import("@dxos/ui-types").ClassNameValue;
} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>;
Content: React.ForwardRefExoticComponent<{
children?: React.ReactNode | undefined;
} & React.RefAttributes<HTMLDivElement>>;
... 6 more ...;
ErrorText: typeof FormErrorText;
}

The Form namespace of @dxos/react-ui-form, rendered with the Next namespace of @dxos/react-ui; Root is the shared one.

Form
.
type Content: React.ForwardRefExoticComponent<{
children?: React.ReactNode | undefined;
} & React.RefAttributes<HTMLDivElement>>
Content
>
<
const Form: {
Root: {
<T extends AnyProperties = AnyProperties>({ children, ...props }: FormRootProps<T>): React.JSX.Element;
displayName: string;
};
Viewport: React.ForwardRefExoticComponent<Omit<import("@dxos/react-ui-form").FormViewportProps, "className"> & {
classNames?: import("@dxos/ui-types").ClassNameValue;
} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>;
Content: React.ForwardRefExoticComponent<{
children?: React.ReactNode | undefined;
} & React.RefAttributes<HTMLDivElement>>;
... 6 more ...;
ErrorText: typeof FormErrorText;
}

The Form namespace of @dxos/react-ui-form, rendered with the Next namespace of @dxos/react-ui; Root is the shared one.

Form
.
type Fields: typeof FormFields
Fields
include?: string[] | undefined

Renders these properties only, in schema order.

include
={['name', 'email']} />
<
const Form: {
Root: {
<T extends AnyProperties = AnyProperties>({ children, ...props }: FormRootProps<T>): React.JSX.Element;
displayName: string;
};
Viewport: React.ForwardRefExoticComponent<Omit<import("@dxos/react-ui-form").FormViewportProps, "className"> & {
classNames?: import("@dxos/ui-types").ClassNameValue;
} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>;
Content: React.ForwardRefExoticComponent<{
children?: React.ReactNode | undefined;
} & React.RefAttributes<HTMLDivElement>>;
... 6 more ...;
ErrorText: typeof FormErrorText;
}

The Form namespace of @dxos/react-ui-form, rendered with the Next namespace of @dxos/react-ui; Root is the shared one.

Form
.
type Actions: typeof FormActions
Actions
/>
</
const Form: {
Root: {
<T extends AnyProperties = AnyProperties>({ children, ...props }: FormRootProps<T>): React.JSX.Element;
displayName: string;
};
Viewport: React.ForwardRefExoticComponent<Omit<import("@dxos/react-ui-form").FormViewportProps, "className"> & {
classNames?: import("@dxos/ui-types").ClassNameValue;
} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>;
Content: React.ForwardRefExoticComponent<{
children?: React.ReactNode | undefined;
} & React.RefAttributes<HTMLDivElement>>;
... 6 more ...;
ErrorText: typeof FormErrorText;
}

The Form namespace of @dxos/react-ui-form, rendered with the Next namespace of @dxos/react-ui; Root is the shared one.

Form
.
type Content: React.ForwardRefExoticComponent<{
children?: React.ReactNode | undefined;
} & React.RefAttributes<HTMLDivElement>>
Content
>
</
const Form: {
Root: {
<T extends AnyProperties = AnyProperties>({ children, ...props }: FormRootProps<T>): React.JSX.Element;
displayName: string;
};
Viewport: React.ForwardRefExoticComponent<Omit<import("@dxos/react-ui-form").FormViewportProps, "className"> & {
classNames?: import("@dxos/ui-types").ClassNameValue;
} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>;
Content: React.ForwardRefExoticComponent<{
children?: React.ReactNode | undefined;
} & React.RefAttributes<HTMLDivElement>>;
... 6 more ...;
ErrorText: typeof FormErrorText;
}

The Form namespace of @dxos/react-ui-form, rendered with the Next namespace of @dxos/react-ui; Root is the shared one.

Form
.
type Root: {
<T extends AnyProperties = AnyProperties>({ children, ...props }: FormRootProps<T>): React.JSX.Element;
displayName: string;
}
Root
>
);

include leaves name and email, in the schema’s order.

ObjectForm takes the type and the object. It needs no Save button, because it writes each change as the user makes it. A property that refers to another object gets a picker of the objects of that type.

The types from ECHO’s Defining types page work as they are.

Example (Editing a person)

import * as
import Schema
Schema
from 'effect/Schema';
import {
import DXN
DXN
,
import Format
Format
,
import Type
Type
} from '@dxos/echo';
import {
const ObjectForm: ({ object, type, schema, showTags }: ObjectFormProps) => React.JSX.Element

An object's properties (and meta tags) as a next Form in its host's grid, writing each change back.

ObjectForm
} from '@dxos/react-ui-form';
class
class Person
Person
extends
import Type
Type
.
const makeObject: <Person>(dxn: DXN.DXN, options?: {
id?: EntityId;
}) => Type.MakeObject<Person>

Factory function to create an ECHO object type.

Returns a Type.Type entity — a live, in-memory TypeSchema instance, NOT a Schema.Schema. Use Type.InstanceType<typeof Foo> for the instance type and Type.getSchema(Foo) to obtain the underlying Effect Schema.

The entity's id defaults to EntityId.deterministic(typename, version) so constructing a type never reaches crypto.getRandomValues() — required for Cloudflare workerd, which forbids RNG calls in global (module-evaluation) scope. Pass { id } to override (e.g. with EntityId.random() from a request handler).

Giving the type a nominal class name keeps its inferred type portable for declaration emit: structural expansion (which can pull in unnameable union members from referenced schemas) is replaced by a reference to the class.

The second call takes either a schema, or struct fields (wrapped in Schema.Struct) with an optional function that pipes annotations onto the struct.

@example

export class Person extends Type.makeObject<Person>(DXN.make('com.example.type.myType', '0.1.0'))(Schema.Struct({
name: Schema.String,
})) {}
export class Tag extends Type.makeObject<Tag>(DXN.make('com.example.type.tag', '0.1.0'))(
{ label: Schema.String },
Annotation.LabelAnnotation.set(['label']),
) {}

@performance ― O(schema size) once at definition time; builds the type entity eagerly, so call it at module scope, not per use.

makeObject
<
class Person
Person
>(
import DXN
DXN
.
const make: <"com.example.type.person">(nsid: "com.example.type.person", version?: string) => DXN.DXN

Constructs a DXN from an NSID (and optional version). Throws if the result is not a valid DXN. Use tryMake for non-throwing string parsing.

Static NSID strings are validated at compile time via

Name

: the final segment must be camelCase (no hyphens). Template-literal strings with a runtime prefix are accepted here but still validated at runtime.

@example make('org.dxos.type.calendar') → 'dxn:org.dxos.type.calendar'

@example make('org.dxos.type.calendar', '1.0.0') → 'dxn:org.dxos.type.calendar:1.0.0'

make
('com.example.type.person', '0.1.0'),
)(
import Schema
Schema
.
function Struct<{
readonly name: Schema.String;
readonly email: Schema.optional<Schema.String>;
}>(fields: {
readonly name: Schema.String;
readonly email: Schema.optional<Schema.String>;
}): Schema.Struct<{
readonly name: Schema.String;
readonly email: Schema.optional<Schema.String>;
}>

Defines a struct schema from a map of field schemas.

Details

Each field value is a schema. Use

optionalKey

or

optional

to mark fields as optional, and

mutableKey

to mark them as mutable. Field definitions are discovered from own enumerable string and symbol properties of fields. Non-enumerable and inherited definitions are ignored.

The resulting schema's Type is a readonly object type with the fields' decoded types. The Encoded form mirrors the field schemas' encoded types. Declared fields on the input may be non-enumerable or inherited and are copied to own properties in the output. The __proto__ field is accepted only when it is an own property. Parsing does not guarantee that output keys retain their input order.

Example (Defining a basic struct)

import { Schema } from "effect"
const Person = Schema.Struct({
name: Schema.String,
age: Schema.Number,
email: Schema.optionalKey(Schema.String)
})
// { readonly name: string; readonly age: number; readonly email?: string }
type Person = typeof Person.Type
Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 }) // => { name: "Alice", age: 30 }

@stability ― stable

@category ― constructors

@since ― 3.10.0

Struct
({
name: Schema.String
name
:
import Schema
Schema
.
const String: Schema.String

Type-level representation of

String

.

Schema for string values. Validates that the input is typeof "string".

@stability ― stable

@category ― models

@since ― 4.0.0

@stability ― stable

@category ― schemas

@since ― 4.0.0

String
,
email: Schema.optional<Schema.String>
email
:
import Schema
Schema
.
const optional: optionalLambda
<Schema.String>(self: Schema.String) => Schema.optional<Schema.String>

Type-level representation returned by

optional

.

Marks a struct field as optional, allowing the key to be absent or undefined.

Details

The resulting property may be absent or explicitly set to undefined. Equivalent to optionalKey(UndefinedOr(S)).

Use

optionalKey

instead if you want exact optional semantics (absent only, not undefined).

Example (Defining an optional field accepting undefined)

import { Schema } from "effect"
const schema = Schema.Struct({
name: Schema.String,
age: Schema.optional(Schema.Number)
})
// { readonly name: string; readonly age?: number | undefined }
type Person = typeof schema.Type

@stability ― stable

@category ― models

@since ― 3.10.0

@stability ― stable

@category ― combinators

@since ― 3.10.0

optional
(
import Format
Format
.
const Email: Schema.String

Email address (RFC 5321). The local part also allows an apostrophe, which real mail carries (o'day@corp.com). https://datatracker.ietf.org/doc/html/rfc5321#section-4.1.2

Email
),
}),
) {}
/** An ECHO object's fields; each change is written to the object as it is made. */
export const
const PersonForm: ({ person }: {
person: Person;
}) => React.JSX.Element

An ECHO object's fields; each change is written to the object as it is made.

PersonForm
= ({
person: Person
person
}: {
person: Person
person
:
class Person
Person
}) => (
<
const ObjectForm: ({ object, type, schema, showTags }: ObjectFormProps) => React.JSX.Element

An object's properties (and meta tags) as a next Form in its host's grid, writing each change back.

ObjectForm
type: Type.AnyEntity
type
={
class Person
Person
}
object: Unknown
object
={
person: Person
person
}
showTags?: boolean | undefined

Render the meta-tags field. Defaults to true.

showTags
={false} />
);

Person is an ECHO type with a name and an optional email, and ObjectForm edits them on person. ObjectForm also shows a field for the object’s tags, and showTags={false} leaves it out.

Connect to ECHO uses ObjectForm for the contacts screen’s edit dialog.