Types
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
| Property | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Unique identifier for the layer |
name | string | Yes | Display name of the layer |
type | string | Yes | Layer type (e.g., "text", "image", "rectangle") |
value | string | Yes | Layer-specific content/value (e.g., text content, image URL) |
cssVars | CSSVars | No | CSS custom properties for styling |
meta | Record<string, unknown> | No | Arbitrary metadata storage |
isLocked | boolean | No | Whether 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
| Property | Type | Description |
|---|---|---|
style | CSSProperties | Computed styles for the layer container |
contentStyle | CSSProperties | Computed 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
| Property | Type | Required | Description |
|---|---|---|---|
type | string | Yes | Unique type identifier |
name | string | Yes | Human-readable name |
defaultValues | Omit<Layer, "id" | "type"> | Yes | Default values for new layers |
render | (layer: LayerWithStyles) => React.ReactNode | Yes | Render function |
icon | ReactNode | No | Icon for UI (string, component, or element) |
keybinding | Keybinding | No | Optional 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
| Property | Type | Description |
|---|---|---|
key | string | Keyboard combination (e.g., "cmd+d", "shift+t") |
label | string | Display label for non-Mac platforms |
labelMac | string | Display label for Mac platforms |
description | string | Human-readable description |
group | string | Category/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"
}FrameSize
Configuration type that defines the canvas frame dimensions.
type FrameSize = {
width: number
height: number
unit?: Unit
}Properties
| Property | Type | Required | Description |
|---|---|---|---|
width | number | Yes | Frame width value |
height | number | Yes | Frame height value |
unit | Unit | No | Unit of measurement (defaults to "px") |
Usage Example
import { type FrameSize } from "@shadcn/designer"
const frameSize: FrameSize = {
width: 1920,
height: 1080,
unit: "px"
}
// Print dimensions (8.5" x 11")
const printFrame: FrameSize = {
width: 8.5,
height: 11,
unit: "in"
}Unit
Type representing supported measurement units in the designer.
type Unit = "px" | "mm" | "in" | "cm" | "pt"Supported Units
| Unit | Description | Common Use Case |
|---|---|---|
px | Pixels | Screen designs, web layouts |
mm | Millimeters | Print designs, physical dimensions |
in | Inches | Print designs, physical dimensions |
cm | Centimeters | Print designs, physical dimensions |
pt | Points | Typography, print designs |
Usage Example
import { type Unit } from "@shadcn/designer"
const currentUnit: Unit = "px"
// Unit conversion utilities are also available
import { convertUnit, toPixels, fromPixels } from "@shadcn/designer"
// Convert 25.4mm to pixels at 96 DPI
const pixels = toPixels(25.4, "mm", 96) // 96px
// Convert 100px to inches at 96 DPI
const inches = fromPixels(100, "in", 96) // ~1.04in