Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typography preview #375

Open
Sepremex opened this issue Aug 21, 2024 · 1 comment
Open

Typography preview #375

Sepremex opened this issue Aug 21, 2024 · 1 comment

Comments

@Sepremex
Copy link

I just started playing with this library, it looks amazing!
Is there away to use custom fonts and have a preview of each font when browsing in the select and when applying it?
Thank you.

@givanz
Copy link
Owner

givanz commented Sep 3, 2024

Thank you.

If the fonts are already loaded in the page (from css) you can add them to the fonts drop down with

Vvveb.FontsManager.addFontList("theme", "Landing", {
	"Inter": {},
	"Open Sans": {}
});

If you want to dynamically load the fonts when the user selects it then you need to add a font manager, you can check the one used for google fonts https://github.com/givanz/VvvebJs/blob/master/libs/builder/plugin-google-fonts.js as a starting point.

addFont is called then the user selects a font from the list.
removeFont is called when the font is no longer used so you can remove it from the list.

MyFontsManager = {
	removeFont: function (fontName) {
	},
	
	addFont: function (fontName) {
	}
}

Vvveb.FontsManager.addProvider("myfonts", MyFontsManager);

let myFonts = {
	"ABeeZee": {
		"category": "sans-serif",
		"subsets": [
			"latin"
		],
		"variants": {
			"italic": {
				"400": {
				}
			},
			"normal": {
				"400": {
				}
			}
		}
	},
	"Abel": {
		"category": "sans-serif",
		"subsets": [
			"latin"
		],
		"variants": {
			"normal": {
				"400": {
				}
			}
		}
	},
};	

Vvveb.FontsManager.addFontList("myfonts", "My Fonts", myFonts);

Font preview is not implemented as it needs to take into account performace optimizations for large list of fonts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants