Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: font selector does not work with recent puck canaries #167

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/internal/puck/components/FontSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ export const FontSelector = ({
<button
key={option.value}
value={option.value}
onClick={() => handleFontChange(option.value)}
onClick={(e) => {
e.preventDefault();
handleFontChange(option.value);
}}
style={{
fontFamily: option.value,
backgroundColor:
Expand Down
8 changes: 7 additions & 1 deletion src/internal/utils/constructThemePuckFields.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { CoreStyle, Style, ThemeConfig } from "../../utils/themeResolver.ts";
import { describe, it, expect } from "vitest";
import { describe, it, expect, vi } from "vitest";
import {
assignValue,
constructThemePuckFields,
constructThemePuckValues,
convertStyleToPuckField,
} from "./constructThemePuckFields.ts";

vi.mock("react", async () => {
return {
useCallback: (fn: any) => fn,
};
});

export const exampleThemeConfig: ThemeConfig = {
text: {
label: "Text",
Expand Down
24 changes: 14 additions & 10 deletions src/internal/utils/constructThemePuckFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ColorSelector } from "../puck/components/ColorSelector.tsx";
import { ThemeData } from "../types/themeData.ts";
import { FontSelector } from "../puck/components/FontSelector.tsx";
import { RenderProps } from "./renderEntityFields.tsx";
import { useCallback } from "react";

// Converts a ThemeConfigSection into a Puck fields object
export const constructThemePuckFields = (themeSection: ThemeConfigSection) => {
Expand Down Expand Up @@ -56,16 +57,19 @@ export const convertStyleToPuckField = (style: CoreStyle, plugin: string) => {
label: style.label,
type: "custom",
options: style.options,
render: ({ onChange, value }: RenderProps) =>
FontSelector({
label: style.label,
options:
typeof style.options === "function"
? style.options()
: style.options,
value,
onChange,
}),
render: useCallback(
({ onChange, value }: RenderProps) =>
FontSelector({
label: style.label,
options:
typeof style.options === "function"
? style.options()
: style.options,
value,
onChange,
}),
[]
),
} as CustomField;
} else {
return {
Expand Down