A UMD bundle is also built to dist, which can be included without the need for any build system. A transpiled CommonJS version (generated with Babel) is available in lib for use with node.js, browserify and webpack. NOTE: The source code for the component is in src. To override styles in your own stylesheet you should use a more precise selector e.g div.ReactFontPicker Development ( src, lib and the build process) keyframes for ripple animation ripple-animation * The Material design ripple effect itself */ĭiv.ReactFontPicker_Wrapper. * Elements that have the Material design click ripple effect */ * Option (font) in the dropdown option list */ * The option that is displayed in the main field */ * Label when a font is selected (floating above the selected option) */ Here are the component CSS classnames for quick reference: /* Component wrapper */ ReactFontPicker rule is not found in the DOM. The default one is injected dynamically if the. You can supply your own stylesheet if the default material design-style doesn't fit for you. It should take one argument which is the selected font's name as string. When a font is selected and the option list is opened again, the selected font text will display this color.Ī function that's called when a font is selected. See previews of each font in the font option list when selecting fonts The list indices should be strings e.g "Arial" The component works as standalone even if you don't supply it with any properties. Var FontPicker = require('react-font-picker') Ĭonsole.log(selectedFont) // Will log font name (string) when being selectedĪll properties are optional. Just require the 'react-font-picker' package which exports the component. If you use this, make sure you have already included React, and it is available as a global variable. You can also use the standalone build by including dist/react-font-picker.js in your page. The easiest way to use react-font-picker is to install it from NPM and include it in your own React build process (using Browserify, Webpack, etc). To build the examples locally, run: npm install It exports the component that works as standalone with local component state or with app state / store (like Redux). Suggestions and contributions are always welcome! Please discuss larger changes via issue before submitting a pull request.This is a ReactJS font picker component with Material Design styling as default styling. View the rendered component on localhost:3000.Generate the library bundle: yarn start.Clone this repository: git clone REPO_URL.setOnChange(onChange: (font: Font) => void): Update the onChange function after the font picker has been initialized.setActiveFont(fontFamily: string): Sets the provided font as the active font.getActiveFont(): Returns the font object of the currently active font.removeFont(fontFamily: string): Removes the specified font from the font list.addFont(fontFamily: string, index?: number): Adds the specified font to the font list (at the given index).getFonts(): Returns a map of all font names/objects.The FontPicker class exposes the following functions: onChange: Function to execute whenever the active font is changed.Possible values: "alphabet", "popularity". sort: Sorting attribute for the font list.limit: Maximum number of fonts to display in the list (the least popular fonts will be omitted).Example: If font => ().startsWith("m"), only fonts whose names begin with "M" will be in the list filter: Function which must evaluate to true for a font to be included in the list.variants: Array of variants which the fonts must include and which will be downloaded on font selection.scripts: Array of scripts which the fonts must include and which will be downloaded on font selection.Possible values: "sans-serif", "serif", "display", "handwriting", "monospace". categories: Array of font categories to include in the list.families: If only specific fonts shall appear in the list, specify their names in an array.Example: If the options object is, use #font-picker-main and. pickerId: If you have multiple font pickers on your site, you need to give them unique IDs which must be appended to the pickers' id attributes and the.options: Object with additional optional parameters:.defaultFamily: Font that is selected on initialization.Const fontPicker = new FontPicker ( apiKey, defaultFamily, options, onChange )
0 Comments
Leave a Reply. |