All Projects → Bryant-Anjos → react-native-highlighted-text

Bryant-Anjos / react-native-highlighted-text

Licence: other
A React Native component to individually style texts inside a text

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
shell
77523 projects

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

tsstyled
A small, fast, and simple CSS-in-JS solution for React.
Stars: ✭ 52 (+188.89%)
Mutual labels:  style
mtpThemeManager
An iOS theme manager with all the features. Everything you expect from a theme manager, contains apply theme to whole app, multiple themes, night mode, styles , ...
Stars: ✭ 13 (-27.78%)
Mutual labels:  style
OutlineTextView
Android TextView with outline
Stars: ✭ 59 (+227.78%)
Mutual labels:  textview
Socially
Socially is a textView which is able to create separate clickable views according to your requirements.
Stars: ✭ 28 (+55.56%)
Mutual labels:  textview
CheckableTextView
A simple and flexible Checked TextView or Checkable TextView
Stars: ✭ 108 (+500%)
Mutual labels:  textview
vue-component-style
A Vue mixin to add style section to components.
Stars: ✭ 16 (-11.11%)
Mutual labels:  style
TextViewPlus
an android library for setting custom font in xml layout
Stars: ✭ 27 (+50%)
Mutual labels:  textview
glitz
Lightweight CSS-in-JS library with high performance written in TypeScript
Stars: ✭ 42 (+133.33%)
Mutual labels:  style
CompositeToggle
Composite toggle system for unity
Stars: ✭ 38 (+111.11%)
Mutual labels:  style
QSvgStyle
QSvgStyle is a themeable SVG style for Qt5 applications
Stars: ✭ 66 (+266.67%)
Mutual labels:  style
markdown.css
📝 The simple CSS to replicate the GitHub Markdown style (Sukka Ver.)
Stars: ✭ 13 (-27.78%)
Mutual labels:  style
STTextView
📝 STTextView is a light-weight library that adds a placeholder to the UITextView.
Stars: ✭ 36 (+100%)
Mutual labels:  textview
embedded-text
Multiline TextBox for the embedded-graphics Rust crate
Stars: ✭ 35 (+94.44%)
Mutual labels:  textview
postcss-gtk
Processes GTK+ CSS into browser CSS
Stars: ✭ 23 (+27.78%)
Mutual labels:  style
KodeEditor
A simple code editor with syntax highlighting and pinch to zoom
Stars: ✭ 60 (+233.33%)
Mutual labels:  textview
PlantUML-colors
This script is to show all named color suggested by PlantUML
Stars: ✭ 52 (+188.89%)
Mutual labels:  style
Android-SGTextView
同时带字体描边 渐变 阴影的TextView - both have stroker, gradient and shadow TextView
Stars: ✭ 18 (+0%)
Mutual labels:  textview
Prestyler
Elegant text formatting tool in Swift 🔥
Stars: ✭ 36 (+100%)
Mutual labels:  style
EasyMoney-Widgets
The widgets (EditText and TextView) for support of money requirements like currency, number formatting, comma formatting etc.
Stars: ✭ 91 (+405.56%)
Mutual labels:  textview
css-render
Generating CSS using JS with considerable flexibility and extensibility, at both server side and client side.
Stars: ✭ 137 (+661.11%)
Mutual labels:  style

React Native Highlighted Text

A React Native component to individually style texts inside a text

Getting Started

Yarn

yarn add react-native-highlighted-text

npm

npm install react-native-highlighted-text

Usage

With normal styles

Place the text you want to style in square brackets as shown in the example below.
[[Write your text here]]
Place all the styles you want into an array in the component's highlightedTextStyles attribute.
The bracketed text will be styled in the same order as the array styles.

import { HighlightedText } from  'react-native-highlighted-text'

<HighlightedText
  style={styles.text}
  highlightedTextStyles={[
    {
      fontSize:  16,
      fontWeight:  'bold',
      fontStyle:  'italic',
    },
    {
      fontSize:  22,
      color:  'red',
      textTransform:  'uppercase',
    },
  ]}
>
  Open up [[App.tsx]] to start working on your [[app!]]
</HighlightedText>

With named styles

Place all the styles you want inside an object in the component's highlightedTextStyles attribute.
In brackets, place the keys of the styling object you want, separated by a comma. Then add a = and then the text you want to style, as shown in the following example:
[[bold,red=Write your text here]]

import { HighlightedText } from  'react-native-highlighted-text'

<HighlightedText
  style={styles.text}
  highlightedTextStyles={{
    bold: {
      fontWeight:  'bold',
    },
    red: {
      color:  'red',
    },
    lg: {
      fontSize:  22,
    },
  }}
