Skip to content

A font picker component supporting Google and system fonts, powered by Bootstrap.

Notifications You must be signed in to change notification settings

wipeautcrafter/fontpicker-v2

Repository files navigation

Bootstrap Font Picker 2

A font picker component supporting Google and system fonts, powered by Bootstrap.

Table of Contents

Features

  • ❤️ Favourites
  • ⌨️ Keyboard shortcuts
  • ⚡ Dynamic font loading
  • 🔤 Custom font support
  • 🔎 Fuzzy search
  • 📐 Advanced metrics filters
  • 📶 Property sorting
  • 🇳🇱 Translations for English, Dutch, German, Spanish and French
  • 💪 No JQuery, just pure ES6

👆 Try it out now!

Screenshots

Light Dark
Button
Dialog

Installation

Although the FontPicker is built on Bootstrap, it does require a tiny stylesheet. Please include it like this:

<link rel="stylesheet" href="fontpicker.css" />

It is also highly recommended to include a preconnect to Google fonts:

<link rel="preconnect" href="https://fonts.gstatic.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin="anonymous" />

Now, depending on your environment, choose one of the following:

  • IIFE Bundle → When using vanilla JavaScript, without ES modules
  • ESM Bundle → When using ES modules or a bundler

IIFE Bundle

Please import the IIFE script using a script tag in your HTML:

<script src="fontpicker.iife.js"></script>

This exposes the FontPicker and FontLoader classes (on window).

ESM Bundle

Please import the ESM bundle using the import directive in your script:

import { FontPicker, FontLoader } from 'fontpicker.js'

This allows you to use FontPicker and FontLoader directly.

Getting started

Create

To create a font picker, first create a button element:

<button id="picker"></button>

Next instantiate the FontPicker, passing a button element and (optional) configuration:

const button = document.querySelector('#picker')
const picker = new FontPicker(button, {
  language: 'en',
  font: 'Open Sans',
  defaultSubset: 'latin',
})

Configure

The picker's configuration can be changed after initialization. This is done by calling .initialize({...}) on the element:

picker.configure({
  language: 'nl',
})

Interact

The picker's various methods and properties can also be accessed directly on the element:

// Set the current font
picker.setFont('Roboto:800')

// Handle events
picker.on('pick', (font) => { ... })

// Open the FontPicker, which returns a promise!
const font = await picker.open()

Documentation

For all methods and properties, please view the documentation.

Developing

To install dependencies:

bun|deno|npm|pnpm|yarn install

To run:

bun|deno|npm|pnpm|yarn run dev

About

A font picker component supporting Google and system fonts, powered by Bootstrap.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published