@webflow/data-types
v1.2.2
Published
Common types and utilities for building Webflow code components. This package provides the `props` utility for defining component properties, TypeScript types for component definitions, and enums for framework and environment constants.
Maintainers
Keywords
Readme
@webflow/data-types
Common types and utilities for building Webflow code components. This package provides the props utility for defining component properties, TypeScript types for component definitions, and enums for framework and environment constants.
Installation
npm i @webflow/data-typesUsage
Defining Component Props
The props utility provides type-safe constructors for all supported prop types. Each prop type corresponds to a different input interface in the Webflow Properties panel.
Basic Example
import { declareComponent } from "@webflow/react";
import { props } from "@webflow/data-types";
function Button({ text, link }) {
return (
<a href={link?.href} target={link?.target}>
{text}
</a>
);
}
export default declareComponent(Button, {
name: "Button",
props: {
text: props.Text({ name: "Button Text", defaultValue: "Click me" }),
link: props.Link({ name: "Link" }),
},
});Available Prop Types
Text / String
Plain text input, provided to the component as a string.
props.Text({
name: "Label",
defaultValue: "Hello World",
group: "Content", // Optional: organize props in groups
tooltip: "The button label", // Optional: help text
});
// Alias
props.String({ name: "Label" });Id
Element ID input, provided to the component as a string. No default value allowed.
props.Id({
name: "Element ID",
tooltip: "Unique identifier for the element",
});Link
Link destination and behavior, provided as an object:
props.Link({ name: "Destination" });
// Runtime value:
// {
// href: string;
// target?: "_self" | "_blank" | string;
// preload?: "prerender" | "prefetch" | "none" | string;
// }Image
Image asset selector, provided as an object:
props.Image({ name: "Hero Image" });
// Runtime value:
// {
// src: string;
// alt?: string;
// }Visibility
Boolean visibility toggle, provided as a boolean.
props.Visibility({
name: "Show Element",
defaultValue: true,
});Slot / Children
Slot for child components, provided as a node (e.g., ReactNode for React).
props.Slot({ name: "Content" });
// Alias
props.Children({ name: "Content" });RichText
Rich text editor input, provided as a string.
props.RichText({
name: "Description",
defaultValue: "<p>Default content</p>",
});Number
Numeric input with optional constraints, provided as a number.
props.Number({
name: "Count",
defaultValue: 5,
min: 0, // Optional: minimum value (clamped)
max: 100, // Optional: maximum value (clamped)
decimals: 2, // Optional: max decimal places (rounded)
});Variant
Dropdown selector for visual variants, provided as a string.
props.Variant({
name: "Style",
options: ["Primary", "Secondary", "Tertiary"],
defaultValue: "Primary", // Optional: defaults to first option
});Boolean
Boolean toggle with custom labels, provided as a boolean.
props.Boolean({
name: "Enabled",
defaultValue: false,
trueLabel: "On", // Optional: label for true state
falseLabel: "Off", // Optional: label for false state
});TextNode
Text node input, provided as a string.
props.TextNode({
name: "Content",
defaultValue: "Default text",
multiline: true, // Optional: allow multiple lines
});Common Options
All prop types support these common options:
name(required): Display name in the Properties panelgroup(optional): Group name for organizing propstooltip(optional): Help text shown in the Properties paneldefaultValue(optional): Default value for the prop (not available forId,Link,Image, andSlottypes)
API Reference
props
An object containing factory functions for creating component props.
Available Methods:
props.Text(options)/props.String(options)- Plain text inputprops.Id(options)- Element ID inputprops.Link(options)- Link destination and behaviorprops.Image(options)- Image asset selectorprops.Visibility(options)- Boolean visibility toggleprops.Slot(options)/props.Children(options)- Slot for child componentsprops.RichText(options)- Rich text editor inputprops.Number(options)- Numeric input with constraintsprops.Variant(options)- Dropdown selector for variantsprops.Boolean(options)- Boolean toggle with custom labelsprops.TextNode(options)- Text node input
TypeScript Types
This package exports comprehensive TypeScript types for building type-safe components. The most important ones are:
ComponentDefinition<ComponentType, NodeType, Props>- Complete component definitionComponentClientRendererFactory<ComponentType, RootType, NodeType>- Client renderer factory typeComponentServerRendererFactory<ComponentType, Stream, StreamOptions, NodeType, StringOptions>- Server renderer factory typeBundleConfigOverrides- Webpack configuration overrides for custom builds
License
MIT
