Skip to content

Commit e040f98

Browse files
committed
WEB-53 Fix everything
1 parent eaf484f commit e040f98

3 files changed

Lines changed: 55 additions & 1 deletion

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { ComponentConfig } from "@puckeditor/core";
2+
import React from "react";
3+
import { cn } from "@/lib/utils";
4+
import { IconName, DynamicIcon, dynamicIconImports } from 'lucide-react/dynamic';
5+
import { defineProps, responsive, field } from "@/lib/puck/define-props";
6+
import type { ResponsiveValue } from "@/lib/puck/responsive";
7+
import { resolveResponsive} from "@/lib/puck/responsive-tailwind";
8+
import { padding as paddingToken, hexCodeColor, type Spacing, type Color } from "@/lib/puck/tokens";
9+
10+
11+
type IconProps = {
12+
size: number;
13+
padding: ResponsiveValue<Spacing>;
14+
color: Color;
15+
icon?: IconName;
16+
};
17+
18+
const props = defineProps({
19+
size: field.raw( { type: "number" }, 55 ),
20+
padding: responsive.select(paddingToken, { label: "Padding", default: "md" }),
21+
color: field.select(hexCodeColor, { label: "Color", default: "sga-red" }),
22+
icon: field.raw( { type: "text" }, undefined),
23+
});
24+
25+
export const Icon: ComponentConfig<IconProps> = {
26+
label: "Icon",
27+
inline: true,
28+
...props,
29+
render: ({ size, padding, color, icon, puck }) => {
30+
const resolvedIcon = (icon && (icon in dynamicIconImports)) ? icon : "landmark";
31+
32+
return (<div ref={puck.dragRef} className={`flex align-items-center justify-items-center`}>
33+
<DynamicIcon
34+
className={cn(
35+
resolveResponsive(padding, paddingToken.classes),
36+
)} name={resolvedIcon} size={size} color={hexCodeColor.classes[color]}/>
37+
</div>);
38+
}
39+
};

src/lib/puck/tokens.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,19 @@ export const bgColor = defineToken({
136136
"sga-red": { label: "SGA Red", classes: "bg-sga-red" },
137137
});
138138

139+
export const hexCodeColor = defineToken({
140+
background: { label: "Background", classes: "#ffffff" },
141+
foreground: { label: "Foreground", classes: "#0a0a0a" },
142+
primary: { label: "Primary", classes: "#171717" },
143+
"primary-foreground": { label: "Primary Foreground", classes: "#fafafa" },
144+
muted: { label: "Muted", classes: "#f5f5f5" },
145+
"muted-foreground": { label: "Muted Foreground", classes: "#737373" },
146+
accent: { label: "Accent", classes: "#f5f5f5" },
147+
"accent-foreground": { label: "Accent Foreground", classes: "#171717" },
148+
destructive: { label: "Destructive", classes: "#e7000b" },
149+
"sga-red": { label: "SGA Red", classes: "#C8102E" },
150+
});
151+
139152
export const textColor = defineToken({
140153
background: { label: "Background", classes: "text-background" },
141154
foreground: { label: "Foreground", classes: "text-foreground" },

src/puck.config.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import { RichTextComponent } from "@/components/puck/blocks/rich-text";
66
import { Media } from "@/components/puck/blocks/media";
77
import { PuckButton } from "@/components/puck/blocks/button";
88
import { Section } from "@/components/puck/blocks/section";
9+
import { Icon } from "./components/puck/blocks/icon";
910

1011
export const config = {
1112
categories: {
1213
layout: { title: "Layout", components: ["Section", "Container", "Columns", "Grid"] },
13-
content: { title: "Content", components: ["Text", "Image"] },
14+
content: { title: "Content", components: ["Text", "Image", "Icon"] },
1415
interactive: { title: "Interactive", components: ["Button"] },
1516
},
1617
components: {
@@ -21,6 +22,7 @@ export const config = {
2122
Text: RichTextComponent,
2223
Image: Media,
2324
Button: PuckButton,
25+
Icon,
2426
},
2527
} satisfies Config;
2628

0 commit comments

Comments
 (0)