Code Monkey home page Code Monkey logo

font-picker-vue's Introduction

Font Picker for Vue

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

  • Automatic font download and generation of the required CSS styles
  • Efficient font previews (previews are loaded dynamically and full fonts are only downloaded on selection)

โ†’ Demo

This is the Vue component for the Font Picker package.

Demo

Getting started

1. Setup

Install the package using NPM:

npm install https://github.com/joebailey26/font-picker-vue

2. Displaying the font picker

Import the <font-picker> component to your Vue code:

import Vue from 'vue';
import FontPicker from 'font-picker-vue';

Vue.use(FontPicker);

Use the component:

<font-picker :api-key="'YOUR-KEY-HERE'" :options="options" :active-font="fontFamily" @change="myFunc"></font-picker

3. Applying the selected font

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

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

Customization

The following props can be passed to the FontPicker component:

  • apiKey (required): Google API key (can be generated here)
  • activeFont: Font that should be selected in the font picker and applied to the text (default: 'Open Sans'). Must be stored in component state, and be updated using an onChange listener
  • options: Object with additional (optional) parameters:
    • name: If you have multiple font pickers on your site, you need to give them unique names (which may only consist of letters and digits). These names must also be appended to the font picker's ID and the .apply-font class name; e.g. if { name: 'main' }, use #font-picker-main and .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 โ€“ possible values: 'sans-serif', 'serif', 'display', handwriting', 'monospace' (default: all categories)
    • variants: Array of variants which the fonts must include and which will be downloaded; the first variant in the array will become the default variant (and will be used in the font picker and the .apply-font class); e.g. ['regular', 'italic', '700', '700italic'] (default: ['regular'])
    • limit: Maximum number of fonts to be displayed in the list (the least popular fonts will be omitted; default: 100)
    • sort: Sorting attribute for the font list โ€“ possible values: 'alphabetical' (default), 'popularity'
  • onChange: Function which is executed whenever the user changes the active font and its stylesheet finishes downloading

font-picker-vue's People

Contributors

samuelmeuli avatar rodrigobendia avatar joebailey26 avatar lk77 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.