diff --git a/apps/docs/src/remix-hook-form/text-field-custom.stories.tsx b/apps/docs/src/remix-hook-form/text-field-custom.stories.tsx index ccf7f5c3..6e2ed668 100644 --- a/apps/docs/src/remix-hook-form/text-field-custom.stories.tsx +++ b/apps/docs/src/remix-hook-form/text-field-custom.stories.tsx @@ -245,6 +245,67 @@ const IconInput = (props: React.InputHTMLAttributes) => ( ); \`\`\` +#### Dynamic Theme Styling with Loader Data + +For dynamic theming based on data from a loader, you can fetch theme data and apply it using CSS custom properties: + +\`\`\`tsx +// In your route loader +export const loader = async () => { + const theme = await getThemeData(); // Fetch theme from your data source + return { theme }; +}; + +// In your component +export default function MyForm() { + const { theme } = useLoaderData(); + + // Apply theme data using CSS custom properties + const themeStyle = { + '--color-primary-DEFAULT': theme?.primary_color, + '--color-secondary-DEFAULT': theme?.secondary_color, + '--color-accent-DEFAULT': theme?.accent_color, + } as React.CSSProperties; + + return ( +
+ +
+ ); +} + +// Custom components that use the CSS custom properties +const DynamicThemedInput = (props: React.InputHTMLAttributes) => ( + +); + +const DynamicThemedLabel = (props: React.ComponentPropsWithoutRef) => ( + +); +\`\`\` + +This approach allows you to dynamically style your form components based on theme data fetched from your loader, making your forms adaptable to different branding requirements. + ### Key Points - Always use React.forwardRef when creating custom components