vercel / geist-font

https://vercel.com/font
SIL Open Font License 1.1
2.13k stars 54 forks source link

Allow options of `GeistSans` and `GeistMono` to be customizable #60

Open mwskwong opened 7 months ago

mwskwong commented 7 months ago

Font Name (Geist Sans/Geist Mono):

This is an enhancement instead of a bug. It would be great if we could customize the options of GeistSans and GeistMono. e.g. may be we can do

import localFont from 'next/font/local';

// since LocalFont is not exported from next/font/local
type LocalFont = Parameters<typeof localFont>[0];

// omitting src, clearly we don't want that part to be customizable.
export const GeistMono = (options?: Omit<LocalFont, 'src'>) =>
  localFont({
    src: './fonts/geist-mono/GeistMono-Variable.woff2',
    variable: '--font-geist-mono',
    adjustFontFallback: false,
    fallback: [
      'ui-monospace',
      'SFMono-Regular',
      'Roboto Mono',
      'Menlo',
      'Monaco',
      'Liberation Mono',
      'DejaVu Sans Mono',
      'Courier New',
      'monospace',
    ],
    ...options,
  });

export const GeistSans = (options?: Omit<LocalFont, 'src'>) =>
  localFont({
    src: './fonts/geist-sans/Geist-Variable.woff2',
    variable: '--font-geist-sans',
    ...options,
  });

Then we can allow users to customize the options they way they want, e.g. for my case, I want to prevent the monospace font from being preloaded.

const geistMono = GeistMono({ preload: false });

This syntax also matches that from next/font/google.