silverstripe/fontpicker

Adds a fontpicker field for selecting fonts

Installs: 1 713

Dependents: 1

Suggesters: 0

Security: 0

Stars: 3

Watchers: 8

Forks: 1

Open Issues: 18

Language:JavaScript

Type:silverstripe-vendormodule


README

Build Status Scrutinizer Code Quality codecov

This module adds a font picker field which can be added anywhere and is used to pick and preview a font.

Usage

To add a FontPickerField you can write the following:

    public function getCMSFields()
    {
        $fields = parent::getCMSFields();

        $fonts = [
            'nunito-sans' => 'Nunito Sans',
            'fira-sans' => 'Fira Sans',
            'merriweather' => 'Merriweather',
        ];

        // Import each font via the google fonts api to render font preview
        foreach ($fonts as $fontTitle) {
            $fontFamilyName = str_replace(' ', '+', $fontTitle);
            Requirements::css("//fonts.googleapis.com/css?family=$fontFamilyName");
        }

        $fields->addFieldsToTab(
            'Root.Main',
            [
                FontPickerField::create(
                    'MainFontFamily',
                    _t(
                        __CLASS__ . '.MainFontFamily',
                        'Main font family'
                    ),
                    $fonts
                )
            ]
        );
        
        return $fields;
    }

See silverstripe/theme-fontpicker for an example.

Versioning

This library follows Semver. According to Semver, you will be able to upgrade to any minor or patch version of this library without any breaking changes to the public API. Semver also requires that we clearly define the public API for this library.

All methods, with public visibility, are part of the public API. All other methods are not part of the public API. Where possible, we'll try to keep protected methods backwards-compatible in minor/patch versions, but if you're overriding methods then please test your work before upgrading.