@delmaredigital/payload-puck 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +73 -0
- package/README.md +1580 -0
- package/dist/AccordionClient.d.mts +24 -0
- package/dist/AccordionClient.d.ts +24 -0
- package/dist/AccordionClient.js +786 -0
- package/dist/AccordionClient.js.map +1 -0
- package/dist/AccordionClient.mjs +784 -0
- package/dist/AccordionClient.mjs.map +1 -0
- package/dist/AnimatedWrapper.d.mts +30 -0
- package/dist/AnimatedWrapper.d.ts +30 -0
- package/dist/AnimatedWrapper.js +379 -0
- package/dist/AnimatedWrapper.js.map +1 -0
- package/dist/AnimatedWrapper.mjs +377 -0
- package/dist/AnimatedWrapper.mjs.map +1 -0
- package/dist/admin/client.d.mts +108 -0
- package/dist/admin/client.d.ts +108 -0
- package/dist/admin/client.js +177 -0
- package/dist/admin/client.js.map +1 -0
- package/dist/admin/client.mjs +173 -0
- package/dist/admin/client.mjs.map +1 -0
- package/dist/admin/index.d.mts +157 -0
- package/dist/admin/index.d.ts +157 -0
- package/dist/admin/index.js +31 -0
- package/dist/admin/index.js.map +1 -0
- package/dist/admin/index.mjs +29 -0
- package/dist/admin/index.mjs.map +1 -0
- package/dist/api/index.d.mts +460 -0
- package/dist/api/index.d.ts +460 -0
- package/dist/api/index.js +588 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/index.mjs +578 -0
- package/dist/api/index.mjs.map +1 -0
- package/dist/components/index.css +339 -0
- package/dist/components/index.css.map +1 -0
- package/dist/components/index.d.mts +222 -0
- package/dist/components/index.d.ts +222 -0
- package/dist/components/index.js +9177 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/index.mjs +9130 -0
- package/dist/components/index.mjs.map +1 -0
- package/dist/config/config.editor.css +339 -0
- package/dist/config/config.editor.css.map +1 -0
- package/dist/config/config.editor.d.mts +153 -0
- package/dist/config/config.editor.d.ts +153 -0
- package/dist/config/config.editor.js +9400 -0
- package/dist/config/config.editor.js.map +1 -0
- package/dist/config/config.editor.mjs +9368 -0
- package/dist/config/config.editor.mjs.map +1 -0
- package/dist/config/index.d.mts +68 -0
- package/dist/config/index.d.ts +68 -0
- package/dist/config/index.js +2017 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/index.mjs +1991 -0
- package/dist/config/index.mjs.map +1 -0
- package/dist/editor/index.d.mts +784 -0
- package/dist/editor/index.d.ts +784 -0
- package/dist/editor/index.js +4517 -0
- package/dist/editor/index.js.map +1 -0
- package/dist/editor/index.mjs +4483 -0
- package/dist/editor/index.mjs.map +1 -0
- package/dist/fields/index.css +339 -0
- package/dist/fields/index.css.map +1 -0
- package/dist/fields/index.d.mts +600 -0
- package/dist/fields/index.d.ts +600 -0
- package/dist/fields/index.js +7739 -0
- package/dist/fields/index.js.map +1 -0
- package/dist/fields/index.mjs +7590 -0
- package/dist/fields/index.mjs.map +1 -0
- package/dist/index-CQu6SzDg.d.mts +327 -0
- package/dist/index-CoUQnyC3.d.ts +327 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +569 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +555 -0
- package/dist/index.mjs.map +1 -0
- package/dist/layouts/index.d.mts +96 -0
- package/dist/layouts/index.d.ts +96 -0
- package/dist/layouts/index.js +394 -0
- package/dist/layouts/index.js.map +1 -0
- package/dist/layouts/index.mjs +378 -0
- package/dist/layouts/index.mjs.map +1 -0
- package/dist/plugin/index.d.mts +289 -0
- package/dist/plugin/index.d.ts +289 -0
- package/dist/plugin/index.js +569 -0
- package/dist/plugin/index.js.map +1 -0
- package/dist/plugin/index.mjs +555 -0
- package/dist/plugin/index.mjs.map +1 -0
- package/dist/render/index.d.mts +109 -0
- package/dist/render/index.d.ts +109 -0
- package/dist/render/index.js +2146 -0
- package/dist/render/index.js.map +1 -0
- package/dist/render/index.mjs +2123 -0
- package/dist/render/index.mjs.map +1 -0
- package/dist/shared-DMAF1AcH.d.mts +545 -0
- package/dist/shared-DMAF1AcH.d.ts +545 -0
- package/dist/theme/index.d.mts +155 -0
- package/dist/theme/index.d.ts +155 -0
- package/dist/theme/index.js +201 -0
- package/dist/theme/index.js.map +1 -0
- package/dist/theme/index.mjs +186 -0
- package/dist/theme/index.mjs.map +1 -0
- package/dist/types-D7D3rZ1J.d.mts +116 -0
- package/dist/types-D7D3rZ1J.d.ts +116 -0
- package/dist/types-_6MvjyKv.d.mts +104 -0
- package/dist/types-_6MvjyKv.d.ts +104 -0
- package/dist/utils/index.d.mts +267 -0
- package/dist/utils/index.d.ts +267 -0
- package/dist/utils/index.js +426 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/index.mjs +412 -0
- package/dist/utils/index.mjs.map +1 -0
- package/dist/utils-DaRs9t0J.d.mts +85 -0
- package/dist/utils-gAvt0Vhw.d.ts +85 -0
- package/examples/README.md +240 -0
- package/examples/api/puck/pages/[id]/route.ts +64 -0
- package/examples/api/puck/pages/[id]/versions/route.ts +47 -0
- package/examples/api/puck/pages/route.ts +45 -0
- package/examples/app/(frontend)/page.tsx +94 -0
- package/examples/app/[...slug]/page.tsx +101 -0
- package/examples/app/pages/[id]/edit/page.tsx +148 -0
- package/examples/components/CustomBanner.tsx +368 -0
- package/examples/config/custom-config.ts +223 -0
- package/examples/config/payload.config.example.ts +64 -0
- package/examples/lib/puck-layouts.ts +258 -0
- package/examples/lib/puck-theme.ts +94 -0
- package/examples/styles/puck-theme.css +171 -0
- package/package.json +157 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { T as ThemeConfig, R as ResolvedTheme, B as ButtonVariantStyles, a as BackgroundStyles, C as ColorPreset } from '../types-_6MvjyKv.js';
|
|
2
|
+
export { b as ButtonVariantConfig, c as ThemeContextValue } from '../types-_6MvjyKv.js';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
+
import { ReactNode } from 'react';
|
|
5
|
+
|
|
6
|
+
interface ThemeProviderProps {
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
/** Theme configuration to apply */
|
|
9
|
+
theme?: ThemeConfig;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Provides theme configuration to descendant Puck components
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* <ThemeProvider theme={{
|
|
17
|
+
* buttonVariants: {
|
|
18
|
+
* default: { classes: 'bg-primary text-white hover:bg-primary/90' }
|
|
19
|
+
* }
|
|
20
|
+
* }}>
|
|
21
|
+
* <PageRenderer data={data} />
|
|
22
|
+
* </ThemeProvider>
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
declare function ThemeProvider({ children, theme }: ThemeProviderProps): react_jsx_runtime.JSX.Element;
|
|
26
|
+
/**
|
|
27
|
+
* Hook to access the current theme
|
|
28
|
+
*
|
|
29
|
+
* Returns DEFAULT_THEME if no ThemeProvider is present,
|
|
30
|
+
* ensuring components work standalone for backwards compatibility.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```tsx
|
|
34
|
+
* function MyComponent() {
|
|
35
|
+
* const theme = useTheme()
|
|
36
|
+
* const buttonClasses = getVariantClasses(theme.buttonVariants, 'primary')
|
|
37
|
+
* return <button className={buttonClasses}>Click me</button>
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
declare function useTheme(): ResolvedTheme;
|
|
42
|
+
/**
|
|
43
|
+
* Gets the default theme for server components
|
|
44
|
+
*
|
|
45
|
+
* Use this when you need theme values in a server component
|
|
46
|
+
* where hooks cannot be used.
|
|
47
|
+
*/
|
|
48
|
+
declare function getDefaultTheme(): ResolvedTheme;
|
|
49
|
+
/**
|
|
50
|
+
* Hook to check if a ThemeProvider is present
|
|
51
|
+
*
|
|
52
|
+
* Useful for conditional logic based on whether theming is configured.
|
|
53
|
+
*/
|
|
54
|
+
declare function useHasThemeProvider(): boolean;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Default Theme Values
|
|
58
|
+
*
|
|
59
|
+
* These defaults ensure backwards compatibility - components render
|
|
60
|
+
* identically to before theming was introduced when no theme is provided.
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Default button variant styles
|
|
65
|
+
* Uses semantic Tailwind classes that map to CSS variables (--primary, --secondary, etc.)
|
|
66
|
+
* This allows consuming apps to customize colors via their theme CSS variables.
|
|
67
|
+
*/
|
|
68
|
+
declare const DEFAULT_BUTTON_VARIANTS: ButtonVariantStyles;
|
|
69
|
+
/**
|
|
70
|
+
* Default CTA button variant styles
|
|
71
|
+
* Uses semantic Tailwind classes that map to CSS variables.
|
|
72
|
+
*/
|
|
73
|
+
declare const DEFAULT_CTA_BUTTON_VARIANTS: ButtonVariantStyles;
|
|
74
|
+
/**
|
|
75
|
+
* Default CTA background styles
|
|
76
|
+
* Uses semantic Tailwind classes that map to CSS variables.
|
|
77
|
+
*/
|
|
78
|
+
declare const DEFAULT_CTA_BACKGROUND_STYLES: BackgroundStyles;
|
|
79
|
+
/**
|
|
80
|
+
* Default color picker presets
|
|
81
|
+
* Matches DEFAULT_PRESETS from ColorPickerField.tsx
|
|
82
|
+
*/
|
|
83
|
+
declare const DEFAULT_COLOR_PRESETS: ColorPreset[];
|
|
84
|
+
/**
|
|
85
|
+
* Default focus ring color class
|
|
86
|
+
* Uses semantic ring color from CSS variables
|
|
87
|
+
*/
|
|
88
|
+
declare const DEFAULT_FOCUS_RING = "focus:ring-ring";
|
|
89
|
+
/**
|
|
90
|
+
* Complete default theme
|
|
91
|
+
* Used when no ThemeProvider is present or no theme config is provided
|
|
92
|
+
*/
|
|
93
|
+
declare const DEFAULT_THEME: ResolvedTheme;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Theme Resolution Utilities
|
|
97
|
+
*
|
|
98
|
+
* Functions for merging user-provided theme config with defaults
|
|
99
|
+
* and safely accessing theme values.
|
|
100
|
+
*/
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Merges user-provided theme config with defaults to create a fully resolved theme
|
|
104
|
+
*/
|
|
105
|
+
declare function resolveTheme(config?: ThemeConfig): ResolvedTheme;
|
|
106
|
+
/**
|
|
107
|
+
* Safely gets variant classes from a variant styles object
|
|
108
|
+
*
|
|
109
|
+
* @param variants - The button variant styles object
|
|
110
|
+
* @param variant - The variant key to look up
|
|
111
|
+
* @param fallback - Fallback variant key if the requested variant doesn't exist
|
|
112
|
+
* @returns The CSS classes string for the variant
|
|
113
|
+
*/
|
|
114
|
+
declare function getVariantClasses(variants: ButtonVariantStyles, variant: string, fallback?: string): string;
|
|
115
|
+
/**
|
|
116
|
+
* Safely gets background style classes
|
|
117
|
+
*
|
|
118
|
+
* @param styles - The background styles object
|
|
119
|
+
* @param style - The style key to look up
|
|
120
|
+
* @param fallback - Fallback style key if the requested style doesn't exist
|
|
121
|
+
* @returns The CSS classes string for the background
|
|
122
|
+
*/
|
|
123
|
+
declare function getBackgroundClasses(styles: BackgroundStyles, style: string, fallback?: string): string;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Example Theme Configuration
|
|
127
|
+
*
|
|
128
|
+
* Copy this file to your project and customize it to match your design system.
|
|
129
|
+
*
|
|
130
|
+
* Usage:
|
|
131
|
+
* 1. Copy this file to your project (e.g., src/lib/puck-theme.ts)
|
|
132
|
+
* 2. Customize the values to match your CSS variables/design tokens
|
|
133
|
+
* 3. Import and pass to PageRenderer or PuckEditor:
|
|
134
|
+
*
|
|
135
|
+
* ```tsx
|
|
136
|
+
* import { puckTheme } from '@/lib/puck-theme'
|
|
137
|
+
*
|
|
138
|
+
* <PageRenderer data={data} config={config} theme={puckTheme} />
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Example theme using shadcn/ui CSS variables
|
|
144
|
+
*
|
|
145
|
+
* This example assumes you have CSS variables like:
|
|
146
|
+
* --primary, --primary-foreground
|
|
147
|
+
* --secondary, --secondary-foreground
|
|
148
|
+
* --accent, --accent-foreground
|
|
149
|
+
* --muted, --muted-foreground
|
|
150
|
+
* --destructive, --destructive-foreground
|
|
151
|
+
* --ring (for focus rings)
|
|
152
|
+
*/
|
|
153
|
+
declare const exampleTheme: ThemeConfig;
|
|
154
|
+
|
|
155
|
+
export { BackgroundStyles, ButtonVariantStyles, ColorPreset, DEFAULT_BUTTON_VARIANTS, DEFAULT_COLOR_PRESETS, DEFAULT_CTA_BACKGROUND_STYLES, DEFAULT_CTA_BUTTON_VARIANTS, DEFAULT_FOCUS_RING, DEFAULT_THEME, ResolvedTheme, ThemeConfig, ThemeProvider, type ThemeProviderProps, exampleTheme, getBackgroundClasses, getDefaultTheme, getVariantClasses, resolveTheme, useHasThemeProvider, useTheme };
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
|
|
7
|
+
// src/theme/context.tsx
|
|
8
|
+
|
|
9
|
+
// src/theme/defaults.ts
|
|
10
|
+
var DEFAULT_BUTTON_VARIANTS = {
|
|
11
|
+
default: { classes: "bg-primary text-primary-foreground hover:bg-primary/90" },
|
|
12
|
+
secondary: { classes: "bg-secondary text-secondary-foreground hover:bg-secondary/80" },
|
|
13
|
+
outline: { classes: "border border-input bg-background hover:bg-accent hover:text-accent-foreground" },
|
|
14
|
+
ghost: { classes: "bg-transparent hover:bg-accent hover:text-accent-foreground" },
|
|
15
|
+
destructive: { classes: "bg-destructive text-destructive-foreground hover:bg-destructive/90" },
|
|
16
|
+
link: { classes: "text-primary underline-offset-4 hover:underline bg-transparent" }
|
|
17
|
+
};
|
|
18
|
+
var DEFAULT_CTA_BUTTON_VARIANTS = {
|
|
19
|
+
primary: { classes: "bg-primary text-primary-foreground hover:bg-primary/90" },
|
|
20
|
+
secondary: { classes: "bg-secondary text-secondary-foreground hover:bg-secondary/80" },
|
|
21
|
+
outline: { classes: "border border-input bg-background hover:bg-accent hover:text-accent-foreground" },
|
|
22
|
+
ghost: { classes: "bg-transparent hover:bg-accent hover:text-accent-foreground" },
|
|
23
|
+
link: { classes: "text-primary underline-offset-4 hover:underline bg-transparent" }
|
|
24
|
+
};
|
|
25
|
+
var DEFAULT_CTA_BACKGROUND_STYLES = {
|
|
26
|
+
default: "bg-muted",
|
|
27
|
+
dark: "bg-foreground text-background",
|
|
28
|
+
light: "bg-background"
|
|
29
|
+
};
|
|
30
|
+
var DEFAULT_COLOR_PRESETS = [
|
|
31
|
+
{ hex: "#ffffff", label: "White" },
|
|
32
|
+
{ hex: "#f9fafb", label: "Gray 50" },
|
|
33
|
+
{ hex: "#f3f4f6", label: "Gray 100" },
|
|
34
|
+
{ hex: "#1f2937", label: "Gray 800" },
|
|
35
|
+
{ hex: "#111827", label: "Gray 900" },
|
|
36
|
+
{ hex: "#000000", label: "Black" },
|
|
37
|
+
{ hex: "#3b82f6", label: "Blue" },
|
|
38
|
+
{ hex: "#10b981", label: "Green" },
|
|
39
|
+
{ hex: "#f59e0b", label: "Amber" },
|
|
40
|
+
{ hex: "#ef4444", label: "Red" }
|
|
41
|
+
];
|
|
42
|
+
var DEFAULT_FOCUS_RING = "focus:ring-ring";
|
|
43
|
+
var DEFAULT_THEME = {
|
|
44
|
+
buttonVariants: DEFAULT_BUTTON_VARIANTS,
|
|
45
|
+
ctaButtonVariants: DEFAULT_CTA_BUTTON_VARIANTS,
|
|
46
|
+
ctaBackgroundStyles: DEFAULT_CTA_BACKGROUND_STYLES,
|
|
47
|
+
colorPresets: DEFAULT_COLOR_PRESETS,
|
|
48
|
+
focusRingColor: DEFAULT_FOCUS_RING
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// src/theme/utils.ts
|
|
52
|
+
function resolveTheme(config) {
|
|
53
|
+
if (!config) return DEFAULT_THEME;
|
|
54
|
+
return {
|
|
55
|
+
buttonVariants: mergeVariants(DEFAULT_BUTTON_VARIANTS, config.buttonVariants),
|
|
56
|
+
ctaButtonVariants: mergeVariants(DEFAULT_CTA_BUTTON_VARIANTS, config.ctaButtonVariants),
|
|
57
|
+
ctaBackgroundStyles: mergeBackgroundStyles(
|
|
58
|
+
DEFAULT_CTA_BACKGROUND_STYLES,
|
|
59
|
+
config.ctaBackgroundStyles
|
|
60
|
+
),
|
|
61
|
+
colorPresets: resolveColorPresets(config),
|
|
62
|
+
focusRingColor: config.focusRingColor ?? DEFAULT_FOCUS_RING
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function mergeVariants(defaults, overrides) {
|
|
66
|
+
if (!overrides) return defaults;
|
|
67
|
+
const result = { ...defaults };
|
|
68
|
+
for (const key of Object.keys(overrides)) {
|
|
69
|
+
const override = overrides[key];
|
|
70
|
+
if (override) {
|
|
71
|
+
result[key] = override;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
function mergeBackgroundStyles(defaults, overrides) {
|
|
77
|
+
if (!overrides) return defaults;
|
|
78
|
+
return { ...defaults, ...overrides };
|
|
79
|
+
}
|
|
80
|
+
function resolveColorPresets(config) {
|
|
81
|
+
if (!config.colorPresets) {
|
|
82
|
+
return DEFAULT_COLOR_PRESETS;
|
|
83
|
+
}
|
|
84
|
+
if (config.extendColorPresets) {
|
|
85
|
+
return [...DEFAULT_COLOR_PRESETS, ...config.colorPresets];
|
|
86
|
+
}
|
|
87
|
+
return config.colorPresets;
|
|
88
|
+
}
|
|
89
|
+
function getVariantClasses(variants, variant, fallback = "default") {
|
|
90
|
+
const config = variants[variant];
|
|
91
|
+
if (config?.classes) {
|
|
92
|
+
return config.classes;
|
|
93
|
+
}
|
|
94
|
+
const fallbackConfig = variants[fallback];
|
|
95
|
+
return fallbackConfig?.classes ?? "";
|
|
96
|
+
}
|
|
97
|
+
function getBackgroundClasses(styles, style, fallback = "default") {
|
|
98
|
+
return styles[style] ?? styles[fallback] ?? "";
|
|
99
|
+
}
|
|
100
|
+
var ThemeContext = react.createContext(null);
|
|
101
|
+
function ThemeProvider({ children, theme }) {
|
|
102
|
+
const resolvedTheme = react.useMemo(() => resolveTheme(theme), [theme]);
|
|
103
|
+
const value = react.useMemo(
|
|
104
|
+
() => ({
|
|
105
|
+
theme: resolvedTheme
|
|
106
|
+
}),
|
|
107
|
+
[resolvedTheme]
|
|
108
|
+
);
|
|
109
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ThemeContext.Provider, { value, children });
|
|
110
|
+
}
|
|
111
|
+
function useTheme() {
|
|
112
|
+
const context = react.useContext(ThemeContext);
|
|
113
|
+
return context?.theme ?? DEFAULT_THEME;
|
|
114
|
+
}
|
|
115
|
+
function getDefaultTheme() {
|
|
116
|
+
return DEFAULT_THEME;
|
|
117
|
+
}
|
|
118
|
+
function useHasThemeProvider() {
|
|
119
|
+
const context = react.useContext(ThemeContext);
|
|
120
|
+
return context !== null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// src/theme/example.ts
|
|
124
|
+
var exampleTheme = {
|
|
125
|
+
// Button component variants
|
|
126
|
+
buttonVariants: {
|
|
127
|
+
default: {
|
|
128
|
+
classes: "bg-primary text-primary-foreground hover:bg-primary/90"
|
|
129
|
+
},
|
|
130
|
+
secondary: {
|
|
131
|
+
classes: "bg-secondary text-secondary-foreground hover:bg-secondary/80"
|
|
132
|
+
},
|
|
133
|
+
outline: {
|
|
134
|
+
classes: "border border-input bg-background hover:bg-accent hover:text-accent-foreground"
|
|
135
|
+
},
|
|
136
|
+
ghost: {
|
|
137
|
+
classes: "hover:bg-accent hover:text-accent-foreground"
|
|
138
|
+
},
|
|
139
|
+
destructive: {
|
|
140
|
+
classes: "bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
|
141
|
+
},
|
|
142
|
+
link: {
|
|
143
|
+
classes: "text-primary underline-offset-4 hover:underline"
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
// CTA button variants
|
|
147
|
+
ctaButtonVariants: {
|
|
148
|
+
primary: {
|
|
149
|
+
classes: "bg-primary text-primary-foreground hover:bg-primary/90"
|
|
150
|
+
},
|
|
151
|
+
secondary: {
|
|
152
|
+
classes: "bg-secondary text-secondary-foreground hover:bg-secondary/80"
|
|
153
|
+
},
|
|
154
|
+
outline: {
|
|
155
|
+
classes: "border border-input bg-background hover:bg-accent hover:text-accent-foreground"
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
// CTA background styles
|
|
159
|
+
ctaBackgroundStyles: {
|
|
160
|
+
default: "bg-muted",
|
|
161
|
+
dark: "bg-primary text-primary-foreground",
|
|
162
|
+
light: "bg-background"
|
|
163
|
+
},
|
|
164
|
+
// Focus ring class
|
|
165
|
+
focusRingColor: "focus:ring-ring",
|
|
166
|
+
// Color picker presets - customize with your brand colors
|
|
167
|
+
colorPresets: [
|
|
168
|
+
{ hex: "#ffffff", label: "White" },
|
|
169
|
+
{ hex: "#f8fafc", label: "Slate 50" },
|
|
170
|
+
{ hex: "#f1f5f9", label: "Slate 100" },
|
|
171
|
+
{ hex: "#e2e8f0", label: "Slate 200" },
|
|
172
|
+
{ hex: "#64748b", label: "Slate 500" },
|
|
173
|
+
{ hex: "#334155", label: "Slate 700" },
|
|
174
|
+
{ hex: "#1e293b", label: "Slate 800" },
|
|
175
|
+
{ hex: "#0f172a", label: "Slate 900" },
|
|
176
|
+
{ hex: "#000000", label: "Black" },
|
|
177
|
+
{ hex: "#3b82f6", label: "Blue" },
|
|
178
|
+
{ hex: "#10b981", label: "Green" },
|
|
179
|
+
{ hex: "#f59e0b", label: "Amber" },
|
|
180
|
+
{ hex: "#ef4444", label: "Red" }
|
|
181
|
+
],
|
|
182
|
+
// Set to true to add your presets to defaults instead of replacing
|
|
183
|
+
extendColorPresets: false
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
exports.DEFAULT_BUTTON_VARIANTS = DEFAULT_BUTTON_VARIANTS;
|
|
187
|
+
exports.DEFAULT_COLOR_PRESETS = DEFAULT_COLOR_PRESETS;
|
|
188
|
+
exports.DEFAULT_CTA_BACKGROUND_STYLES = DEFAULT_CTA_BACKGROUND_STYLES;
|
|
189
|
+
exports.DEFAULT_CTA_BUTTON_VARIANTS = DEFAULT_CTA_BUTTON_VARIANTS;
|
|
190
|
+
exports.DEFAULT_FOCUS_RING = DEFAULT_FOCUS_RING;
|
|
191
|
+
exports.DEFAULT_THEME = DEFAULT_THEME;
|
|
192
|
+
exports.ThemeProvider = ThemeProvider;
|
|
193
|
+
exports.exampleTheme = exampleTheme;
|
|
194
|
+
exports.getBackgroundClasses = getBackgroundClasses;
|
|
195
|
+
exports.getDefaultTheme = getDefaultTheme;
|
|
196
|
+
exports.getVariantClasses = getVariantClasses;
|
|
197
|
+
exports.resolveTheme = resolveTheme;
|
|
198
|
+
exports.useHasThemeProvider = useHasThemeProvider;
|
|
199
|
+
exports.useTheme = useTheme;
|
|
200
|
+
//# sourceMappingURL=index.js.map
|
|
201
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/theme/defaults.ts","../../src/theme/utils.ts","../../src/theme/context.tsx","../../src/theme/example.ts"],"names":["createContext","useMemo","jsx","useContext"],"mappings":";;;;;;;;AAmBO,IAAM,uBAAA,GAA+C;AAAA,EAC1D,OAAA,EAAS,EAAE,OAAA,EAAS,wDAAA,EAAyD;AAAA,EAC7E,SAAA,EAAW,EAAE,OAAA,EAAS,8DAAA,EAA+D;AAAA,EACrF,OAAA,EAAS,EAAE,OAAA,EAAS,gFAAA,EAAiF;AAAA,EACrG,KAAA,EAAO,EAAE,OAAA,EAAS,6DAAA,EAA8D;AAAA,EAChF,WAAA,EAAa,EAAE,OAAA,EAAS,oEAAA,EAAqE;AAAA,EAC7F,IAAA,EAAM,EAAE,OAAA,EAAS,gEAAA;AACnB;AAMO,IAAM,2BAAA,GAAmD;AAAA,EAC9D,OAAA,EAAS,EAAE,OAAA,EAAS,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,WAAA,EAAY;AAAA,IACrC,EAAE,GAAA,EAAK,SAAA,EAAW,KAAA,EAAO,WAAA,EAAY;AAAA,IACrC,EAAE,GAAA,EAAK,SAAA,EAAW,KAAA,EAAO,WAAA,EAAY;AAAA,IACrC,EAAE,GAAA,EAAK,SAAA,EAAW,KAAA,EAAO,OAAA,EAAQ;AAAA,IACjC,EAAE,GAAA,EAAK,SAAA,EAAW,KAAA,EAAO,MAAA,EAAO;AAAA,IAChC,EAAE,GAAA,EAAK,SAAA,EAAW,KAAA,EAAO,OAAA,EAAQ;AAAA,IACjC,EAAE,GAAA,EAAK,SAAA,EAAW,KAAA,EAAO,OAAA,EAAQ;AAAA,IACjC,EAAE,GAAA,EAAK,SAAA,EAAW,KAAA,EAAO,KAAA;AAAM,GACjC;AAAA;AAAA,EAGA,kBAAA,EAAoB;AACtB","file":"index.js","sourcesContent":["/**\n * Default Theme Values\n *\n * These defaults ensure backwards compatibility - components render\n * identically to before theming was introduced when no theme is provided.\n */\n\nimport type {\n ButtonVariantStyles,\n BackgroundStyles,\n ColorPreset,\n ResolvedTheme,\n} from './types'\n\n/**\n * Default button variant styles\n * Uses semantic Tailwind classes that map to CSS variables (--primary, --secondary, etc.)\n * This allows consuming apps to customize colors via their theme CSS variables.\n */\nexport const DEFAULT_BUTTON_VARIANTS: ButtonVariantStyles = {\n default: { classes: 'bg-primary text-primary-foreground hover:bg-primary/90' },\n secondary: { classes: 'bg-secondary text-secondary-foreground hover:bg-secondary/80' },\n outline: { classes: 'border border-input bg-background hover:bg-accent hover:text-accent-foreground' },\n ghost: { classes: 'bg-transparent hover:bg-accent hover:text-accent-foreground' },\n destructive: { classes: 'bg-destructive text-destructive-foreground hover:bg-destructive/90' },\n link: { classes: 'text-primary underline-offset-4 hover:underline bg-transparent' },\n}\n\n/**\n * Default CTA button variant styles\n * Uses semantic Tailwind classes that map to CSS variables.\n */\nexport const DEFAULT_CTA_BUTTON_VARIANTS: ButtonVariantStyles = {\n primary: { classes: 'bg-primary text-primary-foreground hover:bg-primary/90' },\n secondary: { classes: 'bg-secondary text-secondary-foreground hover:bg-secondary/80' },\n outline: { classes: 'border border-input bg-background hover:bg-accent hover:text-accent-foreground' },\n ghost: { classes: 'bg-transparent hover:bg-accent hover:text-accent-foreground' },\n link: { classes: 'text-primary underline-offset-4 hover:underline bg-transparent' },\n}\n\n/**\n * Default CTA background styles\n * Uses semantic Tailwind classes that map to CSS variables.\n */\nexport const DEFAULT_CTA_BACKGROUND_STYLES: BackgroundStyles = {\n default: 'bg-muted',\n dark: 'bg-foreground text-background',\n light: 'bg-background',\n}\n\n/**\n * Default color picker presets\n * Matches DEFAULT_PRESETS from ColorPickerField.tsx\n */\nexport const DEFAULT_COLOR_PRESETS: ColorPreset[] = [\n { hex: '#ffffff', label: 'White' },\n { hex: '#f9fafb', label: 'Gray 50' },\n { hex: '#f3f4f6', label: 'Gray 100' },\n { hex: '#1f2937', label: 'Gray 800' },\n { hex: '#111827', label: 'Gray 900' },\n { hex: '#000000', label: 'Black' },\n { hex: '#3b82f6', label: 'Blue' },\n { hex: '#10b981', label: 'Green' },\n { hex: '#f59e0b', label: 'Amber' },\n { hex: '#ef4444', label: 'Red' },\n]\n\n/**\n * Default focus ring color class\n * Uses semantic ring color from CSS variables\n */\nexport const DEFAULT_FOCUS_RING = 'focus:ring-ring'\n\n/**\n * Complete default theme\n * Used when no ThemeProvider is present or no theme config is provided\n */\nexport const DEFAULT_THEME: ResolvedTheme = {\n buttonVariants: DEFAULT_BUTTON_VARIANTS,\n ctaButtonVariants: DEFAULT_CTA_BUTTON_VARIANTS,\n ctaBackgroundStyles: DEFAULT_CTA_BACKGROUND_STYLES,\n colorPresets: DEFAULT_COLOR_PRESETS,\n focusRingColor: DEFAULT_FOCUS_RING,\n}\n","/**\n * Theme Resolution Utilities\n *\n * Functions for merging user-provided theme config with defaults\n * and safely accessing theme values.\n */\n\nimport type {\n ThemeConfig,\n ResolvedTheme,\n ButtonVariantStyles,\n BackgroundStyles,\n} from './types'\nimport {\n DEFAULT_BUTTON_VARIANTS,\n DEFAULT_CTA_BUTTON_VARIANTS,\n DEFAULT_CTA_BACKGROUND_STYLES,\n DEFAULT_COLOR_PRESETS,\n DEFAULT_FOCUS_RING,\n DEFAULT_THEME,\n} from './defaults'\n\n/**\n * Merges user-provided theme config with defaults to create a fully resolved theme\n */\nexport function resolveTheme(config?: ThemeConfig): ResolvedTheme {\n if (!config) return DEFAULT_THEME\n\n return {\n buttonVariants: mergeVariants(DEFAULT_BUTTON_VARIANTS, config.buttonVariants),\n ctaButtonVariants: mergeVariants(DEFAULT_CTA_BUTTON_VARIANTS, config.ctaButtonVariants),\n ctaBackgroundStyles: mergeBackgroundStyles(\n DEFAULT_CTA_BACKGROUND_STYLES,\n config.ctaBackgroundStyles\n ),\n colorPresets: resolveColorPresets(config),\n focusRingColor: config.focusRingColor ?? DEFAULT_FOCUS_RING,\n }\n}\n\n/**\n * Merges variant overrides with defaults\n */\nfunction mergeVariants(\n defaults: ButtonVariantStyles,\n overrides?: Partial<ButtonVariantStyles>\n): ButtonVariantStyles {\n if (!overrides) return defaults\n\n const result: ButtonVariantStyles = { ...defaults }\n for (const key of Object.keys(overrides)) {\n const override = overrides[key]\n if (override) {\n result[key] = override\n }\n }\n return result\n}\n\n/**\n * Merges background style overrides with defaults\n */\nfunction mergeBackgroundStyles(\n defaults: BackgroundStyles,\n overrides?: Partial<BackgroundStyles>\n): BackgroundStyles {\n if (!overrides) return defaults\n return { ...defaults, ...overrides }\n}\n\n/**\n * Resolves color presets based on config\n */\nfunction resolveColorPresets(config: ThemeConfig) {\n if (!config.colorPresets) {\n return DEFAULT_COLOR_PRESETS\n }\n\n if (config.extendColorPresets) {\n return [...DEFAULT_COLOR_PRESETS, ...config.colorPresets]\n }\n\n return config.colorPresets\n}\n\n/**\n * Safely gets variant classes from a variant styles object\n *\n * @param variants - The button variant styles object\n * @param variant - The variant key to look up\n * @param fallback - Fallback variant key if the requested variant doesn't exist\n * @returns The CSS classes string for the variant\n */\nexport function getVariantClasses(\n variants: ButtonVariantStyles,\n variant: string,\n fallback = 'default'\n): string {\n const config = variants[variant]\n if (config?.classes) {\n return config.classes\n }\n\n const fallbackConfig = variants[fallback]\n return fallbackConfig?.classes ?? ''\n}\n\n/**\n * Safely gets background style classes\n *\n * @param styles - The background styles object\n * @param style - The style key to look up\n * @param fallback - Fallback style key if the requested style doesn't exist\n * @returns The CSS classes string for the background\n */\nexport function getBackgroundClasses(\n styles: BackgroundStyles,\n style: string,\n fallback = 'default'\n): string {\n return styles[style] ?? styles[fallback] ?? ''\n}\n","'use client'\n\n/**\n * Theme Context\n *\n * React context for distributing theme configuration to Puck components.\n * The useTheme() hook returns defaults when no provider is present,\n * ensuring backwards compatibility.\n */\n\nimport { createContext, useContext, useMemo, type ReactNode } from 'react'\nimport type { ThemeConfig, ThemeContextValue, ResolvedTheme } from './types'\nimport { DEFAULT_THEME } from './defaults'\nimport { resolveTheme } from './utils'\n\nconst ThemeContext = createContext<ThemeContextValue | null>(null)\n\nexport interface ThemeProviderProps {\n children: ReactNode\n /** Theme configuration to apply */\n theme?: ThemeConfig\n}\n\n/**\n * Provides theme configuration to descendant Puck components\n *\n * @example\n * ```tsx\n * <ThemeProvider theme={{\n * buttonVariants: {\n * default: { classes: 'bg-primary text-white hover:bg-primary/90' }\n * }\n * }}>\n * <PageRenderer data={data} />\n * </ThemeProvider>\n * ```\n */\nexport function ThemeProvider({ children, theme }: ThemeProviderProps) {\n const resolvedTheme = useMemo(() => resolveTheme(theme), [theme])\n\n const value = useMemo<ThemeContextValue>(\n () => ({\n theme: resolvedTheme,\n }),\n [resolvedTheme]\n )\n\n return <ThemeContext.Provider value={value}>{children}</ThemeContext.Provider>\n}\n\n/**\n * Hook to access the current theme\n *\n * Returns DEFAULT_THEME if no ThemeProvider is present,\n * ensuring components work standalone for backwards compatibility.\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const theme = useTheme()\n * const buttonClasses = getVariantClasses(theme.buttonVariants, 'primary')\n * return <button className={buttonClasses}>Click me</button>\n * }\n * ```\n */\nexport function useTheme(): ResolvedTheme {\n const context = useContext(ThemeContext)\n // Return defaults if no provider - ensures backwards compatibility\n return context?.theme ?? DEFAULT_THEME\n}\n\n/**\n * Gets the default theme for server components\n *\n * Use this when you need theme values in a server component\n * where hooks cannot be used.\n */\nexport function getDefaultTheme(): ResolvedTheme {\n return DEFAULT_THEME\n}\n\n/**\n * Hook to check if a ThemeProvider is present\n *\n * Useful for conditional logic based on whether theming is configured.\n */\nexport function useHasThemeProvider(): boolean {\n const context = useContext(ThemeContext)\n return context !== null\n}\n","/**\n * Example Theme Configuration\n *\n * Copy this file to your project and customize it to match your design system.\n *\n * Usage:\n * 1. Copy this file to your project (e.g., src/lib/puck-theme.ts)\n * 2. Customize the values to match your CSS variables/design tokens\n * 3. Import and pass to PageRenderer or PuckEditor:\n *\n * ```tsx\n * import { puckTheme } from '@/lib/puck-theme'\n *\n * <PageRenderer data={data} config={config} theme={puckTheme} />\n * ```\n */\n\nimport type { ThemeConfig } from './types'\n\n/**\n * Example theme using shadcn/ui CSS variables\n *\n * This example assumes you have CSS variables like:\n * --primary, --primary-foreground\n * --secondary, --secondary-foreground\n * --accent, --accent-foreground\n * --muted, --muted-foreground\n * --destructive, --destructive-foreground\n * --ring (for focus rings)\n */\nexport const exampleTheme: ThemeConfig = {\n // Button component variants\n buttonVariants: {\n default: {\n classes: 'bg-primary text-primary-foreground hover:bg-primary/90',\n },\n secondary: {\n classes: 'bg-secondary text-secondary-foreground hover:bg-secondary/80',\n },\n outline: {\n classes: 'border border-input bg-background hover:bg-accent hover:text-accent-foreground',\n },\n ghost: {\n classes: 'hover:bg-accent hover:text-accent-foreground',\n },\n destructive: {\n classes: 'bg-destructive text-destructive-foreground hover:bg-destructive/90',\n },\n link: {\n classes: 'text-primary underline-offset-4 hover:underline',\n },\n },\n\n // CTA button variants\n ctaButtonVariants: {\n primary: {\n classes: 'bg-primary text-primary-foreground hover:bg-primary/90',\n },\n secondary: {\n classes: 'bg-secondary text-secondary-foreground hover:bg-secondary/80',\n },\n outline: {\n classes: 'border border-input bg-background hover:bg-accent hover:text-accent-foreground',\n },\n },\n\n // CTA background styles\n ctaBackgroundStyles: {\n default: 'bg-muted',\n dark: 'bg-primary text-primary-foreground',\n light: 'bg-background',\n },\n\n // Focus ring class\n focusRingColor: 'focus:ring-ring',\n\n // Color picker presets - customize with your brand colors\n colorPresets: [\n { hex: '#ffffff', label: 'White' },\n { hex: '#f8fafc', label: 'Slate 50' },\n { hex: '#f1f5f9', label: 'Slate 100' },\n { hex: '#e2e8f0', label: 'Slate 200' },\n { hex: '#64748b', label: 'Slate 500' },\n { hex: '#334155', label: 'Slate 700' },\n { hex: '#1e293b', label: 'Slate 800' },\n { hex: '#0f172a', label: 'Slate 900' },\n { hex: '#000000', label: 'Black' },\n { hex: '#3b82f6', label: 'Blue' },\n { hex: '#10b981', label: 'Green' },\n { hex: '#f59e0b', label: 'Amber' },\n { hex: '#ef4444', label: 'Red' },\n ],\n\n // Set to true to add your presets to defaults instead of replacing\n extendColorPresets: false,\n}\n"]}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createContext, useMemo, useContext } from 'react';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
// src/theme/context.tsx
|
|
6
|
+
|
|
7
|
+
// src/theme/defaults.ts
|
|
8
|
+
var DEFAULT_BUTTON_VARIANTS = {
|
|
9
|
+
default: { classes: "bg-primary text-primary-foreground hover:bg-primary/90" },
|
|
10
|
+
secondary: { classes: "bg-secondary text-secondary-foreground hover:bg-secondary/80" },
|
|
11
|
+
outline: { classes: "border border-input bg-background hover:bg-accent hover:text-accent-foreground" },
|
|
12
|
+
ghost: { classes: "bg-transparent hover:bg-accent hover:text-accent-foreground" },
|
|
13
|
+
destructive: { classes: "bg-destructive text-destructive-foreground hover:bg-destructive/90" },
|
|
14
|
+
link: { classes: "text-primary underline-offset-4 hover:underline bg-transparent" }
|
|
15
|
+
};
|
|
16
|
+
var DEFAULT_CTA_BUTTON_VARIANTS = {
|
|
17
|
+
primary: { classes: "bg-primary text-primary-foreground hover:bg-primary/90" },
|
|
18
|
+
secondary: { classes: "bg-secondary text-secondary-foreground hover:bg-secondary/80" },
|
|
19
|
+
outline: { classes: "border border-input bg-background hover:bg-accent hover:text-accent-foreground" },
|
|
20
|
+
ghost: { classes: "bg-transparent hover:bg-accent hover:text-accent-foreground" },
|
|
21
|
+
link: { classes: "text-primary underline-offset-4 hover:underline bg-transparent" }
|
|
22
|
+
};
|
|
23
|
+
var DEFAULT_CTA_BACKGROUND_STYLES = {
|
|
24
|
+
default: "bg-muted",
|
|
25
|
+
dark: "bg-foreground text-background",
|
|
26
|
+
light: "bg-background"
|
|
27
|
+
};
|
|
28
|
+
var DEFAULT_COLOR_PRESETS = [
|
|
29
|
+
{ hex: "#ffffff", label: "White" },
|
|
30
|
+
{ hex: "#f9fafb", label: "Gray 50" },
|
|
31
|
+
{ hex: "#f3f4f6", label: "Gray 100" },
|
|
32
|
+
{ hex: "#1f2937", label: "Gray 800" },
|
|
33
|
+
{ hex: "#111827", label: "Gray 900" },
|
|
34
|
+
{ hex: "#000000", label: "Black" },
|
|
35
|
+
{ hex: "#3b82f6", label: "Blue" },
|
|
36
|
+
{ hex: "#10b981", label: "Green" },
|
|
37
|
+
{ hex: "#f59e0b", label: "Amber" },
|
|
38
|
+
{ hex: "#ef4444", label: "Red" }
|
|
39
|
+
];
|
|
40
|
+
var DEFAULT_FOCUS_RING = "focus:ring-ring";
|
|
41
|
+
var DEFAULT_THEME = {
|
|
42
|
+
buttonVariants: DEFAULT_BUTTON_VARIANTS,
|
|
43
|
+
ctaButtonVariants: DEFAULT_CTA_BUTTON_VARIANTS,
|
|
44
|
+
ctaBackgroundStyles: DEFAULT_CTA_BACKGROUND_STYLES,
|
|
45
|
+
colorPresets: DEFAULT_COLOR_PRESETS,
|
|
46
|
+
focusRingColor: DEFAULT_FOCUS_RING
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// src/theme/utils.ts
|
|
50
|
+
function resolveTheme(config) {
|
|
51
|
+
if (!config) return DEFAULT_THEME;
|
|
52
|
+
return {
|
|
53
|
+
buttonVariants: mergeVariants(DEFAULT_BUTTON_VARIANTS, config.buttonVariants),
|
|
54
|
+
ctaButtonVariants: mergeVariants(DEFAULT_CTA_BUTTON_VARIANTS, config.ctaButtonVariants),
|
|
55
|
+
ctaBackgroundStyles: mergeBackgroundStyles(
|
|
56
|
+
DEFAULT_CTA_BACKGROUND_STYLES,
|
|
57
|
+
config.ctaBackgroundStyles
|
|
58
|
+
),
|
|
59
|
+
colorPresets: resolveColorPresets(config),
|
|
60
|
+
focusRingColor: config.focusRingColor ?? DEFAULT_FOCUS_RING
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function mergeVariants(defaults, overrides) {
|
|
64
|
+
if (!overrides) return defaults;
|
|
65
|
+
const result = { ...defaults };
|
|
66
|
+
for (const key of Object.keys(overrides)) {
|
|
67
|
+
const override = overrides[key];
|
|
68
|
+
if (override) {
|
|
69
|
+
result[key] = override;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
function mergeBackgroundStyles(defaults, overrides) {
|
|
75
|
+
if (!overrides) return defaults;
|
|
76
|
+
return { ...defaults, ...overrides };
|
|
77
|
+
}
|
|
78
|
+
function resolveColorPresets(config) {
|
|
79
|
+
if (!config.colorPresets) {
|
|
80
|
+
return DEFAULT_COLOR_PRESETS;
|
|
81
|
+
}
|
|
82
|
+
if (config.extendColorPresets) {
|
|
83
|
+
return [...DEFAULT_COLOR_PRESETS, ...config.colorPresets];
|
|
84
|
+
}
|
|
85
|
+
return config.colorPresets;
|
|
86
|
+
}
|
|
87
|
+
function getVariantClasses(variants, variant, fallback = "default") {
|
|
88
|
+
const config = variants[variant];
|
|
89
|
+
if (config?.classes) {
|
|
90
|
+
return config.classes;
|
|
91
|
+
}
|
|
92
|
+
const fallbackConfig = variants[fallback];
|
|
93
|
+
return fallbackConfig?.classes ?? "";
|
|
94
|
+
}
|
|
95
|
+
function getBackgroundClasses(styles, style, fallback = "default") {
|
|
96
|
+
return styles[style] ?? styles[fallback] ?? "";
|
|
97
|
+
}
|
|
98
|
+
var ThemeContext = createContext(null);
|
|
99
|
+
function ThemeProvider({ children, theme }) {
|
|
100
|
+
const resolvedTheme = useMemo(() => resolveTheme(theme), [theme]);
|
|
101
|
+
const value = useMemo(
|
|
102
|
+
() => ({
|
|
103
|
+
theme: resolvedTheme
|
|
104
|
+
}),
|
|
105
|
+
[resolvedTheme]
|
|
106
|
+
);
|
|
107
|
+
return /* @__PURE__ */ jsx(ThemeContext.Provider, { value, children });
|
|
108
|
+
}
|
|
109
|
+
function useTheme() {
|
|
110
|
+
const context = useContext(ThemeContext);
|
|
111
|
+
return context?.theme ?? DEFAULT_THEME;
|
|
112
|
+
}
|
|
113
|
+
function getDefaultTheme() {
|
|
114
|
+
return DEFAULT_THEME;
|
|
115
|
+
}
|
|
116
|
+
function useHasThemeProvider() {
|
|
117
|
+
const context = useContext(ThemeContext);
|
|
118
|
+
return context !== null;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// src/theme/example.ts
|
|
122
|
+
var exampleTheme = {
|
|
123
|
+
// Button component variants
|
|
124
|
+
buttonVariants: {
|
|
125
|
+
default: {
|
|
126
|
+
classes: "bg-primary text-primary-foreground hover:bg-primary/90"
|
|
127
|
+
},
|
|
128
|
+
secondary: {
|
|
129
|
+
classes: "bg-secondary text-secondary-foreground hover:bg-secondary/80"
|
|
130
|
+
},
|
|
131
|
+
outline: {
|
|
132
|
+
classes: "border border-input bg-background hover:bg-accent hover:text-accent-foreground"
|
|
133
|
+
},
|
|
134
|
+
ghost: {
|
|
135
|
+
classes: "hover:bg-accent hover:text-accent-foreground"
|
|
136
|
+
},
|
|
137
|
+
destructive: {
|
|
138
|
+
classes: "bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
|
139
|
+
},
|
|
140
|
+
link: {
|
|
141
|
+
classes: "text-primary underline-offset-4 hover:underline"
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
// CTA button variants
|
|
145
|
+
ctaButtonVariants: {
|
|
146
|
+
primary: {
|
|
147
|
+
classes: "bg-primary text-primary-foreground hover:bg-primary/90"
|
|
148
|
+
},
|
|
149
|
+
secondary: {
|
|
150
|
+
classes: "bg-secondary text-secondary-foreground hover:bg-secondary/80"
|
|
151
|
+
},
|
|
152
|
+
outline: {
|
|
153
|
+
classes: "border border-input bg-background hover:bg-accent hover:text-accent-foreground"
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
// CTA background styles
|
|
157
|
+
ctaBackgroundStyles: {
|
|
158
|
+
default: "bg-muted",
|
|
159
|
+
dark: "bg-primary text-primary-foreground",
|
|
160
|
+
light: "bg-background"
|
|
161
|
+
},
|
|
162
|
+
// Focus ring class
|
|
163
|
+
focusRingColor: "focus:ring-ring",
|
|
164
|
+
// Color picker presets - customize with your brand colors
|
|
165
|
+
colorPresets: [
|
|
166
|
+
{ hex: "#ffffff", label: "White" },
|
|
167
|
+
{ hex: "#f8fafc", label: "Slate 50" },
|
|
168
|
+
{ hex: "#f1f5f9", label: "Slate 100" },
|
|
169
|
+
{ hex: "#e2e8f0", label: "Slate 200" },
|
|
170
|
+
{ hex: "#64748b", label: "Slate 500" },
|
|
171
|
+
{ hex: "#334155", label: "Slate 700" },
|
|
172
|
+
{ hex: "#1e293b", label: "Slate 800" },
|
|
173
|
+
{ hex: "#0f172a", label: "Slate 900" },
|
|
174
|
+
{ hex: "#000000", label: "Black" },
|
|
175
|
+
{ hex: "#3b82f6", label: "Blue" },
|
|
176
|
+
{ hex: "#10b981", label: "Green" },
|
|
177
|
+
{ hex: "#f59e0b", label: "Amber" },
|
|
178
|
+
{ hex: "#ef4444", label: "Red" }
|
|
179
|
+
],
|
|
180
|
+
// Set to true to add your presets to defaults instead of replacing
|
|
181
|
+
extendColorPresets: false
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
export { DEFAULT_BUTTON_VARIANTS, DEFAULT_COLOR_PRESETS, DEFAULT_CTA_BACKGROUND_STYLES, DEFAULT_CTA_BUTTON_VARIANTS, DEFAULT_FOCUS_RING, DEFAULT_THEME, ThemeProvider, exampleTheme, getBackgroundClasses, getDefaultTheme, getVariantClasses, resolveTheme, useHasThemeProvider, useTheme };
|
|
185
|
+
//# sourceMappingURL=index.mjs.map
|
|
186
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/theme/defaults.ts","../../src/theme/utils.ts","../../src/theme/context.tsx","../../src/theme/example.ts"],"names":[],"mappings":";;;;;;AAmBO,IAAM,uBAAA,GAA+C;AAAA,EAC1D,OAAA,EAAS,EAAE,OAAA,EAAS,wDAAA,EAAyD;AAAA,EAC7E,SAAA,EAAW,EAAE,OAAA,EAAS,8DAAA,EAA+D;AAAA,EACrF,OAAA,EAAS,EAAE,OAAA,EAAS,gFAAA,EAAiF;AAAA,EACrG,KAAA,EAAO,EAAE,OAAA,EAAS,6DAAA,EAA8D;AAAA,EAChF,WAAA,EAAa,EAAE,OAAA,EAAS,oEAAA,EAAqE;AAAA,EAC7F,IAAA,EAAM,EAAE,OAAA,EAAS,gEAAA;AACnB;AAMO,IAAM,2BAAA,GAAmD;AAAA,EAC9D,OAAA,EAAS,EAAE,OAAA,EAAS,wDAAA,EAAyD;AAAA,EAC7E,SAAA,EAAW,EAAE,OAAA,EAAS,8DAAA,EAA+D;AAAA,EACrF,OAAA,EAAS,EAAE,OAAA,EAAS,gFAAA,EAAiF;AAAA,EACrG,KAAA,EAAO,EAAE,OAAA,EAAS,6DAAA,EAA8D;AAAA,EAChF,IAAA,EAAM,EAAE,OAAA,EAAS,gEAAA;AACnB;AAMO,IAAM,6BAAA,GAAkD;AAAA,EAC7D,OAAA,EAAS,UAAA;AAAA,EAC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AAW,KAAA,EAAO,OAAA,EAAQ;AAAA,IACjC,EAAE,GAAA,EAAK,SAAA,EAAW,KAAA,EAAO,OAAA,EAAQ;AAAA,IACjC,EAAE,GAAA,EAAK,SAAA,EAAW,KAAA,EAAO,KAAA;AAAM,GACjC;AAAA;AAAA,EAGA,kBAAA,EAAoB;AACtB","file":"index.mjs","sourcesContent":["/**\n * Default Theme Values\n *\n * These defaults ensure backwards compatibility - components render\n * identically to before theming was introduced when no theme is provided.\n */\n\nimport type {\n ButtonVariantStyles,\n BackgroundStyles,\n ColorPreset,\n ResolvedTheme,\n} from './types'\n\n/**\n * Default button variant styles\n * Uses semantic Tailwind classes that map to CSS variables (--primary, --secondary, etc.)\n * This allows consuming apps to customize colors via their theme CSS variables.\n */\nexport const DEFAULT_BUTTON_VARIANTS: ButtonVariantStyles = {\n default: { classes: 'bg-primary text-primary-foreground hover:bg-primary/90' },\n secondary: { classes: 'bg-secondary text-secondary-foreground hover:bg-secondary/80' },\n outline: { classes: 'border border-input bg-background hover:bg-accent hover:text-accent-foreground' },\n ghost: { classes: 'bg-transparent hover:bg-accent hover:text-accent-foreground' },\n destructive: { classes: 'bg-destructive text-destructive-foreground hover:bg-destructive/90' },\n link: { classes: 'text-primary underline-offset-4 hover:underline bg-transparent' },\n}\n\n/**\n * Default CTA button variant styles\n * Uses semantic Tailwind classes that map to CSS variables.\n */\nexport const DEFAULT_CTA_BUTTON_VARIANTS: ButtonVariantStyles = {\n primary: { classes: 'bg-primary text-primary-foreground hover:bg-primary/90' },\n secondary: { classes: 'bg-secondary text-secondary-foreground hover:bg-secondary/80' },\n outline: { classes: 'border border-input bg-background hover:bg-accent hover:text-accent-foreground' },\n ghost: { classes: 'bg-transparent hover:bg-accent hover:text-accent-foreground' },\n link: { classes: 'text-primary underline-offset-4 hover:underline bg-transparent' },\n}\n\n/**\n * Default CTA background styles\n * Uses semantic Tailwind classes that map to CSS variables.\n */\nexport const DEFAULT_CTA_BACKGROUND_STYLES: BackgroundStyles = {\n default: 'bg-muted',\n dark: 'bg-foreground text-background',\n light: 'bg-background',\n}\n\n/**\n * Default color picker presets\n * Matches DEFAULT_PRESETS from ColorPickerField.tsx\n */\nexport const DEFAULT_COLOR_PRESETS: ColorPreset[] = [\n { hex: '#ffffff', label: 'White' },\n { hex: '#f9fafb', label: 'Gray 50' },\n { hex: '#f3f4f6', label: 'Gray 100' },\n { hex: '#1f2937', label: 'Gray 800' },\n { hex: '#111827', label: 'Gray 900' },\n { hex: '#000000', label: 'Black' },\n { hex: '#3b82f6', label: 'Blue' },\n { hex: '#10b981', label: 'Green' },\n { hex: '#f59e0b', label: 'Amber' },\n { hex: '#ef4444', label: 'Red' },\n]\n\n/**\n * Default focus ring color class\n * Uses semantic ring color from CSS variables\n */\nexport const DEFAULT_FOCUS_RING = 'focus:ring-ring'\n\n/**\n * Complete default theme\n * Used when no ThemeProvider is present or no theme config is provided\n */\nexport const DEFAULT_THEME: ResolvedTheme = {\n buttonVariants: DEFAULT_BUTTON_VARIANTS,\n ctaButtonVariants: DEFAULT_CTA_BUTTON_VARIANTS,\n ctaBackgroundStyles: DEFAULT_CTA_BACKGROUND_STYLES,\n colorPresets: DEFAULT_COLOR_PRESETS,\n focusRingColor: DEFAULT_FOCUS_RING,\n}\n","/**\n * Theme Resolution Utilities\n *\n * Functions for merging user-provided theme config with defaults\n * and safely accessing theme values.\n */\n\nimport type {\n ThemeConfig,\n ResolvedTheme,\n ButtonVariantStyles,\n BackgroundStyles,\n} from './types'\nimport {\n DEFAULT_BUTTON_VARIANTS,\n DEFAULT_CTA_BUTTON_VARIANTS,\n DEFAULT_CTA_BACKGROUND_STYLES,\n DEFAULT_COLOR_PRESETS,\n DEFAULT_FOCUS_RING,\n DEFAULT_THEME,\n} from './defaults'\n\n/**\n * Merges user-provided theme config with defaults to create a fully resolved theme\n */\nexport function resolveTheme(config?: ThemeConfig): ResolvedTheme {\n if (!config) return DEFAULT_THEME\n\n return {\n buttonVariants: mergeVariants(DEFAULT_BUTTON_VARIANTS, config.buttonVariants),\n ctaButtonVariants: mergeVariants(DEFAULT_CTA_BUTTON_VARIANTS, config.ctaButtonVariants),\n ctaBackgroundStyles: mergeBackgroundStyles(\n DEFAULT_CTA_BACKGROUND_STYLES,\n config.ctaBackgroundStyles\n ),\n colorPresets: resolveColorPresets(config),\n focusRingColor: config.focusRingColor ?? DEFAULT_FOCUS_RING,\n }\n}\n\n/**\n * Merges variant overrides with defaults\n */\nfunction mergeVariants(\n defaults: ButtonVariantStyles,\n overrides?: Partial<ButtonVariantStyles>\n): ButtonVariantStyles {\n if (!overrides) return defaults\n\n const result: ButtonVariantStyles = { ...defaults }\n for (const key of Object.keys(overrides)) {\n const override = overrides[key]\n if (override) {\n result[key] = override\n }\n }\n return result\n}\n\n/**\n * Merges background style overrides with defaults\n */\nfunction mergeBackgroundStyles(\n defaults: BackgroundStyles,\n overrides?: Partial<BackgroundStyles>\n): BackgroundStyles {\n if (!overrides) return defaults\n return { ...defaults, ...overrides }\n}\n\n/**\n * Resolves color presets based on config\n */\nfunction resolveColorPresets(config: ThemeConfig) {\n if (!config.colorPresets) {\n return DEFAULT_COLOR_PRESETS\n }\n\n if (config.extendColorPresets) {\n return [...DEFAULT_COLOR_PRESETS, ...config.colorPresets]\n }\n\n return config.colorPresets\n}\n\n/**\n * Safely gets variant classes from a variant styles object\n *\n * @param variants - The button variant styles object\n * @param variant - The variant key to look up\n * @param fallback - Fallback variant key if the requested variant doesn't exist\n * @returns The CSS classes string for the variant\n */\nexport function getVariantClasses(\n variants: ButtonVariantStyles,\n variant: string,\n fallback = 'default'\n): string {\n const config = variants[variant]\n if (config?.classes) {\n return config.classes\n }\n\n const fallbackConfig = variants[fallback]\n return fallbackConfig?.classes ?? ''\n}\n\n/**\n * Safely gets background style classes\n *\n * @param styles - The background styles object\n * @param style - The style key to look up\n * @param fallback - Fallback style key if the requested style doesn't exist\n * @returns The CSS classes string for the background\n */\nexport function getBackgroundClasses(\n styles: BackgroundStyles,\n style: string,\n fallback = 'default'\n): string {\n return styles[style] ?? styles[fallback] ?? ''\n}\n","'use client'\n\n/**\n * Theme Context\n *\n * React context for distributing theme configuration to Puck components.\n * The useTheme() hook returns defaults when no provider is present,\n * ensuring backwards compatibility.\n */\n\nimport { createContext, useContext, useMemo, type ReactNode } from 'react'\nimport type { ThemeConfig, ThemeContextValue, ResolvedTheme } from './types'\nimport { DEFAULT_THEME } from './defaults'\nimport { resolveTheme } from './utils'\n\nconst ThemeContext = createContext<ThemeContextValue | null>(null)\n\nexport interface ThemeProviderProps {\n children: ReactNode\n /** Theme configuration to apply */\n theme?: ThemeConfig\n}\n\n/**\n * Provides theme configuration to descendant Puck components\n *\n * @example\n * ```tsx\n * <ThemeProvider theme={{\n * buttonVariants: {\n * default: { classes: 'bg-primary text-white hover:bg-primary/90' }\n * }\n * }}>\n * <PageRenderer data={data} />\n * </ThemeProvider>\n * ```\n */\nexport function ThemeProvider({ children, theme }: ThemeProviderProps) {\n const resolvedTheme = useMemo(() => resolveTheme(theme), [theme])\n\n const value = useMemo<ThemeContextValue>(\n () => ({\n theme: resolvedTheme,\n }),\n [resolvedTheme]\n )\n\n return <ThemeContext.Provider value={value}>{children}</ThemeContext.Provider>\n}\n\n/**\n * Hook to access the current theme\n *\n * Returns DEFAULT_THEME if no ThemeProvider is present,\n * ensuring components work standalone for backwards compatibility.\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const theme = useTheme()\n * const buttonClasses = getVariantClasses(theme.buttonVariants, 'primary')\n * return <button className={buttonClasses}>Click me</button>\n * }\n * ```\n */\nexport function useTheme(): ResolvedTheme {\n const context = useContext(ThemeContext)\n // Return defaults if no provider - ensures backwards compatibility\n return context?.theme ?? DEFAULT_THEME\n}\n\n/**\n * Gets the default theme for server components\n *\n * Use this when you need theme values in a server component\n * where hooks cannot be used.\n */\nexport function getDefaultTheme(): ResolvedTheme {\n return DEFAULT_THEME\n}\n\n/**\n * Hook to check if a ThemeProvider is present\n *\n * Useful for conditional logic based on whether theming is configured.\n */\nexport function useHasThemeProvider(): boolean {\n const context = useContext(ThemeContext)\n return context !== null\n}\n","/**\n * Example Theme Configuration\n *\n * Copy this file to your project and customize it to match your design system.\n *\n * Usage:\n * 1. Copy this file to your project (e.g., src/lib/puck-theme.ts)\n * 2. Customize the values to match your CSS variables/design tokens\n * 3. Import and pass to PageRenderer or PuckEditor:\n *\n * ```tsx\n * import { puckTheme } from '@/lib/puck-theme'\n *\n * <PageRenderer data={data} config={config} theme={puckTheme} />\n * ```\n */\n\nimport type { ThemeConfig } from './types'\n\n/**\n * Example theme using shadcn/ui CSS variables\n *\n * This example assumes you have CSS variables like:\n * --primary, --primary-foreground\n * --secondary, --secondary-foreground\n * --accent, --accent-foreground\n * --muted, --muted-foreground\n * --destructive, --destructive-foreground\n * --ring (for focus rings)\n */\nexport const exampleTheme: ThemeConfig = {\n // Button component variants\n buttonVariants: {\n default: {\n classes: 'bg-primary text-primary-foreground hover:bg-primary/90',\n },\n secondary: {\n classes: 'bg-secondary text-secondary-foreground hover:bg-secondary/80',\n },\n outline: {\n classes: 'border border-input bg-background hover:bg-accent hover:text-accent-foreground',\n },\n ghost: {\n classes: 'hover:bg-accent hover:text-accent-foreground',\n },\n destructive: {\n classes: 'bg-destructive text-destructive-foreground hover:bg-destructive/90',\n },\n link: {\n classes: 'text-primary underline-offset-4 hover:underline',\n },\n },\n\n // CTA button variants\n ctaButtonVariants: {\n primary: {\n classes: 'bg-primary text-primary-foreground hover:bg-primary/90',\n },\n secondary: {\n classes: 'bg-secondary text-secondary-foreground hover:bg-secondary/80',\n },\n outline: {\n classes: 'border border-input bg-background hover:bg-accent hover:text-accent-foreground',\n },\n },\n\n // CTA background styles\n ctaBackgroundStyles: {\n default: 'bg-muted',\n dark: 'bg-primary text-primary-foreground',\n light: 'bg-background',\n },\n\n // Focus ring class\n focusRingColor: 'focus:ring-ring',\n\n // Color picker presets - customize with your brand colors\n colorPresets: [\n { hex: '#ffffff', label: 'White' },\n { hex: '#f8fafc', label: 'Slate 50' },\n { hex: '#f1f5f9', label: 'Slate 100' },\n { hex: '#e2e8f0', label: 'Slate 200' },\n { hex: '#64748b', label: 'Slate 500' },\n { hex: '#334155', label: 'Slate 700' },\n { hex: '#1e293b', label: 'Slate 800' },\n { hex: '#0f172a', label: 'Slate 900' },\n { hex: '#000000', label: 'Black' },\n { hex: '#3b82f6', label: 'Blue' },\n { hex: '#10b981', label: 'Green' },\n { hex: '#f59e0b', label: 'Amber' },\n { hex: '#ef4444', label: 'Red' },\n ],\n\n // Set to true to add your presets to defaults instead of replacing\n extendColorPresets: false,\n}\n"]}
|