bernaferrari / FigmaToCode

Generate responsive pages and apps on HTML, Tailwind, Flutter and SwiftUI.
https://www.figma.com/community/plugin/842128343887142055
GNU General Public License v3.0
3.58k stars 262 forks source link

Support font family in Tailwind #83

Closed ryan0x44 closed 9 months ago

ryan0x44 commented 9 months ago

I've noticed font family is not currently supported with Tailwind CSS.

Per https://github.com/bernaferrari/FigmaToCode/blob/main/packages/backend/src/tailwind/tailwindTextBuilder.ts#L98

  // todo fontFamily
  //  fontFamily(node: TextNode): this {
  //    return this;
  //  }

In Tailwind the default configuration is https://github.com/tailwindlabs/tailwindcss/blob/master/stubs/config.full.js#L302-L323

    fontFamily: {
      sans: [
        'ui-sans-serif',
        'system-ui',
        'sans-serif',
        '"Apple Color Emoji"',
        '"Segoe UI Emoji"',
        '"Segoe UI Symbol"',
        '"Noto Color Emoji"',
      ],
      serif: ['ui-serif', 'Georgia', 'Cambria', '"Times New Roman"', 'Times', 'serif'],
      mono: [
        'ui-monospace',
        'SFMono-Regular',
        'Menlo',
        'Monaco',
        'Consolas',
        '"Liberation Mono"',
        '"Courier New"',
        'monospace',
      ],
    },

where

and we can add custom fonts e.g. in tailwind.config.ts

  theme: {
    extend: {
      fontFamily: {
        mon: ['Montserrat', '"Open Sans"', ...defaultTheme.fontFamily.sans],
      },
    }
  },

allows us to use font-mon class to apply the Montserrat font.

In other for Figma To Code to correctly support font's, it would need a way of mapping the current fonts to the correct Tailwind classes based on the tailwind config.

Alternative ideas:

Is there some kind of plan/preferred approach here?

bernaferrari commented 9 months ago

Thanks!