

- #HTML FONT PICKER HOW TO#
- #HTML FONT PICKER INSTALL#
- #HTML FONT PICKER UPDATE#
- #HTML FONT PICKER CODE#
The table below outlines all css variables the component accepts, their purpose, and their default values. The preview component at the top of this article uses some overrides to change the hover colors. If these defaults do not fit, the component also accepts overrides via CSS variables. This can be used to hide the component and show an error message if there is an issue.īy default, this component provides its own styles for sizes, borders, and text hover effects. If there is an error loading the fonts, the error object will be emitted in this property. This can be useful for preview/demo purposes. This will emit on hover regardless of whether or not the user selects it. When the user hovers over a font, this will emit an event of type iGoogleFont. In most cases, font.family is all the consumer needs to work with. When the users selects a different font, this will emit an event of type iGoogleFont which contains information about the selected font.
#HTML FONT PICKER CODE#
The code below shows a simple example where the component is placed with some input and output properties. Add the selector to your html file: byte-this-google-font-selector-input.Import ByteThisNgxGoogleFontsModule into your module: any module which will use the component must import our library module.
#HTML FONT PICKER INSTALL#
#HTML FONT PICKER UPDATE#
The user can type the first few characters of a name, and the list will update to the fonts which begin with that prefix. This interface element also contains web-safe fonts. The ngx-google-fonts package contains functionailty for loading, rendering, and allowing the user to select google fonts via drop-down interface. If a hover is no longer happening, this will reset to some default value. It will dynamically update as the hover event changes. This paragraph is rendered with the font currently being hovered over in the input element above. Try it out with a few different selections and observe how it behaves: Loading fonts. It takes care of loading the list of fonts, presenting them on click, and dynamically lazy-loading each font as it comes into view. The component below is a preview of the font selector.
#HTML FONT PICKER HOW TO#
In the sections below, I'll outline how to get started with using this component, then outline the behavior and customizability in more detail. Lazy loading all required fonts as they come into view.Īfter developing, I've made this component open source and installable via npm.Emitting events for hover and user selection.Allowing the user to filter the list by prefix.Allowing the user to select from a drop-down-like list, where each font name renders in its own font.Loading the list of Google fonts, and combining with web safe fonts.This component is a purely Angular component which provides functionality for:

Therefore, I've decided to create this component myself from scratch. The few choices available were either not working, incomplete in some manner, or required bringing in external dependencies, such as jQuery. Since input events are fired every time an adjustment is made to the value (for example, if the brightness of the color is increased), these will happen repeatedly as the color picker is used.While working on an app for this site, I was looking for a publicly-available font selector input component for Angular and was surprised by how few choices there were. It changes the color of the first paragraph element in the document to match the new value of the color input. The updateFirst() function is called in response to the input event. We provide two functions that deal with color changes. These are both seen below.įinally, we call select() to select the text content of the color input if the control is implemented as a text field (this has no effect if a color picker interface is provided instead). Then the color input's input event is set up to call our updateFirst() function, and the change event is set to call updateAll(). This gets a reference to the color element in a variable called colorWell, then sets the color input's value to the value in defaultColor. addEventListener ( "change", updateAll, false ) addEventListener ( "input", updateFirst, false ) ĬolorWell. querySelector ( "#colorWell" ) ĬolorWell.
