From e040f985a9a61c40ced48c01a9503ebffbd50ceb Mon Sep 17 00:00:00 2001 From: Grace Silge Date: Tue, 14 Apr 2026 09:27:13 -0400 Subject: [PATCH] WEB-53 Fix everything --- src/components/puck/blocks/icon.tsx | 39 +++++++++++++++++++++++++++++ src/lib/puck/tokens.ts | 13 ++++++++++ src/puck.config.tsx | 4 ++- 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/components/puck/blocks/icon.tsx diff --git a/src/components/puck/blocks/icon.tsx b/src/components/puck/blocks/icon.tsx new file mode 100644 index 0000000..4288886 --- /dev/null +++ b/src/components/puck/blocks/icon.tsx @@ -0,0 +1,39 @@ +import { ComponentConfig } from "@puckeditor/core"; +import React from "react"; +import { cn } from "@/lib/utils"; +import { IconName, DynamicIcon, dynamicIconImports } from 'lucide-react/dynamic'; +import { defineProps, responsive, field } from "@/lib/puck/define-props"; +import type { ResponsiveValue } from "@/lib/puck/responsive"; +import { resolveResponsive} from "@/lib/puck/responsive-tailwind"; +import { padding as paddingToken, hexCodeColor, type Spacing, type Color } from "@/lib/puck/tokens"; + + +type IconProps = { + size: number; + padding: ResponsiveValue; + color: Color; + icon?: IconName; +}; + +const props = defineProps({ + size: field.raw( { type: "number" }, 55 ), + padding: responsive.select(paddingToken, { label: "Padding", default: "md" }), + color: field.select(hexCodeColor, { label: "Color", default: "sga-red" }), + icon: field.raw( { type: "text" }, undefined), +}); + +export const Icon: ComponentConfig = { + label: "Icon", + inline: true, + ...props, + render: ({ size, padding, color, icon, puck }) => { + const resolvedIcon = (icon && (icon in dynamicIconImports)) ? icon : "landmark"; + + return (
+ +
); + } +}; \ No newline at end of file diff --git a/src/lib/puck/tokens.ts b/src/lib/puck/tokens.ts index 38bbf33..c0b79ea 100644 --- a/src/lib/puck/tokens.ts +++ b/src/lib/puck/tokens.ts @@ -136,6 +136,19 @@ export const bgColor = defineToken({ "sga-red": { label: "SGA Red", classes: "bg-sga-red" }, }); +export const hexCodeColor = defineToken({ + background: { label: "Background", classes: "#ffffff" }, + foreground: { label: "Foreground", classes: "#0a0a0a" }, + primary: { label: "Primary", classes: "#171717" }, + "primary-foreground": { label: "Primary Foreground", classes: "#fafafa" }, + muted: { label: "Muted", classes: "#f5f5f5" }, + "muted-foreground": { label: "Muted Foreground", classes: "#737373" }, + accent: { label: "Accent", classes: "#f5f5f5" }, + "accent-foreground": { label: "Accent Foreground", classes: "#171717" }, + destructive: { label: "Destructive", classes: "#e7000b" }, + "sga-red": { label: "SGA Red", classes: "#C8102E" }, +}); + export const textColor = defineToken({ background: { label: "Background", classes: "text-background" }, foreground: { label: "Foreground", classes: "text-foreground" }, diff --git a/src/puck.config.tsx b/src/puck.config.tsx index e4f813d..0d4ea99 100644 --- a/src/puck.config.tsx +++ b/src/puck.config.tsx @@ -6,11 +6,12 @@ import { RichTextComponent } from "@/components/puck/blocks/rich-text"; import { Media } from "@/components/puck/blocks/media"; import { PuckButton } from "@/components/puck/blocks/button"; import { Section } from "@/components/puck/blocks/section"; +import { Icon } from "./components/puck/blocks/icon"; export const config = { categories: { layout: { title: "Layout", components: ["Section", "Container", "Columns", "Grid"] }, - content: { title: "Content", components: ["Text", "Image"] }, + content: { title: "Content", components: ["Text", "Image", "Icon"] }, interactive: { title: "Interactive", components: ["Button"] }, }, components: { @@ -21,6 +22,7 @@ export const config = { Text: RichTextComponent, Image: Media, Button: PuckButton, + Icon, }, } satisfies Config;