TypeScript type definitions for building with the designer

The designer provides a comprehensive set of TypeScript types for type-safe development. These types define the structure of layers, styling properties, keyboard shortcuts, and configuration objects, ensuring proper validation and IntelliSense support throughout your application.

Layer

The core type representing a design layer on the canvas. Each layer contains metadata, styling, and content information.

type Layer = {
  id: string
  name: string
  type: string
  value: string
  cssVars?: CSSVars
  meta?: Record<string, unknown>
  isLocked?: boolean
}

Properties

PropertyTypeRequiredDescription
idstringYesUnique identifier for the layer
namestringYesDisplay name of the layer
typestringYesLayer type (e.g., "text", "image", "rectangle")
valuestringYesLayer-specific content/value (e.g., text content, image URL)
cssVarsCSSVarsNoCSS custom properties for styling
metaRecord<string, unknown>NoArbitrary metadata storage
isLockedbooleanNoWhether the layer is locked from editing

Usage Examples

Basic Layer Creation:

import { type Layer } from "@shadcn/designer"
 
const textLayer: Layer = {
  id: "layer-1",
  name: "My Text",
  type: "text",
  value: "Hello World",
  cssVars: {
    "--font-size": "24px",
    "--color": "#000000"
  }
}

Layer with Metadata:

const imageLayer: Layer = {
  id: "layer-2",
  name: "Hero Image",
  type: "image",
  value: "/images/hero.jpg",
  meta: {
    alt: "Hero section background",
    uploadedAt: new Date().toISOString(),
    fileSize: 1024000
  },
  isLocked: true
}

Working with Layers:

function LayerComponent({ layer }: { layer: Layer }) {
  const displayName = layer.isLocked ? `🔒 ${layer.name}` : layer.name
  
  return (
    <div className="layer-item">
      <h3>{displayName}</h3>
      <span className="layer-type">{layer.type}</span>
      {layer.meta?.description && (
        <p>{layer.meta.description as string}</p>
      )}
    </div>
  )
}

LayerWithStyles

Extended layer type that includes computed CSS styles for rendering.

type LayerWithStyles = Layer & {
  style: CSSProperties
  contentStyle: CSSProperties
}

Additional Properties

PropertyTypeDescription
styleCSSPropertiesComputed styles for the layer container
contentStyleCSSPropertiesComputed styles for the layer content

Usage Example

import { type LayerWithStyles } from "@shadcn/designer"
 
function RenderLayer({ layer }: { layer: LayerWithStyles }) {
  return (
    <div style={layer.style} className="layer">
      <div style={layer.contentStyle} className="layer-content">
        {layer.value}
      </div>
    </div>
  )
}

LayerType

Configuration type that defines how a specific layer type behaves and renders.

type LayerType = {
  type: string
  name: string
  defaultValues: Omit<Layer, "id" | "type">
  render: (layer: LayerWithStyles) => React.ReactNode
  icon?: ReactNode
  keybinding?: Keybinding
}

Properties

PropertyTypeRequiredDescription
typestringYesUnique type identifier
namestringYesHuman-readable name
defaultValuesOmit<Layer, "id" | "type">YesDefault values for new layers
render(layer: LayerWithStyles) => React.ReactNodeYesRender function
iconReactNodeNoIcon for UI (string, component, or element)
keybindingKeybindingNoOptional keyboard shortcut

Usage Example

import { type LayerType } from "@shadcn/designer"
import { TextIcon } from "lucide-react"
 
const textLayerType: LayerType = {
  type: "text",
  name: "Text",
  icon: TextIcon, // Can be a React component
  defaultValues: {
    name: "Text",
    value: "Enter text...",
    cssVars: {
      "--font-size": "16px",
      "--color": "#000000"
    }
  },
  render: (layer) => (
    <div style={layer.style}>
      <span style={layer.contentStyle}>{layer.value}</span>
    </div>
  ),
  keybinding: {
    key: "t",
    label: "T",
    labelMac: "T",
    description: "Add text layer",
    group: "layer"
  }
}
 
// You can also use strings (including emojis)
const blobLayerType: LayerType = {
  type: "blob",
  name: "Blob",
  icon: "🍡", // Can be a string or emoji
  defaultValues: {
    name: "Blob",
    value: "",
  },
  render: (layer) => <div>Blob content</div>
}
 
// Or JSX elements
const customLayerType: LayerType = {
  type: "custom",
  name: "Custom",
  icon: <span className="text-blue-500">★</span>, // Can be JSX
  defaultValues: {
    name: "Custom",
    value: "",
  },
  render: (layer) => <div>Custom content</div>
}

Keybinding

Configuration type for keyboard shortcuts.

type Keybinding = {
  key: string
  label: string
  labelMac: string
  description: string
  group: string
}

Properties

PropertyTypeDescription
keystringKeyboard combination (e.g., "cmd+d", "shift+t")
labelstringDisplay label for non-Mac platforms
labelMacstringDisplay label for Mac platforms
descriptionstringHuman-readable description
groupstringCategory/group for organization

Usage Example

import { type Keybinding } from "@shadcn/designer"
 
const duplicateKeybinding: Keybinding = {
  key: "cmd+d",
  label: "Ctrl+D",
  labelMac: "⌘D",
  description: "Duplicate selected layers",
  group: "layer"
}

CSSVars

Type for CSS custom properties used in layer styling.

type CSSVars = Record<string, string>

Usage Example

import { type CSSVars } from "@shadcn/designer"
 
const layerStyles: CSSVars = {
  "--width": "200px",
  "--height": "100px",
  "--background": "#f0f0f0",
  "--border-radius": "8px",
  "--font-size": "16px",
  "--color": "#333333"
}