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

✨ (theme) Custom font option #1268

Merged
merged 2 commits into from
Feb 20, 2024
Merged

✨ (theme) Custom font option #1268

merged 2 commits into from
Feb 20, 2024

Conversation

baptisteArno
Copy link
Owner

@baptisteArno baptisteArno commented Feb 20, 2024

Closes #1249

Summary by CodeRabbit

  • New Features

    • Introduced components for customizing fonts, including Google and custom font options.
    • Enhanced theme customization by simplifying theme objects and adding new font customization options.
    • Implemented dynamic font injection for web pages based on user-selected font configurations.
  • Bug Fixes

    • Fixed a condition in theme template card rendering to correctly check avatar enablement.
    • Corrected font property handling across various components to support both string and object types.
  • Refactor

    • Updated option properties in RadioButtons component to be readonly.
    • Simplified logic for setting CSS variables for fonts, including checks for font types and existence.
  • Documentation

    • Added constants and schemas for supporting new font types in theme customization.

Copy link

vercel bot commented Feb 20, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
builder-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 20, 2024 9:30am
landing-page-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 20, 2024 9:30am
viewer-v2 🔄 Building (Inspect) Visit Preview Feb 20, 2024 9:30am

Copy link

coderabbitai bot commented Feb 20, 2024

Walkthrough

These changes across multiple files in the codebase primarily introduce and enhance font customization features, including the ability to select custom fonts or Google fonts for the application interface. The updates include new components for font selection, adjustments to theme settings to accommodate these selections, and utility functions to apply the chosen fonts across the application. The modifications ensure that fonts are consistently applied and offer a more flexible theming experience.

Changes

Files Summary
.../inputs/RadioButtons.tsx, .../features/theme/components/general/GeneralSettings.tsx Updated options prop to readonly in RadioButtons.tsx; Enhanced font selection logic in GeneralSettings.tsx
.../features/theme/components/ThemeTemplateCard.tsx Inverted condition check for avatar?.isEnabled
.../features/theme/components/general/CustomFontForm.tsx, .../features/theme/components/general/FontForm.tsx, .../features/theme/components/general/GoogleFontForm.tsx Introduced components for custom and Google font selection
.../features/theme/galleryTemplates.ts Simplified theme objects by removing specific theme details
.../components/TypebotPageV3.tsx, .../pages/[[...publicId]].tsx Added font property handling
.../bot-engine/src/components/TypebotViewer.tsx Simplified font check logic
.../bot-engine/src/features/theme/utils/setCssVariablesValue.ts, .../embeds/js/src/utils/setCssVariablesValue.ts Updated logic for setting font family CSS variables
.../embeds/js/src/components/Bot.tsx, .../embeds/js/src/utils/injectFont.ts Added font handling in bot initialization and introduced dynamic font injection function
.../schemas/features/typebot/theme/constants.ts, .../schemas/features/typebot/theme/schema.ts Updated theme schema to include custom and Google fonts

Related issues

  • Issue baptisteArno/typebot.io#1249: The changes in this PR directly address the objectives outlined in the issue by introducing custom font selection and management capabilities, ensuring these fonts are applied consistently across the application, and providing support for popular font file formats.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 5

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 927feae and 808be84.
Files ignored due to path filters (2)
  • apps/docs/openapi/builder.json is excluded by: !**/*.json
  • apps/docs/openapi/viewer.json is excluded by: !**/*.json
Files selected for processing (16)
  • apps/builder/src/components/inputs/RadioButtons.tsx (1 hunks)
  • apps/builder/src/features/theme/components/ThemeTemplateCard.tsx (1 hunks)
  • apps/builder/src/features/theme/components/general/CustomFontForm.tsx (1 hunks)
  • apps/builder/src/features/theme/components/general/FontForm.tsx (1 hunks)
  • apps/builder/src/features/theme/components/general/GeneralSettings.tsx (4 hunks)
  • apps/builder/src/features/theme/components/general/GoogleFontForm.tsx (1 hunks)
  • apps/builder/src/features/theme/galleryTemplates.ts (6 hunks)
  • apps/viewer/src/components/TypebotPageV3.tsx (2 hunks)
  • apps/viewer/src/pages/[[...publicId]].tsx (4 hunks)
  • packages/deprecated/bot-engine/src/components/TypebotViewer.tsx (2 hunks)
  • packages/deprecated/bot-engine/src/features/theme/utils/setCssVariablesValue.ts (1 hunks)
  • packages/embeds/js/src/components/Bot.tsx (4 hunks)
  • packages/embeds/js/src/utils/injectFont.ts (1 hunks)
  • packages/embeds/js/src/utils/setCssVariablesValue.ts (1 hunks)
  • packages/schemas/features/typebot/theme/constants.ts (2 hunks)
  • packages/schemas/features/typebot/theme/schema.ts (3 hunks)
Additional comments: 14
packages/schemas/features/typebot/theme/constants.ts (1)
  • 27-36: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [9-33]

The addition of fontTypes as a constant array and its use in the defaultTheme object is a good practice for maintaining consistency and readability in the codebase. The use of as const for fontTypes ensures TypeScript treats it as a readonly tuple, which is excellent for type safety when dealing with a known set of string values. The update to the defaultTheme to include a font object with type and family properties aligns with the new font customization feature. This change is well-implemented and follows best practices for defining and using constants in TypeScript.

