1.1.0 • Published 5 years ago

react-unity-rich-text v1.1.0

Weekly downloads
13
License
MIT
Repository
github
Last release
5 years ago

react-unity-rich-text

React component to parse and stylize unity rich text

NPM JavaScript Style Guide

Demo

This component can be used to render Unity's Rich Text in the webpage by creating span tags with the appropriate styling.

Install

npm install --save react-unity-rich-text

Usage

Check out the demo

import React, { Component } from 'react'

import UnityRichTextComponent from 'react-unity-rich-text'

class Example extends Component {
  render () {
    return (
      <UnityRichTextComponent>
        {"<size=30>Some unity <color=#ff0000ff>RICH</color> text</size>"}
      <UnityRichTextComponent>
    )
  }
}

Unity Rich Text

(adapted from the official documentation)

Supported tags

The following list describes all the styling tags supported by Unity.

TagDescriptionExample
bRenders the text in boldface.We are <b>not</b> amused.
iRenders the text in italics.We are <i>usually</i> not amused.
sizeSets the size of the text according to the parameter value, given in pixels.We are <size=50>largely</size> unaffected.
colorSets the color of the text according to the parameter value. The color can be specified in the traditional HTML format. #rrggbbaa or by using the default colors seen in the documentation<color=#00ffffff>…</color>

Props

The Unity Rich Text Component can receive functions as props to handle the styling of the span for each kind of supported tag. All of these must be functions that return a react style.

PropertyParametersDefault return
onBold{fontWeight: 'bold'}
onItalic{fontStyle: 'italic'}
onSizesize{fontSize: \`${size}px\`}
onColorcolor{color: color}

License

MIT © emargollo

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago