silverstripe/fontpicker

Adds a fontpicker field for selecting fonts

Installs: 943

Dependents: 1

Suggesters: 0

Security: 0

Stars: 3

Watchers: 5

Forks: 0

Open Issues: 0

Language:JavaScript

Type:silverstripe-vendormodule

dev-master / 1.x-dev 2020-05-04 23:53 UTC

This package is not auto-updated.

Last update: 2020-06-25 05:56:42 UTC


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.