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

feat: font family selection #154

Merged
merged 5 commits into from
Nov 15, 2024
Merged

feat: font family selection #154

merged 5 commits into from
Nov 15, 2024

Conversation

benlife5
Copy link
Contributor

@benlife5 benlife5 commented Nov 13, 2024

  • Links a set of default Google Fonts to the via themeResolver
  • Exports that list of default fonts for use in theme.config
  • Implements a custom Font Picker in the theme sidebar for any field with the plugin fontFamily
  • Exports utilities for generating font weight options based on the selected font family

PR for the other library components coming later

Usage

//theme.config.ts
const fonts: FontRegistry = {
  Georgia: {
    italics: true,
    minWeight: 400,
    maxWeight: 900,
    fallback: "serif",
  },
  ...defaultFonts,
};
const fontOptions = constructFontSelectOptions(fonts);
export const themeConfig: ThemeConfig = {
  heading1: {
      label: "Heading 1",
      styles: {
        fontFamily: {
          label: "Font",
          type: "select",
          plugin: "fontFamily",
          options: fontOptions,
          default: "sans-serif",
        },
        fontWeight: {
          label: "Font Weight",
          type: "select",
          plugin: "fontWeight",
          options: () => (
            getFontWeightOptions({
              fontCssVariable: "--fontFamily-heading1-fontFamily",
              fontList: fonts,
            })
          ),
          default: "700",
        },
      },
    },

Dropdown

Screenshot 2024-11-13 at 3 51 43 PM

File Breakdown

Google Fonts

  • src/utils/applyTheme.ts
  • src/utils/visualEditorFonts.ts

Component Updates

  • src/components/puck/atoms/body.tsx
  • src/components/puck/atoms/heading.tsx
    • src/components/puck/BodyText.tsx
  • src/components/puck/HeadingText.tsx

Theme Manager sidebar font picker

  • src/internal/puck/components/FontSelector.tsx
  • src/internal/puck/ui/puck.css
  • src/internal/utils/constructThemePuckFields.ts

@benlife5 benlife5 requested a review from a team November 13, 2024 20:59
mkilpatrick
mkilpatrick previously approved these changes Nov 14, 2024
@benlife5 benlife5 merged commit 4d78935 into main Nov 15, 2024
10 checks passed
@benlife5 benlife5 deleted the fonts branch November 15, 2024 19:35
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.

2 participants