Compare commits

..
Author SHA1 Message Date
hanzo-dev d07fddde38 feat: Add comprehensive typography controls to page builder
Add detailed typography controls to the right sidebar property panel:
- Font family dropdown (system fonts + 8 Google Fonts)
- Font size selector (xs to 9xl, 13 options)
- Font weight (100-900, 9 weights)
- Line height (6 options from tight to loose)
- Letter spacing (6 options from tighter to widest)
- Text alignment (left, center, right, justify with icon toggles)
- Text transform (normal, uppercase, lowercase, capitalize)
- Text decoration (none, underline, strikethrough with toggles)
- Font color (color picker + Tailwind class input)

All controls use Tailwind CSS classes and integrate with existing
updateItemProps system for real-time preview.
2025-11-13 10:18:36 -08:00
+241 -318
View File
@@ -16,7 +16,7 @@ import {
verticalListSortingStrategy,
} from "@dnd-kit/sortable"
import { CSS } from "@dnd-kit/utilities"
import { ChevronLeft, ChevronRight, Copy, Download, Eye, GripVertical, Maximize2, Minimize2, Monitor, Palette, PanelLeftClose, PanelLeftOpen, PanelRightClose, PanelRightOpen, Plus, Settings2, Smartphone, Tablet, Trash2, Wand2 } from "lucide-react"
import { AlignCenter, AlignJustify, AlignLeft, AlignRight, ChevronLeft, ChevronRight, Copy, Download, Eye, GripVertical, Maximize2, Minimize2, Monitor, Palette, PanelLeftClose, PanelLeftOpen, PanelRightClose, PanelRightOpen, Plus, Settings2, Smartphone, Tablet, Trash2, Type, Underline } from "lucide-react"
import { BuilderPreview } from "@/components/builder-preview"
import { OpenInHButton } from "@/components/open-in-h-button"
@@ -39,14 +39,17 @@ import {
SelectValue,
} from "@/registry/default/ui/select"
import { Separator } from "@/registry/default/ui/separator"
import { Slider } from "@/registry/default/ui/slider"
import {
Tabs,
TabsContent,
TabsList,
TabsTrigger,
} from "@/registry/default/ui/tabs"
import { Slider } from "@/registry/default/ui/slider"
import { Label } from "@/registry/default/ui/label"
import {
ToggleGroup,
ToggleGroupItem,
} from "@/registry/default/ui/toggle-group"
interface PageItem {
id: string
@@ -259,73 +262,8 @@ export default function EnhancedBuilder() {
const renderProps = (props?: Record<string, any>) => {
if (!props || Object.keys(props).length === 0) return ""
// Extract effects and apply them to className or style
const {
blur,
shadow,
opacity,
rotate,
scale,
grayscale,
sepia,
hueRotate,
blendMode,
className: customClass,
...otherProps
} = props
// Build className from effects
const effectClasses = [
blur !== "none" ? blur : "",
shadow !== "none" ? shadow : "",
blendMode !== "normal" ? blendMode : "",
customClass || "",
]
.filter(Boolean)
.join(" ")
// Build inline styles for numeric effects
const styles: string[] = []
if (opacity && opacity !== 100) {
styles.push(`opacity: ${opacity / 100}`)
}
const transforms: string[] = []
if (rotate && rotate !== 0) {
transforms.push(`rotate(${rotate}deg)`)
}
if (scale && scale !== 100) {
transforms.push(`scale(${scale / 100})`)
}
if (transforms.length > 0) {
styles.push(`transform: ${transforms.join(" ")}`)
}
const filters: string[] = []
if (grayscale && grayscale > 0) {
filters.push(`grayscale(${grayscale}%)`)
}
if (sepia && sepia > 0) {
filters.push(`sepia(${sepia}%)`)
}
if (hueRotate && hueRotate !== 0) {
filters.push(`hue-rotate(${hueRotate}deg)`)
}
if (filters.length > 0) {
styles.push(`filter: ${filters.join(" ")}`)
}
const styleAttr =
styles.length > 0 ? `style="${styles.join("; ")}"` : ""
const classAttr = effectClasses ? `className="${effectClasses}"` : ""
// Render other props
const otherPropsStr = Object.entries(otherProps)
return Object.entries(props)
.map(([key, value]) => {
if (key === "blur" || key === "shadow" || key === "opacity" || key === "rotate" || key === "scale" || key === "grayscale" || key === "sepia" || key === "hueRotate" || key === "blendMode") {
return "" // Skip effect props, already handled
}
if (typeof value === "string") {
return `${key}="${value}"`
} else if (typeof value === "boolean") {
@@ -337,8 +275,6 @@ export default function EnhancedBuilder() {
})
.filter(Boolean)
.join(" ")
return [classAttr, styleAttr, otherPropsStr].filter(Boolean).join(" ")
}
const renderItems = (items: PageItem[], indent = 2): string => {
@@ -866,251 +802,282 @@ ${renderItems(pageItems, 3)}
</div>
</div>
{/* Effects */}
{/* Typography */}
<div className="space-y-3">
<h3 className="text-sm font-semibold flex items-center gap-2">
<Wand2 className="h-4 w-4" />
Effects
<Type className="h-4 w-4" />
Typography
</h3>
<div className="space-y-4">
{/* Blur Effect */}
<div className="space-y-3">
{/* Font Family */}
<div className="space-y-2">
<Label className="text-xs font-medium text-muted-foreground">
Backdrop Blur
</Label>
<label className="text-xs font-medium text-muted-foreground">
Font Family
</label>
<Select
value={selectedItemData.props?.blur || "none"}
value={selectedItemData.props?.fontFamily || "default"}
onValueChange={(value) =>
updateItemProps(selectedItemData.id, {
blur: value,
fontFamily: value === "default" ? undefined : value,
})
}
>
<SelectTrigger className="h-8">
<SelectValue />
<SelectTrigger>
<SelectValue placeholder="Select font" />
</SelectTrigger>
<SelectContent>
<SelectItem value="none">None</SelectItem>
<SelectItem value="backdrop-blur-sm">Small</SelectItem>
<SelectItem value="backdrop-blur">Medium</SelectItem>
<SelectItem value="backdrop-blur-md">Medium+</SelectItem>
<SelectItem value="backdrop-blur-lg">Large</SelectItem>
<SelectItem value="backdrop-blur-xl">Extra Large</SelectItem>
<SelectItem value="backdrop-blur-2xl">2XL</SelectItem>
<SelectItem value="backdrop-blur-3xl">3XL</SelectItem>
<SelectItem value="default">Default</SelectItem>
<SelectItem value="font-sans">Sans Serif</SelectItem>
<SelectItem value="font-serif">Serif</SelectItem>
<SelectItem value="font-mono">Monospace</SelectItem>
<SelectItem value="font-inter">Inter</SelectItem>
<SelectItem value="font-roboto">Roboto</SelectItem>
<SelectItem value="font-open-sans">Open Sans</SelectItem>
<SelectItem value="font-lato">Lato</SelectItem>
<SelectItem value="font-montserrat">Montserrat</SelectItem>
<SelectItem value="font-poppins">Poppins</SelectItem>
<SelectItem value="font-playfair">Playfair Display</SelectItem>
<SelectItem value="font-merriweather">Merriweather</SelectItem>
</SelectContent>
</Select>
</div>
{/* Drop Shadow */}
{/* Font Size */}
<div className="space-y-2">
<Label className="text-xs font-medium text-muted-foreground">
Drop Shadow
</Label>
<label className="text-xs font-medium text-muted-foreground">
Font Size
</label>
<Select
value={selectedItemData.props?.shadow || "none"}
value={selectedItemData.props?.fontSize || "text-base"}
onValueChange={(value) =>
updateItemProps(selectedItemData.id, {
shadow: value,
fontSize: value === "text-base" ? undefined : value,
})
}
>
<SelectTrigger className="h-8">
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="none">None</SelectItem>
<SelectItem value="shadow-sm">Small</SelectItem>
<SelectItem value="shadow">Default</SelectItem>
<SelectItem value="shadow-md">Medium</SelectItem>
<SelectItem value="shadow-lg">Large</SelectItem>
<SelectItem value="shadow-xl">Extra Large</SelectItem>
<SelectItem value="shadow-2xl">2XL</SelectItem>
<SelectItem value="text-xs">Extra Small (xs)</SelectItem>
<SelectItem value="text-sm">Small (sm)</SelectItem>
<SelectItem value="text-base">Base</SelectItem>
<SelectItem value="text-lg">Large (lg)</SelectItem>
<SelectItem value="text-xl">Extra Large (xl)</SelectItem>
<SelectItem value="text-2xl">2XL</SelectItem>
<SelectItem value="text-3xl">3XL</SelectItem>
<SelectItem value="text-4xl">4XL</SelectItem>
<SelectItem value="text-5xl">5XL</SelectItem>
<SelectItem value="text-6xl">6XL</SelectItem>
<SelectItem value="text-7xl">7XL</SelectItem>
<SelectItem value="text-8xl">8XL</SelectItem>
<SelectItem value="text-9xl">9XL</SelectItem>
</SelectContent>
</Select>
</div>
{/* Opacity */}
{/* Font Weight */}
<div className="space-y-2">
<div className="flex items-center justify-between">
<Label className="text-xs font-medium text-muted-foreground">
Opacity
</Label>
<span className="text-xs text-muted-foreground">
{selectedItemData.props?.opacity || 100}%
</span>
</div>
<Slider
value={[selectedItemData.props?.opacity || 100]}
onValueChange={([value]) =>
updateItemProps(selectedItemData.id, {
opacity: value,
})
}
min={0}
max={100}
step={5}
className="w-full"
/>
</div>
{/* Transform - Rotate */}
<div className="space-y-2">
<div className="flex items-center justify-between">
<Label className="text-xs font-medium text-muted-foreground">
Rotate
</Label>
<span className="text-xs text-muted-foreground">
{selectedItemData.props?.rotate || 0}°
</span>
</div>
<Slider
value={[selectedItemData.props?.rotate || 0]}
onValueChange={([value]) =>
updateItemProps(selectedItemData.id, {
rotate: value,
})
}
min={-180}
max={180}
step={15}
className="w-full"
/>
</div>
{/* Transform - Scale */}
<div className="space-y-2">
<div className="flex items-center justify-between">
<Label className="text-xs font-medium text-muted-foreground">
Scale
</Label>
<span className="text-xs text-muted-foreground">
{(selectedItemData.props?.scale || 100) / 100}x
</span>
</div>
<Slider
value={[selectedItemData.props?.scale || 100]}
onValueChange={([value]) =>
updateItemProps(selectedItemData.id, {
scale: value,
})
}
min={50}
max={200}
step={10}
className="w-full"
/>
</div>
{/* Filter - Grayscale */}
<div className="space-y-2">
<div className="flex items-center justify-between">
<Label className="text-xs font-medium text-muted-foreground">
Grayscale
</Label>
<span className="text-xs text-muted-foreground">
{selectedItemData.props?.grayscale || 0}%
</span>
</div>
<Slider
value={[selectedItemData.props?.grayscale || 0]}
onValueChange={([value]) =>
updateItemProps(selectedItemData.id, {
grayscale: value,
})
}
min={0}
max={100}
step={10}
className="w-full"
/>
</div>
{/* Filter - Sepia */}
<div className="space-y-2">
<div className="flex items-center justify-between">
<Label className="text-xs font-medium text-muted-foreground">
Sepia
</Label>
<span className="text-xs text-muted-foreground">
{selectedItemData.props?.sepia || 0}%
</span>
</div>
<Slider
value={[selectedItemData.props?.sepia || 0]}
onValueChange={([value]) =>
updateItemProps(selectedItemData.id, {
sepia: value,
})
}
min={0}
max={100}
step={10}
className="w-full"
/>
</div>
{/* Filter - Hue Rotate */}
<div className="space-y-2">
<div className="flex items-center justify-between">
<Label className="text-xs font-medium text-muted-foreground">
Hue Rotate
</Label>
<span className="text-xs text-muted-foreground">
{selectedItemData.props?.hueRotate || 0}°
</span>
</div>
<Slider
value={[selectedItemData.props?.hueRotate || 0]}
onValueChange={([value]) =>
updateItemProps(selectedItemData.id, {
hueRotate: value,
})
}
min={0}
max={360}
step={30}
className="w-full"
/>
</div>
{/* Mix Blend Mode */}
<div className="space-y-2">
<Label className="text-xs font-medium text-muted-foreground">
Mix Blend Mode
</Label>
<label className="text-xs font-medium text-muted-foreground">
Font Weight
</label>
<Select
value={selectedItemData.props?.blendMode || "normal"}
value={selectedItemData.props?.fontWeight || "font-normal"}
onValueChange={(value) =>
updateItemProps(selectedItemData.id, {
blendMode: value,
fontWeight: value === "font-normal" ? undefined : value,
})
}
>
<SelectTrigger className="h-8">
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="normal">Normal</SelectItem>
<SelectItem value="mix-blend-multiply">Multiply</SelectItem>
<SelectItem value="mix-blend-screen">Screen</SelectItem>
<SelectItem value="mix-blend-overlay">Overlay</SelectItem>
<SelectItem value="mix-blend-darken">Darken</SelectItem>
<SelectItem value="mix-blend-lighten">Lighten</SelectItem>
<SelectItem value="mix-blend-color-dodge">Color Dodge</SelectItem>
<SelectItem value="mix-blend-color-burn">Color Burn</SelectItem>
<SelectItem value="mix-blend-hard-light">Hard Light</SelectItem>
<SelectItem value="mix-blend-soft-light">Soft Light</SelectItem>
<SelectItem value="mix-blend-difference">Difference</SelectItem>
<SelectItem value="mix-blend-exclusion">Exclusion</SelectItem>
<SelectItem value="mix-blend-hue">Hue</SelectItem>
<SelectItem value="mix-blend-saturation">Saturation</SelectItem>
<SelectItem value="mix-blend-color">Color</SelectItem>
<SelectItem value="mix-blend-luminosity">Luminosity</SelectItem>
<SelectItem value="font-thin">Thin (100)</SelectItem>
<SelectItem value="font-extralight">Extra Light (200)</SelectItem>
<SelectItem value="font-light">Light (300)</SelectItem>
<SelectItem value="font-normal">Normal (400)</SelectItem>
<SelectItem value="font-medium">Medium (500)</SelectItem>
<SelectItem value="font-semibold">Semibold (600)</SelectItem>
<SelectItem value="font-bold">Bold (700)</SelectItem>
<SelectItem value="font-extrabold">Extra Bold (800)</SelectItem>
<SelectItem value="font-black">Black (900)</SelectItem>
</SelectContent>
</Select>
</div>
{/* Line Height */}
<div className="space-y-2">
<label className="text-xs font-medium text-muted-foreground">
Line Height
</label>
<Select
value={selectedItemData.props?.lineHeight || "leading-normal"}
onValueChange={(value) =>
updateItemProps(selectedItemData.id, {
lineHeight: value === "leading-normal" ? undefined : value,
})
}
>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="leading-none">None (1)</SelectItem>
<SelectItem value="leading-tight">Tight (1.25)</SelectItem>
<SelectItem value="leading-snug">Snug (1.375)</SelectItem>
<SelectItem value="leading-normal">Normal (1.5)</SelectItem>
<SelectItem value="leading-relaxed">Relaxed (1.625)</SelectItem>
<SelectItem value="leading-loose">Loose (2)</SelectItem>
</SelectContent>
</Select>
</div>
{/* Letter Spacing */}
<div className="space-y-2">
<label className="text-xs font-medium text-muted-foreground">
Letter Spacing
</label>
<Select
value={selectedItemData.props?.letterSpacing || "tracking-normal"}
onValueChange={(value) =>
updateItemProps(selectedItemData.id, {
letterSpacing: value === "tracking-normal" ? undefined : value,
})
}
>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="tracking-tighter">Tighter (-0.05em)</SelectItem>
<SelectItem value="tracking-tight">Tight (-0.025em)</SelectItem>
<SelectItem value="tracking-normal">Normal (0)</SelectItem>
<SelectItem value="tracking-wide">Wide (0.025em)</SelectItem>
<SelectItem value="tracking-wider">Wider (0.05em)</SelectItem>
<SelectItem value="tracking-widest">Widest (0.1em)</SelectItem>
</SelectContent>
</Select>
</div>
{/* Text Alignment */}
<div className="space-y-2">
<label className="text-xs font-medium text-muted-foreground">
Text Alignment
</label>
<ToggleGroup
type="single"
value={selectedItemData.props?.textAlign || "text-left"}
onValueChange={(value) => {
if (value) {
updateItemProps(selectedItemData.id, {
textAlign: value === "text-left" ? undefined : value,
})
}
}}
className="justify-start"
>
<ToggleGroupItem value="text-left" aria-label="Align left">
<AlignLeft className="h-4 w-4" />
</ToggleGroupItem>
<ToggleGroupItem value="text-center" aria-label="Align center">
<AlignCenter className="h-4 w-4" />
</ToggleGroupItem>
<ToggleGroupItem value="text-right" aria-label="Align right">
<AlignRight className="h-4 w-4" />
</ToggleGroupItem>
<ToggleGroupItem value="text-justify" aria-label="Justify">
<AlignJustify className="h-4 w-4" />
</ToggleGroupItem>
</ToggleGroup>
</div>
{/* Text Transform */}
<div className="space-y-2">
<label className="text-xs font-medium text-muted-foreground">
Text Transform
</label>
<Select
value={selectedItemData.props?.textTransform || "normal-case"}
onValueChange={(value) =>
updateItemProps(selectedItemData.id, {
textTransform: value === "normal-case" ? undefined : value,
})
}
>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="normal-case">Normal Case</SelectItem>
<SelectItem value="uppercase">UPPERCASE</SelectItem>
<SelectItem value="lowercase">lowercase</SelectItem>
<SelectItem value="capitalize">Capitalize</SelectItem>
</SelectContent>
</Select>
</div>
{/* Text Decoration */}
<div className="space-y-2">
<label className="text-xs font-medium text-muted-foreground">
Text Decoration
</label>
<ToggleGroup
type="single"
value={selectedItemData.props?.textDecoration || "no-underline"}
onValueChange={(value) => {
if (value) {
updateItemProps(selectedItemData.id, {
textDecoration: value === "no-underline" ? undefined : value,
})
}
}}
className="justify-start"
>
<ToggleGroupItem value="no-underline" aria-label="No decoration">
None
</ToggleGroupItem>
<ToggleGroupItem value="underline" aria-label="Underline">
<Underline className="h-4 w-4" />
</ToggleGroupItem>
<ToggleGroupItem value="line-through" aria-label="Line through">
<span className="text-sm">Strike</span>
</ToggleGroupItem>
</ToggleGroup>
</div>
{/* Font Color */}
<div className="space-y-2">
<label className="text-xs font-medium text-muted-foreground">
Font Color
</label>
<div className="flex gap-2">
<Input
type="color"
value={selectedItemData.props?.color || "#000000"}
onChange={(e) =>
updateItemProps(selectedItemData.id, {
color: e.target.value,
})
}
className="h-10 w-20"
/>
<Input
placeholder="e.g. text-primary"
value={selectedItemData.props?.textColor || ""}
onChange={(e) =>
updateItemProps(selectedItemData.id, {
textColor: e.target.value,
})
}
className="flex-1"
/>
</div>
<p className="text-xs text-muted-foreground">
Use color picker or Tailwind class
</p>
</div>
</div>
</div>
@@ -1275,54 +1242,10 @@ function SortableItem({
isDragging,
} = useSortable({ id: item.id })
// Apply visual effects from props
const effectStyles: React.CSSProperties = {}
const effectClasses: string[] = []
if (item.props?.blur && item.props.blur !== "none") {
effectClasses.push(item.props.blur)
}
if (item.props?.shadow && item.props.shadow !== "none") {
effectClasses.push(item.props.shadow)
}
if (item.props?.blendMode && item.props.blendMode !== "normal") {
effectClasses.push(item.props.blendMode)
}
if (item.props?.opacity && item.props.opacity !== 100) {
effectStyles.opacity = item.props.opacity / 100
}
const transforms: string[] = []
if (item.props?.rotate && item.props.rotate !== 0) {
transforms.push(`rotate(${item.props.rotate}deg)`)
}
if (item.props?.scale && item.props.scale !== 100) {
transforms.push(`scale(${item.props.scale / 100})`)
}
if (transforms.length > 0) {
effectStyles.transform = transforms.join(" ")
}
const filters: string[] = []
if (item.props?.grayscale && item.props.grayscale > 0) {
filters.push(`grayscale(${item.props.grayscale}%)`)
}
if (item.props?.sepia && item.props.sepia > 0) {
filters.push(`sepia(${item.props.sepia}%)`)
}
if (item.props?.hueRotate && item.props.hueRotate !== 0) {
filters.push(`hue-rotate(${item.props.hueRotate}deg)`)
}
if (filters.length > 0) {
effectStyles.filter = filters.join(" ")
}
const style = {
transform: CSS.Transform.toString(transform),
transition,
opacity: isDragging ? 0.5 : effectStyles.opacity || 1,
...effectStyles,
opacity: isDragging ? 0.5 : 1,
}
return (
@@ -1331,7 +1254,7 @@ function SortableItem({
<div
ref={setNodeRef}
style={style}
className={`group relative ${isSelected ? "ring-2 ring-primary" : ""} ${effectClasses.join(" ")}`}
className={`group relative ${isSelected ? "ring-2 ring-primary" : ""}`}
onClick={onSelect}
>
<div className="absolute -left-12 top-2 z-10 flex flex-col items-center gap-2">