npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-font-style

v0.0.11

Published

React font style editor

Downloads

67

Readme

React font style

A simple but customizable react font style editor

version

Demo

When to use this component?

If you just want to get the font style, doesn't care about the text content, this component can do the trick. All the toolbars, text content is customizable. It means that you can change in any use case.

Features

  • Pure font style editor — Support drag and drop tab
  • Highly customizable — all the styles and button is customizable
  • Pluggable toolbar button — Add extra toolbar button to meet your usage

Table of Contents

Get started

Install it with yarn or npm.

$ yarn add react-font-style

Required Webpack configuration

Currently, this component import css in the component. You need to use webpack css-loader to bundle the file. Or it will fail.

The example webpack setting:

{
  test: /\.css$/,
  loaders: [
    'style-loader',
    'css-loader?modules'
  ]
}

Usage

Minimal setup

import React, {Component} from 'react';
import FontStyle from 'react-font-style';

class Basic extends Component {
  handleChange(style) {
    // do something when style change
  }

  render() {
    return (
      <FontStyle onChange={this.handleChange}/>
    )
  }
}

Customized example

You can control display which button, the style when user click the button and add extra toolbar button (seems like plugin).

import React, {Component} from 'react';
import FontStyle from 'react-font-style';
import ButtonGroup from 'react-font-style/lib/ui/ButtonGroup';
import IconButton from 'react-font-style/lib/ui/IconButton';

class Plugin extends React.Component {
  render() {
    return (
      {/* Use react-font-style/lib component to make sure buttons are same style */}
      <ButtonGroup>
        <IconButton iconClassName="icon-extra" {/* define the icon class in your css file */}
                    onMouseDown={() => alert('this is a pluggable button')}/>
      </ButtonGroup>
    )
  }
}

class Customized extends Component {
  handleChange(style) {
    // do something when style changes
  }

  render() {
    return (
      <FontStyle onChange={this.handleChange}
                 defaultStyle={{backgroundColor: '#333', color: '#b6a4a4'}}
                 customizedPlugin={<Plugin/>}
                 customConfig={{
                    display: [
                      'INLINE_STYLE_BUTTONS',
                      'FONT_SIZE_DROPDOWN'
                    ],
                    FONT_SIZE_DROPDOWN: [
                      {
                        type: 'font-1',
                        label: 'font-1',    
                        style: {
                          fontSize: '1em'
                        }
                      },
                      {
                        type: 'font-3',
                        label: 'font-3',    
                        style: {
                          fontSize: '3em'
                        }
                      }
                    ]
                 }}/>
    )
  }
}

Props

Custom config

The default custom config is here.

By changing this config, you can decide which button you want to display. But remember, you CANNOT add other display button to this list. If you want to add another toolbar button which is not supported by this component, you should use customizedPlugin to add it.

The mechanism of dealing with your custom config and default config is through Object.extend(). It will do the shallow merge of custom config and default config.

Thus, for example, if you just want to display INLINE_STYLE_BUTTONS. Here is what you pass:

<FontStyle customConfig={{display: ['INLINE_STYLE_BUTTONS']}}/>

If you want to display all of the buttons, but you want to change the font size style. You want to use em as the unit.

<FontStyle customConfig={{
  FONT_SIZE_DROPDOWN: [
    {
      type: 'font-1',
      label: 'font-1',    
      style: {
        fontSize: '1em'
      }
    },
    {
      type: 'font-3',
      label: 'font-3',    
      style: {
        fontSize: '3em'
      }
    }
  ]
}}/>

So that's it. It's fully customizable.

References

This lib is referenced a lot from react-rte.

For my personal use case, I don't need a full editor. The only thing I want to know is the style. That's why I created this component.

Todo

  • [] write more test
  • [] extract the css from the component to remove webpack dependency

License

MIT @ctxhou