apps/builder/src/features/theme/components/general/CustomFontForm.tsx (1)
  • 10-31: The CustomFontForm component is well-structured and provides a clear interface for updating custom font properties like family and url. The use of TextInput components for each property and the handling of changes through updateFamily and updateUrl functions are straightforward and effective. However, it's important to ensure that the TextInput component properly handles edge cases, such as user input validation or trimming whitespace. While this is more about the TextInput component itself, it's a good practice to consider these aspects when dealing with user inputs.
apps/viewer/src/components/TypebotPageV3.tsx (1)
  • 57-61: The TypebotPageV3 component correctly passes the font prop to the Standard component, allowing for font customization in the viewer. This change is straightforward and aligns with the objectives of the PR to enhance theme customization. The use of font ?? undefined ensures that the prop is either a valid font object or undefined, which is a good practice for optional props. This change is well-implemented and follows best practices.
apps/builder/src/components/inputs/RadioButtons.tsx (1)
  • 13-13: The update to make the options prop of the RadioButtons component readonly is a good practice for ensuring immutability. This change helps prevent accidental modifications to the options array, which could lead to unexpected behavior. Marking props as readonly when they are not intended to be modified is a best practice in TypeScript for enhancing code safety and clarity.
packages/schemas/features/typebot/theme/schema.ts (1)
  • 36-52: The introduction of googleFontSchema, customFontSchema, and the updated fontSchema to include a discriminated union of these two schemas is a robust implementation for handling different font types. This approach leverages TypeScript's type system to ensure type safety and clarity when working with fonts. The use of z.discriminatedUnion for fontSchema is particularly noteworthy, as it allows for precise type inference based on the type property. This change significantly enhances the theme schema's flexibility and maintainability.
apps/builder/src/features/theme/galleryTemplates.ts (1)
  • 39-53: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [18-104]

The simplification of theme details in galleryTemplates.ts by removing specific colors and fonts for various templates and focusing on essential properties like buttons and fonts is a strategic move towards a more customizable theme approach. This change aligns with the PR's objectives to enhance theme customization capabilities. However, it's important to ensure that these changes do not inadvertently remove any critical theme functionality or customization options that users might rely on. The remaining configurations, such as button colors and font settings, are well-defined and contribute to a more streamlined and flexible theme design.

apps/builder/src/features/theme/components/general/GeneralSettings.tsx (1)
  • 114-125: The integration of RadioButtons and FontForm components in GeneralSettings.tsx to replace the FontSelector is a significant improvement in handling font customization. This change allows for a more flexible and user-friendly interface for selecting and configuring fonts. The use of fontTypes with RadioButtons for selecting the font type and FontForm for detailed font configuration demonstrates a good understanding of component composition and state management. This update aligns with the PR's objectives to enhance theme customization capabilities and is well-implemented.
apps/builder/src/features/theme/components/ThemeTemplateCard.tsx (1)
  • 216-216: The condition for rendering the AvatarPreview component has been inverted from if (avatar?.isEnabled) to if (!avatar?.isEnabled). This change means the avatar preview will not be rendered when avatar.isEnabled is true, which seems counterintuitive. Please verify if this is the intended behavior, as it typically makes sense to show the avatar preview when it is enabled.
packages/embeds/js/src/utils/setCssVariablesValue.ts (1)
  • 71-73: The updated logic for setting the font family CSS variable correctly handles different scenarios where generalTheme.font can be a string or an object with a family property. This change improves the flexibility and robustness of font configuration handling.
apps/viewer/src/pages/[[...publicId]].tsx (1)
  • 119-119: The addition of the font property to the TypebotV3PageProps interface and its handling in the retrieval of publishedTypebot aligns with the PR's objectives to enhance theme customization. This change is implemented correctly and ensures the custom font configuration is passed along and used appropriately.
packages/embeds/js/src/components/Bot.tsx (4)
  • 15-15: The addition of the Font import from @typebot.io/schemas is necessary for supporting custom fonts, aligning with the PR's objectives.
  • 29-29: The addition of the font property to BotProps correctly extends the component's capabilities to support custom fonts.
  • 47-47: The call to injectFont with props.font in the initializeBot function correctly ensures that custom fonts are applied when initializing the bot.
  • 205-208: Replacing injectCustomFont with injectFont in the BotContent component is correctly implemented to support the application of custom fonts.

@baptisteArno
Copy link
Owner Author

@coderabbitai review

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 808be84 and ca54e58.
Files selected for processing (2)
  • apps/builder/src/features/theme/components/general/GoogleFontForm.tsx (1 hunks)
  • packages/embeds/js/src/utils/injectFont.ts (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • apps/builder/src/features/theme/components/general/GoogleFontForm.tsx
  • packages/embeds/js/src/utils/injectFont.ts

@baptisteArno baptisteArno merged commit 7cf1a3e into main Feb 20, 2024
5 checks passed
@baptisteArno baptisteArno deleted the feat/custom-font branch February 20, 2024 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add custom font option
1 participant