All Projects → fram-x → react-native-styled-text

fram-x / react-native-styled-text

Licence: MIT license
Styled Text for React Native

Programming Languages

javascript
184084 projects - #8 most used programming language
objective c
16641 projects - #2 most used programming language
Starlark
911 projects
java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to react-native-styled-text

log-utils
Basic logging utils: colors, symbols and timestamp.
Stars: ✭ 24 (-57.89%)
Mutual labels:  color, style
ColorPick.js
A simple and minimal jQuery color picker plugin for the modern web.
Stars: ✭ 48 (-15.79%)
Mutual labels:  color, style
cfmt
Small library for simple and convenient formatted stylized output to the console.
Stars: ✭ 46 (-19.3%)
Mutual labels:  color, format
Linearicons
Linearicons is the highest quality set of line icons, matching with minimalist UI designs in iOS.
Stars: ✭ 64 (+12.28%)
Mutual labels:  fonts, style
Tiza
Console styling for browsers
Stars: ✭ 74 (+29.82%)
Mutual labels:  color, style
React Native Text Size
Measure text accurately before laying it out and get font information from your App.
Stars: ✭ 238 (+317.54%)
Mutual labels:  fonts, text
texthighlighter
a no dependency typescript npm package for highlighting user selected text
Stars: ✭ 17 (-70.18%)
Mutual labels:  color, text
AutoFormatInputWatcher
This repository contains input watcher for auto formatting digits in edit text
Stars: ✭ 15 (-73.68%)
Mutual labels:  text, format
Nord Highlightjs
An arctic, north-bluish clean and elegant highlight.js theme.
Stars: ✭ 49 (-14.04%)
Mutual labels:  color, style
Leetheme
优雅的主题管理库- 一行代码完成多样式切换
Stars: ✭ 762 (+1236.84%)
Mutual labels:  color, style
Art
🎨 ASCII art library for Python
Stars: ✭ 1,026 (+1700%)
Mutual labels:  fonts, text
text-style-editor
Text style editor widget for flutter
Stars: ✭ 25 (-56.14%)
Mutual labels:  fonts, text
prettype
An easy to use text stylizer for your desktop!
Stars: ✭ 14 (-75.44%)
Mutual labels:  fonts, style
leeks.js
Simple ANSI styling for your terminal
Stars: ✭ 12 (-78.95%)
Mutual labels:  color, style
baseline
New method for creating leading on the web
Stars: ✭ 31 (-45.61%)
Mutual labels:  fonts, text
terminal-style
🎨 Return your terminal message in style! Change the text style, text color and text background color from the terminal, console or shell interface with ANSI color codes. Support for Laravel and Composer.
Stars: ✭ 16 (-71.93%)
Mutual labels:  color, style
table
Produces a string that represents slice data in a text table, inspired by gajus/table.
Stars: ✭ 130 (+128.07%)
Mutual labels:  text, format
Prestyler
Elegant text formatting tool in Swift 🔥
Stars: ✭ 36 (-36.84%)
Mutual labels:  text, style
Theme Ui
Build consistent, themeable React apps based on constraint-based design principles
Stars: ✭ 4,150 (+7180.7%)
Mutual labels:  color, style
Neural Tools
Tools made for usage alongside artistic style transfer projects
Stars: ✭ 150 (+163.16%)
Mutual labels:  color, style

Styled Text for React Native

Introduction

The purpose of this library is to support easy rendering of mixed text styles.

The library implements a StyledText component taking an HTML-like string in the children property and an optional text styles property.

Try it out

Online demo on expo.io

Installation

To install the library into your project, run yarn or npm:

yarn add react-native-styled-text

or

npm i react-native-styled-text

Examples

Using default styles

For simple styling StyledText supports some predefined styles:

  • b: bold
  • i: italic
  • u: underline

Example:

import { StyleSheet } from 'react-native';
import StyledText from 'react-native-styled-text';

...
  <StyledText
    style={styles.header}
  >
    {"Ha<i>pp</i>y <b>Styling</b>!"}
  </StyledText>
...

const styles = StyleSheet.create({
  header: {
    fontSize: 24,
    color: 'orange',
    textAlign: 'center',
    padding: 30,
  },
});

Renders as

Using custom styles

For richer styling, you set the textStyles property of StyledText to an object (e.g. StyleSheet) containing your custom text styles and apply these styles in the text property.

Example:

import { StyleSheet } from 'react-native';
import StyledText from 'react-native-styled-text';

...
  <StyledText
    style={styles.welcome}
    textStyles={textStyles}
  >
    {"Welcome to <b><u>React Native</u> <demo><i>Styled</i> Text</demo></b> demo!"}
  </StyledText>
...

const styles = StyleSheet.create({
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    padding: 30,
  },
});

const textStyles = StyleSheet.create({
  demo: {
    textShadowOffset: { width: 2, height: 2 },
    textShadowColor: '#555555',
    textShadowRadius: 6,
    fontSize: 24,
    color: '#22AA44',
  },
});

Renders as

How it works

Internally, the render function of StyledText parses the value of the children property, which must be a string, and returns a nested structure of React Native Text components.

From the example above:

<StyledText style={styles.header}>{'Ha<i>pp</i>y <b>Styling</b>!'}</StyledText>

would be transformed to:

<Text style={styles.header}>
  Ha<Text style={defaultStyles.i}>pp</Text>y{' '}
  <Text style={defaultStyles.b}>Styling</Text>!
</Text>

So StyledText just provides a more compact, readable and flexible coding of nested Text components.

API

In addition to the React Native Text properties, StyledText supports the following properties, with a restriction on the children proerty:

Name Description
children String with style tags for mixed styling of the text. Each style tag must match one of the styles provided in textStyles or one of the default styles, see below. (Optional)
textStyles Object (e.g. StyleSheet) containing definition of the styles used in the provided text. (Optional)

The following default styles are defined:

Name Description
b bold
i italic
u underline

Contributors

Bjørn Egil Hansen (@bjornegil)

Sponsors

Fram X - a cross platform app company from Norway.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].