All Projects → samuelmeuli → font-picker-react

samuelmeuli / font-picker-react

Licence: MIT license
✏️ Font selector component for Google Fonts

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
CSS
56736 projects

Projects that are alternatives of or similar to font-picker-react

Awesome Fonts
Curated list of fonts and everything
Stars: ✭ 798 (+533.33%)
Mutual labels:  fonts, google-fonts
Gftools
Misc tools for working with the Google Fonts library
Stars: ✭ 132 (+4.76%)
Mutual labels:  fonts, google-fonts
Fontsource
Self-host Open Source fonts in neatly bundled NPM packages.
Stars: ✭ 836 (+563.49%)
Mutual labels:  fonts, google-fonts
Work Sans
A grotesque sans.
Stars: ✭ 1,319 (+946.83%)
Mutual labels:  fonts, google-fonts
Urbanist
Urbanist is a low-contrast, geometric sans-serif inspired by Modernist design and typography.
Stars: ✭ 374 (+196.83%)
Mutual labels:  fonts, google-fonts
fontless
🚀🔒 Host your own Google Fonts.
Stars: ✭ 63 (-50%)
Mutual labels:  fonts, google-fonts
Google Fonts Module
Google Fonts module for NuxtJS
Stars: ✭ 98 (-22.22%)
Mutual labels:  fonts, google-fonts
HiGoogleFonts
HiGoogleFonts allows you to add a Google font picker to easily display a list of Google fonts. The picker shows an instant preview of the font style without loading the font css.
Stars: ✭ 44 (-65.08%)
Mutual labels:  google-fonts, font-picker
typefaces
Collection of Google fonts as typeface data for usage with three.js, react-three-fiber, and other tools.
Stars: ✭ 53 (-57.94%)
Mutual labels:  fonts, google-fonts
Yrsa Rasa
Yrsa & Rasa: fonts for Latin and Gujarati
Stars: ✭ 200 (+58.73%)
Mutual labels:  fonts, google-fonts
Inkwell
An inkwell to use custom fonts on the fly.
Stars: ✭ 146 (+15.87%)
Mutual labels:  fonts, google-fonts
web-fonts-repository
A simple webfont hosting. Google Fonts alternative for your own fonts.
Stars: ✭ 99 (-21.43%)
Mutual labels:  fonts, google-fonts
seed-fonts
WordPress plugin that helps you use web fonts (@font-face) easier. You can use 5 ready-generated Thai-English web fonts, or use your own collection.
Stars: ✭ 20 (-84.13%)
Mutual labels:  fonts, google-fonts
eczar
Eczar: fonts for Devanagari and Latin
Stars: ✭ 52 (-58.73%)
Mutual labels:  fonts, google-fonts
react-touch-ripple
Create ripple effect from Material Design with React
Stars: ✭ 27 (-78.57%)
Mutual labels:  react-component
fontman
Manage and update your installed fonts.
Stars: ✭ 20 (-84.13%)
Mutual labels:  fonts
react-carousel-minimal
React.js Responsive Minimal Carousel
Stars: ✭ 76 (-39.68%)
Mutual labels:  react-component
Slice
An open-source, cross-platform GUI app to generate custom font design spaces from variable fonts
Stars: ✭ 62 (-50.79%)
Mutual labels:  fonts
react-liff
A react context provider for LIFF (LINE Front-end Framework)
Stars: ✭ 22 (-82.54%)
Mutual labels:  react-component
react-native-nested-listview
A UI component for React Native for representing nested arrays of N levels
Stars: ✭ 163 (+29.37%)
Mutual labels:  react-component

Font Picker for React

A simple, customizable font picker allowing users to preview, select and use Google Fonts on your website.

  • Simple setup
  • No dependencies
  • Automatic font download and generation of the required CSS selectors
  • Efficient font previews (full fonts are only downloaded on selection)

Demo

This is the React component for the Font Picker library.

Font picker demo

Getting started

To be able to access the API, you'll need to generate a Google Fonts API key.

1. Setup

Install the font-picker-react package using NPM:

npm install font-picker-react

2. Displaying the font picker

Add the FontPicker component to your React code:

import React, { Component } from "react";
import FontPicker from "font-picker-react";

export default class ExampleComponent extends Component {
	constructor(props) {
		super(props);
		this.state = {
			activeFontFamily: "Open Sans",
		};
	}

	render() {
		return (
			<div>
				<FontPicker
					apiKey="YOUR_API_KEY"
					activeFontFamily={this.state.activeFontFamily}
					onChange={(nextFont) =>
						this.setState({
							activeFontFamily: nextFont.family,
						})
					}
				/>
				<p className="apply-font">The font will be applied to this text.</p>
			</div>
		);
	}
}

3. Applying the selected font

Add the class "apply-font" to all JSX elements you want to apply the selected font to.

When the user selects a font, it will automatically be downloaded and applied to all elements with the "apply-font" class.

Props

The following props can be passed to the FontPicker component:

  • apiKey (required): Google API key
  • activeFontFamily: Font that should be selected in the font picker and applied to the text. Should be stored in the component state and updated using onChange
  • onChange: Function which is executed when the user changes the active font. This function should update activeFontFamily in the component state
  • pickerId: If you have multiple font pickers on your site, you need to give them unique IDs which must be provided as a prop and appended to the .apply-font class names. Example: If pickerId="main", use className="apply-font-main"
  • families: If only specific fonts shall appear in the list, specify their names in an array. Default: All font families
  • categories: Array of font categories to include in the list. Possible values: "sans-serif", "serif", "display", "handwriting", "monospace". Default: All categories
  • scripts: Array of scripts which the fonts must include and which will be downloaded on font selection. Default: ["latin"]. Example: ["latin", "greek", "hebrew"] (see all possible values)
  • variants: Array of variants which the fonts must include and which will be downloaded on font selection. Default: ["regular"]. Example: ["regular", "italic", "700", "700italic"] (see all possible values)
  • filter: Function which must evaluate to true for a font to be included in the list. Default: font => true. Example: If font => font.family.toLowerCase().startsWith("m"), only fonts whose names begin with "M" will be in the list
  • limit: Maximum number of fonts to display in the list (the least popular fonts will be omitted). Default: 50
  • sort: Sorting attribute for the font list. Possible values: "alphabet", "popularity". Default: "alphabet"

Currently, only the activeFontFamily, onChange and sort props are reactive.

Development

Requirements: Node.js, Yarn

  1. Clone this repository: git clone REPO_URL
  2. Install all dependencies: yarn
  3. Generate the library bundle: yarn start
  4. View the rendered component on localhost:3000

Suggestions and contributions are always welcome! Please discuss larger changes via issue before submitting a pull request.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].