>
  Lorem, ipsum [[bold=dolor]] sit amet consectetur adipisicing
  [[red=elit]]. Quaerat ducimus dicta cum [[lg=expedita]] consectetur quod
  tempore voluptatum autem aspernatur. [[bold,red,lg=Aliquid]].
</HighlightedText>

With numbered styles

Place all the styles you want inside an array in the component's highlightedTextStyles attribute.
In brackets, place the position (starting at 1) of the styling object you want, separated by a comma. Then add a = and then the text you want to style, as shown in the following example:
[[1,3=Write your text here]]

import { HighlightedText } from  'react-native-highlighted-text'

<HighlightedText
  style={styles.text}
  highlightedTextStyles={[
    {
      fontWeight: 'bold',
    },
    {
      color: 'red',
    },
    {
      fontSize: 22,
    },
  ]}
>
  Lorem, ipsum [[1=dolor]] sit amet consectetur adipisicing [[2=elit]].
  Quaerat ducimus dicta cum [[3=expedita]] consectetur quod tempore
  voluptatum autem aspernatur. [[1,2,3=Aliquid]].
</HighlightedText>

Functions

It's possible to add functions to highlighted texts in a prop called onPressHighlighted. They receive the clicked text as argument, it is useful to do things such as a link to redirect to a external site.

But is only possible to add only one function for each single highlighted text, if a text get various styles like in named styles, it will be get only the first function that match with the key used.

Functions in this props will follow the same highlightedTextStyles' structure. If the highlightedTextStyles is an array, the onPressHighlighted will be an array too, if the highlightedTextStyles is an object the onPressHighlighted will be an object, and so on.

onPressHighlighted examples:

With normal styles

import { HighlightedText } from  'react-native-highlighted-text'

<HighlightedText
  style={styles.text}
  highlightedTextStyles={[ ... ]}
  onPressHighlighted={[
    (text) => Alert.alert(text),
    (text) => console.log('Hello ' + text),
  ]}
>
  Open up [[App.tsx]] to start working on your [[app!]]
</HighlightedText>

With named styles

import { HighlightedText } from  'react-native-highlighted-text'

<HighlightedText
  style={styles.text}
  highlightedTextStyles={{ ... }}
  onPressHighlighted={{
    red: (text) => Alert.alert(text),
    bold: (text) => console.log('Hello ' + text),
  }}
>
  Open up [[red=App.tsx]] to start working on your [[bold=app!]]
</HighlightedText>

With numbered styles

import { HighlightedText } from  'react-native-highlighted-text'

<HighlightedText
  style={styles.text}
  highlightedTextStyles={[ ... ]}
  onPressHighlighted={[
    (text) => Alert.alert(text),
    (text) => console.log('Hello ' + text),
  ]}
>
  Open up [[1=App.tsx]] to start working on your [[2=app!]]
</HighlightedText>

Change the highlight character

By default, the character to highlight texts is the square brackets [], having to put them around the text like as [[highlighted text here]].

It was chosen because the curly brackets {} are to execute javascript inside react elements, then the square brackets avoids this behavior.

If you want to change the default character there are a prop with some options availables to do this. They are the characters prop and its values are square-brackets ([]), curly-brackets ({}), tags (<>) and parenthesis (()).

Examples

import { HighlightedText } from  'react-native-highlighted-text'

<HighlightedText
  style={styles.text}
  highlightedTextStyles={[ ... ]}
  characters="parenthesis"
>
  Open up ((App.tsx)) to start working on your ((app!))
</HighlightedText>
import { HighlightedText } from  'react-native-highlighted-text'

<HighlightedText
  style={styles.text}
  highlightedTextStyles={[ ... ]}
  characters="square-brackets"
>
  {`Open up {{App.tsx}} to start working on your {{app!}}`}
</HighlightedText>
import { HighlightedText } from  'react-native-highlighted-text'

<HighlightedText
  style={styles.text}
  highlightedTextStyles={[ ... ]}
  characters="tags"
>
  {`Open up <<App.tsx>> to start working on your <<app!>>`}
</HighlightedText>

Properties

Prop Description Default Required
highlightedTextStyles Styles of the highlighted texts, TextStyle's array or TextStyle's object. None Yes
onPressHighlighted Functions to run in the highlighted text, receives the text clicked as argument, Array<(text: string) => void> or Record<string, (text: string) => void>. None No
characters Character used to highlight the words. square-brackets ([]), curly-brackets ({}), tags (<>) or parenthesis (()) square-brackets No
...Text Props React Native Text Props None No

Examples

You can see examples on the following links:

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].